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
.IChannelInfo
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IDomainInfo
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.DomainInfo
;
24 * The class <code>ChannelInfoTest</code> contains tests for the class <code>{@link DomainInfo}</code>.
27 @SuppressWarnings("nls")
28 public class DomainInfoTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
32 private IDomainInfo fDomainInfo1
= null;
33 private IDomainInfo fDomainInfo2
= null;
34 private IChannelInfo fChannelInfo1
= null;
35 private IChannelInfo fChannelInfo2
= null;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * Perform pre-test initialization.
45 * if the initialization fails for some reason
50 // Get test instances from the factory
51 ModelImplFactory factory
= new ModelImplFactory();
52 fChannelInfo1
= factory
.getChannel1();
53 fChannelInfo2
= factory
.getChannel2();
54 fDomainInfo1
= factory
.getDomainInfo1();
55 fDomainInfo2
= factory
.getDomainInfo2();
59 * Perform post-test clean-up.
62 * if the clean-up fails for some reason
66 public void tearDown() {
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * Run the ChannelInfo() constructor test.
81 public void testDomainInfo() {
82 DomainInfo result
= new DomainInfo("test");
83 assertNotNull(result
);
85 assertEquals("test", result
.getName());
86 assertEquals(0, result
.getChannels().length
);
89 public void testDomainInfoCopy() {
90 DomainInfo channelInfo
= new DomainInfo((DomainInfo
)fDomainInfo1
);
91 IChannelInfo
[] orignalEvents
= fDomainInfo1
.getChannels();
92 IChannelInfo
[] resultEvents
= channelInfo
.getChannels();
93 for (int i
= 0; i
< orignalEvents
.length
; i
++) {
94 assertEquals(orignalEvents
[i
], resultEvents
[i
]);
98 public void testDomainlCopy2() {
100 DomainInfo domain
= null;
101 new DomainInfo(domain
);
104 catch (IllegalArgumentException e
) {
110 * Run the long getNumberOfSubBuffers() method test.
113 public void testGetAndSetters() {
115 // Note that addChannel() has been executed in setUp()
116 // check get method here
117 assertEquals(1, fDomainInfo1
.getChannels().length
);
118 assertNotNull(fDomainInfo1
.getChannels()[0]);
119 assertEquals(fChannelInfo1
, fDomainInfo1
.getChannels()[0]);
121 IDomainInfo domain
= new DomainInfo("domain");
122 List
<IChannelInfo
> list
= new LinkedList
<IChannelInfo
>();
123 list
.add(fChannelInfo1
);
124 list
.add(fChannelInfo2
);
125 domain
.setChannels(list
);
127 IChannelInfo
[] result
= domain
.getChannels();
128 assertEquals(2, result
.length
);
129 assertEquals(fChannelInfo1
, result
[0]);
130 assertEquals(fChannelInfo2
, result
[1]);
133 public void testToString_1() {
134 DomainInfo fixture
= new DomainInfo("domain");
136 String result
= fixture
.toString();
138 assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None)]", result
);
142 * Run the String toString() method test.
145 public void testToString_2() {
146 String result
= fDomainInfo1
.toString();
148 assertEquals("[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_DEFAULT)],State=ENABLED)])])]", result
);
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
155 public void testEqualsReflexivity() {
156 assertTrue("equals", fDomainInfo1
.equals(fDomainInfo1
));
157 assertTrue("equals", fDomainInfo2
.equals(fDomainInfo2
));
159 assertTrue("equals", !fDomainInfo1
.equals(fDomainInfo2
));
160 assertTrue("equals", !fDomainInfo2
.equals(fDomainInfo1
));
163 public void testEqualsSymmetry() {
164 DomainInfo event1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
165 DomainInfo event2
= new DomainInfo((DomainInfo
)fDomainInfo2
);
167 assertTrue("equals", event1
.equals(fDomainInfo1
));
168 assertTrue("equals", fDomainInfo1
.equals(event1
));
170 assertTrue("equals", event2
.equals(fDomainInfo2
));
171 assertTrue("equals", fDomainInfo2
.equals(event2
));
174 public void testEqualsTransivity() {
175 DomainInfo channel1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
176 DomainInfo channel2
= new DomainInfo((DomainInfo
)fDomainInfo1
);
177 DomainInfo channel3
= new DomainInfo((DomainInfo
)fDomainInfo1
);
179 assertTrue("equals", channel1
.equals(channel2
));
180 assertTrue("equals", channel2
.equals(channel3
));
181 assertTrue("equals", channel1
.equals(channel3
));
184 public void testEqualsNull() throws Exception
{
185 assertTrue("equals", !fDomainInfo1
.equals(null));
186 assertTrue("equals", !fDomainInfo2
.equals(null));
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
193 public void testHashCode() {
194 DomainInfo channel1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
195 DomainInfo channel2
= new DomainInfo((DomainInfo
)fDomainInfo2
);
197 assertTrue("hashCode", fDomainInfo1
.hashCode() == channel1
.hashCode());
198 assertTrue("hashCode", fDomainInfo2
.hashCode() == channel2
.hashCode());
200 assertTrue("hashCode", fDomainInfo1
.hashCode() != channel2
.hashCode());
201 assertTrue("hashCode", fDomainInfo2
.hashCode() != channel1
.hashCode());