21
21
import org .junit .Test ;
22
22
import org .junit .runner .RunWith ;
23
23
import org .junit .runners .Parameterized ;
24
+ import org .junit .runners .Parameterized .Parameters ;
24
25
25
26
import io .sloeber .core .api .BoardDescriptor ;
26
27
import io .sloeber .core .api .BoardsManager ;
33
34
public class CreateAndCompileExamples {
34
35
private static int mCounter = 0 ;
35
36
private CodeDescriptor myCodeDescriptor ;
37
+ private BoardDescriptor myBoardid ;
36
38
37
- public CreateAndCompileExamples (CodeDescriptor codeDescriptor ) {
39
+ public CreateAndCompileExamples (String name , BoardDescriptor boardid , CodeDescriptor codeDescriptor ) {
40
+ this .myBoardid = boardid ;
38
41
this .myCodeDescriptor = codeDescriptor ;
39
42
40
43
}
41
44
42
45
@ SuppressWarnings ("rawtypes" )
43
- @ Parameterized . Parameters
46
+ @ Parameters ( name = "{index}: {0}" )
44
47
public static Collection examples () {
45
- LinkedList <CodeDescriptor > examples = new LinkedList <>();
48
+ Map <String , String > myOptions = new HashMap <>();
49
+ String [] lines = new String ("" ).split ("\n " ); //$NON-NLS-1$
50
+ for (String curLine : lines ) {
51
+ String [] values = curLine .split ("=" , 2 ); //$NON-NLS-1$
52
+ if (values .length == 2 ) {
53
+ myOptions .put (values [0 ], values [1 ]);
54
+ }
55
+ }
56
+ BoardDescriptor leonardoBoardid = BoardsManager .getBoardID ("package_index.json" , "arduino" ,
57
+ "Arduino AVR Boards" , "leonardo" , myOptions );
58
+ if (leonardoBoardid == null ) {
59
+ fail ("leonardo Board not found" );
60
+ return null ;
61
+ }
62
+ BoardDescriptor unoBoardid = BoardsManager .getBoardID ("package_index.json" , "arduino" , "Arduino AVR Boards" ,
63
+ "uno" , myOptions );
64
+ if (unoBoardid == null ) {
65
+ fail ("uno Board not found" );
66
+ return null ;
67
+ }
68
+
69
+ LinkedList <Object []> examples = new LinkedList <>();
46
70
TreeMap <String , IPath > exampleFolders = BoardsManager .getAllExamples (null );
47
71
for (Map .Entry <String , IPath > curexample : exampleFolders .entrySet ()) {
48
72
ArrayList <Path > paths = new ArrayList <>();
49
73
50
74
paths .add (new Path (curexample .getValue ().toString ()));
51
75
CodeDescriptor codeDescriptor = CodeDescriptor .createExample (false , paths );
76
+ if (isExampleOkForLeonardo (curexample .getKey ())) {
77
+ Object [] theData = new Object [] { "leonardo :" + curexample .getKey (), leonardoBoardid , codeDescriptor };
52
78
53
- examples .add (codeDescriptor );
79
+ examples .add (theData );
80
+ }
81
+ if (isExampleOkForUno (curexample .getKey ())) {
82
+ Object [] theData = new Object [] { "Uno :" + curexample .getKey (), unoBoardid , codeDescriptor };
83
+
84
+ examples .add (theData );
85
+ }
54
86
}
55
87
56
88
return examples ;
57
89
58
90
}
59
91
92
+ private static boolean isExampleOkForUno (String key ) {
93
+ final String [] notOkForUno = { "Esploraexamples-Beginners-EsploraAccelerometer" ,
94
+ "Esploraexamples-Beginners-EsploraBlink" , "Esploraexamples-Beginners-EsploraJoystickMouse" ,
95
+ "Esploraexamples-Beginners-EsploraLedShow" , "Esploraexamples-Beginners-EsploraLedShow2" };
96
+ if (key .startsWith ("Esploraexamples" ))
97
+ return false ;
98
+ if (Arrays .asList (notOkForUno ).contains (key ))
99
+ return false ;
100
+ return true ; // default everything is fine
101
+ }
102
+
103
+ private static boolean isExampleOkForLeonardo (String key ) {
104
+ final String [] notOkForLeonardo = { "Esploraexamples-Beginners-EsploraJoystickMouse" };
105
+ if (Arrays .asList (notOkForLeonardo ).contains (key ))
106
+ return false ;
107
+ return true ; // default everything is fine
108
+ }
109
+
60
110
/*
61
111
* In new new installations (of the Sloeber development environment) the
62
112
* installer job will trigger downloads These mmust have finished before we
@@ -76,24 +126,8 @@ public static void installAdditionalBoards() {
76
126
}
77
127
78
128
@ Test
79
- public void testLeonardo () {
80
-
81
- Map <String , String > myOptions = new HashMap <>();
82
- String [] lines = new String ("" ).split ("\n " ); //$NON-NLS-1$
83
- for (String curLine : lines ) {
84
- String [] values = curLine .split ("=" , 2 ); //$NON-NLS-1$
85
- if (values .length == 2 ) {
86
- myOptions .put (values [0 ], values [1 ]);
87
- }
88
- }
89
-
90
- BoardDescriptor boardid = BoardsManager .getBoardID ("package_index.json" , "arduino" , "Arduino AVR Boards" ,
91
- "leonardo" , myOptions );
92
- if (boardid == null ) {
93
- fail ("Uno Board not found" );
94
- return ;
95
- }
96
- BuildAndVerify (boardid , this .myCodeDescriptor );
129
+ public void testExamples () {
130
+ BuildAndVerify (this .myBoardid , this .myCodeDescriptor );
97
131
98
132
}
99
133
0 commit comments