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