Commit | Line | Data |
---|---|---|
d132bcc7 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
b0318660 | 3 | * |
d132bcc7 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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
d132bcc7 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9315aeee | 12 | package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl; |
d132bcc7 BH |
13 | |
14 | import junit.framework.TestCase; | |
15 | ||
9315aeee BH |
16 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IProbeEventInfo; |
17 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement; | |
18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; | |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.BaseEventInfo; | |
20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ProbeEventInfo; | |
d132bcc7 BH |
21 | |
22 | /** | |
23 | * The class <code>BaseEventInfoTest</code> contains test for the class <code>{@link BaseEventInfo}</code>. | |
24 | */ | |
b0318660 | 25 | @SuppressWarnings({"nls", "javadoc"}) |
d132bcc7 BH |
26 | public class ProbeEventInfoTest extends TestCase { |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Test data | |
30 | // ------------------------------------------------------------------------ | |
31 | private IProbeEventInfo fEventInfo1 = null; | |
32 | private IProbeEventInfo fEventInfo2 = null; | |
b0318660 | 33 | |
d132bcc7 BH |
34 | // ------------------------------------------------------------------------ |
35 | // Housekeeping | |
36 | // ------------------------------------------------------------------------ | |
37 | /** | |
38 | * Perform pre-test initialization. | |
39 | * | |
40 | * @throws Exception if the initialization fails for some reason | |
41 | * | |
42 | */ | |
43 | @Override | |
44 | public void setUp() throws Exception { | |
45 | ModelImplFactory factory = new ModelImplFactory(); | |
46 | fEventInfo1 = factory.getProbeEventInfo1(); | |
47 | fEventInfo2 = factory.getProbeEventInfo2(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Perform post-test clean-up. | |
52 | * | |
53 | * @throws Exception if the clean-up fails for some reason | |
54 | * | |
55 | */ | |
56 | @Override | |
57 | public void tearDown() throws Exception { | |
58 | } | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Tests | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | /** | |
65 | * Run the BaseEventInfo() constructor test. | |
66 | * | |
67 | */ | |
68 | public void testBaseEventInfo() { | |
69 | ProbeEventInfo fixture = new ProbeEventInfo("event"); | |
70 | assertNotNull(fixture); | |
b0318660 | 71 | |
d132bcc7 | 72 | TraceEventType result = fixture.getEventType(); |
b0318660 | 73 | |
d132bcc7 BH |
74 | assertEquals("event", fixture.getName()); |
75 | assertEquals("unknown", result.getInName()); | |
76 | assertEquals("UNKNOWN", result.name()); | |
77 | assertEquals("UNKNOWN", result.toString()); | |
78 | assertEquals(3, result.ordinal()); | |
b0318660 | 79 | |
d132bcc7 BH |
80 | TraceEnablement state = fixture.getState(); |
81 | assertEquals("disabled", state.getInName()); | |
82 | assertEquals("DISABLED", state.name()); | |
83 | assertEquals("DISABLED", state.toString()); | |
84 | assertEquals(0, state.ordinal()); | |
b0318660 | 85 | |
d132bcc7 BH |
86 | assertNull(fixture.getAddress()); |
87 | assertNull(fixture.getOffset()); | |
88 | assertNull(fixture.getSymbol()); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Test Copy Constructor | |
93 | */ | |
94 | public void testEventInfoCopy() { | |
95 | ProbeEventInfo info = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
b0318660 | 96 | |
d132bcc7 BH |
97 | assertEquals(fEventInfo1.getName(), info.getName()); |
98 | assertEquals(fEventInfo1.getEventType(), info.getEventType()); | |
99 | assertEquals(fEventInfo1.getState(), info.getState()); | |
100 | assertEquals(fEventInfo1.getAddress(), info.getAddress()); | |
101 | assertEquals(fEventInfo1.getOffset(), info.getOffset()); | |
102 | assertEquals(fEventInfo1.getSymbol(), info.getSymbol()); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Test Copy Constructor | |
107 | */ | |
108 | public void testEventCopy2() { | |
109 | try { | |
110 | ProbeEventInfo info = null; | |
111 | new ProbeEventInfo(info); | |
112 | fail("null copy"); | |
113 | } | |
114 | catch (IllegalArgumentException e) { | |
115 | // Success | |
116 | } | |
117 | } | |
b0318660 | 118 | |
d132bcc7 | 119 | /** |
b0318660 | 120 | * Getter/Setter tests |
d132bcc7 BH |
121 | */ |
122 | public void testGetAndSetter() { | |
123 | ProbeEventInfo fixture = new ProbeEventInfo("event"); | |
b0318660 | 124 | |
d132bcc7 BH |
125 | fixture.setAddress("0xc12344321"); |
126 | String result = fixture.getAddress(); | |
127 | ||
128 | assertNotNull(result); | |
129 | assertEquals("0xc12344321", result); | |
130 | ||
131 | fixture.setOffset("0x1000"); | |
132 | result = fixture.getOffset(); | |
133 | ||
134 | assertNotNull(result); | |
135 | assertEquals("0x1000", result); | |
136 | ||
137 | fixture.setSymbol("cpu_idle"); | |
138 | result = fixture.getSymbol(); | |
139 | ||
140 | assertNotNull(result); | |
141 | assertEquals("cpu_idle", result); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Run the String toString() method test. | |
146 | */ | |
147 | public void testToString_1() { | |
148 | assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)],fAddress=0xc1231234)]", fEventInfo1.toString()); | |
149 | assertEquals("[ProbeEventInfo([EventInfo([BaseEventInfo([TraceInfo(Name=probeEvent2)],type=UNKNOWN,level=TRACE_DEBUG)],State=DISABLED)],fOffset=0x100,fSymbol=init_post)]", fEventInfo2.toString()); | |
150 | } | |
151 | ||
152 | // ------------------------------------------------------------------------ | |
153 | // equals | |
154 | // ------------------------------------------------------------------------ | |
155 | public void testEqualsReflexivity() { | |
156 | assertTrue("equals", fEventInfo1.equals(fEventInfo1)); | |
157 | assertTrue("equals", fEventInfo2.equals(fEventInfo2)); | |
158 | ||
159 | assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); | |
160 | assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); | |
161 | } | |
b0318660 | 162 | |
d132bcc7 BH |
163 | public void testEqualsSymmetry() { |
164 | ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
165 | ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2); | |
166 | ||
167 | assertTrue("equals", info1.equals(fEventInfo1)); | |
168 | assertTrue("equals", fEventInfo1.equals(info1)); | |
169 | ||
170 | assertTrue("equals", info2.equals(fEventInfo2)); | |
171 | assertTrue("equals", fEventInfo2.equals(info2)); | |
172 | } | |
b0318660 | 173 | |
d132bcc7 BH |
174 | public void testEqualsTransivity() { |
175 | ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
176 | ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
177 | ProbeEventInfo info3 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
178 | ||
179 | assertTrue("equals", info1.equals(info2)); | |
180 | assertTrue("equals", info2.equals(info3)); | |
181 | assertTrue("equals", info1.equals(info3)); | |
182 | } | |
b0318660 | 183 | |
d132bcc7 BH |
184 | public void testEqualsNull() { |
185 | assertTrue("equals", !fEventInfo1.equals(null)); | |
186 | assertTrue("equals", !fEventInfo2.equals(null)); | |
187 | } | |
b0318660 | 188 | |
d132bcc7 BH |
189 | // ------------------------------------------------------------------------ |
190 | // hashCode | |
191 | // ------------------------------------------------------------------------ | |
192 | ||
193 | public void testHashCode() { | |
194 | ProbeEventInfo info1 = new ProbeEventInfo((ProbeEventInfo)fEventInfo1); | |
195 | ProbeEventInfo info2 = new ProbeEventInfo((ProbeEventInfo)fEventInfo2); | |
196 | ||
197 | assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); | |
198 | assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); | |
199 | ||
200 | assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); | |
201 | assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); | |
202 | } | |
203 | } |