Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial design and implementation | |
11 | * Bernd Hufmann - Fixed warnings | |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ui.tests.statistics; | |
15 | ||
16 | import java.util.Arrays; | |
17 | import java.util.Collection; | |
18 | import java.util.Vector; | |
19 | ||
20 | import junit.framework.TestCase; | |
21 | ||
6c13869b FC |
22 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
23 | import org.eclipse.linuxtools.tmf.core.event.TmfEventContent; | |
24 | import org.eclipse.linuxtools.tmf.core.event.TmfEventReference; | |
25 | import org.eclipse.linuxtools.tmf.core.event.TmfEventSource; | |
26 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; | |
27 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
28 | import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray; | |
79e08fd0 BH |
29 | import org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfExtraEventInfo; |
30 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.Messages; | |
31 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseStatisticsTree; | |
32 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree; | |
33 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeNode; | |
34 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfTreeContentProvider; | |
79e08fd0 BH |
35 | |
36 | @SuppressWarnings("nls") | |
37 | public class TmfTreeContentProviderTest extends TestCase { | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Fields | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
43 | private String fTestName = null; | |
44 | ||
45 | private final String fTypeId1 = "Some type1"; | |
46 | private final String fTypeId2 = "Some type2"; | |
47 | ||
48 | private final String fLabel0 = "label1"; | |
49 | private final String fLabel1 = "label2"; | |
50 | private final String[] fLabels = new String[] { fLabel0, fLabel1 }; | |
51 | ||
52 | private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2, 5); | |
53 | private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2, 5); | |
54 | ||
55 | private final TmfEventSource fSource = new TmfEventSource("Source"); | |
56 | ||
57 | private final TmfEventType fType1 = new TmfEventType(fTypeId1, fLabels); | |
58 | private final TmfEventType fType2 = new TmfEventType(fTypeId2, fLabels); | |
59 | ||
60 | private final TmfEventReference fReference = new TmfEventReference("Some reference"); | |
61 | ||
62 | private final TmfEvent fEvent1; | |
63 | private final TmfEvent fEvent2; | |
64 | ||
65 | private final TmfEventContent fContent1; | |
66 | private final TmfEventContent fContent2; | |
67 | ||
68 | private final TmfBaseStatisticsTree fStatsData; | |
69 | ||
70 | private final ITmfExtraEventInfo fExtraInfo; | |
71 | ||
72 | private final TmfTreeContentProvider treeProvider; | |
73 | ||
74 | // ------------------------------------------------------------------------ | |
75 | // Housekeeping | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | /** | |
79 | * @param name | |
80 | * of the test | |
81 | */ | |
82 | public TmfTreeContentProviderTest(final String name) { | |
83 | super(name); | |
84 | ||
85 | fTestName = name; | |
86 | ||
87 | fEvent1 = new TmfEvent(fTimestamp1, fSource, fType1, fReference); | |
88 | fContent1 = new TmfEventContent(fEvent1, "Some content"); | |
89 | fEvent1.setContent(fContent1); | |
90 | ||
91 | fEvent2 = new TmfEvent(fTimestamp1, fTimestamp2, fSource, fType2, fReference); | |
92 | fContent2 = new TmfEventContent(fEvent2, "Some other content"); | |
93 | fEvent2.setContent(fContent2); | |
94 | ||
95 | fStatsData = new TmfBaseStatisticsTree(); | |
96 | fExtraInfo = new ITmfExtraEventInfo() { | |
97 | @Override | |
98 | public String getTraceName() { | |
99 | return name; | |
100 | } | |
101 | }; | |
102 | fStatsData.registerEvent(fEvent1, fExtraInfo); | |
103 | fStatsData.registerEvent(fEvent2, fExtraInfo); | |
104 | ||
105 | treeProvider = new TmfTreeContentProvider(); | |
106 | } | |
107 | ||
108 | // ------------------------------------------------------------------------ | |
109 | // GetChildren | |
110 | // ------------------------------------------------------------------------ | |
111 | ||
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]); | |
115 | ||
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())); | |
119 | ||
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()); | |
125 | } else { | |
126 | fail(); | |
127 | } | |
128 | } | |
129 | } | |
130 | ||
131 | // ------------------------------------------------------------------------ | |
132 | // GetParent | |
133 | // ------------------------------------------------------------------------ | |
134 | ||
135 | public void testGetParent() { | |
136 | TmfStatisticsTreeNode parent = (TmfStatisticsTreeNode) treeProvider.getParent(fStatsData.get(new TmfFixedArray<String>(fTestName))); | |
137 | ||
138 | assertNotNull("getParent", parent); | |
139 | assertTrue("getParent", parent.getPath().equals(AbsTmfStatisticsTree.ROOT)); | |
140 | } | |
141 | ||
142 | // ------------------------------------------------------------------------ | |
143 | // HasChildren | |
144 | // ------------------------------------------------------------------------ | |
145 | ||
146 | public void testHasChildren() { | |
147 | Boolean hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(AbsTmfStatisticsTree.ROOT)); | |
148 | assertTrue("hasChildren", hasChildren); | |
149 | ||
150 | hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName))); | |
151 | assertTrue("hasChildren", hasChildren); | |
152 | ||
153 | hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes))); | |
154 | assertTrue("hasChildren", hasChildren); | |
155 | ||
156 | hasChildren = treeProvider.hasChildren(fStatsData.getOrCreate(new TmfFixedArray<String>(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getType().toString()))); | |
157 | assertFalse("hasChildren", hasChildren); | |
158 | } | |
159 | ||
160 | // ------------------------------------------------------------------------ | |
161 | // GetElements | |
162 | // ------------------------------------------------------------------------ | |
163 | ||
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))); | |
169 | } | |
170 | } |