gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core.tests / src / org / eclipse / linuxtools / lttng2 / control / core / tests / model / impl / DomainInfoTest.java
CommitLineData
eb1bab5b 1/**********************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
b0318660 3 *
eb1bab5b
BH
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
b0318660
AM
8 *
9 * Contributors:
eb1bab5b 10 * Bernd Hufmann - Initial API and implementation
2ba3d0a1 11 * Alexandre Montplaisir - Port to JUnit4
eb1bab5b 12 **********************************************************************/
2ba3d0a1 13
8e8c0226 14package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl;
eb1bab5b 15
2ba3d0a1
AM
16import static org.junit.Assert.*;
17
eb1bab5b
BH
18import java.util.LinkedList;
19import java.util.List;
20
8e8c0226
AM
21import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
22import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
23import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.DomainInfo;
2ba3d0a1
AM
24import org.junit.Before;
25import org.junit.Test;
eb1bab5b
BH
26
27/**
2ba3d0a1
AM
28 * The class <code>ChannelInfoTest</code> contains tests for the class
29 * <code>{@link DomainInfo}</code>.
eb1bab5b 30 */
2ba3d0a1
AM
31public class DomainInfoTest {
32
eb1bab5b
BH
33 // ------------------------------------------------------------------------
34 // Test data
35 // ------------------------------------------------------------------------
2ba3d0a1 36
eb1bab5b
BH
37 private IDomainInfo fDomainInfo1 = null;
38 private IDomainInfo fDomainInfo2 = null;
39 private IChannelInfo fChannelInfo1 = null;
40 private IChannelInfo fChannelInfo2 = null;
41
42 // ------------------------------------------------------------------------
43 // Housekeeping
44 // ------------------------------------------------------------------------
b0318660 45
eb1bab5b
BH
46 /**
47 * Perform pre-test initialization.
eb1bab5b 48 */
2ba3d0a1 49 @Before
eb1bab5b
BH
50 public void setUp() {
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();
57 }
58
eb1bab5b
BH
59 // ------------------------------------------------------------------------
60 // Tests
61 // ------------------------------------------------------------------------
b0318660 62
eb1bab5b
BH
63 // ------------------------------------------------------------------------
64 // Constructors
65 // ------------------------------------------------------------------------
66
67 /**
68 * Run the ChannelInfo() constructor test.
eb1bab5b 69 */
2ba3d0a1 70 @Test
eb1bab5b
BH
71 public void testDomainInfo() {
72 DomainInfo result = new DomainInfo("test");
73 assertNotNull(result);
b0318660 74
eb1bab5b
BH
75 assertEquals("test", result.getName());
76 assertEquals(0, result.getChannels().length);
77 }
78
2ba3d0a1
AM
79 /**
80 * Test the copy constructor.
81 */
82 @Test
eb1bab5b
BH
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]);
89 }
90 }
91
2ba3d0a1
AM
92 /**
93 * Test the copy constructor.
94 */
95 @Test
eb1bab5b
BH
96 public void testDomainlCopy2() {
97 try {
98 DomainInfo domain = null;
99 new DomainInfo(domain);
100 fail("null copy");
101 }
102 catch (IllegalArgumentException e) {
103 // Success
104 }
105 }
106
107 /**
108 * Run the long getNumberOfSubBuffers() method test.
eb1bab5b 109 */
2ba3d0a1 110 @Test
eb1bab5b 111 public void testGetAndSetters() {
b0318660 112
eb1bab5b
BH
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]);
b0318660 118
eb1bab5b 119 IDomainInfo domain = new DomainInfo("domain");
e0838ca1 120 List<IChannelInfo> list = new LinkedList<>();
eb1bab5b
BH
121 list.add(fChannelInfo1);
122 list.add(fChannelInfo2);
123 domain.setChannels(list);
b0318660 124
eb1bab5b
BH
125 IChannelInfo[] result = domain.getChannels();
126 assertEquals(2, result.length);
127 assertEquals(fChannelInfo1, result[0]);
128 assertEquals(fChannelInfo2, result[1]);
129 }
130
2ba3d0a1
AM
131 /**
132 * Run the String toString() method test.
133 */
134 @Test
eb1bab5b
BH
135 public void testToString_1() {
136 DomainInfo fixture = new DomainInfo("domain");
137
138 String result = fixture.toString();
139
9d8a90ad 140 assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None,isKernel=false)]", result);
eb1bab5b
BH
141 }
142
143 /**
144 * Run the String toString() method test.
eb1bab5b 145 */
2ba3d0a1 146 @Test
eb1bab5b
BH
147 public void testToString_2() {
148 String result = fDomainInfo1.toString();
149
54f2dcc0 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,levelType=LOGLEVEL_ONLY)])],isKernel=false)]", result);
eb1bab5b 151 }
b0318660 152
eb1bab5b
BH
153 // ------------------------------------------------------------------------
154 // equals
155 // ------------------------------------------------------------------------
156
2ba3d0a1
AM
157 /**
158 * Run the equals() method test.
159 */
160 @Test
eb1bab5b
BH
161 public void testEqualsReflexivity() {
162 assertTrue("equals", fDomainInfo1.equals(fDomainInfo1));
163 assertTrue("equals", fDomainInfo2.equals(fDomainInfo2));
164
165 assertTrue("equals", !fDomainInfo1.equals(fDomainInfo2));
166 assertTrue("equals", !fDomainInfo2.equals(fDomainInfo1));
167 }
b0318660 168
2ba3d0a1
AM
169 /**
170 * Run the equals() method test.
171 */
172 @Test
eb1bab5b
BH
173 public void testEqualsSymmetry() {
174 DomainInfo event1 = new DomainInfo((DomainInfo)fDomainInfo1);
175 DomainInfo event2 = new DomainInfo((DomainInfo)fDomainInfo2);
176
177 assertTrue("equals", event1.equals(fDomainInfo1));
178 assertTrue("equals", fDomainInfo1.equals(event1));
179
180 assertTrue("equals", event2.equals(fDomainInfo2));
181 assertTrue("equals", fDomainInfo2.equals(event2));
182 }
b0318660 183
2ba3d0a1
AM
184 /**
185 * Run the equals() method test.
186 */
187 @Test
eb1bab5b
BH
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);
192
193 assertTrue("equals", channel1.equals(channel2));
194 assertTrue("equals", channel2.equals(channel3));
195 assertTrue("equals", channel1.equals(channel3));
196 }
b0318660 197
2ba3d0a1
AM
198 /**
199 * Run the equals() method test.
200 */
201 @Test
ea21cd65 202 public void testEqualsNull() {
eb1bab5b
BH
203 assertTrue("equals", !fDomainInfo1.equals(null));
204 assertTrue("equals", !fDomainInfo2.equals(null));
205 }
b0318660 206
eb1bab5b
BH
207 // ------------------------------------------------------------------------
208 // hashCode
209 // ------------------------------------------------------------------------
210
2ba3d0a1
AM
211 /**
212 * Run the hashCode() method test.
213 */
214 @Test
eb1bab5b
BH
215 public void testHashCode() {
216 DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1);
217 DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo2);
218
219 assertTrue("hashCode", fDomainInfo1.hashCode() == channel1.hashCode());
220 assertTrue("hashCode", fDomainInfo2.hashCode() == channel2.hashCode());
221
222 assertTrue("hashCode", fDomainInfo1.hashCode() != channel2.hashCode());
223 assertTrue("hashCode", fDomainInfo2.hashCode() != channel1.hashCode());
224 }
225}
This page took 0.063143 seconds and 5 git commands to generate.