ss: Add AttributeTreeTest unit test
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 25 Mar 2015 15:27:50 +0000 (11:27 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 30 Oct 2015 21:45:10 +0000 (17:45 -0400)
Change-Id: I7a67d33ad694370393fa2789e2508233ec570877
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/45686
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AllTests.java
statesystem/org.eclipse.tracecompass.statesystem.core.tests/src/org/eclipse/tracecompass/statesystem/core/tests/AttributeTreeTest.java [new file with mode: 0644]

index 82e23a4f3b43fbc91a13b46fbd683555b1fb6c40..97edf6e407226dceec3a8212f6b58ee8d03aee8f 100644 (file)
@@ -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 (file)
index 0000000..9fa9aee
--- /dev/null
@@ -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.
+     * <p>
+     * Tests that an attribute tree written to file is read back correctly.
+     * <p>
+     * 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();
+        }
+    }
+}
This page took 0.027611 seconds and 5 git commands to generate.