| 1 | package org.eclipse.linuxtools.ctf.core.tests.types; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertFalse; |
| 5 | import static org.junit.Assert.assertNotNull; |
| 6 | import static org.junit.Assert.assertNull; |
| 7 | import static org.junit.Assert.assertTrue; |
| 8 | |
| 9 | import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; |
| 10 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; |
| 11 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; |
| 12 | import org.eclipse.linuxtools.ctf.core.tests.TestParams; |
| 13 | import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; |
| 14 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; |
| 15 | import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader; |
| 16 | import org.eclipse.linuxtools.ctf.core.trace.Stream; |
| 17 | import org.junit.After; |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | /** |
| 22 | * The class <code>EventDeclarationTest</code> contains tests for the class |
| 23 | * <code>{@link EventDeclaration}</code>. |
| 24 | * |
| 25 | * @author ematkho |
| 26 | * @version $Revision: 1.0 $ |
| 27 | */ |
| 28 | @SuppressWarnings("javadoc") |
| 29 | public class EventDeclarationTest { |
| 30 | |
| 31 | private EventDeclaration fixture; |
| 32 | |
| 33 | /** |
| 34 | * Launch the test. |
| 35 | * |
| 36 | * @param args |
| 37 | * the command line arguments |
| 38 | */ |
| 39 | public static void main(String[] args) { |
| 40 | new org.junit.runner.JUnitCore().run(EventDeclarationTest.class); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Perform pre-test initialization. |
| 45 | * |
| 46 | * @throws CTFReaderException |
| 47 | */ |
| 48 | @Before |
| 49 | public void setUp() throws CTFReaderException { |
| 50 | fixture = new EventDeclaration(); |
| 51 | fixture.setContext(new StructDeclaration(1L)); |
| 52 | fixture.setId(1L); |
| 53 | fixture.setFields(new StructDeclaration(1L)); |
| 54 | fixture.setStream(new Stream(TestParams.createTrace())); |
| 55 | fixture.setName(""); //$NON-NLS-1$ |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Perform post-test clean-up. |
| 60 | */ |
| 61 | @After |
| 62 | public void tearDown() { |
| 63 | // Add additional tear down code here |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Run the EventDeclaration() constructor test. |
| 68 | */ |
| 69 | @Test |
| 70 | public void testEventDeclaration() { |
| 71 | EventDeclaration result = new EventDeclaration(); |
| 72 | assertNotNull(result); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Run the boolean contextIsSet() method test. |
| 77 | */ |
| 78 | @Test |
| 79 | public void testContextIsSet() { |
| 80 | boolean result = fixture.contextIsSet(); |
| 81 | assertTrue(result); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Run the boolean contextIsSet() method test. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testContextIsSet_null() { |
| 89 | fixture.setContext((StructDeclaration) null); |
| 90 | |
| 91 | boolean result = fixture.contextIsSet(); |
| 92 | assertFalse(result); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Run the boolean equals(Object) method test. |
| 97 | * |
| 98 | * @throws CTFReaderException |
| 99 | */ |
| 100 | @Test |
| 101 | public void testEquals() throws CTFReaderException { |
| 102 | EventDeclaration obj = new EventDeclaration(); |
| 103 | obj.setContext(new StructDeclaration(1L)); |
| 104 | obj.setId(1L); |
| 105 | obj.setFields(new StructDeclaration(1L)); |
| 106 | obj.setStream(new Stream(TestParams.createTrace())); |
| 107 | obj.setName(""); //$NON-NLS-1$ |
| 108 | |
| 109 | assertTrue(fixture.equals(fixture)); |
| 110 | boolean result = fixture.equals(obj); |
| 111 | assertFalse(result); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Run the boolean equals(Object) method test. |
| 116 | */ |
| 117 | @Test |
| 118 | public void testEquals_null() { |
| 119 | Object obj = null; |
| 120 | |
| 121 | boolean result = fixture.equals(obj); |
| 122 | assertFalse(result); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Run the boolean equals(Object) method test. |
| 127 | */ |
| 128 | @Test |
| 129 | public void testEquals_emptyObject() { |
| 130 | Object obj = new Object(); |
| 131 | |
| 132 | boolean result = fixture.equals(obj); |
| 133 | assertFalse(result); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Run the boolean equals(Object) method test. |
| 138 | */ |
| 139 | @Test |
| 140 | public void testEquals_other1() { |
| 141 | EventDeclaration obj = new EventDeclaration(); |
| 142 | obj.setContext(fixture.getContext()); |
| 143 | |
| 144 | boolean result = fixture.equals(obj); |
| 145 | assertFalse(result); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Run the boolean equals(Object) method test. |
| 150 | */ |
| 151 | @Test |
| 152 | public void testEquals_other2() { |
| 153 | EventDeclaration obj = new EventDeclaration(); |
| 154 | obj.setContext(new StructDeclaration(1L)); |
| 155 | obj.setFields(new StructDeclaration(1L)); |
| 156 | |
| 157 | boolean result = fixture.equals(obj); |
| 158 | assertFalse(result); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Run the boolean equals(Object) method test. |
| 163 | */ |
| 164 | @Test |
| 165 | public void testEquals_other3() { |
| 166 | EventDeclaration obj = new EventDeclaration(); |
| 167 | obj.setContext(new StructDeclaration(1L)); |
| 168 | obj.setId(1L); |
| 169 | obj.setFields(new StructDeclaration(1L)); |
| 170 | |
| 171 | boolean result = fixture.equals(obj); |
| 172 | assertFalse(result); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Run the boolean equals(Object) method test. |
| 177 | */ |
| 178 | @Test |
| 179 | public void testEquals_other4() { |
| 180 | EventDeclaration obj = new EventDeclaration(); |
| 181 | obj.setContext(new StructDeclaration(1L)); |
| 182 | obj.setId(1L); |
| 183 | obj.setFields(new StructDeclaration(1L)); |
| 184 | obj.setName(""); //$NON-NLS-1$ |
| 185 | |
| 186 | boolean result = fixture.equals(obj); |
| 187 | assertFalse(result); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Run the boolean fieldsIsSet() method test. |
| 192 | */ |
| 193 | @Test |
| 194 | public void testFieldsIsSet() { |
| 195 | boolean result = fixture.fieldsIsSet(); |
| 196 | assertTrue(result); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Run the boolean fieldsIsSet() method test. |
| 201 | */ |
| 202 | @Test |
| 203 | public void testFieldsIsSet_null() { |
| 204 | fixture.setFields((StructDeclaration) null); |
| 205 | |
| 206 | boolean result = fixture.fieldsIsSet(); |
| 207 | assertFalse(result); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Run the StructDeclaration getFields() method test. |
| 212 | */ |
| 213 | @Test |
| 214 | public void testGetFields() { |
| 215 | StructDeclaration result = fixture.getFields(); |
| 216 | assertNotNull(result); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Run the Long getId() method test. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testGetId() { |
| 224 | Long result = fixture.getId(); |
| 225 | assertNotNull(result); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Run the String getName() method test. |
| 230 | */ |
| 231 | @Test |
| 232 | public void testGetName() { |
| 233 | String result = fixture.getName(); |
| 234 | assertNotNull(result); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Run the Stream getStream() method test. |
| 239 | */ |
| 240 | @Test |
| 241 | public void testGetStream() { |
| 242 | Stream result = fixture.getStream(); |
| 243 | assertNotNull(result); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Run the int hashCode() method test. |
| 248 | */ |
| 249 | @Test |
| 250 | public void testHashCode() { |
| 251 | int result = fixture.hashCode(); |
| 252 | assertTrue(0 != result); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Run the int hashCode() method test. |
| 257 | */ |
| 258 | @Test |
| 259 | public void testHashCode_null() { |
| 260 | fixture.setStream((Stream) null); |
| 261 | fixture.setName((String) null); |
| 262 | |
| 263 | int result = fixture.hashCode(); |
| 264 | assertTrue(0 != result); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Run the boolean idIsSet() method test. |
| 269 | */ |
| 270 | @Test |
| 271 | public void testIdIsSet() { |
| 272 | boolean result = fixture.idIsSet(); |
| 273 | assertTrue(result); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Run the boolean nameIsSet() method test. |
| 278 | */ |
| 279 | @Test |
| 280 | public void testNameIsSet() { |
| 281 | boolean result = fixture.nameIsSet(); |
| 282 | assertTrue(result); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Run the boolean nameIsSet() method test. |
| 287 | */ |
| 288 | @Test |
| 289 | public void testNameIsSet_null() { |
| 290 | fixture.setName((String) null); |
| 291 | |
| 292 | boolean result = fixture.nameIsSet(); |
| 293 | assertFalse(result); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Run the boolean streamIsSet() method test. |
| 298 | */ |
| 299 | @Test |
| 300 | public void testStreamIsSet() { |
| 301 | boolean result = fixture.streamIsSet(); |
| 302 | assertTrue(result); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Run the boolean streamIsSet() method test. |
| 307 | */ |
| 308 | @Test |
| 309 | public void testStreamIsSet_null() { |
| 310 | fixture.setStream((Stream) null); |
| 311 | |
| 312 | boolean result = fixture.streamIsSet(); |
| 313 | assertEquals(false, result); |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Test for the EventDefinition class |
| 318 | * |
| 319 | * @throws CTFReaderException |
| 320 | */ |
| 321 | @Test |
| 322 | public void testEventDefinition() throws CTFReaderException { |
| 323 | CTFTrace trace = TestParams.createTrace(); |
| 324 | CTFTraceReader tr = new CTFTraceReader(trace); |
| 325 | tr.advance(); |
| 326 | EventDefinition ed = new EventDefinition(null, null); |
| 327 | ed = tr.getCurrentEventDef(); |
| 328 | assertNotNull(ed); |
| 329 | assertNotNull(ed.getPath()); |
| 330 | assertNotNull(ed.getDeclaration()); |
| 331 | assertNotNull(ed.getFields()); |
| 332 | assertNull(ed.getContext()); |
| 333 | assertNotNull(ed.getPacketContext()); |
| 334 | assertNotNull(ed.getCPU()); |
| 335 | assertNotNull(ed.getPacketContext()); |
| 336 | assertNotNull(ed.getStreamInputReader()); |
| 337 | assertNull(ed.lookupDefinition("context")); //$NON-NLS-1$ |
| 338 | assertNotNull(ed.lookupDefinition("fields")); //$NON-NLS-1$ |
| 339 | assertNull(ed.lookupDefinition("other")); //$NON-NLS-1$ |
| 340 | assertNotNull(ed.toString()); |
| 341 | ed.setContext( ed.getFields()); |
| 342 | assertNotNull(ed.toString()); |
| 343 | } |
| 344 | |
| 345 | EventDeclaration e1; |
| 346 | EventDeclaration e2; |
| 347 | |
| 348 | |
| 349 | @Test |
| 350 | public void testEquals1(){ |
| 351 | e1 = new EventDeclaration(); |
| 352 | assertFalse(e1.equals(null)); |
| 353 | } |
| 354 | |
| 355 | @Test |
| 356 | public void testEquals2(){ |
| 357 | e1 = EventDeclaration.getLostEventDeclaration(); |
| 358 | assertFalse(e1.equals(new Long(23L))); |
| 359 | } |
| 360 | |
| 361 | @Test |
| 362 | public void testEquals3(){ |
| 363 | e1 = EventDeclaration.getLostEventDeclaration(); |
| 364 | assertEquals(e1,e1); |
| 365 | } |
| 366 | |
| 367 | @Test |
| 368 | public void testEquals4(){ |
| 369 | e1 = EventDeclaration.getLostEventDeclaration(); |
| 370 | e2 = EventDeclaration.getLostEventDeclaration(); |
| 371 | assertEquals(e1,e2); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void testEquals5(){ |
| 376 | e1 = EventDeclaration.getLostEventDeclaration(); |
| 377 | e2 = new EventDeclaration(); |
| 378 | assertFalse(e1.equals(e2)); |
| 379 | } |
| 380 | } |