@@ -339,3 +339,153 @@ func TestBoardOptions(t *testing.T) {
339
339
// require.NoError(t, err, "marshaling result")
340
340
// fmt.Print(string(data))
341
341
}
342
+
343
+ func TestBoardMatching (t * testing.T ) {
344
+ brd01 := & Board {
345
+ Properties : properties .NewFromHashmap (map [string ]string {
346
+ "upload_port.pid" : "0x0010" ,
347
+ "upload_port.vid" : "0x2341" ,
348
+ }),
349
+ }
350
+ require .True (t , brd01 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
351
+ "pid" : "0x0010" ,
352
+ "vid" : "0x2341" ,
353
+ })))
354
+ require .False (t , brd01 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
355
+ "pid" : "xxx" ,
356
+ "vid" : "0x2341" ,
357
+ })))
358
+ require .False (t , brd01 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
359
+ "pid" : "0x0010" ,
360
+ })))
361
+ // Extra port properties are OK
362
+ require .True (t , brd01 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
363
+ "pid" : "0x0010" ,
364
+ "vid" : "0x2341" ,
365
+ "serial" : "942947289347893247" ,
366
+ })))
367
+
368
+ // Indexed identifications
369
+ brd02 := & Board {
370
+ Properties : properties .NewFromHashmap (map [string ]string {
371
+ "upload_port.0.pid" : "0x0010" ,
372
+ "upload_port.0.vid" : "0x2341" ,
373
+ "upload_port.1.pid" : "0x0042" ,
374
+ "upload_port.1.vid" : "0x2341" ,
375
+ "upload_port.2.pid" : "0x0010" ,
376
+ "upload_port.2.vid" : "0x2A03" ,
377
+ "upload_port.3.pid" : "0x0042" ,
378
+ "upload_port.3.vid" : "0x2A03" ,
379
+ "upload_port.4.pid" : "0x0210" ,
380
+ "upload_port.4.vid" : "0x2341" ,
381
+ "upload_port.5.pid" : "0x0242" ,
382
+ "upload_port.5.vid" : "0x2341" ,
383
+ }),
384
+ }
385
+ require .True (t , brd02 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
386
+ "pid" : "0x0242" ,
387
+ "vid" : "0x2341" ,
388
+ })))
389
+ require .True (t , brd02 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
390
+ "pid" : "0x0242" ,
391
+ "vid" : "0x2341" ,
392
+ "serial" : "897439287289347" ,
393
+ })))
394
+
395
+ // Indexed starting from 1
396
+ brd03 := & Board {
397
+ Properties : properties .NewFromHashmap (map [string ]string {
398
+ "upload_port.1.pid" : "0x0042" ,
399
+ "upload_port.1.vid" : "0x2341" ,
400
+ "upload_port.2.pid" : "0x0010" ,
401
+ "upload_port.2.vid" : "0x2A03" ,
402
+ "upload_port.3.pid" : "0x0042" ,
403
+ "upload_port.3.vid" : "0x2A03" ,
404
+ "upload_port.4.pid" : "0x0210" ,
405
+ "upload_port.4.vid" : "0x2341" ,
406
+ "upload_port.5.pid" : "0x0242" ,
407
+ "upload_port.5.vid" : "0x2341" ,
408
+ }),
409
+ }
410
+ require .True (t , brd03 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
411
+ "pid" : "0x0242" ,
412
+ "vid" : "0x2341" ,
413
+ })))
414
+ require .True (t , brd03 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
415
+ "pid" : "0x0242" ,
416
+ "vid" : "0x2341" ,
417
+ "serial" : "897439287289347" ,
418
+ })))
419
+
420
+ // Mixed indentificiations (not-permitted)
421
+ brd04 := & Board {
422
+ Properties : properties .NewFromHashmap (map [string ]string {
423
+ "upload_port.pid" : "0x2222" ,
424
+ "upload_port.vid" : "0x3333" ,
425
+ "upload_port.0.pid" : "0x0010" ,
426
+ "upload_port.0.vid" : "0x2341" ,
427
+ "upload_port.1.pid" : "0x0042" ,
428
+ "upload_port.1.vid" : "0x2341" ,
429
+ "upload_port.2.pid" : "0x0010" ,
430
+ "upload_port.2.vid" : "0x2A03" ,
431
+ "upload_port.3.pid" : "0x0042" ,
432
+ "upload_port.3.vid" : "0x2A03" ,
433
+ }),
434
+ }
435
+ require .True (t , brd04 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
436
+ "pid" : "0x0042" ,
437
+ "vid" : "0x2341" ,
438
+ })))
439
+ require .True (t , brd04 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
440
+ "pid" : "0x0042" ,
441
+ "vid" : "0x2341" ,
442
+ "serial" : "897439287289347" ,
443
+ })))
444
+ require .False (t , brd04 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
445
+ "pid" : "0x2222" ,
446
+ "vid" : "0x3333" ,
447
+ })))
448
+ require .False (t , brd04 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
449
+ "pid" : "0x2222" ,
450
+ "vid" : "0x3333" ,
451
+ "serial" : "897439287289347" ,
452
+ })))
453
+
454
+ // Mixed protocols
455
+ brd05 := & Board {
456
+ Properties : properties .NewFromHashmap (map [string ]string {
457
+ "upload_port.0.pid" : "0x0010" ,
458
+ "upload_port.0.vid" : "0x2341" ,
459
+ "upload_port.1.pears" : "2" ,
460
+ "upload_port.1.apples" : "3" ,
461
+ "upload_port.1.lemons" : "X" ,
462
+ "upload_port.2.pears" : "100" ,
463
+ "upload_port.3.mac" : "0x0010" ,
464
+ "upload_port.3.vid" : "0x2341" ,
465
+ }),
466
+ }
467
+ require .True (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
468
+ "pid" : "0x0010" ,
469
+ "vid" : "0x2341" ,
470
+ })))
471
+ require .True (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
472
+ "pears" : "2" ,
473
+ "apples" : "3" ,
474
+ "lemons" : "X" ,
475
+ })))
476
+ require .True (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
477
+ "pears" : "100" ,
478
+ })))
479
+ require .True (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
480
+ "mac" : "0x0010" ,
481
+ "vid" : "0x2341" ,
482
+ })))
483
+ require .False (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
484
+ "pears" : "2" ,
485
+ })))
486
+ require .True (t , brd05 .IsBoardMatchingIDProperties (properties .NewFromHashmap (map [string ]string {
487
+ "pears" : "100" ,
488
+ "apples" : "300" ,
489
+ "lemons" : "XXX" ,
490
+ })))
491
+ }
0 commit comments