Commit | Line | Data |
---|---|---|
79e08fd0 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2011, 2014 Ericsson |
abbdd66a | 3 | * |
79e08fd0 BH |
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 | |
abbdd66a | 8 | * |
79e08fd0 | 9 | * Contributors: |
09667aa4 | 10 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and Implementation |
79e08fd0 | 11 | * Bernd Hufmann - Fixed header and warnings |
90ed5958 | 12 | * Alexandre Montplaisir - Port to JUnit4 |
79e08fd0 | 13 | *******************************************************************************/ |
90ed5958 | 14 | |
2bdf0193 | 15 | package org.eclipse.tracecompass.tmf.ui.tests.statistics; |
79e08fd0 | 16 | |
90ed5958 AM |
17 | import static org.junit.Assert.assertEquals; |
18 | import static org.junit.Assert.assertNotNull; | |
19 | import static org.junit.Assert.assertNull; | |
20 | import static org.junit.Assert.assertTrue; | |
79e08fd0 | 21 | |
90ed5958 | 22 | import java.util.List; |
79e08fd0 | 23 | |
aa353506 | 24 | import org.eclipse.jdt.annotation.NonNull; |
79e08fd0 BH |
25 | import org.eclipse.jface.viewers.ColumnLabelProvider; |
26 | import org.eclipse.jface.viewers.ViewerComparator; | |
1743f395 BH |
27 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.Messages; |
28 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnData; | |
29 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider; | |
30 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree; | |
31 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode; | |
32 | import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider; | |
2bdf0193 AM |
33 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
34 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; | |
35 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
36 | import org.eclipse.tracecompass.tmf.core.event.TmfEventField; | |
37 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
38 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; | |
0c7471fb | 39 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
90ed5958 | 40 | import org.junit.Test; |
64636df8 BH |
41 | |
42 | /** | |
43 | * TmfBaseColumnDataProvider test cases. | |
df2b3dbb | 44 | * |
64636df8 | 45 | */ |
90ed5958 | 46 | public class TmfBaseColumnDataProviderTest { |
79e08fd0 BH |
47 | |
48 | // ------------------------------------------------------------------------ | |
49 | // Fields | |
50 | // ------------------------------------------------------------------------ | |
90ed5958 AM |
51 | |
52 | private static final double DELTA = 1e-15; | |
53 | ||
05627bda MD |
54 | private final static String LEVEL_COLUMN = Messages.TmfStatisticsView_LevelColumn; |
55 | private final static String EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsColumn; | |
abbdd66a | 56 | |
79e08fd0 BH |
57 | private TmfBaseColumnDataProvider provider; |
58 | ||
90ed5958 | 59 | private static final String fTestName = "ColumnDataProviderTest"; |
79e08fd0 | 60 | |
aa353506 AM |
61 | private final @NonNull String fTypeId1 = "Some type1"; |
62 | private final @NonNull String fTypeId2 = "Some type2"; | |
79e08fd0 BH |
63 | |
64 | private final String fLabel0 = "label1"; | |
65 | private final String fLabel1 = "label2"; | |
66 | private final String fLabel2 = "label3"; | |
67 | private final String[] fLabels = new String[] { fLabel0, fLabel1, fLabel2 }; | |
68 | ||
065cc19b AM |
69 | private final TmfTimestamp fTimestamp1 = new TmfTimestamp(12345, (byte) 2); |
70 | private final TmfTimestamp fTimestamp2 = new TmfTimestamp(12350, (byte) 2); | |
71 | private final TmfTimestamp fTimestamp3 = new TmfTimestamp(12355, (byte) 2); | |
79e08fd0 | 72 | |
e600c338 AM |
73 | private final TmfEventType fType1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels)); |
74 | private final TmfEventType fType2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels)); | |
75 | private final TmfEventType fType3 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels)); | |
79e08fd0 | 76 | |
2771b032 AM |
77 | private final ITmfEvent fEvent1; |
78 | private final ITmfEvent fEvent2; | |
79 | private final ITmfEvent fEvent3; | |
79e08fd0 | 80 | |
4c564a2d FC |
81 | private final TmfEventField fContent1; |
82 | private final TmfEventField fContent2; | |
83 | private final TmfEventField fContent3; | |
79e08fd0 | 84 | |
36033ff0 | 85 | private final TmfStatisticsTree fStatsData; |
79e08fd0 | 86 | |
79e08fd0 BH |
87 | // ------------------------------------------------------------------------ |
88 | // Housekeeping | |
89 | // ------------------------------------------------------------------------ | |
90 | ||
64636df8 BH |
91 | /** |
92 | * Constructor | |
64636df8 | 93 | */ |
90ed5958 | 94 | public TmfBaseColumnDataProviderTest() { |
214cc822 | 95 | fContent1 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some content", null); |
e1de2fd4 | 96 | fEvent1 = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, fTimestamp1, fType1, fContent1); |
79e08fd0 | 97 | |
214cc822 | 98 | fContent2 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other content", null); |
e1de2fd4 | 99 | fEvent2 = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, fTimestamp2, fType2, fContent2); |
79e08fd0 | 100 | |
214cc822 | 101 | fContent3 = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, "Some other different content", null); |
e1de2fd4 | 102 | fEvent3 = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, fTimestamp3, fType3, fContent3); |
79e08fd0 | 103 | |
36033ff0 | 104 | fStatsData = new TmfStatisticsTree(); |
89c06060 | 105 | |
7588c810 | 106 | fStatsData.getOrCreateNode(fTestName, Messages.TmfStatisticsData_EventTypes); |
89c06060 AM |
107 | |
108 | fStatsData.setTotal(fTestName, true, 3); | |
578716e6 MK |
109 | fStatsData.setTypeCount(fTestName, fEvent1.getName(), true, 1); |
110 | fStatsData.setTypeCount(fTestName, fEvent2.getName(), true, 1); | |
111 | fStatsData.setTypeCount(fTestName, fEvent3.getName(), true, 1); | |
79e08fd0 BH |
112 | |
113 | provider = new TmfBaseColumnDataProvider(); | |
114 | } | |
115 | ||
116 | // ------------------------------------------------------------------------ | |
117 | // Get Column Data | |
118 | // ------------------------------------------------------------------------ | |
90ed5958 | 119 | |
64636df8 BH |
120 | /** |
121 | * Method with test cases. | |
122 | */ | |
90ed5958 | 123 | @Test |
79e08fd0 | 124 | public void testGetColumnData() { |
9fa32496 | 125 | List<TmfBaseColumnData> columnsData = provider.getColumnData(); |
79e08fd0 | 126 | assertNotNull("getColumnData", columnsData); |
df2b3dbb | 127 | assertEquals("getColumnData", 4, columnsData.size()); |
79e08fd0 | 128 | |
7588c810 | 129 | TmfStatisticsTreeNode parentNode = fStatsData.getNode(fTestName); |
578716e6 MK |
130 | TmfStatisticsTreeNode treeNode1 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent1.getName()); |
131 | TmfStatisticsTreeNode treeNode2 = fStatsData.getNode(fTestName, Messages.TmfStatisticsData_EventTypes, fEvent3.getName()); | |
79e08fd0 BH |
132 | ViewerComparator vComp = null; |
133 | for (TmfBaseColumnData columnData : columnsData) { | |
134 | assertNotNull("getColumnData", columnData); | |
135 | assertNotNull("getColumnData", columnData.getHeader()); | |
136 | assertNotNull("getColumnData", columnData.getTooltip()); | |
abbdd66a | 137 | |
79e08fd0 BH |
138 | // Testing labelProvider |
139 | ColumnLabelProvider labelProvider = columnData.getLabelProvider(); | |
140 | if (columnData.getHeader().compareTo(LEVEL_COLUMN) == 0) { | |
7588c810 | 141 | assertEquals("getColumnData", 0, labelProvider.getText(treeNode1).compareTo(treeNode1.getName())); |
79e08fd0 | 142 | } else if (columnData.getHeader().compareTo(EVENTS_COUNT_COLUMN) == 0) { |
df2b3dbb VP |
143 | // might not work because of machine local number format |
144 | assertEquals("getColumnData", "1", labelProvider.getText(treeNode1)); | |
79e08fd0 BH |
145 | } |
146 | ||
147 | // Testing comparator | |
148 | vComp = columnData.getComparator(); | |
149 | if (columnData.getHeader().compareTo(LEVEL_COLUMN) == 0) { | |
150 | assertTrue("getColumnData", vComp.compare(null, treeNode1, treeNode2) < 0); | |
151 | assertTrue("getColumnData", vComp.compare(null, treeNode2, treeNode1) > 0); | |
152 | assertTrue("getColumnData", vComp.compare(null, treeNode1, treeNode1) == 0); | |
153 | } else if (columnData.getHeader().compareTo(EVENTS_COUNT_COLUMN) == 0) { | |
89c06060 AM |
154 | assertTrue("getColumnData", vComp.compare(null, treeNode1, treeNode2) == 0); |
155 | assertTrue("getColumnData", vComp.compare(null, treeNode2, treeNode1) == 0); | |
79e08fd0 BH |
156 | assertTrue("getColumnData", vComp.compare(null, treeNode1, treeNode1) == 0); |
157 | } | |
158 | ||
159 | // Testing percentage provider | |
160 | ITmfColumnPercentageProvider percentProvider = columnData.getPercentageProvider(); | |
161 | if (columnData.getHeader().compareTo(LEVEL_COLUMN) == 0) { | |
162 | assertNull("getColumnData", percentProvider); | |
163 | } else if (columnData.getHeader().compareTo(EVENTS_COUNT_COLUMN) == 0) { | |
89c06060 | 164 | double percentage = (double) treeNode1.getValues().getTotal() / parentNode.getValues().getTotal(); |
90ed5958 | 165 | assertEquals("getColumnData", percentage, percentProvider.getPercentage(treeNode1), DELTA); |
79e08fd0 BH |
166 | } |
167 | } | |
168 | } | |
09667aa4 | 169 | } |