Commit | Line | Data |
---|---|---|
95bf10e7 | 1 | /******************************************************************************* |
8e964be1 | 2 | * Copyright (c) 2012-2013 Ericsson |
95bf10e7 AM |
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 | * Matthew Khouzam - Initial generation with CodePro tools | |
11 | * Alexandre Montplaisir - Clean up, consolidate redundant tests | |
12 | *******************************************************************************/ | |
13 | ||
a3fc8213 AM |
14 | package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor; |
15 | ||
b4f71e4a FC |
16 | import static org.junit.Assert.assertArrayEquals; |
17 | import static org.junit.Assert.assertEquals; | |
18 | import static org.junit.Assert.assertNotNull; | |
8e964be1 | 19 | import static org.junit.Assert.assertNull; |
6cfa0200 | 20 | import static org.junit.Assert.assertSame; |
5dd1fa65 | 21 | import static org.junit.Assume.assumeTrue; |
8e964be1 MK |
22 | |
23 | import java.util.Set; | |
a3fc8213 | 24 | |
a3fc8213 AM |
25 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfIterator; |
26 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; | |
6cfa0200 | 27 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEventFactory; |
a3fc8213 AM |
28 | import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace; |
29 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; | |
81c8e6f7 | 30 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; |
9ac63b5b | 31 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; |
6cfa0200 | 32 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
a3fc8213 | 33 | import org.junit.Before; |
6cfa0200 | 34 | import org.junit.BeforeClass; |
a3fc8213 AM |
35 | import org.junit.Test; |
36 | ||
37 | /** | |
95bf10e7 AM |
38 | * The class <code>CtfTmfEventTest</code> contains tests for the class |
39 | * <code>{@link CtfTmfEvent}</code>. | |
a3fc8213 AM |
40 | * |
41 | * @author ematkho | |
42 | * @version $Revision: 1.0 $ | |
43 | */ | |
44 | public class CtfTmfEventTest { | |
45 | ||
9ac63b5b | 46 | private static final CtfTmfTestTrace testTrace = CtfTmfTestTrace.KERNEL; |
5dd1fa65 | 47 | |
6cfa0200 | 48 | private static CtfTmfEvent nullEvent; |
a3fc8213 AM |
49 | private CtfTmfEvent fixture; |
50 | ||
6cfa0200 AM |
51 | /** |
52 | * Test class initialization | |
53 | */ | |
54 | @BeforeClass | |
55 | public static void initialize() { | |
56 | nullEvent = CtfTmfEventFactory.getNullEvent(); | |
57 | } | |
58 | ||
a3fc8213 AM |
59 | /** |
60 | * Perform pre-test initialization. | |
a3fc8213 AM |
61 | */ |
62 | @Before | |
5dd1fa65 | 63 | public void setUp() { |
9ac63b5b AM |
64 | assumeTrue(testTrace.exists()); |
65 | CtfTmfTrace trace = testTrace.getTrace(); | |
a3fc8213 AM |
66 | CtfIterator tr = new CtfIterator(trace); |
67 | tr.advance(); | |
68 | fixture = tr.getCurrentEvent(); | |
69 | } | |
70 | ||
a3fc8213 AM |
71 | /** |
72 | * Run the CTFEvent(EventDefinition,StreamInputReader) constructor test. | |
73 | */ | |
74 | @Test | |
75 | public void testCTFEvent_read() { | |
76 | assertNotNull(fixture); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Run the int getCPU() method test. | |
81 | */ | |
82 | @Test | |
83 | public void testGetCPU() { | |
a3fc8213 | 84 | int result = nullEvent.getCPU(); |
a3fc8213 AM |
85 | assertEquals(-1, result); |
86 | } | |
87 | ||
a3fc8213 AM |
88 | /** |
89 | * Run the String getEventName() method test. | |
90 | */ | |
91 | @Test | |
92 | public void testGetEventName() { | |
a3fc8213 | 93 | String result = nullEvent.getEventName(); |
cad06250 | 94 | assertEquals("Empty CTF event", result); |
a3fc8213 AM |
95 | } |
96 | ||
97 | /** | |
98 | * Run the ArrayList<String> getFieldNames() method test. | |
99 | */ | |
100 | @Test | |
101 | public void testGetFieldNames() { | |
102 | String[] result = fixture.getContent().getFieldNames(); | |
103 | assertNotNull(result); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Run the Object getFieldValue(String) method test. | |
108 | */ | |
109 | @Test | |
110 | public void testGetFieldValue() { | |
cad06250 | 111 | String fieldName = "pid"; |
788ddcbc | 112 | ITmfEventField result = fixture.getContent().getField(fieldName); |
a3fc8213 AM |
113 | |
114 | assertNotNull(result); | |
788ddcbc | 115 | assertNotNull(result.getValue()); |
a3fc8213 AM |
116 | } |
117 | ||
118 | /** | |
119 | * Run the HashMap<String, CTFEventField> getFields() method test. | |
120 | */ | |
121 | @Test | |
122 | public void testGetFields() { | |
a3fc8213 | 123 | ITmfEventField[] fields = nullEvent.getContent().getFields(); |
81c8e6f7 MK |
124 | ITmfEventField[] fields2 = new ITmfEventField[0]; |
125 | assertArrayEquals(fields2, fields); | |
a3fc8213 AM |
126 | } |
127 | ||
128 | /** | |
129 | * Run the long getID() method test. | |
130 | */ | |
131 | @Test | |
132 | public void testGetID() { | |
a3fc8213 | 133 | long result = nullEvent.getID(); |
a3fc8213 AM |
134 | assertEquals(-1L, result); |
135 | } | |
136 | ||
a3fc8213 AM |
137 | /** |
138 | * Run the long getTimestamp() method test. | |
a3fc8213 AM |
139 | */ |
140 | @Test | |
141 | public void testGetTimestamp() { | |
58f3bc52 | 142 | long result = nullEvent.getTimestamp().getValue(); |
a3fc8213 AM |
143 | assertEquals(-1L, result); |
144 | } | |
81c8e6f7 | 145 | |
95bf10e7 | 146 | /** |
6cfa0200 | 147 | * Test the getters for the reference, source and type. |
95bf10e7 | 148 | */ |
81c8e6f7 | 149 | @Test |
95bf10e7 | 150 | public void testGetters() { |
81c8e6f7 MK |
151 | long rank = fixture.getRank(); |
152 | CtfTmfTrace trace = fixture.getTrace(); | |
81c8e6f7 MK |
153 | String reference = fixture.getReference(); |
154 | String source = fixture.getSource(); | |
155 | ITmfEventType type = fixture.getType(); | |
5dd1fa65 | 156 | assertEquals(ITmfContext.UNKNOWN_RANK, rank); |
cad06250 AM |
157 | assertEquals("test", trace.getName()); |
158 | assertEquals("channel0_1", reference); | |
159 | assertEquals("1", source); | |
160 | assertEquals("lttng_statedump_vm_map", type.toString()); | |
81c8e6f7 MK |
161 | } |
162 | ||
8e964be1 MK |
163 | /** |
164 | * Test the custom CTF attributes methods. The test trace doesn't have any, | |
165 | * so the list of attributes should be empty. | |
166 | */ | |
167 | @Test | |
168 | public void testCustomAttributes() { | |
169 | Set<String> attributes = fixture.listCustomAttributes(); | |
170 | assertEquals(0, attributes.size()); | |
171 | ||
cad06250 | 172 | String attrib = fixture.getCustomAttribute("bozo"); |
8e964be1 MK |
173 | assertNull(attrib); |
174 | } | |
175 | ||
95bf10e7 AM |
176 | /** |
177 | * Test the toString() method | |
178 | */ | |
81c8e6f7 | 179 | @Test |
0879b6b9 | 180 | public void testToString() { |
81c8e6f7 | 181 | String s = fixture.getContent().toString(); |
cad06250 | 182 | assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s); |
81c8e6f7 | 183 | } |
6cfa0200 AM |
184 | |
185 | /** | |
186 | * Test the {@link CtfTmfEventFactory#getNullEvent()} method, and the | |
187 | * nullEvent's values. | |
188 | */ | |
189 | @Test | |
190 | public void testNullEvent() { | |
191 | CtfTmfEvent nullEvent2 = CtfTmfEventFactory.getNullEvent(); | |
192 | assertSame(nullEvent2, nullEvent); | |
193 | assertNotNull(nullEvent); | |
194 | assertEquals(-1, nullEvent.getCPU()); | |
cad06250 AM |
195 | assertEquals("Empty CTF event", nullEvent.getEventName()); |
196 | assertEquals("No stream", nullEvent.getReference()); | |
6cfa0200 AM |
197 | assertArrayEquals(new ITmfEventField[0], nullEvent.getContent().getFields()); |
198 | assertEquals(-1L, nullEvent.getID()); | |
199 | assertEquals(-1L, nullEvent.getTimestamp().getValue()); | |
200 | } | |
a3fc8213 | 201 | } |