@@ -554,3 +554,81 @@ func TestBoardMatching(t *testing.T) {
554
554
"lemons" : "XXX" ,
555
555
})))
556
556
}
557
+
558
+ func TestBoardConfigMatching (t * testing.T ) {
559
+ brd01 := & Board {
560
+ Properties : properties .NewFromHashmap (map [string ]string {
561
+ "upload_port.pid" : "0x0010" ,
562
+ "upload_port.vid" : "0x2341" ,
563
+ "menu.cpu.atmega1280" : "ATmega1280" ,
564
+ "menu.cpu.atmega1280.upload_port.cpu" : "atmega1280" ,
565
+ "menu.cpu.atmega1280.build_cpu" : "atmega1280" ,
566
+ "menu.cpu.atmega2560" : "ATmega2560" ,
567
+ "menu.cpu.atmega2560.upload_port.cpu" : "atmega2560" ,
568
+ "menu.cpu.atmega2560.build_cpu" : "atmega2560" ,
569
+ "menu.mem.1k" : "1KB" ,
570
+ "menu.mem.1k.upload_port.mem" : "1" ,
571
+ "menu.mem.1k.build_mem" : "1024" ,
572
+ "menu.mem.2k" : "2KB" ,
573
+ "menu.mem.2k.upload_port.1.mem" : "2" ,
574
+ "menu.mem.2k.upload_port.2.ab" : "ef" ,
575
+ "menu.mem.2k.upload_port.2.cd" : "gh" ,
576
+ "menu.mem.2k.build_mem" : "2048" ,
577
+ }),
578
+ PlatformRelease : & PlatformRelease {
579
+ Platform : & Platform {
580
+ Architecture : "avr" ,
581
+ Package : & Package {
582
+ Name : "arduino" ,
583
+ },
584
+ },
585
+ Menus : properties .NewFromHashmap (map [string ]string {
586
+ "cpu" : "Processor" ,
587
+ "mem" : "Memory" ,
588
+ }),
589
+ },
590
+ }
591
+
592
+ type m map [string ]string
593
+ type Test struct {
594
+ testName string
595
+ identificationProps map [string ]string
596
+ configOutput map [string ]string
597
+ }
598
+
599
+ tests := []Test {
600
+ {"Simple" ,
601
+ m {"pid" : "0x0010" , "vid" : "0x2341" },
602
+ m {}},
603
+ {"WithConfig1" ,
604
+ m {"pid" : "0x0010" , "vid" : "0x2341" , "cpu" : "atmega2560" },
605
+ m {"cpu" : "atmega2560" }},
606
+ {"WithConfig2" ,
607
+ m {"pid" : "0x0010" , "vid" : "0x2341" , "cpu" : "atmega1280" },
608
+ m {"cpu" : "atmega1280" }},
609
+ {"WithDoubleConfig1" ,
610
+ m {"pid" : "0x0010" , "vid" : "0x2341" , "cpu" : "atmega1280" , "mem" : "1" },
611
+ m {"cpu" : "atmega1280" , "mem" : "1k" }},
612
+ {"WithDoubleConfig2" ,
613
+ m {"pid" : "0x0010" , "vid" : "0x2341" , "cpu" : "atmega1280" , "ab" : "ef" },
614
+ m {"cpu" : "atmega1280" }},
615
+ {"WithDoubleConfig3" ,
616
+ m {"pid" : "0x0010" , "vid" : "0x2341" , "cpu" : "atmega1280" , "ab" : "ef" , "cd" : "gh" },
617
+ m {"cpu" : "atmega1280" , "mem" : "2k" }},
618
+ {"WithIncompleteIdentificationProps" ,
619
+ m {"cpu" : "atmega1280" },
620
+ nil },
621
+ }
622
+ for _ , test := range tests {
623
+ t .Run (test .testName , func (t * testing.T ) {
624
+ identificationProps := properties .NewFromHashmap (test .identificationProps )
625
+ if test .configOutput != nil {
626
+ require .True (t , brd01 .IsBoardMatchingIDProperties (identificationProps ))
627
+ config := brd01 .IdentifyBoardConfiguration (identificationProps )
628
+ require .EqualValues (t , test .configOutput , config .AsMap ())
629
+ } else {
630
+ require .False (t , brd01 .IsBoardMatchingIDProperties (identificationProps ))
631
+ }
632
+ })
633
+ }
634
+ }
0 commit comments