Search in sources :

Example 1 with EepromAuthenticatorDefinition

use of com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition in project tcMenu by davetcc.

the class AuthenticatorDefinition method readFromProject.

static AuthenticatorDefinition readFromProject(String encoding) {
    if (StringHelper.isStringEmptyOrNull(encoding))
        return new NoAuthenticatorDefinition();
    try {
        if (encoding.startsWith("rom:")) {
            var entries = encoding.split(":");
            if (entries.length != 3)
                return new NoAuthenticatorDefinition();
            int offset = Integer.parseInt(entries[1]);
            int numRemotes = Integer.parseInt(entries[2]);
            return new EepromAuthenticatorDefinition(offset, numRemotes);
        } else if (encoding.startsWith("flash:")) {
            var remoteIds = encoding.split(":");
            int current = 2;
            var remoteList = new ArrayList<FlashRemoteId>();
            while ((current + 1) < remoteIds.length) {
                remoteList.add(new FlashRemoteId(remoteIds[current], remoteIds[current + 1]));
                current += 2;
            }
            return new ReadOnlyAuthenticatorDefinition(remoteIds[1], remoteList);
        } else
            return new NoAuthenticatorDefinition();
    } catch (Exception ex) {
        return new NoAuthenticatorDefinition();
    }
}
Also used : ReadOnlyAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition) EepromAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition) NoAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.NoAuthenticatorDefinition)

Example 2 with EepromAuthenticatorDefinition

use of com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition in project tcMenu by davetcc.

the class ArduinoGeneratorTest method runConversionWith.

@SuppressWarnings("unchecked")
private void runConversionWith(EmbeddedPlatform platform, String templateToUse, boolean recursiveName) throws IOException {
    ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
    MenuTree tree = buildSimpleTreeReadOnly();
    ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    var standardOptions = new CodeGeneratorOptionsBuilder().withPlatform(ARDUINO32.getBoardId()).withEepromDefinition(new AVREepromDefinition()).withAuthenticationDefinition(new EepromAuthenticatorDefinition(100, 3)).withExpanderDefinitions(new IoExpanderDefinitionCollection(List.of(new CustomDeviceExpander("123")))).withAppName("app").withNewId(UUID.fromString("4490f2fb-a48b-4c89-b6e5-7f557e5f6faf")).withRecursiveNaming(recursiveName).codeOptions();
    ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, platform);
    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(), standardOptions));
    VariableNameGenerator gen = new VariableNameGenerator(tree, false, Set.of());
    assertEquals("GenState", gen.makeNameToVar(generateItemWithName("Gen &^%State")));
    assertEquals("ChannelÖôóò", gen.makeNameToVar(generateItemWithName("ChannelÖôóò")));
    var cppGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.cpp")));
    var hGenerated = new String(Files.readAllBytes(projectDir.resolve(projectDir.getFileName() + "_menu.h")));
    var pluginGeneratedH = new String(Files.readAllBytes(projectDir.resolve("source.h")));
    var pluginGeneratedCPP = new String(Files.readAllBytes(projectDir.resolve("source.cpp")));
    var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".cpp")).readAllBytes());
    var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream(templateToUse + ".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);
    Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(projectDir.resolve(projectDir.getFileName() + ".ino")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) AVREepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.AVREepromDefinition) EepromAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) CustomDeviceExpander(com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) BiConsumer(java.util.function.BiConsumer)

Aggregations

EepromAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition)2 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)1 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)1 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)1 NoAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.NoAuthenticatorDefinition)1 ReadOnlyAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition)1 AVREepromDefinition (com.thecoderscorner.menu.editorui.generator.parameters.eeprom.AVREepromDefinition)1 CustomDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander)1 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)1 BiConsumer (java.util.function.BiConsumer)1