Search in sources :

Example 1 with TestExecutor

use of de.neemann.digital.testing.TestExecutor in project Digital by hneemann.

the class TestExamples method check.

/**
 * Loads the model and initializes and test it if test cases are present
 *
 * @param dig the model file
 */
public static void check(File dig) throws Exception {
    boolean shouldFail = dig.getName().endsWith("Error.dig");
    ToBreakRunner br;
    try {
        br = new ToBreakRunner(dig);
    } catch (Exception e) {
        if (shouldFail) {
            return;
        } else
            throw e;
    }
    try {
        boolean isLib = dig.getPath().replace('\\', '/').contains("/lib/");
        assertTrue("wrong locked mode", isLib == br.getCircuit().getAttributes().get(Keys.LOCKED_MODE));
        try {
            for (VisualElement el : br.getCircuit().getElements()) if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
                String label = el.getElementAttributes().getCleanLabel();
                TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
                Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
                try {
                    TestExecutor tr = new TestExecutor(td).create(model);
                    if (label.contains("Failing"))
                        assertFalse(dig.getName() + ":" + label, tr.allPassed());
                    else
                        assertTrue(dig.getName() + ":" + label, tr.allPassed());
                    testCasesInFiles++;
                } finally {
                    model.close();
                }
            }
        } catch (Exception e) {
            if (shouldFail) {
                return;
            } else
                throw e;
        }
        assertFalse("File should fail but doesn't!", shouldFail);
    } finally {
        br.close();
    }
}
Also used : TestExecutor(de.neemann.digital.testing.TestExecutor) Model(de.neemann.digital.core.Model) VisualElement(de.neemann.digital.draw.elements.VisualElement) ModelCreator(de.neemann.digital.draw.model.ModelCreator) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription)

Example 2 with TestExecutor

use of de.neemann.digital.testing.TestExecutor in project Digital by hneemann.

the class JarComponentManagerTest method testJarAvailable.

public void testJarAvailable() throws PinException, NodeException, IOException, ElementNotFoundException, TestingDataException {
    ToBreakRunner br = new ToBreakRunner("dig/jarLib/jarLibTest.dig") {

        @Override
        public void initLibrary(ElementLibrary library) {
            library.addExternalJarComponents(new File(Resources.getRoot(), "dig/jarLib/pluginExample-1.0-SNAPSHOT.jar"));
            assertNull(library.checkForException());
        }
    };
    for (VisualElement ve : br.getCircuit().getElements()) {
        if (ve.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
            TestCaseDescription td = ve.getElementAttributes().get(TestCaseElement.TESTDATA);
            TestExecutor tr = new TestExecutor(td).create(br.getModel());
            assertTrue(tr.allPassed());
        }
    }
}
Also used : TestExecutor(de.neemann.digital.testing.TestExecutor) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) VisualElement(de.neemann.digital.draw.elements.VisualElement) File(java.io.File) TestCaseDescription(de.neemann.digital.testing.TestCaseDescription)

Aggregations

VisualElement (de.neemann.digital.draw.elements.VisualElement)2 TestCaseDescription (de.neemann.digital.testing.TestCaseDescription)2 TestExecutor (de.neemann.digital.testing.TestExecutor)2 Model (de.neemann.digital.core.Model)1 ModelCreator (de.neemann.digital.draw.model.ModelCreator)1 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)1 File (java.io.File)1