Search in sources :

Example 1 with TestAlgorithm

use of org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm in project elk by eclipse.

the class LayoutTestRunner method initializeAlgorithms.

/**
 * Loads all algorithms configured in the test class.
 */
private void initializeAlgorithms(final TestClass testClass, final List<Throwable> errors) {
    testAlgorithms.addAll(TestAlgorithm.fromTestClass(testClass, errors));
    // If we have whitebox tests, we need to check stuff
    if (!whiteboxTests.isEmpty()) {
        // Ensure that there is at least one specific layout algorithm
        if (testAlgorithms.isEmpty() || testAlgorithms.get(0).getAlgorithmData() == null) {
            errors.add(new Exception("Whitebox tests require explicit @Algorithm annotations."));
        } else {
            // Ensure that all algorithms are whitebox testable
            for (TestAlgorithm algorithm : testAlgorithms) {
                LayoutAlgorithmData algorithmData = algorithm.getAlgorithmData();
                AbstractLayoutProvider layoutProvider = algorithmData.getInstancePool().fetch();
                if (!(layoutProvider instanceof IWhiteBoxTestable)) {
                    errors.add(new Exception("Algorithm " + algorithmData.getId() + " is not whitebox testable."));
                }
                algorithmData.getInstancePool().release(layoutProvider);
            }
        }
    }
    if (testAlgorithms.isEmpty()) {
        testAlgorithms.add(TestAlgorithm.identity());
    }
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) TestAlgorithm(org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm) IWhiteBoxTestable(org.eclipse.elk.core.testing.IWhiteBoxTestable) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 2 with TestAlgorithm

use of org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm in project elk by eclipse.

the class ExperimentStatement method evaluate.

@Override
public void evaluate() throws Throwable {
    createTestGraph();
    // Create a test controller if we have whitebox tests and the layout algorithm
    TestController testController = null;
    if (!this.experimentRunner.getParentRunner().getWhiteboxTests().isEmpty()) {
        TestAlgorithm algorithm = experimentRunner.getExperimentalObject().getLayoutAlgorithm();
        testController = new TestController(algorithm.getAlgorithmData().getId());
        testController.addLayoutExecutionListener(this);
    }
    // Let the recursive graph layout engine run the layout algorithm (if we have a test controller, that will
    // automatically cause white box tests to run)
    RecursiveGraphLayoutEngine layoutEngine = new RecursiveGraphLayoutEngine();
    layoutEngine.layout(testGraph, testController, new BasicProgressMonitor());
    // Stop listening to the test controller
    if (testController != null) {
        testController.removeLayoutExecutionListener(this);
    }
    // Run blackbox tests now that the layout algorithm has finished
    runBlackboxTests();
    // Cleanly handle all whitebox tests that did not execute because their processors didn't run
    simulateWhiteboxTestsForNotifiers();
    testGraph = null;
}
Also used : TestAlgorithm(org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm) TestController(org.eclipse.elk.core.testing.TestController) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor)

Aggregations

TestAlgorithm (org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm)2 AbstractLayoutProvider (org.eclipse.elk.core.AbstractLayoutProvider)1 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)1 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)1 IWhiteBoxTestable (org.eclipse.elk.core.testing.IWhiteBoxTestable)1 TestController (org.eclipse.elk.core.testing.TestController)1 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)1