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
.IBaseEventInfo
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IUstProviderInfo
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.BaseEventInfo
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.UstProviderInfo
;
25 * The class <code>ChannelInfoTest</code> contains tests for the class <code>{@link UstProviderInfo}</code>.
28 @SuppressWarnings("nls")
29 public class UstProviderInfoTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
33 private IUstProviderInfo fUstProviderInfo1
= null;
34 private IUstProviderInfo fUstProviderInfo2
= null;
36 private IBaseEventInfo fEventInfo1
= null;
37 private IBaseEventInfo fEventInfo2
= null;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * Perform pre-test initialization.
47 * if the initialization fails for some reason
52 ModelImplFactory factory
= new ModelImplFactory();
53 fUstProviderInfo1
= factory
.getUstProviderInfo1();
54 fUstProviderInfo2
= factory
.getUstProviderInfo2();
55 fEventInfo1
= factory
.getBaseEventInfo1();
56 fEventInfo1
= factory
.getBaseEventInfo2();
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 UstProviderInfo() constructor test.
82 public void testUstProviderInfo() {
83 IUstProviderInfo result
= new UstProviderInfo("test");
84 assertNotNull(result
);
86 assertEquals("test", result
.getName());
87 assertEquals(0, result
.getPid());
88 assertEquals(0, result
.getEvents().length
);
91 public void testUstProviderInfoCopy() {
92 IUstProviderInfo providerInf
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
94 assertEquals(fUstProviderInfo1
.getName(), providerInf
.getName());
95 assertEquals(fUstProviderInfo1
.getPid(), providerInf
.getPid());
96 assertEquals(fUstProviderInfo1
.getEvents().length
, providerInf
.getEvents().length
);
98 IBaseEventInfo
[] orignalEvents
= fUstProviderInfo1
.getEvents();
99 IBaseEventInfo
[] resultEvents
= providerInf
.getEvents();
100 for (int i
= 0; i
< orignalEvents
.length
; i
++) {
101 assertEquals(orignalEvents
[i
], resultEvents
[i
]);
105 public void testUstProviderCopy2() {
107 UstProviderInfo providerInfo
= null;
108 new UstProviderInfo(providerInfo
);
111 catch (IllegalArgumentException e
) {
117 * Run the IEventInfo[] getEvents() method test.
120 public void testGetAndSetters() {
121 IUstProviderInfo fixture
= new UstProviderInfo("test");
122 fixture
.setPid(2468);
125 IBaseEventInfo event
= new BaseEventInfo("event");
126 fixture
.addEvent(event
);
128 // Verify the stored events
129 IBaseEventInfo
[] result
= fixture
.getEvents();
131 assertNotNull(result
);
132 assertEquals(1, result
.length
);
133 assertNotNull(result
[0]);
134 assertTrue(event
.equals(result
[0]));
136 assertEquals(2468, fixture
.getPid());
140 * Run the void setEvents(List<IBaseEventInfo>) method test.
143 public void testSetEvents_1() {
144 UstProviderInfo fixture
= new UstProviderInfo("test");
145 fixture
.setPid(2468);
146 List
<IBaseEventInfo
> events
= new LinkedList
<IBaseEventInfo
>();
147 events
.add(fEventInfo1
);
148 events
.add(fEventInfo2
);
149 fixture
.setEvents(events
);
151 IBaseEventInfo
[] infos
= fixture
.getEvents();
153 assertEquals(events
.size(), infos
.length
);
155 for (int i
= 0; i
< infos
.length
; i
++) {
156 assertEquals(events
.get(i
), infos
[i
]);
160 public void testToString_1() {
161 UstProviderInfo fixture
= new UstProviderInfo("test");
162 fixture
.setPid(2468);
163 String result
= fixture
.toString();
165 assertEquals("[EventInfo([TraceInfo(Name=test)],PID=2468,Events=None)]", result
);
169 * Run the String toString() method test.
172 public void testToString_2() {
173 String result
= fUstProviderInfo2
.toString();
174 assertEquals("[EventInfo([TraceInfo(Name=myUST2)],PID=2345,Events=[BaseEventInfo([TraceInfo(Name=event1)],type=UNKNOWN,level=TRACE_DEFAULT)][BaseEventInfo([TraceInfo(Name=event2)],type=TRACEPOINT,level=TRACE_DEFAULT)])]", result
);
177 // ------------------------------------------------------------------------
179 // ------------------------------------------------------------------------
181 public void testEqualsReflexivity() {
182 assertTrue("equals", fUstProviderInfo1
.equals(fUstProviderInfo1
));
183 assertTrue("equals", fUstProviderInfo2
.equals(fUstProviderInfo2
));
185 assertTrue("equals", !fUstProviderInfo1
.equals(fUstProviderInfo2
));
186 assertTrue("equals", !fUstProviderInfo2
.equals(fUstProviderInfo1
));
189 public void testEqualsSymmetry() {
190 UstProviderInfo event1
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
191 UstProviderInfo event2
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo2
);
193 assertTrue("equals", event1
.equals(fUstProviderInfo1
));
194 assertTrue("equals", fUstProviderInfo1
.equals(event1
));
196 assertTrue("equals", event2
.equals(fUstProviderInfo2
));
197 assertTrue("equals", fUstProviderInfo2
.equals(event2
));
200 public void testEqualsTransivity() {
201 UstProviderInfo UstProvider1
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
202 UstProviderInfo UstProvider2
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
203 UstProviderInfo UstProvider3
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
205 assertTrue("equals", UstProvider1
.equals(UstProvider2
));
206 assertTrue("equals", UstProvider2
.equals(UstProvider3
));
207 assertTrue("equals", UstProvider1
.equals(UstProvider3
));
210 public void testEqualsNull() throws Exception
{
211 assertTrue("equals", !fUstProviderInfo1
.equals(null));
212 assertTrue("equals", !fUstProviderInfo2
.equals(null));
215 // ------------------------------------------------------------------------
217 // ------------------------------------------------------------------------
219 public void testHashCode() {
220 UstProviderInfo UstProvider1
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo1
);
221 UstProviderInfo UstProvider2
= new UstProviderInfo((UstProviderInfo
)fUstProviderInfo2
);
223 assertTrue("hashCode", fUstProviderInfo1
.hashCode() == UstProvider1
.hashCode());
224 assertTrue("hashCode", fUstProviderInfo2
.hashCode() == UstProvider2
.hashCode());
226 assertTrue("hashCode", fUstProviderInfo1
.hashCode() != UstProvider2
.hashCode());
227 assertTrue("hashCode", fUstProviderInfo2
.hashCode() != UstProvider1
.hashCode());