summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMathieu Denis2012-08-15 17:04:37 (EDT)
committer Alexandre Montplaisir2012-08-21 13:10:56 (EDT)
commit1cc34943150b79e8f17bdee74a61ee2f7cd9ceca (patch)
tree86b9d7bc7453a672aee59bcf996c5a9153e0e39c
parentc06aa04ae3fc440b37d570fe661397807f48b53d (diff)
downloadorg.eclipse.linuxtools-1cc34943150b79e8f17bdee74a61ee2f7cd9ceca.zip
org.eclipse.linuxtools-1cc34943150b79e8f17bdee74a61ee2f7cd9ceca.tar.gz
org.eclipse.linuxtools-1cc34943150b79e8f17bdee74a61ee2f7cd9ceca.tar.bz2
tmf: Updates statistics test cases
Change-Id: I5c40b27da713dd67e5e39abdc09f0c7cafe016fa Signed-off-by: Mathieu Denis <mathieu.denis@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/7306 Reviewed-by: Bernd Hufmann <bhufmann@gmail.com> IP-Clean: Bernd Hufmann <bhufmann@gmail.com> Tested-by: Bernd Hufmann <bhufmann@gmail.com> Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im> Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java1
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTest.java143
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java100
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java37
-rwxr-xr-xlttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java2
6 files changed, 256 insertions, 29 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java
index 8d8ce22..406204d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/AllTests.java
@@ -33,6 +33,7 @@ public class AllTests {
suite.addTestSuite(TmfStatisticsTreeNodeTest.class);
suite.addTestSuite(TmfStatisticsTreeRootFactoryTest.class);
suite.addTestSuite(TmfTreeContentProviderTest.class);
+ suite.addTestSuite(TmfStatisticsTest.class);
// $JUnit-END$
return suite;
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java
index 95399ab..4d93a32 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfBaseStatisticsDataTest.java
@@ -140,6 +140,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
TmfStatisticsTreeNode temp;
while (iterChild.hasNext()) {
temp = iterChild.next();
+ assertEquals(0, fStatsData.getChildren(temp.getPath()).size());
if (keyExpected.contains(temp.getKey())) {
keyExpected.removeElement(temp.getKey());
} else {
@@ -188,6 +189,7 @@ public class TmfBaseStatisticsDataTest extends TestCase {
TmfStatisticsTreeNode temp;
while (iterChild.hasNext()) {
temp = iterChild.next();
+ assertEquals(0, fStatsData.getAllChildren(temp.getPath()).size());
if (keyExpected.contains(temp.getKey())) {
keyExpected.removeElement(temp.getKey());
} else {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTest.java
new file mode 100644
index 0000000..3c5e22d
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTest.java
@@ -0,0 +1,143 @@
+package org.eclipse.linuxtools.tmf.ui.tests.statistics;
+
+import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatistics;
+
+import junit.framework.TestCase;
+
+/**
+ * TmfStatistics Test Cases.
+ */
+public class TmfStatisticsTest extends TestCase {
+
+ // ------------------------------------------------------------------------
+ // Fields
+ // ------------------------------------------------------------------------
+
+ TmfStatistics stats = new TmfStatistics();
+
+ // ------------------------------------------------------------------------
+ // Checks initial state
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test the initial state of the counters
+ */
+ public void testInitialState() {
+ assertEquals(0, stats.getTotal());
+ assertEquals(0, stats.getPartial());
+ }
+
+ // ------------------------------------------------------------------------
+ // Increment Total no parameter
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test incrementing the total counter
+ */
+ public void testIncrementTotal() {
+ for (int i = 1; i < 10; ++i) {
+ stats.incrementTotal();
+ assertEquals(i, stats.getTotal());
+ }
+ // Checks if the partial counter was affected
+ assertEquals(0, stats.getPartial());
+ }
+
+ /**
+ * Test incrementing the total counter by an amount
+ */
+ public void testIncrementTotal1Arg() {
+ int i = 1, expected = 0;
+ while (expected < 100) {
+ expected += i;
+ stats.incrementTotal(i);
+ assertEquals(expected, stats.getTotal());
+ i += i;
+ }
+ // Increment by a negative number do nothing
+ stats.incrementTotal(-10);
+ assertEquals(expected, stats.getTotal());
+
+ // Checks if the partial counter was affected
+ assertEquals(0, stats.getPartial());
+ }
+
+ /**
+ * Test incrementing the partial counter
+ */
+ public void testIncrementPartial() {
+ for (int i = 1; i < 10; ++i) {
+ stats.incrementPartial();
+ assertEquals(i, stats.getPartial());
+ }
+ // Checks if the total counter was affected
+ assertEquals(0, stats.getTotal());
+ }
+
+ /**
+ * Test incrementing the partial counter by a certain amount
+ */
+ public void testIncrementPartial1Arg() {
+ int i = 1, expected = 0;
+ while (expected < 100) {
+ expected += i;
+ stats.incrementPartial(i);
+ assertEquals(expected, stats.getPartial());
+ i += i;
+ }
+ // Increment by a negative number. It should do nothing.
+ stats.incrementPartial(-10);
+ assertEquals(expected, stats.getPartial());
+
+ // Checks if the total counter was affected
+ assertEquals(0, stats.getTotal());
+ }
+
+ /**
+ * Test of the reset for the total counter
+ */
+ public void testResetTotal() {
+ stats.incrementTotal(123);
+ assertEquals(123, stats.getTotal());
+
+ stats.resetTotalCount();
+ assertEquals(0, stats.getTotal());
+
+ // test when already at 0
+ stats.resetTotalCount();
+ assertEquals(0, stats.getTotal());
+
+ // The counters should still be in a usable state
+ stats.incrementPartial();
+ stats.incrementPartial(3);
+ assertEquals(4, stats.getPartial());
+
+ stats.incrementTotal();
+ stats.incrementTotal(2);
+ assertEquals(3, stats.getTotal());
+ }
+
+ /**
+ * Test of the reset for the partial counter
+ */
+ public void testResetPartial() {
+ stats.incrementPartial(456);
+ assertEquals(456, stats.getPartial());
+
+ stats.resetPartialCount();
+ assertEquals(0, stats.getPartial());
+
+ // test when already at 0
+ stats.resetPartialCount();
+ assertEquals(0, stats.getPartial());
+
+ // The counters should still be in a usable state
+ stats.incrementPartial();
+ stats.incrementPartial(2);
+ assertEquals(3, stats.getPartial());
+
+ stats.incrementTotal();
+ stats.incrementTotal(3);
+ assertEquals(4, stats.getTotal());
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java
index 4a6e12d..1fb9fd6 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeNodeTest.java
@@ -59,8 +59,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
private final String fSource = "Source";
private final TmfEventType fType1 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId1, TmfEventField.makeRoot(fLabels));
- private final TmfEventType fType3 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
+ private final TmfEventType fType2 = new TmfEventType(fContext, fTypeId2, TmfEventField.makeRoot(fLabels));
private final String fReference = "Some reference";
@@ -93,21 +92,34 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
fEvent1 = new TmfEvent(null, fTimestamp1, fSource, fType1, fContent1, fReference);
fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content");
- fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType2, fContent2, fReference);
+ fEvent2 = new TmfEvent(null, fTimestamp2, fSource, fType1, fContent2, fReference);
fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content");
- fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType3, fContent3, fReference);
+ fEvent3 = new TmfEvent(null, fTimestamp3, fSource, fType2, fContent3, fReference);
fStatsData = new TmfBaseStatisticsTree();
fExtraInfo = new ITmfExtraEventInfo() {
@Override
public String getTraceName() {
- return name;
+ return fTestName;
}
};
fStatsData.registerEvent(fEvent1, fExtraInfo);
fStatsData.registerEvent(fEvent2, fExtraInfo);
fStatsData.registerEvent(fEvent3, fExtraInfo);
+
+ // Registers some events in time range
+ fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent1, fExtraInfo);
+
+ fStatsData.registerEventInTimeRange(fEvent2, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent2, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent2, fExtraInfo);
+
+ fStatsData.registerEventInTimeRange(fEvent3, fExtraInfo);
+ fStatsData.registerEventInTimeRange(fEvent3, fExtraInfo);
}
// ------------------------------------------------------------------------
@@ -128,11 +140,11 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
assertFalse("containsChild", rootNode.containsChild(null));
assertTrue("containsChild", traceNode.containsChild(catNode.getKey()));
- assertFalse("containsChild", traceNode.containsChild(fEvent1.getType().toString()));
+ assertFalse("containsChild", traceNode.containsChild(fType1.toString()));
assertFalse("containsChild", traceNode.containsChild(null));
- assertTrue("containsChild", catNode.containsChild(fEvent1.getType().toString()));
- assertTrue("containsChild", catNode.containsChild(fEvent3.getType().toString()));
+ assertTrue("containsChild", catNode.containsChild(fType1.toString()));
+ assertTrue("containsChild", catNode.containsChild(fType2.toString()));
assertFalse("containsChild", catNode.containsChild(null));
}
@@ -157,8 +169,8 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
Vector<String> keyExpected = new Vector<String>();
- keyExpected.add(fEvent1.getType().toString());
- keyExpected.add(fEvent3.getType().toString());
+ keyExpected.add(fType1.toString());
+ keyExpected.add(fType2.toString());
// Getting children of a category
childrenTreeNode = treeNode.getChildren();
assertEquals("getChildren", 2, childrenTreeNode.size());
@@ -200,13 +212,13 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
assertEquals("getChildren", Messages.TmfStatisticsData_EventTypes, treeNode.getKey());
Vector<String> keyExpected = new Vector<String>();
- keyExpected.add(fEvent1.getType().toString());
- keyExpected.add(fEvent3.getType().toString());
+ keyExpected.add(fType1.toString());
+ keyExpected.add(fType2.toString());
/*
* It should return the eventType even though the number of events
* equals 0
*/
- fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString())).reset();
+ fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString())).reset();
// Getting children of a category
childrenTreeNode = treeNode.getAllChildren();
assertEquals("getChildren", 2, childrenTreeNode.size());
@@ -238,7 +250,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
assertEquals("getNbChildren", 1, rootNode.getNbChildren());
assertEquals("getNbChildren", 1, traceNode.getNbChildren());
@@ -257,7 +269,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
assertTrue("hasChildren", rootNode.hasChildren());
assertTrue("hasChildren", traceNode.hasChildren());
@@ -270,7 +282,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
// ------------------------------------------------------------------------
/**
- * Test geting oft parent.
+ * Test getting of parent.
*/
public void testGetParent() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
@@ -291,7 +303,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
parentNode = newNode.getParent();
assertNull("getParent", parentNode);
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
parentNode = elementNode.getParent();
assertNull("getParent", parentNode);
@@ -316,12 +328,12 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
assertEquals("getKey", 0, rootNode.getKey().compareTo(AbsTmfStatisticsTree.ROOT.get(0)));
assertEquals("getKey", 0, traceNode.getKey().compareTo(fTestName));
assertEquals("getKey", 0, catNode.getKey().compareTo(Messages.TmfStatisticsData_EventTypes));
- assertEquals("getKey", 0, elementNode.getKey().compareTo(fEvent1.getType().toString()));
+ assertEquals("getKey", 0, elementNode.getKey().compareTo(fType1.toString()));
}
// ------------------------------------------------------------------------
@@ -335,12 +347,12 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
assertTrue("getPath", rootNode.getPath().equals(AbsTmfStatisticsTree.ROOT));
assertTrue("getPath", traceNode.getPath().equals(new TmfFixedArray<String>(fTestName)));
assertTrue("getPath", catNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes)));
- assertTrue("getPath", elementNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString())));
+ assertTrue("getPath", elementNode.getPath().equals(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString())));
}
// ------------------------------------------------------------------------
@@ -348,20 +360,20 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
// ------------------------------------------------------------------------
/**
- * Test gettomg statistic value.
+ * Test getting statistic value.
*/
public void testGetValue() {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
- TmfStatisticsTreeNode elementNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getType().toString()));
+ TmfStatisticsTreeNode elementNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
+ TmfStatisticsTreeNode elementNode3 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.toString()));
assertEquals("getValue", 0, rootNode.getValue().getTotal());
assertEquals("getValue", 3, traceNode.getValue().getTotal());
assertEquals("getValue", 0, catNode.getValue().getTotal());
assertEquals("getValue", 2, elementNode1.getValue().getTotal());
- assertEquals("getValue", 1, elementNode2.getValue().getTotal());
+ assertEquals("getValue", 1, elementNode3.getValue().getTotal());
}
// ------------------------------------------------------------------------
@@ -375,7 +387,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
- TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()));
+ TmfStatisticsTreeNode elementNode = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
elementNode.reset();
assertEquals("reset", 0, elementNode.getValue().getTotal());
@@ -383,7 +395,7 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
catNode.reset();
assertEquals("reset", 0, catNode.getValue().getTotal());
assertEquals("reset", 0, catNode.getNbChildren());
- assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString())));
+ assertNull("reset", fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString())));
traceNode.reset();
assertEquals("reset", 0, traceNode.getValue().getTotal());
@@ -394,4 +406,38 @@ public class TmfStatisticsTreeNodeTest extends TestCase {
assertEquals("reset", 0, rootNode.getValue().getTotal());
assertEquals("reset", 1, rootNode.getNbChildren());
}
+
+ /**
+ * Test reset time range value of the node in the tree. It should only clear
+ * the time range value without removing any node from the tree.
+ */
+ public void testResetTimeRangeValue() {
+ TmfStatisticsTreeNode rootNode = fStatsData.get(AbsTmfStatisticsTree.ROOT);
+ TmfStatisticsTreeNode traceNode = fStatsData.get(new TmfFixedArray<String>(fTestName));
+ TmfStatisticsTreeNode catNode = traceNode.getChildren().iterator().next();
+ TmfStatisticsTreeNode eventTypeNode1 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType1.toString()));
+ TmfStatisticsTreeNode eventTypeNode2 = fStatsData.get(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fType2.toString()));
+
+ rootNode.resetTimeRangeValue();
+
+ assertEquals(0, rootNode.getValue().getPartial());
+ assertEquals(0, traceNode.getValue().getPartial());
+ assertEquals(0, catNode.getValue().getPartial());
+ assertEquals(0, eventTypeNode1.getValue().getPartial());
+ assertEquals(0, eventTypeNode2.getValue().getPartial());
+
+ // Checks the state of the statistics tree
+ Collection<TmfStatisticsTreeNode> rootChildren = rootNode.getAllChildren();
+ assertEquals(1, rootChildren.size());
+ assertTrue(rootChildren.contains(traceNode));
+
+ Collection<TmfStatisticsTreeNode> traceChildren = traceNode.getAllChildren();
+ assertEquals(1, traceChildren.size());
+ assertTrue(traceChildren.contains(catNode));
+
+ Collection<TmfStatisticsTreeNode> catChildren = catNode.getAllChildren();
+ assertEquals(2, catChildren.size());
+ assertTrue(catChildren.contains(eventTypeNode1));
+ assertTrue(catChildren.contains(eventTypeNode2));
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java
index 1b35472..bd2b06f 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.tests/src/org/eclipse/linuxtools/tmf/ui/tests/statistics/TmfStatisticsTreeRootFactoryTest.java
@@ -53,7 +53,7 @@ public class TmfStatisticsTreeRootFactoryTest extends TestCase {
}
/**
- * Test adding of statistics tree root.
+ * Adding of statistics tree root.
*/
public void addStatsTreeRoot() {
fStatisticsData1 = new TmfBaseStatisticsTree();
@@ -64,6 +64,38 @@ public class TmfStatisticsTreeRootFactoryTest extends TestCase {
TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey2, fStatisticsData3);
}
+ /**
+ * Clean the statistics tree
+ */
+ public void removeStatsTreeRoot() {
+ TmfStatisticsTreeRootFactory.removeAll();
+ }
+
+ /**
+ * Test adding of statistics tree root. It should not throw exceptions
+ */
+ public void testaddStatsTreeRoot() {
+ removeStatsTreeRoot();
+
+ try {
+ TmfStatisticsTreeRootFactory.addStatsTreeRoot(null, null);
+ TmfStatisticsTreeRootFactory.addStatsTreeRoot(null, fStatisticsData1);
+ TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, null);
+ assertNull(TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1));
+
+ TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData1);
+ assertSame(fStatisticsData1, TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
+
+ // Overwriting the value
+ TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData2);
+ assertSame(fStatisticsData2, TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
+
+ // Success
+ } catch(Exception e) {
+ fail("AddStatsTreeRoot");
+ }
+ }
+
// ------------------------------------------------------------------------
// get
// ------------------------------------------------------------------------
@@ -119,6 +151,9 @@ public class TmfStatisticsTreeRootFactoryTest extends TestCase {
assertNull("removeStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTree(fDataKey1));
try {
+ // Trying to remove the same branch from the tree.
+ TmfStatisticsTreeRootFactory.removeStatTreeRoot(fDataKey1);
+
TmfStatisticsTreeRootFactory.removeStatTreeRoot(null);
// Success
} catch (Exception e) {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
index 95a4dcd..b1d97a8 100755
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/model/TmfStatisticsTreeNode.java
@@ -86,7 +86,7 @@ public class TmfStatisticsTreeNode {
}
/**
- * Get the children of this node.
+ * Gets every children of this node even if no event has been registered for a node.
*
* @return Direct children of this node.
*/