Commit | Line | Data |
---|---|---|
a3fc8213 AM |
1 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; |
2 | ||
b4f71e4a FC |
3 | import static org.junit.Assert.assertArrayEquals; |
4 | import static org.junit.Assert.assertEquals; | |
5 | import static org.junit.Assert.assertNotNull; | |
a3fc8213 AM |
6 | |
7 | import java.io.FileNotFoundException; | |
8 | ||
9 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator; | |
10 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; | |
11 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; | |
12 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; | |
b4f71e4a | 13 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; |
a3fc8213 AM |
14 | import org.junit.After; |
15 | import org.junit.Before; | |
16 | import org.junit.Test; | |
17 | ||
18 | /** | |
19 | * The class <code>CTFEventTest</code> contains tests for the class | |
20 | * <code>{@link CTFEvent}</code>. | |
21 | * | |
22 | * @author ematkho | |
23 | * @version $Revision: 1.0 $ | |
24 | */ | |
25 | public class CtfTmfEventTest { | |
26 | ||
27 | private CtfTmfEvent fixture; | |
28 | ||
29 | /** | |
30 | * Launch the test. | |
31 | * | |
32 | * @param args | |
33 | * the command line arguments | |
34 | */ | |
35 | public static void main(String[] args) { | |
36 | new org.junit.runner.JUnitCore().run(CtfTmfEventTest.class); | |
37 | } | |
38 | ||
39 | /** | |
40 | * Perform pre-test initialization. | |
41 | * | |
42 | * @throws FileNotFoundException | |
43 | */ | |
44 | @Before | |
b4f71e4a | 45 | public void setUp() throws TmfTraceException { |
a3fc8213 AM |
46 | CtfTmfTrace trace = TestParams.createTrace(); |
47 | CtfIterator tr = new CtfIterator(trace); | |
48 | tr.advance(); | |
49 | fixture = tr.getCurrentEvent(); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Perform post-test clean-up. | |
54 | */ | |
55 | @After | |
56 | public void tearDown() { | |
57 | // Add additional tear down code here | |
58 | } | |
59 | ||
60 | /** | |
61 | * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test. | |
62 | */ | |
63 | @Test | |
64 | public void testCTFEvent_read() { | |
65 | assertNotNull(fixture); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Run the int getCPU() method test. | |
70 | */ | |
71 | @Test | |
72 | public void testGetCPU() { | |
73 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
74 | int result = nullEvent.getCPU(); | |
75 | ||
76 | assertEquals(-1, result); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Run the String getChannelName() method test. | |
81 | */ | |
82 | @Test | |
83 | public void testGetChannelName() { | |
84 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
85 | String result = nullEvent.getChannelName(); | |
86 | ||
87 | assertEquals("No stream", result); //$NON-NLS-1$ | |
88 | } | |
89 | ||
90 | /** | |
91 | * Run the String getEventName() method test. | |
92 | */ | |
93 | @Test | |
94 | public void testGetEventName() { | |
95 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
96 | String result = nullEvent.getEventName(); | |
97 | ||
98 | assertEquals("Empty CTF event", result); //$NON-NLS-1$ | |
99 | } | |
100 | ||
101 | /** | |
102 | * Run the ArrayList<String> getFieldNames() method test. | |
103 | */ | |
104 | @Test | |
105 | public void testGetFieldNames() { | |
106 | String[] result = fixture.getContent().getFieldNames(); | |
107 | assertNotNull(result); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Run the Object getFieldValue(String) method test. | |
112 | */ | |
113 | @Test | |
114 | public void testGetFieldValue() { | |
115 | String fieldName = "id"; //$NON-NLS-1$ | |
116 | Object result = fixture.getContent().getField(fieldName).getValue(); | |
117 | ||
118 | assertNotNull(result); | |
119 | } | |
120 | ||
121 | /** | |
122 | * Run the HashMap<String, CTFEventField> getFields() method test. | |
123 | */ | |
124 | @Test | |
125 | public void testGetFields() { | |
126 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
127 | ITmfEventField[] fields = nullEvent.getContent().getFields(); | |
128 | ||
129 | assertArrayEquals(null, fields); | |
130 | } | |
131 | ||
132 | /** | |
133 | * Run the long getID() method test. | |
134 | */ | |
135 | @Test | |
136 | public void testGetID() { | |
137 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
138 | long result = nullEvent.getID(); | |
139 | ||
140 | assertEquals(-1L, result); | |
141 | } | |
142 | ||
143 | ||
144 | /** | |
145 | * Run the CTFEvent getNullEvent() method test. | |
146 | */ | |
147 | @Test | |
148 | public void testGetNullEvent() { | |
149 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
150 | ||
151 | assertNotNull(nullEvent); | |
152 | assertEquals(-1, nullEvent.getCPU()); | |
153 | assertEquals("Empty CTF event", nullEvent.getEventName()); //$NON-NLS-1$ | |
154 | assertEquals("No stream", nullEvent.getChannelName()); //$NON-NLS-1$ | |
155 | assertArrayEquals(null, nullEvent.getContent().getFields()); | |
156 | assertEquals(-1L, nullEvent.getID()); | |
157 | assertEquals(-1L, nullEvent.getTimestampValue()); | |
158 | } | |
159 | ||
160 | /** | |
161 | * Run the long getTimestamp() method test. | |
162 | * | |
163 | */ | |
164 | @Test | |
165 | public void testGetTimestamp() { | |
166 | CtfTmfEvent nullEvent = CtfTmfEvent.getNullEvent(); | |
167 | long result = nullEvent.getTimestampValue(); | |
168 | ||
169 | assertEquals(-1L, result); | |
170 | } | |
171 | } |