From: Patrick Tasse Date: Wed, 25 Mar 2015 15:27:50 +0000 (-0400) Subject: ss: Add AttributeTreeTest unit test X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=ad0a2354b20e7447b1f866fafaaadd96e9d72f7f;p=deliverable%2Ftracecompass.git ss: Add AttributeTreeTest unit test Change-Id: I7a67d33ad694370393fa2789e2508233ec570877 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/45686 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle Reviewed-by: Alexandre Montplaisir --- diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AllTests.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AllTests.java index 82e23a4f3b..97edf6e407 100644 --- a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AllTests.java +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AllTests.java @@ -21,6 +21,7 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ + AttributeTreeTest.class, StateSystemPushPopTest.class, StateSystemUtilsTest.class, org.eclipse.tracecompass.statesystem.core.tests.backend.AllTests.class, diff --git a/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AttributeTreeTest.java b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AttributeTreeTest.java new file mode 100644 index 0000000000..9fa9aee2db --- /dev/null +++ b/statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AttributeTreeTest.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2015 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.tracecompass.statesystem.core.tests; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.eclipse.tracecompass.internal.statesystem.core.AttributeTree; +import org.eclipse.tracecompass.internal.statesystem.core.StateSystem; +import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; +import org.eclipse.tracecompass.statesystem.core.backend.StateHistoryBackendFactory; +import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; +import org.junit.Test; + +/** + * Test the {@link AttributeTree} class + * + * @author Patrick Tasse + */ +public class AttributeTreeTest { + + private static final String THREADS = "Threads"; + private static final String[] NAMES = { + "", // '' + "\0", // 'Null' + "a", // 'a' + "\"", // '"' + "/", // '/' + "\\", // '\' + "ab", // 'ab' + "\"\"", // '""' + "a/", // 'a/' + "a\\", // 'a\' + "/a", // '/a' + "//", // '//' + "/\\", // '/\' + "\\a", // '\a' + "\\/", // '\/' + "\\\\", // '\\' + "abc", // 'abc' + "\"/\"", // '"/"' + "ab/", // 'ab/' + "ab\\", // 'ab\' + "a/b", // 'a/b' + "a//", // 'a//' + "a/\\", // 'a/\' + "a\\b", // 'a\b' + "a\\/", // 'a\/' + "a\\\\", // 'a\\' + "/ab", // '/ab' + "/a/", // '/a/' + "/a\\", // '/a\' + "//a", // '//a' + "///", // '///' + "//\\", // '//\' + "/\\a", // '/\a' + "/\\/", // '/\/' + "/\\\\", // '/\\' + "\\ab", // '\ab' + "\\a/", // '\a/' + "\\a\\", // '\a\' + "\\/a", // '\/a' + "\\//", // '\//' + "\\/\\", // '\/\' + "\\\\a", // '\\a' + "\\\\/", // '\\/' + "\\\\\\" // '\\\' + }; + private static final String STATUS = "Status"; + + /** + * Test attribute tree file storage. + *

+ * Tests that an attribute tree written to file is read back correctly. + *

+ * Tests {@link AttributeTree#writeSelf(File, long)} and + * {@link AttributeTree#AttributeTree(StateSystem, FileInputStream)}. + * + * @throws IOException + * if there is an error accessing the test file + * @throws AttributeNotFoundException + * if the test fails + */ + @Test + public void testAttributeTreeFileStorage() throws IOException, AttributeNotFoundException { + File file = File.createTempFile("AttributeTreeTest", ".ht"); + IStateHistoryBackend backend1 = StateHistoryBackendFactory.createNullBackend("test"); + StateSystem ss1 = new StateSystem(backend1); + AttributeTree attributeTree1 = new AttributeTree(ss1); + for (String name : NAMES) { + String[] path = new String[] { THREADS, name, STATUS }; + attributeTree1.getQuarkAndAdd(-1, path); + } + attributeTree1.writeSelf(file, 0L); + ss1.dispose(); + + IStateHistoryBackend backend2 = StateHistoryBackendFactory.createNullBackend("test"); + StateSystem ss2 = new StateSystem(backend2); + try (FileInputStream fis = new FileInputStream(file)) { + AttributeTree attributeTree2 = new AttributeTree(ss2, fis); + for (String name : NAMES) { + String[] path = new String[] { THREADS, name, STATUS }; + int quark = attributeTree2.getQuarkDontAdd(-1, path); + assertArrayEquals(path, attributeTree2.getFullAttributePathArray(quark)); + assertEquals(name, attributeTree2.getAttributeName(attributeTree2.getParentAttributeQuark(quark))); + } + } finally { + ss2.dispose(); + file.delete(); + } + } +}