1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.core
.tests
.control
.model
.impl
;
16 import static org
.junit
.Assert
.*;
18 import java
.util
.LinkedList
;
19 import java
.util
.List
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IChannelInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IDomainInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.DomainInfo
;
24 import org
.junit
.Before
;
25 import org
.junit
.Test
;
28 * The class <code>ChannelInfoTest</code> contains tests for the class
29 * <code>{@link DomainInfo}</code>.
31 public class DomainInfoTest
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
37 private IDomainInfo fDomainInfo1
= null;
38 private IDomainInfo fDomainInfo2
= null;
39 private IChannelInfo fChannelInfo1
= null;
40 private IChannelInfo fChannelInfo2
= null;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
47 * Perform pre-test initialization.
51 // Get test instances from the factory
52 ModelImplFactory factory
= new ModelImplFactory();
53 fChannelInfo1
= factory
.getChannel1();
54 fChannelInfo2
= factory
.getChannel2();
55 fDomainInfo1
= factory
.getDomainInfo1();
56 fDomainInfo2
= factory
.getDomainInfo2();
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
68 * Run the ChannelInfo() constructor test.
71 public void testDomainInfo() {
72 DomainInfo result
= new DomainInfo("test");
73 assertNotNull(result
);
75 assertEquals("test", result
.getName());
76 assertEquals(0, result
.getChannels().length
);
80 * Test the copy constructor.
83 public void testDomainInfoCopy() {
84 DomainInfo channelInfo
= new DomainInfo((DomainInfo
)fDomainInfo1
);
85 IChannelInfo
[] orignalEvents
= fDomainInfo1
.getChannels();
86 IChannelInfo
[] resultEvents
= channelInfo
.getChannels();
87 for (int i
= 0; i
< orignalEvents
.length
; i
++) {
88 assertEquals(orignalEvents
[i
], resultEvents
[i
]);
93 * Test the copy constructor.
96 public void testDomainlCopy2() {
98 DomainInfo domain
= null;
99 new DomainInfo(domain
);
102 catch (IllegalArgumentException e
) {
108 * Run the long getNumberOfSubBuffers() method test.
111 public void testGetAndSetters() {
113 // Note that addChannel() has been executed in setUp()
114 // check get method here
115 assertEquals(1, fDomainInfo1
.getChannels().length
);
116 assertNotNull(fDomainInfo1
.getChannels()[0]);
117 assertEquals(fChannelInfo1
, fDomainInfo1
.getChannels()[0]);
119 IDomainInfo domain
= new DomainInfo("domain");
120 List
<IChannelInfo
> list
= new LinkedList
<>();
121 list
.add(fChannelInfo1
);
122 list
.add(fChannelInfo2
);
123 domain
.setChannels(list
);
125 IChannelInfo
[] result
= domain
.getChannels();
126 assertEquals(2, result
.length
);
127 assertEquals(fChannelInfo1
, result
[0]);
128 assertEquals(fChannelInfo2
, result
[1]);
132 * Run the String toString() method test.
135 public void testToString_1() {
136 DomainInfo fixture
= new DomainInfo("domain");
138 String result
= fixture
.toString();
140 assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None,isKernel=false)]", result
);
144 * Run the String toString() method test.
147 public void testToString_2() {
148 String result
= fDomainInfo1
.toString();
150 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_DEBUG)],State=ENABLED)])],isKernel=false)]", result
);
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
158 * Run the equals() method test.
161 public void testEqualsReflexivity() {
162 assertTrue("equals", fDomainInfo1
.equals(fDomainInfo1
));
163 assertTrue("equals", fDomainInfo2
.equals(fDomainInfo2
));
165 assertTrue("equals", !fDomainInfo1
.equals(fDomainInfo2
));
166 assertTrue("equals", !fDomainInfo2
.equals(fDomainInfo1
));
170 * Run the equals() method test.
173 public void testEqualsSymmetry() {
174 DomainInfo event1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
175 DomainInfo event2
= new DomainInfo((DomainInfo
)fDomainInfo2
);
177 assertTrue("equals", event1
.equals(fDomainInfo1
));
178 assertTrue("equals", fDomainInfo1
.equals(event1
));
180 assertTrue("equals", event2
.equals(fDomainInfo2
));
181 assertTrue("equals", fDomainInfo2
.equals(event2
));
185 * Run the equals() method test.
188 public void testEqualsTransivity() {
189 DomainInfo channel1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
190 DomainInfo channel2
= new DomainInfo((DomainInfo
)fDomainInfo1
);
191 DomainInfo channel3
= new DomainInfo((DomainInfo
)fDomainInfo1
);
193 assertTrue("equals", channel1
.equals(channel2
));
194 assertTrue("equals", channel2
.equals(channel3
));
195 assertTrue("equals", channel1
.equals(channel3
));
199 * Run the equals() method test.
202 public void testEqualsNull() {
203 assertTrue("equals", !fDomainInfo1
.equals(null));
204 assertTrue("equals", !fDomainInfo2
.equals(null));
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 * Run the hashCode() method test.
215 public void testHashCode() {
216 DomainInfo channel1
= new DomainInfo((DomainInfo
)fDomainInfo1
);
217 DomainInfo channel2
= new DomainInfo((DomainInfo
)fDomainInfo2
);
219 assertTrue("hashCode", fDomainInfo1
.hashCode() == channel1
.hashCode());
220 assertTrue("hashCode", fDomainInfo2
.hashCode() == channel2
.hashCode());
222 assertTrue("hashCode", fDomainInfo1
.hashCode() != channel2
.hashCode());
223 assertTrue("hashCode", fDomainInfo2
.hashCode() != channel1
.hashCode());