use of com.thecoderscorner.menu.editorui.generator.arduino.ArduinoGenerator in project tcMenu by davetcc.
the class MbedGeneratorTest method testMbedConversion.
@SuppressWarnings("unchecked")
@Test
public void testMbedConversion() throws IOException {
ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
MenuTree tree = buildTreeFromJson(LARGE_MENU_STRUCTURE);
tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10001).withName("Authenticator").withMenuType(AUTHENTICATION).withEepromAddr(-1).menuItem());
tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10002).withName("IoT Monitor").withMenuType(REMOTE_IOT_MONITOR).withEepromAddr(-1).menuItem());
ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
when(installer.getVersionOfLibrary("core-remote", InstallationType.CURRENT_PLUGIN)).thenReturn(VersionInfo.fromString("2.2.1"));
var flashRemotes = List.of(new FlashRemoteId("name1", "first-uuid"), new FlashRemoteId("name2", "second-uuid"));
var options = new CodeGeneratorOptionsBuilder().withPlatform(MBED_RTOS.getBoardId()).withAppName("tester").withNewId(SERVER_UUID).withEepromDefinition(new BspStm32EepromDefinition(50)).withAuthenticationDefinition(new ReadOnlyAuthenticatorDefinition("1234", flashRemotes)).withExpanderDefinitions(new IoExpanderDefinitionCollection()).withRecursiveNaming(true).withSaveToSrc(true).codeOptions();
ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, MBED_RTOS);
var firstPlugin = pluginConfig.getPlugins().get(0);
firstPlugin.getProperties().stream().filter(p -> p.getName().equals("SWITCH_IODEVICE")).findFirst().ifPresent(p -> p.setLatestValue("io23017"));
assertTrue(generator.startConversion(projectDir, pluginConfig.getPlugins(), tree, List.of(), options));
var sourceDir = projectDir.resolve("src");
var cppGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.cpp")));
var hGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.h")));
var pluginGeneratedH = new String(Files.readAllBytes(sourceDir.resolve("source.h")));
var pluginGeneratedCPP = new String(Files.readAllBytes(sourceDir.resolve("source.cpp")));
var pluginGeneratedTransport = new String(Files.readAllBytes(sourceDir.resolve("MySpecialTransport.h")));
var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.cpp")).readAllBytes());
var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.h")).readAllBytes());
cppGenerated = cppGenerated.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
cppTemplate = cppTemplate.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
// these files should line up. IF they do not because of the change in the ArduinoGenerator,
// then make sure the change is good before adjusting the templates.
assertEqualsIgnoringCRLF(cppTemplate, cppGenerated);
assertEqualsIgnoringCRLF(hTemplate, hGenerated);
assertEqualsIgnoringCRLF("CPP_FILE_CONTENT 10 otherKey", pluginGeneratedCPP);
assertEqualsIgnoringCRLF("H_FILE_CONTENT 10 otherKey", pluginGeneratedH);
assertEqualsIgnoringCRLF("My Transport file", pluginGeneratedTransport);
Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(sourceDir.resolve("project_main.cpp")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
Aggregations