lttng: Port unit tests to JUnit4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / DomainInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
15
16 import static org.junit.Assert.*;
17
18 import java.util.LinkedList;
19 import java.util.List;
20
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;
26
27 /**
28 * The class <code>ChannelInfoTest</code> contains tests for the class
29 * <code>{@link DomainInfo}</code>.
30 */
31 @SuppressWarnings("nls")
32 public class DomainInfoTest {
33
34 // ------------------------------------------------------------------------
35 // Test data
36 // ------------------------------------------------------------------------
37
38 private IDomainInfo fDomainInfo1 = null;
39 private IDomainInfo fDomainInfo2 = null;
40 private IChannelInfo fChannelInfo1 = null;
41 private IChannelInfo fChannelInfo2 = null;
42
43 // ------------------------------------------------------------------------
44 // Housekeeping
45 // ------------------------------------------------------------------------
46
47 /**
48 * Perform pre-test initialization.
49 */
50 @Before
51 public void setUp() {
52 // Get test instances from the factory
53 ModelImplFactory factory = new ModelImplFactory();
54 fChannelInfo1 = factory.getChannel1();
55 fChannelInfo2 = factory.getChannel2();
56 fDomainInfo1 = factory.getDomainInfo1();
57 fDomainInfo2 = factory.getDomainInfo2();
58 }
59
60 // ------------------------------------------------------------------------
61 // Tests
62 // ------------------------------------------------------------------------
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 /**
69 * Run the ChannelInfo() constructor test.
70 */
71 @Test
72 public void testDomainInfo() {
73 DomainInfo result = new DomainInfo("test");
74 assertNotNull(result);
75
76 assertEquals("test", result.getName());
77 assertEquals(0, result.getChannels().length);
78 }
79
80 /**
81 * Test the copy constructor.
82 */
83 @Test
84 public void testDomainInfoCopy() {
85 DomainInfo channelInfo = new DomainInfo((DomainInfo)fDomainInfo1);
86 IChannelInfo[] orignalEvents = fDomainInfo1.getChannels();
87 IChannelInfo[] resultEvents = channelInfo.getChannels();
88 for (int i = 0; i < orignalEvents.length; i++) {
89 assertEquals(orignalEvents[i], resultEvents[i]);
90 }
91 }
92
93 /**
94 * Test the copy constructor.
95 */
96 @Test
97 public void testDomainlCopy2() {
98 try {
99 DomainInfo domain = null;
100 new DomainInfo(domain);
101 fail("null copy");
102 }
103 catch (IllegalArgumentException e) {
104 // Success
105 }
106 }
107
108 /**
109 * Run the long getNumberOfSubBuffers() method test.
110 */
111 @Test
112 public void testGetAndSetters() {
113
114 // Note that addChannel() has been executed in setUp()
115 // check get method here
116 assertEquals(1, fDomainInfo1.getChannels().length);
117 assertNotNull(fDomainInfo1.getChannels()[0]);
118 assertEquals(fChannelInfo1, fDomainInfo1.getChannels()[0]);
119
120 IDomainInfo domain = new DomainInfo("domain");
121 List<IChannelInfo> list = new LinkedList<IChannelInfo>();
122 list.add(fChannelInfo1);
123 list.add(fChannelInfo2);
124 domain.setChannels(list);
125
126 IChannelInfo[] result = domain.getChannels();
127 assertEquals(2, result.length);
128 assertEquals(fChannelInfo1, result[0]);
129 assertEquals(fChannelInfo2, result[1]);
130 }
131
132 /**
133 * Run the String toString() method test.
134 */
135 @Test
136 public void testToString_1() {
137 DomainInfo fixture = new DomainInfo("domain");
138
139 String result = fixture.toString();
140
141 assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None,isKernel=false)]", result);
142 }
143
144 /**
145 * Run the String toString() method test.
146 */
147 @Test
148 public void testToString_2() {
149 String result = fDomainInfo1.toString();
150
151 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);
152 }
153
154 // ------------------------------------------------------------------------
155 // equals
156 // ------------------------------------------------------------------------
157
158 /**
159 * Run the equals() method test.
160 */
161 @Test
162 public void testEqualsReflexivity() {
163 assertTrue("equals", fDomainInfo1.equals(fDomainInfo1));
164 assertTrue("equals", fDomainInfo2.equals(fDomainInfo2));
165
166 assertTrue("equals", !fDomainInfo1.equals(fDomainInfo2));
167 assertTrue("equals", !fDomainInfo2.equals(fDomainInfo1));
168 }
169
170 /**
171 * Run the equals() method test.
172 */
173 @Test
174 public void testEqualsSymmetry() {
175 DomainInfo event1 = new DomainInfo((DomainInfo)fDomainInfo1);
176 DomainInfo event2 = new DomainInfo((DomainInfo)fDomainInfo2);
177
178 assertTrue("equals", event1.equals(fDomainInfo1));
179 assertTrue("equals", fDomainInfo1.equals(event1));
180
181 assertTrue("equals", event2.equals(fDomainInfo2));
182 assertTrue("equals", fDomainInfo2.equals(event2));
183 }
184
185 /**
186 * Run the equals() method test.
187 */
188 @Test
189 public void testEqualsTransivity() {
190 DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1);
191 DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo1);
192 DomainInfo channel3 = new DomainInfo((DomainInfo)fDomainInfo1);
193
194 assertTrue("equals", channel1.equals(channel2));
195 assertTrue("equals", channel2.equals(channel3));
196 assertTrue("equals", channel1.equals(channel3));
197 }
198
199 /**
200 * Run the equals() method test.
201 */
202 @Test
203 public void testEqualsNull() {
204 assertTrue("equals", !fDomainInfo1.equals(null));
205 assertTrue("equals", !fDomainInfo2.equals(null));
206 }
207
208 // ------------------------------------------------------------------------
209 // hashCode
210 // ------------------------------------------------------------------------
211
212 /**
213 * Run the hashCode() method test.
214 */
215 @Test
216 public void testHashCode() {
217 DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1);
218 DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo2);
219
220 assertTrue("hashCode", fDomainInfo1.hashCode() == channel1.hashCode());
221 assertTrue("hashCode", fDomainInfo2.hashCode() == channel2.hashCode());
222
223 assertTrue("hashCode", fDomainInfo1.hashCode() != channel2.hashCode());
224 assertTrue("hashCode", fDomainInfo2.hashCode() != channel1.hashCode());
225 }
226 }
This page took 0.039182 seconds and 5 git commands to generate.