mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Introducing "defaultTarget" board is the one selected in preferences is not available. Closes #1731
This commit is contained in:
parent
b530742603
commit
4e262a566d
@ -44,6 +44,7 @@ public class TargetPlatform {
|
|||||||
* Contains preferences for every defined board
|
* Contains preferences for every defined board
|
||||||
*/
|
*/
|
||||||
private Map<String, TargetBoard> boards = new LinkedHashMap<String, TargetBoard>();
|
private Map<String, TargetBoard> boards = new LinkedHashMap<String, TargetBoard>();
|
||||||
|
private TargetBoard defaultBoard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains preferences for every defined programmer
|
* Contains preferences for every defined programmer
|
||||||
@ -86,11 +87,16 @@ public class TargetPlatform {
|
|||||||
boardsPreferences.remove("menu");
|
boardsPreferences.remove("menu");
|
||||||
|
|
||||||
// Create boards
|
// Create boards
|
||||||
for (String id : boardsPreferences.keySet()) {
|
Set<String> boardIDs = boardsPreferences.keySet();
|
||||||
|
for (String id : boardIDs) {
|
||||||
PreferencesMap preferences = boardsPreferences.get(id);
|
PreferencesMap preferences = boardsPreferences.get(id);
|
||||||
TargetBoard board = new TargetBoard(id, preferences, this);
|
TargetBoard board = new TargetBoard(id, preferences, this);
|
||||||
boards.put(id, board);
|
boards.put(id, board);
|
||||||
}
|
}
|
||||||
|
if (!boardIDs.isEmpty()) {
|
||||||
|
PreferencesMap preferences = boardsPreferences.get(boardIDs.iterator().next());
|
||||||
|
defaultBoard = new TargetBoard(id, preferences, this);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TargetPlatformException(format(_("Error loading {0}"),
|
throw new TargetPlatformException(format(_("Error loading {0}"),
|
||||||
boardsFile.getAbsolutePath()), e);
|
boardsFile.getAbsolutePath()), e);
|
||||||
@ -156,7 +162,10 @@ public class TargetPlatform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TargetBoard getBoard(String boardId) {
|
public TargetBoard getBoard(String boardId) {
|
||||||
return boards.get(boardId);
|
if (boards.containsKey(boardId)) {
|
||||||
|
return boards.get(boardId);
|
||||||
|
}
|
||||||
|
return defaultBoard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TargetPackage getContainerPackage() {
|
public TargetPackage getContainerPackage() {
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package processing.app;
|
package processing.app;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.Before;
|
||||||
|
|
||||||
public abstract class AbstractWithPreferencesTest {
|
public abstract class AbstractWithPreferencesTest {
|
||||||
|
|
||||||
@BeforeClass
|
@Before
|
||||||
public static void init() throws Exception {
|
public void init() throws Exception {
|
||||||
Base.initPlatform();
|
Base.initPlatform();
|
||||||
Preferences.init(null);
|
Preferences.init(null);
|
||||||
|
Theme.init();
|
||||||
|
|
||||||
|
Base.untitledFolder = Base.createTempFolder("untitled");
|
||||||
|
Base.untitledFolder.deleteOnExit();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
35
app/test/processing/app/DefaultTargetTest.java
Normal file
35
app/test/processing/app/DefaultTargetTest.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package processing.app;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import processing.app.debug.TargetBoard;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
public class DefaultTargetTest extends AbstractWithPreferencesTest {
|
||||||
|
|
||||||
|
private String oldBoardID;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void saveBoardFromPreferences() throws Exception {
|
||||||
|
oldBoardID = Preferences.get("board");
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void restoreBoardIntoPreferences() throws Exception {
|
||||||
|
Preferences.set("board", oldBoardID);
|
||||||
|
Preferences.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultTarget() throws Exception {
|
||||||
|
Preferences.set("board", "unreal_board");
|
||||||
|
|
||||||
|
// should not raise an exception
|
||||||
|
new Base(new String[0]);
|
||||||
|
|
||||||
|
TargetBoard targetBoard = Base.getTargetBoard();
|
||||||
|
assertNotEquals("unreal_board", targetBoard.getId());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user