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
.event
.TmfEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventContent
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
26 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
27 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.ITmfExtraEventInfo
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.Messages
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfBaseStatisticsTree
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.AbsTmfStatisticsTree
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfStatisticsTreeNode
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfTreeContentProvider
;
34 import org
.eclipse
.linuxtools
.tmf
.util
.TmfFixedArray
;
36 @SuppressWarnings("nls")
37 public class TmfTreeContentProviderTest
extends TestCase
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 private String fTestName
= null;
45 private final String fTypeId1
= "Some type1";
46 private final String fTypeId2
= "Some type2";
48 private final String fLabel0
= "label1";
49 private final String fLabel1
= "label2";
50 private final String
[] fLabels
= new String
[] { fLabel0
, fLabel1
};
52 private final TmfTimestamp fTimestamp1
= new TmfTimestamp(12345, (byte) 2, 5);
53 private final TmfTimestamp fTimestamp2
= new TmfTimestamp(12350, (byte) 2, 5);
55 private final TmfEventSource fSource
= new TmfEventSource("Source");
57 private final TmfEventType fType1
= new TmfEventType(fTypeId1
, fLabels
);
58 private final TmfEventType fType2
= new TmfEventType(fTypeId2
, fLabels
);
60 private final TmfEventReference fReference
= new TmfEventReference("Some reference");
62 private final TmfEvent fEvent1
;
63 private final TmfEvent fEvent2
;
65 private final TmfEventContent fContent1
;
66 private final TmfEventContent fContent2
;
68 private final TmfBaseStatisticsTree fStatsData
;
70 private final ITmfExtraEventInfo fExtraInfo
;
72 private final TmfTreeContentProvider treeProvider
;
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
82 public TmfTreeContentProviderTest(final String name
) {
87 fEvent1
= new TmfEvent(fTimestamp1
, fSource
, fType1
, fReference
);
88 fContent1
= new TmfEventContent(fEvent1
, "Some content");
89 fEvent1
.setContent(fContent1
);
91 fEvent2
= new TmfEvent(fTimestamp1
, fTimestamp2
, fSource
, fType2
, fReference
);
92 fContent2
= new TmfEventContent(fEvent2
, "Some other content");
93 fEvent2
.setContent(fContent2
);
95 fStatsData
= new TmfBaseStatisticsTree();
96 fExtraInfo
= new ITmfExtraEventInfo() {
98 public String
getTraceName() {
102 fStatsData
.registerEvent(fEvent1
, fExtraInfo
);
103 fStatsData
.registerEvent(fEvent2
, fExtraInfo
);
105 treeProvider
= new TmfTreeContentProvider();
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
112 public void testGetChildren() {
113 Object
[] objectArray
= treeProvider
.getChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
114 TmfStatisticsTreeNode
[] childrenNode
= Arrays
.asList(objectArray
).toArray(new TmfStatisticsTreeNode
[0]);
116 Collection
<TmfFixedArray
<String
>> childrenExpected
= new Vector
<TmfFixedArray
<String
>>();
117 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().toString()));
118 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent2
.getType().toString()));
120 assertEquals("getChildren", childrenExpected
.size(), childrenNode
.length
);
121 // assertTrue("getChildren", childrenPath.equals(childrenExpected));
122 for (TmfStatisticsTreeNode childNode
: childrenNode
) {
123 if (childrenExpected
.contains(childNode
.getPath())) {
124 childrenExpected
.remove(childNode
.getPath());
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
135 public void testGetParent() {
136 TmfStatisticsTreeNode parent
= (TmfStatisticsTreeNode
) treeProvider
.getParent(fStatsData
.get(new TmfFixedArray
<String
>(fTestName
)));
138 assertNotNull("getParent", parent
);
139 assertTrue("getParent", parent
.getPath().equals(AbsTmfStatisticsTree
.ROOT
));
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
146 public void testHasChildren() {
147 Boolean hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(AbsTmfStatisticsTree
.ROOT
));
148 assertTrue("hasChildren", hasChildren
);
150 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
)));
151 assertTrue("hasChildren", hasChildren
);
153 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
154 assertTrue("hasChildren", hasChildren
);
156 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().toString())));
157 assertFalse("hasChildren", hasChildren
);
160 // ------------------------------------------------------------------------
162 // ------------------------------------------------------------------------
164 public void testGetElements() {
165 Object
[] objectElements
= treeProvider
.getElements(fStatsData
.get(AbsTmfStatisticsTree
.ROOT
));
166 TmfStatisticsTreeNode
[] nodeElements
= Arrays
.asList(objectElements
).toArray(new TmfStatisticsTreeNode
[0]);
167 assertEquals("getElements", 1, nodeElements
.length
);
168 assertTrue("getElements", nodeElements
[0].getPath().equals(new TmfFixedArray
<String
>(fTestName
)));