Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core.tests / src / org / eclipse / linuxtools / lttng / core / tests / state / resource / LTTngStateResourceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.core.tests.state.resource;
13
14 import junit.framework.TestCase;
15
16 import org.eclipse.linuxtools.lttng.core.state.resource.ILttngStateContext;
17 import org.eclipse.linuxtools.lttng.core.state.resource.LTTngStateResource;
18 import org.eclipse.linuxtools.lttng.core.state.resource.ILTTngStateResource.GlobalStateMode;
19 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
20 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21
22 /**
23 * For inherited methods see: LTTngTreeNodeTest
24 *
25 * @author alvaro
26 *
27 */
28 @SuppressWarnings("nls")
29 public class LTTngStateResourceTest extends TestCase {
30 // =======================================================================
31 // Data
32 // =======================================================================
33
34 // Common context for all tests
35 ILttngStateContext context;
36
37 LTTngStateResource node10;
38 LTTngStateResource node20;
39 LTTngStateResource node30;
40 LTTngStateResource node40;
41 LTTngStateResource node50;
42 LTTngStateResource node60;
43
44 LTTngStateResource node15;
45 LTTngStateResource node25;
46 LTTngStateResource node35;
47 LTTngStateResource node45;
48 LTTngStateResource node55;
49 LTTngStateResource node65;
50 LTTngStateResource node67;
51
52 // ========================================================================
53 // Preparations and Finish
54 // =======================================================================
55 /* (non-Javadoc)
56 * @see junit.framework.TestCase#setUp()
57 */
58 @Override
59 protected void setUp() throws Exception {
60 super.setUp();
61 context = getContext();
62 // Create state resources and assign a parent
63 node10 = new LTTngStateResource(10L, "node10", context, this);
64 node20 = new LTTngStateResource(20L, node10, "node20", context, this);
65 node30 = new LTTngStateResource(30L, node20, "node30", context, this);
66 node40 = new LTTngStateResource(40L, node30, "node40", context, this);
67 node50 = new LTTngStateResource(50L, node40, "node50", context, this);
68 node60 = new LTTngStateResource(60L, node50, "node60", context, this);
69
70 //Adding first children
71 node10.addChild(node20);
72 node20.addChild(node30);
73 node30.addChild(node40);
74 node40.addChild(node50);
75 node50.addChild(node60);
76
77 //create additional nodes
78 node15 = new LTTngStateResource(15L, node10, "node15", context, this);
79 node25 = new LTTngStateResource(25L, node20, "node25", context, this);
80 node35 = new LTTngStateResource(35L, node30, "node35", context, this);
81 node45 = new LTTngStateResource(45L, node40, "node45", context, this);
82 node55 = new LTTngStateResource(55L, node50, "node55", context, this);
83 node65 = new LTTngStateResource(65L, node60, "node65", context, this);
84 node67 = new LTTngStateResource(67L, node60, "node67", context, this);
85
86 // Add more children to instances
87 node10.addChild(node15);
88 node20.addChild(node25);
89 node30.addChild(node35);
90 node40.addChild(node45);
91 node50.addChild(node55);
92 node60.addChild(node65);
93 node60.addChild(node67);
94 }
95
96 /**
97 * @return
98 */
99 private ILttngStateContext getContext() {
100 return new ILttngStateContext() {
101
102 @Override
103 public TmfTimeRange getTraceTimeWindow() {
104 return null;
105 }
106
107 @Override
108 public ITmfTrace<?> getTraceIdRef() {
109 return null;
110 }
111
112 @Override
113 public String getTraceId() {
114 return "Test Trace";
115 }
116
117 @Override
118 public int getNumberOfCpus() {
119 return 1;
120 }
121
122 @Override
123 public TmfTimeRange getExperimentTimeWindow() {
124 return null;
125 }
126
127 @Override
128 public String getExperimentName() {
129 return "Test Experiment";
130 }
131
132 @Override
133 public long getIdentifier() {
134 return 0;
135 }
136 };
137 }
138
139 /* (non-Javadoc)
140 * @see junit.framework.TestCase#tearDown()
141 */
142 @Override
143 protected void tearDown() throws Exception {
144 super.tearDown();
145 }
146
147 // ========================================================================
148 // Methods
149 // =======================================================================
150 /**
151 * Test method for
152 * {@link org.eclipse.linuxtools.lttng.core.state.resource.LTTngStateResource#getChildren()}
153 * .
154 */
155 public void testGetChildren() {
156 LTTngStateResource[] childrensOf60 = node60.getChildren();
157 assertNotNull(childrensOf60);
158
159 int size = childrensOf60.length;
160 assertEquals(2, size);
161
162 LTTngStateResource child65 = childrensOf60[0];
163 LTTngStateResource child67 = childrensOf60[1];
164
165 assertNotNull(child65);
166 assertNotNull(child67);
167
168 assertEquals("node65", child65.getName());
169 assertEquals("node67", child67.getName());
170 }
171
172 /**
173 * Test method for
174 * {@link org.eclipse.linuxtools.lttng.core.state.resource.LTTngStateResource#getStateMode()}
175 */
176 public void testStateMode() {
177 // check default
178 assertEquals("unknown", node60.getStateMode().getInName());
179
180 // check setting
181 node60.setStateMode(GlobalStateMode.LTT_STATEMODE_WAIT_FORK);
182 assertEquals("waitfork", node60.getStateMode().getInName());
183
184 }
185
186 /**
187 * Test method for
188 * {@link org.eclipse.linuxtools.lttng.core.state.resource.LTTngStateResource#getContext()}
189 */
190 public void testContext() {
191 assertEquals(context, node60.getContext());
192 }
193 }
This page took 0.034804 seconds and 5 git commands to generate.