~ubuntu-branches/ubuntu/vivid/eclipse-linuxtools/vivid-proposed

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.core.tests/src/org/eclipse/linuxtools/lttng2/core/tests/control/model/impl/SessionInfoTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam, Jakub Adam, tony mancill
  • Date: 2014-10-11 11:44:05 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20141011114405-yazjvxfzzhmi5sgj
Tags: 3.1.0-1
[ Jakub Adam ]
* New upstream release (Closes: #761524).
* Refreshed d/patches.
* Don't build removed feature org.eclipse.linuxtools.tools.launch
  - merged into org.eclipse.linuxtools.profiling.
* Use javac target 1.7.
* Build new feature org.eclipse.linuxtools.dataviewers.feature
  - required by Valgrind integration.
* Build-depend on eclipse-remote-services-api and eclipse-cdt-autotools.
* Bump Standards-Version to 3.9.6.
* Override incompatible-java-bytecode-format - linuxtools needs Java 7.
* Remove unused codeless-jar override.

[ tony mancill ]
* Tweak short package description to make lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.IDomainInfo;
22
 
import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
23
 
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
24
 
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
25
 
import org.junit.Before;
26
 
import org.junit.Test;
27
 
 
28
 
/**
29
 
 * The class <code>ChannelInfoTest</code> contains tests for the class
30
 
 * <code>{@link SessionInfo}</code>.
31
 
 */
32
 
public class SessionInfoTest {
33
 
 
34
 
    // ------------------------------------------------------------------------
35
 
    // Test data
36
 
    // ------------------------------------------------------------------------
37
 
 
38
 
    private ISessionInfo fSessionInfo1 = null;
39
 
    private ISessionInfo fSessionInfo2 = null;
40
 
 
41
 
    private IDomainInfo fDomainInfo1 = null;
42
 
    private IDomainInfo fDomainInfo2 = null;
43
 
 
44
 
    // ------------------------------------------------------------------------
45
 
    // Housekeeping
46
 
    // ------------------------------------------------------------------------
47
 
 
48
 
    /**
49
 
     * Perform pre-test initialization.
50
 
     */
51
 
    @Before
52
 
    public void setUp() {
53
 
        ModelImplFactory factory = new ModelImplFactory();
54
 
        fSessionInfo1 = factory.getSessionInfo1();
55
 
        fDomainInfo1 = factory.getDomainInfo1();
56
 
        fSessionInfo2 = factory.getSessionInfo2();
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 testSessionInfo() {
73
 
        ISessionInfo result = new SessionInfo("test");
74
 
        assertNotNull(result);
75
 
 
76
 
        assertEquals("test", result.getName());
77
 
        assertEquals("", result.getSessionPath());
78
 
        TraceSessionState state = result.getSessionState();
79
 
        assertEquals("inactive", state.getInName());
80
 
        assertEquals("INACTIVE", state.name());
81
 
        assertEquals("INACTIVE", state.toString());
82
 
        assertEquals(0, state.ordinal());
83
 
        assertEquals(0, result.getDomains().length);
84
 
    }
85
 
 
86
 
    /**
87
 
     * Test copy constructor.
88
 
     */
89
 
    @Test
90
 
    public void testSessionInfoCopy() {
91
 
        SessionInfo sessionInfo = new SessionInfo((SessionInfo)fSessionInfo1);
92
 
 
93
 
        assertEquals(sessionInfo.getName(), fSessionInfo1.getName());
94
 
        assertEquals(sessionInfo.getSessionPath(), fSessionInfo1.getSessionPath());
95
 
        assertEquals(sessionInfo.getSessionState(), fSessionInfo1.getSessionState());
96
 
 
97
 
        IDomainInfo[] orignalDomains = fSessionInfo1.getDomains();
98
 
        IDomainInfo[] resultDomains = sessionInfo.getDomains();
99
 
        for (int i = 0; i < orignalDomains.length; i++) {
100
 
            assertEquals(orignalDomains[i], resultDomains[i]);
101
 
        }
102
 
    }
103
 
 
104
 
    /**
105
 
     * Test copy constructor.
106
 
     */
107
 
    @Test
108
 
    public void testSessionCopy2() {
109
 
        try {
110
 
            SessionInfo session = null;
111
 
            new SessionInfo(session);
112
 
            fail("null copy");
113
 
        }
114
 
        catch (IllegalArgumentException e) {
115
 
            // Success
116
 
        }
117
 
    }
118
 
 
119
 
    /**
120
 
     * Run the long getNumberOfSubBuffers() method test.
121
 
     */
122
 
    @Test
123
 
    public void testGetAndSetters() {
124
 
 
125
 
        // Note that addDomain() has been executed in setUp()
126
 
        // check get method here
127
 
        assertEquals(1, fSessionInfo1.getDomains().length);
128
 
        assertNotNull(fSessionInfo1.getDomains()[0]);
129
 
        assertEquals(fDomainInfo1, fSessionInfo1.getDomains()[0]);
130
 
 
131
 
        ISessionInfo session = new SessionInfo("session");
132
 
        List<IDomainInfo> list = new LinkedList<IDomainInfo>();
133
 
        list.add(fDomainInfo1);
134
 
        list.add(fDomainInfo2);
135
 
        session.setDomains(list);
136
 
 
137
 
        IDomainInfo[] result = session.getDomains();
138
 
        assertEquals(2, result.length);
139
 
        assertEquals(fDomainInfo1, result[0]);
140
 
        assertEquals(fDomainInfo2, result[1]);
141
 
 
142
 
        session.setSessionPath("/home/user");
143
 
        assertEquals("/home/user", session.getSessionPath());
144
 
 
145
 
        session.setSessionState("active");
146
 
        TraceSessionState state = session.getSessionState();
147
 
        state = session.getSessionState();
148
 
        assertEquals("active", state.getInName());
149
 
        assertEquals("ACTIVE", state.name());
150
 
        assertEquals("ACTIVE", state.toString());
151
 
        assertEquals(1, state.ordinal());
152
 
 
153
 
        session.setSessionState("inactive");
154
 
        state = session.getSessionState();
155
 
        assertEquals("inactive", state.getInName());
156
 
        assertEquals("INACTIVE", state.name());
157
 
        assertEquals("INACTIVE", state.toString());
158
 
        assertEquals(0, state.ordinal());
159
 
 
160
 
        session.setSessionState("test");
161
 
        state = session.getSessionState();
162
 
        assertEquals("inactive", state.getInName());
163
 
        assertEquals("INACTIVE", state.name());
164
 
        assertEquals("INACTIVE", state.toString());
165
 
        assertEquals(0, state.ordinal());
166
 
 
167
 
        session.setSessionState(TraceSessionState.ACTIVE);
168
 
        state = session.getSessionState();
169
 
        assertEquals("active", state.getInName());
170
 
        assertEquals("ACTIVE", state.name());
171
 
        assertEquals("ACTIVE", state.toString());
172
 
        assertEquals(1, state.ordinal());
173
 
 
174
 
        session.setSessionState(TraceSessionState.INACTIVE);
175
 
        state = session.getSessionState();
176
 
        assertEquals("inactive", state.getInName());
177
 
        assertEquals("INACTIVE", state.name());
178
 
        assertEquals("INACTIVE", state.toString());
179
 
        assertEquals(0, state.ordinal());
180
 
    }
181
 
 
182
 
    /**
183
 
     * Run the String toString() method test.
184
 
     */
185
 
    @Test
186
 
    public void testToString_1() {
187
 
        ISessionInfo fixture = new SessionInfo("sessionName");
188
 
 
189
 
        String result = fixture.toString();
190
 
 
191
 
        // add additional test code here
192
 
        assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],Path=,State=INACTIVE,isStreamedTrace=false,Domains=)]", result);
193
 
    }
194
 
 
195
 
    /**
196
 
     * Run the String toString() method test.
197
 
     */
198
 
    @Test
199
 
    public void testToString_2() {
200
 
        String result = fSessionInfo1.toString();
201
 
 
202
 
        // add additional test code here
203
 
        assertEquals("[SessionInfo([TraceInfo(Name=session1)],Path=/home/user/lttng-trace/mysession/,State=ACTIVE,isStreamedTrace=false,snapshotInfo="
204
 
                + "[SnapshotInfo([TraceInfo(Name=snapshot-1)],snapshotPath=/home/user/lttng-trace/mysession/,ID=1,isStreamedSnapshot=false)],"
205
 
                    + "Domains=[DomainInfo([TraceInfo(Name=test1)],"
206
 
                        + "Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),"
207
 
                            + "Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)])],"
208
 
                + "isKernel=false)])]", result);
209
 
    }
210
 
 
211
 
    /**
212
 
     * Run the String toString() method test.
213
 
     */
214
 
    @Test
215
 
    public void testToString_3() {
216
 
        SessionInfo info = new SessionInfo((SessionInfo)fSessionInfo1);
217
 
        info.setSnapshotInfo(null);
218
 
        info.setSessionPath("/home/user/lttng-trace/mysession/");
219
 
 
220
 
        String result = info.toString();
221
 
 
222
 
        // add additional test code here
223
 
        assertEquals("[SessionInfo([TraceInfo(Name=session1)],Path=/home/user/lttng-trace/mysession/,State=ACTIVE,isStreamedTrace=false,"
224
 
                    + "Domains=[DomainInfo([TraceInfo(Name=test1)],"
225
 
                        + "Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),"
226
 
                            + "Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)])],"
227
 
                + "isKernel=false)])]", result);
228
 
    }
229
 
 
230
 
    // ------------------------------------------------------------------------
231
 
    // equals
232
 
    // ------------------------------------------------------------------------
233
 
 
234
 
    /**
235
 
     * Run the {@link SessionInfo#equals} method test.
236
 
     */
237
 
    @Test
238
 
    public void testEqualsReflexivity() {
239
 
        assertTrue("equals", fSessionInfo1.equals(fSessionInfo1));
240
 
        assertTrue("equals", fSessionInfo2.equals(fSessionInfo2));
241
 
 
242
 
        assertTrue("equals", !fSessionInfo1.equals(fSessionInfo2));
243
 
        assertTrue("equals", !fSessionInfo2.equals(fSessionInfo1));
244
 
    }
245
 
 
246
 
    /**
247
 
     * Run the {@link SessionInfo#equals} method test.
248
 
     */
249
 
    @Test
250
 
    public void testEqualsSymmetry() {
251
 
        SessionInfo event1 = new SessionInfo((SessionInfo)fSessionInfo1);
252
 
        SessionInfo event2 = new SessionInfo((SessionInfo)fSessionInfo2);
253
 
 
254
 
        assertTrue("equals", event1.equals(fSessionInfo1));
255
 
        assertTrue("equals", fSessionInfo1.equals(event1));
256
 
 
257
 
        assertTrue("equals", event2.equals(fSessionInfo2));
258
 
        assertTrue("equals", fSessionInfo2.equals(event2));
259
 
    }
260
 
 
261
 
    /**
262
 
     * Run the {@link SessionInfo#equals} method test.
263
 
     */
264
 
    @Test
265
 
    public void testEqualsTransivity() {
266
 
        SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
267
 
        SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo1);
268
 
        SessionInfo channel3 = new SessionInfo((SessionInfo)fSessionInfo1);
269
 
 
270
 
        assertTrue("equals", channel1.equals(channel2));
271
 
        assertTrue("equals", channel2.equals(channel3));
272
 
        assertTrue("equals", channel1.equals(channel3));
273
 
    }
274
 
 
275
 
    /**
276
 
     * Run the {@link SessionInfo#equals} method test.
277
 
     */
278
 
    @Test
279
 
    public void testEqualsNull() {
280
 
        assertTrue("equals", !fSessionInfo1.equals(null));
281
 
        assertTrue("equals", !fSessionInfo2.equals(null));
282
 
    }
283
 
 
284
 
    // ------------------------------------------------------------------------
285
 
    // hashCode
286
 
    // ------------------------------------------------------------------------
287
 
 
288
 
    /**
289
 
     * Run the {@link SessionInfo#hashCode} method test.
290
 
     */
291
 
    @Test
292
 
    public void testHashCode() {
293
 
        SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
294
 
        SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo2);
295
 
 
296
 
        assertTrue("hashCode", fSessionInfo1.hashCode() == channel1.hashCode());
297
 
        assertTrue("hashCode", fSessionInfo2.hashCode() == channel2.hashCode());
298
 
 
299
 
        assertTrue("hashCode", fSessionInfo1.hashCode() != channel2.hashCode());
300
 
        assertTrue("hashCode", fSessionInfo2.hashCode() != channel1.hashCode());
301
 
    }
302
 
}
 
 
b'\\ No newline at end of file'