Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
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 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.tests.control.model.impl; | |
13 | ||
14 | import java.util.LinkedList; | |
15 | import java.util.List; | |
16 | ||
17 | import junit.framework.TestCase; | |
18 | ||
19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; | |
21 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo; | |
23 | ||
24 | /** | |
25 | * The class <code>ChannelInfoTest</code> contains tests for the class <code>{@link SessionInfo}</code>. | |
26 | * | |
27 | */ | |
28 | @SuppressWarnings("nls") | |
29 | public class SessionInfoTest extends TestCase { | |
30 | // ------------------------------------------------------------------------ | |
31 | // Test data | |
32 | // ------------------------------------------------------------------------ | |
33 | private ISessionInfo fSessionInfo1 = null; | |
34 | private ISessionInfo fSessionInfo2 = null; | |
35 | ||
36 | private IDomainInfo fDomainInfo1 = null; | |
37 | private IDomainInfo fDomainInfo2 = null; | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Housekeeping | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
43 | /** | |
44 | * Perform pre-test initialization. | |
45 | * | |
46 | * @throws Exception | |
47 | * if the initialization fails for some reason | |
48 | * | |
49 | */ | |
50 | @Override | |
51 | public void setUp() { | |
52 | ModelImplFactory factory = new ModelImplFactory(); | |
53 | fSessionInfo1 = factory.getSessionInfo1(); | |
54 | fDomainInfo1 = factory.getDomainInfo1(); | |
55 | fSessionInfo2 = factory.getSessionInfo2(); | |
56 | fDomainInfo2 = factory.getDomainInfo2(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Perform post-test clean-up. | |
61 | * | |
62 | * @throws Exception | |
63 | * if the clean-up fails for some reason | |
64 | * | |
65 | */ | |
66 | @Override | |
67 | public void tearDown() { | |
68 | } | |
69 | ||
70 | // ------------------------------------------------------------------------ | |
71 | // Tests | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
74 | // ------------------------------------------------------------------------ | |
75 | // Constructors | |
76 | // ------------------------------------------------------------------------ | |
77 | ||
78 | /** | |
79 | * Run the ChannelInfo() constructor test. | |
80 | * | |
81 | */ | |
82 | public void testSessionInfo() { | |
83 | ISessionInfo result = new SessionInfo("test"); | |
84 | assertNotNull(result); | |
85 | ||
86 | assertEquals("test", result.getName()); | |
87 | assertEquals("", result.getSessionPath()); | |
88 | TraceSessionState state = result.getSessionState(); | |
89 | assertEquals("inactive", state.getInName()); | |
90 | assertEquals("INACTIVE", state.name()); | |
91 | assertEquals("INACTIVE", state.toString()); | |
92 | assertEquals(0, state.ordinal()); | |
93 | assertEquals(0, result.getDomains().length); | |
94 | } | |
95 | ||
96 | public void testSessionInfoCopy() { | |
97 | SessionInfo sessionInfo = new SessionInfo((SessionInfo)fSessionInfo1); | |
98 | ||
99 | assertEquals(sessionInfo.getName(), fSessionInfo1.getName()); | |
100 | assertEquals(sessionInfo.getSessionPath(), fSessionInfo1.getSessionPath()); | |
101 | assertEquals(sessionInfo.getSessionState(), fSessionInfo1.getSessionState()); | |
102 | ||
103 | IDomainInfo[] orignalDomains = fSessionInfo1.getDomains(); | |
104 | IDomainInfo[] resultDomains = sessionInfo.getDomains(); | |
105 | for (int i = 0; i < orignalDomains.length; i++) { | |
106 | assertEquals(orignalDomains[i], resultDomains[i]); | |
107 | } | |
108 | } | |
109 | ||
110 | public void testSessionCopy2() { | |
111 | try { | |
112 | SessionInfo session = null; | |
113 | new SessionInfo(session); | |
114 | fail("null copy"); | |
115 | } | |
116 | catch (IllegalArgumentException e) { | |
117 | // Success | |
118 | } | |
119 | } | |
120 | ||
121 | /** | |
122 | * Run the long getNumberOfSubBuffers() method test. | |
123 | * | |
124 | */ | |
125 | public void testGetAndSetters() { | |
126 | ||
127 | // Note that addDomain() has been executed in setUp() | |
128 | // check get method here | |
129 | assertEquals(1, fSessionInfo1.getDomains().length); | |
130 | assertNotNull(fSessionInfo1.getDomains()[0]); | |
131 | assertEquals(fDomainInfo1, fSessionInfo1.getDomains()[0]); | |
132 | ||
133 | ISessionInfo session = new SessionInfo("session"); | |
134 | List<IDomainInfo> list = new LinkedList<IDomainInfo>(); | |
135 | list.add(fDomainInfo1); | |
136 | list.add(fDomainInfo2); | |
137 | session.setDomains(list); | |
138 | ||
139 | IDomainInfo[] result = session.getDomains(); | |
140 | assertEquals(2, result.length); | |
141 | assertEquals(fDomainInfo1, result[0]); | |
142 | assertEquals(fDomainInfo2, result[1]); | |
143 | ||
144 | session.setSessionPath("/home/user"); | |
145 | assertEquals("/home/user", session.getSessionPath()); | |
146 | ||
147 | session.setSessionState("active"); | |
148 | TraceSessionState state = session.getSessionState(); | |
149 | state = session.getSessionState(); | |
150 | assertEquals("active", state.getInName()); | |
151 | assertEquals("ACTIVE", state.name()); | |
152 | assertEquals("ACTIVE", state.toString()); | |
153 | assertEquals(1, state.ordinal()); | |
154 | ||
155 | session.setSessionState("inactive"); | |
156 | state = session.getSessionState(); | |
157 | assertEquals("inactive", state.getInName()); | |
158 | assertEquals("INACTIVE", state.name()); | |
159 | assertEquals("INACTIVE", state.toString()); | |
160 | assertEquals(0, state.ordinal()); | |
161 | ||
162 | session.setSessionState("test"); | |
163 | state = session.getSessionState(); | |
164 | assertEquals("inactive", state.getInName()); | |
165 | assertEquals("INACTIVE", state.name()); | |
166 | assertEquals("INACTIVE", state.toString()); | |
167 | assertEquals(0, state.ordinal()); | |
168 | ||
169 | session.setSessionState(TraceSessionState.ACTIVE); | |
170 | state = session.getSessionState(); | |
171 | assertEquals("active", state.getInName()); | |
172 | assertEquals("ACTIVE", state.name()); | |
173 | assertEquals("ACTIVE", state.toString()); | |
174 | assertEquals(1, state.ordinal()); | |
175 | ||
176 | session.setSessionState(TraceSessionState.INACTIVE); | |
177 | state = session.getSessionState(); | |
178 | assertEquals("inactive", state.getInName()); | |
179 | assertEquals("INACTIVE", state.name()); | |
180 | assertEquals("INACTIVE", state.toString()); | |
181 | assertEquals(0, state.ordinal()); | |
182 | } | |
183 | ||
184 | public void testToString_1() { | |
185 | ISessionInfo fixture = new SessionInfo("sessionName"); | |
186 | ||
187 | String result = fixture.toString(); | |
188 | ||
189 | // add additional test code here | |
190 | assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],State=INACTIVE,Domains=)]", result); | |
191 | } | |
192 | ||
193 | /** | |
194 | * Run the String toString() method test. | |
195 | * | |
196 | */ | |
197 | public void testToString_2() { | |
198 | String result = fSessionInfo1.toString(); | |
199 | ||
200 | // add additional test code here | |
9d8a90ad | 201 | assertEquals("[SessionInfo([TraceInfo(Name=session1)],State=ACTIVE,Domains=[DomainInfo([TraceInfo(Name=test1)],Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)])],isKernel=false)])]", result); |
eb1bab5b BH |
202 | } |
203 | ||
204 | // ------------------------------------------------------------------------ | |
205 | // equals | |
206 | // ------------------------------------------------------------------------ | |
207 | ||
208 | public void testEqualsReflexivity() { | |
209 | assertTrue("equals", fSessionInfo1.equals(fSessionInfo1)); | |
210 | assertTrue("equals", fSessionInfo2.equals(fSessionInfo2)); | |
211 | ||
212 | assertTrue("equals", !fSessionInfo1.equals(fSessionInfo2)); | |
213 | assertTrue("equals", !fSessionInfo2.equals(fSessionInfo1)); | |
214 | } | |
215 | ||
216 | public void testEqualsSymmetry() { | |
217 | SessionInfo event1 = new SessionInfo((SessionInfo)fSessionInfo1); | |
218 | SessionInfo event2 = new SessionInfo((SessionInfo)fSessionInfo2); | |
219 | ||
220 | assertTrue("equals", event1.equals(fSessionInfo1)); | |
221 | assertTrue("equals", fSessionInfo1.equals(event1)); | |
222 | ||
223 | assertTrue("equals", event2.equals(fSessionInfo2)); | |
224 | assertTrue("equals", fSessionInfo2.equals(event2)); | |
225 | } | |
226 | ||
227 | public void testEqualsTransivity() { | |
228 | SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1); | |
229 | SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo1); | |
230 | SessionInfo channel3 = new SessionInfo((SessionInfo)fSessionInfo1); | |
231 | ||
232 | assertTrue("equals", channel1.equals(channel2)); | |
233 | assertTrue("equals", channel2.equals(channel3)); | |
234 | assertTrue("equals", channel1.equals(channel3)); | |
235 | } | |
236 | ||
237 | public void testEqualsNull() throws Exception { | |
238 | assertTrue("equals", !fSessionInfo1.equals(null)); | |
239 | assertTrue("equals", !fSessionInfo2.equals(null)); | |
240 | } | |
241 | ||
242 | // ------------------------------------------------------------------------ | |
243 | // hashCode | |
244 | // ------------------------------------------------------------------------ | |
245 | ||
246 | public void testHashCode() { | |
247 | SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1); | |
248 | SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo2); | |
249 | ||
250 | assertTrue("hashCode", fSessionInfo1.hashCode() == channel1.hashCode()); | |
251 | assertTrue("hashCode", fSessionInfo2.hashCode() == channel2.hashCode()); | |
252 | ||
253 | assertTrue("hashCode", fSessionInfo1.hashCode() != channel2.hashCode()); | |
254 | assertTrue("hashCode", fSessionInfo2.hashCode() != channel1.hashCode()); | |
255 | }} |