timing.core: add testing for less used functions in the segment store
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 1 Oct 2016 05:42:39 +0000 (01:42 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 25 Oct 2016 22:47:29 +0000 (18:47 -0400)
Increases code coverage to ~80%. More importantly, makes the contract
automatically tested for new segment stores.

Change-Id: Id7c476a8df3254b01732a44e46227da4280274f2
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/82310
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-by: Hudson CI
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/src/org/eclipse/tracecompass/segmentstore/core/tests/AbstractTestSegmentStore.java
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/src/org/eclipse/tracecompass/segmentstore/core/tests/ArrayListStoreTest.java
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/src/org/eclipse/tracecompass/segmentstore/core/tests/LazyArrayListStoreTest.java
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/src/org/eclipse/tracecompass/segmentstore/core/tests/OldTreeMapStoreTest.java
statesystem/org.eclipse.tracecompass.segmentstore.core.tests/src/org/eclipse/tracecompass/segmentstore/core/tests/TreeMapStoreTest.java

index 3fecaf97de70474096c51533b8329a9450eb7770..ac51468ee7934a893a925223792f7f2f7200d48b 100644 (file)
@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -58,6 +59,16 @@ public abstract class AbstractTestSegmentStore {
      */
     protected abstract ISegmentStore<@NonNull ISegment> getSegmentStore();
 
+    /**
+     * Get the segment store to test with initial data
+     *
+     * @param data
+     *            the data
+     *
+     * @return the segment store
+     */
+    protected abstract ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data);
+
     private static final @NonNull ISegment SEGMENT_2_6 = new BasicSegment(2, 6);
     private static final @NonNull ISegment SEGMENT_4_6 = new BasicSegment(4, 6);
     private static final @NonNull ISegment SEGMENT_4_8 = new BasicSegment(4, 8);
@@ -103,6 +114,62 @@ public abstract class AbstractTestSegmentStore {
         assertEquals(SEGMENTS.size(), fSegmentStore.size());
     }
 
+    /**
+     * Testing isEmpty() method
+     */
+    @Test
+    public void testIsEmpty() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+    }
+
+    /**
+     * Testing adding a collection with the addAll method
+     */
+    @Test
+    public void testAddAll() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+        fSegmentStore.addAll(SEGMENTS);
+        assertTrue(fSegmentStore.containsAll(SEGMENTS));
+    }
+
+    /**
+     * Testing "copy" constructor
+     */
+    @Test
+    public void testAddAllConstructor() {
+        @SuppressWarnings("null")
+        ISegmentStore<@NonNull ISegment> other = getSegmentStore(fSegmentStore.toArray(new ISegment[fSegmentStore.size()]));
+        assertTrue(fSegmentStore.containsAll(other));
+        assertTrue(other.containsAll(fSegmentStore));
+    }
+
+    /**
+     * Testing "copy" constructor out of order
+     */
+    @Test
+    public void testAddAllConstructorOutOfOrder() {
+        @SuppressWarnings("null")
+        ISegmentStore<@NonNull ISegment> other = getSegmentStore(REVERSE_SEGMENTS.toArray(new ISegment[fSegmentStore.size()]));
+        assertTrue(fSegmentStore.containsAll(other));
+        assertTrue(other.containsAll(fSegmentStore));
+    }
+
+    /**
+     * Testing adding an out of order collection with the addAll method
+     */
+    @Test
+    public void testAddAllOutOfOrder() {
+        assertFalse(fSegmentStore.isEmpty());
+        fSegmentStore.clear();
+        assertTrue(fSegmentStore.isEmpty());
+        fSegmentStore.addAll(REVERSE_SEGMENTS);
+        assertTrue(fSegmentStore.containsAll(SEGMENTS));
+    }
+
     /**
      * Test the contains() method.
      */
@@ -115,6 +182,18 @@ public abstract class AbstractTestSegmentStore {
         assertFalse(fSegmentStore.contains(otherSegment));
     }
 
+    /**
+     * Test containsAll() method
+     */
+    public void testContainsAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        assertTrue(store.containsAll(Collections.emptyList()));
+        assertTrue(store.containsAll(Collections.singleton(SEGMENT_2_6)));
+        assertFalse(store.containsAll(Collections.singleton(SEGMENT_4_6)));
+    }
+
     /**
      * Test the toArray() method.
      */
@@ -367,7 +446,7 @@ public abstract class AbstractTestSegmentStore {
     }
 
     /**
-     * Test to check ordered iterators
+     *  Test to check ordered iterators
      */
     @Test
     public void testSortedIterator() {
@@ -402,4 +481,37 @@ public abstract class AbstractTestSegmentStore {
             assertTrue(comparator.compare(prev, current) <= 0);
         }
     }
+
+    /**
+     * Test retainAll() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRetainAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.retainAll(Collections.emptyList());
+    }
+
+    /**
+     * Test remove() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRemove() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.remove(SEGMENT_2_6);
+    }
+
+    /**
+     * Test removeAll() contract
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testRemoveAll() {
+        ISegmentStore<@NonNull ISegment> store = getSegmentStore();
+
+        store.add(SEGMENT_2_6);
+        store.removeAll(Collections.emptyList());
+    }
 }
\ No newline at end of file
index 23496ea20cd54c6247284fefb8a3120165b10761..0501999c04a8bc3760572d0492272024a76081b7 100644 (file)
@@ -26,4 +26,9 @@ public class ArrayListStoreTest extends AbstractTestSegmentStore {
     protected ISegmentStore<@NonNull ISegment> getSegmentStore() {
         return new ArrayListStore<>();
     }
+
+    @Override
+    protected ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data) {
+        return new ArrayListStore<>(data);
+    }
 }
\ No newline at end of file
index d41f9e6cafe4abbe29921df2871e18d6c1989241..48008d4ee7b375d43e502472d0a8091608939ce7 100644 (file)
@@ -26,4 +26,8 @@ public class LazyArrayListStoreTest extends AbstractTestSegmentStore {
         return new LazyArrayListStore<>();
     }
 
+    @Override
+    protected ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data) {
+        return new LazyArrayListStore<>(data);
+    }
 }
\ No newline at end of file
index 9f7466a288d486c30ace022ebf317050b457ea9d..8f2078795926055148173ec9aa368180bfba7be2 100644 (file)
@@ -12,11 +12,13 @@ package org.eclipse.tracecompass.segmentstore.core.tests;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
+import java.util.Arrays;
+
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.segmentstore.core.treemap.TreeMapStore;
 import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
+import org.eclipse.tracecompass.segmentstore.core.treemap.TreeMapStore;
 import org.junit.Test;
 
 /**
@@ -33,6 +35,13 @@ public class OldTreeMapStoreTest extends AbstractTestSegmentStore {
         return new TreeMapStore<>();
     }
 
+    @Override
+    protected ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data) {
+        TreeMapStore<@NonNull ISegment> treeMapStore = new TreeMapStore<>();
+        treeMapStore.addAll(Arrays.asList(data));
+        return treeMapStore;
+    }
+
     /**
      * Try adding duplicate elements, they should be ignored
      */
index f2f96b919ed47a260364097e4f6693ea21a4987c..56f79c4011199e46c51c5d63f4aefdbe2c8c7efb 100644 (file)
@@ -12,6 +12,8 @@ package org.eclipse.tracecompass.segmentstore.core.tests;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
+import java.util.Arrays;
+
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.segmentstore.core.treemap.TreeMapStore;
 import org.eclipse.tracecompass.segmentstore.core.BasicSegment;
@@ -31,6 +33,16 @@ public class TreeMapStoreTest extends AbstractTestSegmentStore {
         return new TreeMapStore<>();
     }
 
+    /**
+     * The TreeMapStore does not have a bulk loader, if it ever gets one, it should be tested here.
+     */
+    @Override
+    protected ISegmentStore<@NonNull ISegment> getSegmentStore(@NonNull ISegment @NonNull [] data) {
+        TreeMapStore<@NonNull ISegment> treeMapStore = new TreeMapStore<>();
+        treeMapStore.addAll(Arrays.asList(data));
+        return treeMapStore;
+    }
+
     /**
      * Try adding duplicate elements, they should be ignored
      */
This page took 0.02778 seconds and 5 git commands to generate.