Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / src / org / eclipse / linuxtools / lttng / ui / tests / control / model / impl / DomainInfoTest.java
1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.tests.control.model.impl;
13
14 import java.util.LinkedList;
15 import java.util.List;
16
17 import junit.framework.TestCase;
18
19 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo;
20 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IDomainInfo;
21 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.DomainInfo;
22
23 /**
24 * The class <code>ChannelInfoTest</code> contains tests for the class <code>{@link DomainInfo}</code>.
25 *
26 */
27 @SuppressWarnings("nls")
28 public class DomainInfoTest extends TestCase {
29 // ------------------------------------------------------------------------
30 // Test data
31 // ------------------------------------------------------------------------
32 private IDomainInfo fDomainInfo1 = null;
33 private IDomainInfo fDomainInfo2 = null;
34 private IChannelInfo fChannelInfo1 = null;
35 private IChannelInfo fChannelInfo2 = null;
36
37 // ------------------------------------------------------------------------
38 // Housekeeping
39 // ------------------------------------------------------------------------
40
41 /**
42 * Perform pre-test initialization.
43 *
44 * @throws Exception
45 * if the initialization fails for some reason
46 *
47 */
48 @Override
49 public void setUp() {
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();
56 }
57
58 /**
59 * Perform post-test clean-up.
60 *
61 * @throws Exception
62 * if the clean-up fails for some reason
63 *
64 */
65 @Override
66 public void tearDown() {
67 }
68
69 // ------------------------------------------------------------------------
70 // Tests
71 // ------------------------------------------------------------------------
72
73 // ------------------------------------------------------------------------
74 // Constructors
75 // ------------------------------------------------------------------------
76
77 /**
78 * Run the ChannelInfo() constructor test.
79 *
80 */
81 public void testDomainInfo() {
82 DomainInfo result = new DomainInfo("test");
83 assertNotNull(result);
84
85 assertEquals("test", result.getName());
86 assertEquals(0, result.getChannels().length);
87 }
88
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]);
95 }
96 }
97
98 public void testDomainlCopy2() {
99 try {
100 DomainInfo domain = null;
101 new DomainInfo(domain);
102 fail("null copy");
103 }
104 catch (IllegalArgumentException e) {
105 // Success
106 }
107 }
108
109 /**
110 * Run the long getNumberOfSubBuffers() method test.
111 *
112 */
113 public void testGetAndSetters() {
114
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]);
120
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);
126
127 IChannelInfo[] result = domain.getChannels();
128 assertEquals(2, result.length);
129 assertEquals(fChannelInfo1, result[0]);
130 assertEquals(fChannelInfo2, result[1]);
131 }
132
133 public void testToString_1() {
134 DomainInfo fixture = new DomainInfo("domain");
135
136 String result = fixture.toString();
137
138 assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None,isKernel=false)]", result);
139 }
140
141 /**
142 * Run the String toString() method test.
143 *
144 */
145 public void testToString_2() {
146 String result = fDomainInfo1.toString();
147
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_DEBUG)],State=ENABLED)])],isKernel=false)]", result);
149 }
150
151 // ------------------------------------------------------------------------
152 // equals
153 // ------------------------------------------------------------------------
154
155 public void testEqualsReflexivity() {
156 assertTrue("equals", fDomainInfo1.equals(fDomainInfo1));
157 assertTrue("equals", fDomainInfo2.equals(fDomainInfo2));
158
159 assertTrue("equals", !fDomainInfo1.equals(fDomainInfo2));
160 assertTrue("equals", !fDomainInfo2.equals(fDomainInfo1));
161 }
162
163 public void testEqualsSymmetry() {
164 DomainInfo event1 = new DomainInfo((DomainInfo)fDomainInfo1);
165 DomainInfo event2 = new DomainInfo((DomainInfo)fDomainInfo2);
166
167 assertTrue("equals", event1.equals(fDomainInfo1));
168 assertTrue("equals", fDomainInfo1.equals(event1));
169
170 assertTrue("equals", event2.equals(fDomainInfo2));
171 assertTrue("equals", fDomainInfo2.equals(event2));
172 }
173
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);
178
179 assertTrue("equals", channel1.equals(channel2));
180 assertTrue("equals", channel2.equals(channel3));
181 assertTrue("equals", channel1.equals(channel3));
182 }
183
184 public void testEqualsNull() throws Exception {
185 assertTrue("equals", !fDomainInfo1.equals(null));
186 assertTrue("equals", !fDomainInfo2.equals(null));
187 }
188
189 // ------------------------------------------------------------------------
190 // hashCode
191 // ------------------------------------------------------------------------
192
193 public void testHashCode() {
194 DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1);
195 DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo2);
196
197 assertTrue("hashCode", fDomainInfo1.hashCode() == channel1.hashCode());
198 assertTrue("hashCode", fDomainInfo2.hashCode() == channel2.hashCode());
199
200 assertTrue("hashCode", fDomainInfo1.hashCode() != channel2.hashCode());
201 assertTrue("hashCode", fDomainInfo2.hashCode() != channel1.hashCode());
202 }
203 }
This page took 0.035482 seconds and 5 git commands to generate.