Skip to content

Commit 50b43c5

Browse files
author
jantje
committed
Unit testing now based on actual available boards
1 parent d43690d commit 50b43c5

File tree

5 files changed

+105
-464
lines changed

5 files changed

+105
-464
lines changed

io.sloeber.core/src/io/sloeber/core/tools/TxtFile.java

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,9 @@ public String[] getMenuItemNamesFromMenuID(String menuID, String boardID) {
128128
return new String[0];
129129
}
130130

131-
String SearchKey = menuID + DOT + boardID + DOT;
132-
SearchKey = SearchKey.toUpperCase();
133-
for (Entry<String, String> e2 : menuInfo.entrySet()) {
134-
int numsubkeys = e2.getKey().split("\\.").length; //$NON-NLS-1$
135-
boolean startOk = e2.getKey().toUpperCase().startsWith(SearchKey);
136-
if ((numsubkeys == 3) && (startOk))
137-
ret.add(e2.getValue());
138-
}
139-
// from Arduino IDE 1.5.4 menu is subset of the board. The previous code
140-
// will not return a result
141131
Map<String, String> boardInfo = this.fileContent.get(boardID);
142132
if (boardInfo != null) {
143-
SearchKey = MENU + DOT + menuID + DOT;
133+
String SearchKey = MENU + DOT + menuID + DOT;
144134
SearchKey = SearchKey.toUpperCase();
145135
for (Entry<String, String> e2 : boardInfo.entrySet()) {
146136
int numsubkeys = e2.getKey().split("\\.").length; //$NON-NLS-1$
@@ -152,6 +142,38 @@ public String[] getMenuItemNamesFromMenuID(String menuID, String boardID) {
152142
return ret.toArray(new String[ret.size()]);
153143
}
154144

145+
/**
146+
* Get all the acceptable values for a option for a board The outcome of
147+
* this method can be used to fill a
148+
*
149+
* @param menu
150+
* the id of a menu not the name
151+
* @param boardID
152+
* the id of a board not the name
153+
* @return The IDs that are the possible selections
154+
*/
155+
public String[] getMenuItemIDsFromMenuID(String menuID, String boardID) {
156+
HashSet<String> ret = new HashSet<>();
157+
Map<String, String> menuInfo = this.fileContent.get(MENU);
158+
if (menuInfo == null) {
159+
return new String[0];
160+
}
161+
162+
Map<String, String> boardInfo = this.fileContent.get(boardID);
163+
if (boardInfo != null) {
164+
String SearchKey = MENU + DOT + menuID + DOT;
165+
SearchKey = SearchKey.toUpperCase();
166+
for (Entry<String, String> e2 : boardInfo.entrySet()) {
167+
String[] subKeys = e2.getKey().split("\\.");//$NON-NLS-1$
168+
int numsubkeys = subKeys.length;
169+
boolean startOk = e2.getKey().toUpperCase().startsWith(SearchKey);
170+
if ((numsubkeys == 3) && (startOk))
171+
ret.add(subKeys[2]);
172+
}
173+
}
174+
return ret.toArray(new String[ret.size()]);
175+
}
176+
155177
/**
156178
* this is public String[] getAllNames(String[] toaddNames) with a empty
157179
* toaddnames
@@ -177,7 +199,7 @@ public String[] getAllNames() {
177199
*
178200
*/
179201
public String[] getAllNames(String[] toaddNames) {
180-
if (this.mLastLoadedTxtFile.equals(Const.EMPTY_STRING)) {
202+
if (this.mLastLoadedTxtFile.equals(new String())) {
181203
return toaddNames;
182204
}
183205
HashSet<String> allNames = new HashSet<>();
@@ -347,9 +369,11 @@ public File getTxtFile() {
347369

348370
public String getMenuNameFromID(String menuID) {
349371
Map<String, String> menuSectionMap = getSection(MENU);
350-
for (Entry<String, String> curOption : menuSectionMap.entrySet()) {
351-
if (curOption.getKey().equalsIgnoreCase(menuID)) {
352-
return curOption.getValue();
372+
if (menuSectionMap != null) {
373+
for (Entry<String, String> curOption : menuSectionMap.entrySet()) {
374+
if (curOption.getKey().equalsIgnoreCase(menuID)) {
375+
return curOption.getValue();
376+
}
353377
}
354378
}
355379
return MENU + " ID " + menuID + Messages.Boards_not_found; //$NON-NLS-1$
@@ -378,7 +402,7 @@ public String getMenuItemNameFromMenuItemID(String boardID, String menuID, Strin
378402
public String getNameFromID(String myBoardID) {
379403
Map<String, String> boardSection = getSection(myBoardID);
380404
if (boardSection == null) {
381-
return Const.EMPTY_STRING;
405+
return new String();
382406
}
383407
return boardSection.get("name"); //$NON-NLS-1$
384408
}

0 commit comments

Comments
 (0)