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