1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation
11 * Bernd Hufmann - Fixed warnings
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.statistics
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collection
;
18 import java
.util
.Vector
;
20 import junit
.framework
.TestCase
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfFixedArray
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.ITmfExtraEventInfo
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.AbsTmfStatisticsTree
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.Messages
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfBaseStatisticsTree
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfStatisticsTreeNode
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfTreeContentProvider
;
36 * TmfTreeContentProvider Test Cases.
38 @SuppressWarnings("nls")
39 public class TmfTreeContentProviderTest
extends TestCase
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 private String fTestName
= null;
47 private final String fContext
= "UnitTest";
48 private final String fTypeId1
= "Some type1";
49 private final String fTypeId2
= "Some type2";
51 private final String fLabel0
= "label1";
52 private final String fLabel1
= "label2";
53 private final String
[] fLabels
= new String
[] { fLabel0
, fLabel1
};
55 private final TmfTimestamp fTimestamp1
= new TmfTimestamp(12345, (byte) 2, 5);
56 private final TmfTimestamp fTimestamp2
= new TmfTimestamp(12350, (byte) 2, 5);
58 private final String fSource
= "Source";
60 private final TmfEventType fType1
= new TmfEventType(fContext
, fTypeId1
, TmfEventField
.makeRoot(fLabels
));
61 private final TmfEventType fType2
= new TmfEventType(fContext
, fTypeId2
, TmfEventField
.makeRoot(fLabels
));
63 private final String fReference
= "Some reference";
65 private final TmfEvent fEvent1
;
66 private final TmfEvent fEvent2
;
68 private final TmfEventField fContent1
;
69 private final TmfEventField fContent2
;
71 private final TmfBaseStatisticsTree fStatsData
;
73 private final ITmfExtraEventInfo fExtraInfo
;
75 private final TmfTreeContentProvider treeProvider
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
85 public TmfTreeContentProviderTest(final String name
) {
90 fContent1
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, "Some content");
91 fEvent1
= new TmfEvent(null, fTimestamp1
, fSource
, fType1
, fContent1
, fReference
);
93 fContent2
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, "Some other content");
94 fEvent2
= new TmfEvent(null, fTimestamp2
, fSource
, fType2
, fContent2
, fReference
);
96 fStatsData
= new TmfBaseStatisticsTree();
97 fExtraInfo
= new ITmfExtraEventInfo() {
99 public String
getTraceName() {
103 fStatsData
.registerEvent(fEvent1
, fExtraInfo
);
104 fStatsData
.registerEvent(fEvent2
, fExtraInfo
);
106 treeProvider
= new TmfTreeContentProvider();
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
114 * Test getting of children.
116 public void testGetChildren() {
117 Object
[] objectArray
= treeProvider
.getChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
118 TmfStatisticsTreeNode
[] childrenNode
= Arrays
.asList(objectArray
).toArray(new TmfStatisticsTreeNode
[0]);
120 Collection
<TmfFixedArray
<String
>> childrenExpected
= new Vector
<TmfFixedArray
<String
>>();
121 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().getName()));
122 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent2
.getType().getName()));
124 assertEquals("getChildren", childrenExpected
.size(), childrenNode
.length
);
125 // assertTrue("getChildren", childrenPath.equals(childrenExpected));
126 for (TmfStatisticsTreeNode childNode
: childrenNode
) {
127 if (childrenExpected
.contains(childNode
.getPath())) {
128 childrenExpected
.remove(childNode
.getPath());
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
140 * Test getting of parent.
142 public void testGetParent() {
143 TmfStatisticsTreeNode parent
= (TmfStatisticsTreeNode
) treeProvider
.getParent(fStatsData
.get(new TmfFixedArray
<String
>(fTestName
)));
145 assertNotNull("getParent", parent
);
146 assertTrue("getParent", parent
.getPath().equals(AbsTmfStatisticsTree
.ROOT
));
149 // ------------------------------------------------------------------------
151 // ------------------------------------------------------------------------
153 * Test checking for children.
155 public void testHasChildren() {
156 Boolean hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(AbsTmfStatisticsTree
.ROOT
));
157 assertTrue("hasChildren", hasChildren
);
159 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
)));
160 assertTrue("hasChildren", hasChildren
);
162 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
163 assertTrue("hasChildren", hasChildren
);
165 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().getName())));
166 assertFalse("hasChildren", hasChildren
);
169 // ------------------------------------------------------------------------
171 // ------------------------------------------------------------------------
174 * Test getting of elements.
176 public void testGetElements() {
177 Object
[] objectElements
= treeProvider
.getElements(fStatsData
.get(AbsTmfStatisticsTree
.ROOT
));
178 TmfStatisticsTreeNode
[] nodeElements
= Arrays
.asList(objectElements
).toArray(new TmfStatisticsTreeNode
[0]);
179 assertEquals("getElements", 1, nodeElements
.length
);
180 assertTrue("getElements", nodeElements
[0].getPath().equals(new TmfFixedArray
<String
>(fTestName
)));