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