1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.tests
.control
.model
.impl
;
14 import java
.util
.LinkedList
;
15 import java
.util
.List
;
17 import junit
.framework
.TestCase
;
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
;
25 * The class <code>ChannelInfoTest</code> contains tests for the class <code>{@link SessionInfo}</code>.
28 @SuppressWarnings("nls")
29 public class SessionInfoTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
33 private ISessionInfo fSessionInfo1
= null;
34 private ISessionInfo fSessionInfo2
= null;
36 private IDomainInfo fDomainInfo1
= null;
37 private IDomainInfo fDomainInfo2
= null;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * Perform pre-test initialization.
47 * if the initialization fails for some reason
52 ModelImplFactory factory
= new ModelImplFactory();
53 fSessionInfo1
= factory
.getSessionInfo1();
54 fDomainInfo1
= factory
.getDomainInfo1();
55 fSessionInfo2
= factory
.getSessionInfo2();
56 fDomainInfo2
= factory
.getDomainInfo2();
60 * Perform post-test clean-up.
63 * if the clean-up fails for some reason
67 public void tearDown() {
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * Run the ChannelInfo() constructor test.
82 public void testSessionInfo() {
83 ISessionInfo result
= new SessionInfo("test");
84 assertNotNull(result
);
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
);
96 public void testSessionInfoCopy() {
97 SessionInfo sessionInfo
= new SessionInfo((SessionInfo
)fSessionInfo1
);
99 assertEquals(sessionInfo
.getName(), fSessionInfo1
.getName());
100 assertEquals(sessionInfo
.getSessionPath(), fSessionInfo1
.getSessionPath());
101 assertEquals(sessionInfo
.getSessionState(), fSessionInfo1
.getSessionState());
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
]);
110 public void testSessionCopy2() {
112 SessionInfo session
= null;
113 new SessionInfo(session
);
116 catch (IllegalArgumentException e
) {
122 * Run the long getNumberOfSubBuffers() method test.
125 public void testGetAndSetters() {
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]);
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
);
139 IDomainInfo
[] result
= session
.getDomains();
140 assertEquals(2, result
.length
);
141 assertEquals(fDomainInfo1
, result
[0]);
142 assertEquals(fDomainInfo2
, result
[1]);
144 session
.setSessionPath("/home/user");
145 assertEquals("/home/user", session
.getSessionPath());
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());
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());
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());
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());
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());
184 public void testToString_1() {
185 ISessionInfo fixture
= new SessionInfo("sessionName");
187 String result
= fixture
.toString();
189 // add additional test code here
190 assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],State=INACTIVE,Domains=)]", result
);
194 * Run the String toString() method test.
197 public void testToString_2() {
198 String result
= fSessionInfo1
.toString();
200 // add additional test code here
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)])])])]", result
);
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
208 public void testEqualsReflexivity() {
209 assertTrue("equals", fSessionInfo1
.equals(fSessionInfo1
));
210 assertTrue("equals", fSessionInfo2
.equals(fSessionInfo2
));
212 assertTrue("equals", !fSessionInfo1
.equals(fSessionInfo2
));
213 assertTrue("equals", !fSessionInfo2
.equals(fSessionInfo1
));
216 public void testEqualsSymmetry() {
217 SessionInfo event1
= new SessionInfo((SessionInfo
)fSessionInfo1
);
218 SessionInfo event2
= new SessionInfo((SessionInfo
)fSessionInfo2
);
220 assertTrue("equals", event1
.equals(fSessionInfo1
));
221 assertTrue("equals", fSessionInfo1
.equals(event1
));
223 assertTrue("equals", event2
.equals(fSessionInfo2
));
224 assertTrue("equals", fSessionInfo2
.equals(event2
));
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
);
232 assertTrue("equals", channel1
.equals(channel2
));
233 assertTrue("equals", channel2
.equals(channel3
));
234 assertTrue("equals", channel1
.equals(channel3
));
237 public void testEqualsNull() throws Exception
{
238 assertTrue("equals", !fSessionInfo1
.equals(null));
239 assertTrue("equals", !fSessionInfo2
.equals(null));
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
246 public void testHashCode() {
247 SessionInfo channel1
= new SessionInfo((SessionInfo
)fSessionInfo1
);
248 SessionInfo channel2
= new SessionInfo((SessionInfo
)fSessionInfo2
);
250 assertTrue("hashCode", fSessionInfo1
.hashCode() == channel1
.hashCode());
251 assertTrue("hashCode", fSessionInfo2
.hashCode() == channel2
.hashCode());
253 assertTrue("hashCode", fSessionInfo1
.hashCode() != channel2
.hashCode());
254 assertTrue("hashCode", fSessionInfo2
.hashCode() != channel1
.hashCode());