0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import unittest
|
|
18 |
import os
|
|
19 |
import logging
|
3
|
20 |
|
0
|
21 |
from cone.public import *
|
|
22 |
from cone.public import _plugin_reader
|
|
23 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
24 |
|
3
|
25 |
|
|
26 |
class MockImpl(plugin.ImplBase):
|
|
27 |
def __init__(self, data):
|
|
28 |
self.data = data
|
|
29 |
self.generate_invoked = False
|
|
30 |
|
|
31 |
@classmethod
|
|
32 |
def create(cls, resource_ref, configuration, data):
|
|
33 |
impl = cls(data)
|
|
34 |
plugin.ImplBase.__init__(impl, resource_ref, configuration)
|
|
35 |
return impl
|
|
36 |
|
|
37 |
def generate(self, context=None):
|
|
38 |
if context and hasattr(context,'objects'):
|
|
39 |
context.objects.append(self)
|
|
40 |
self.generate_invoked = True
|
|
41 |
|
|
42 |
def __repr__(self):
|
|
43 |
return "MockImpl(%r)" % self.data
|
|
44 |
|
|
45 |
def __eq__(self, other):
|
|
46 |
if type(self) == type(other):
|
|
47 |
return self.data == other.data
|
|
48 |
else:
|
|
49 |
return False
|
|
50 |
|
|
51 |
def __ne__(self, other):
|
|
52 |
return not (self == other)
|
|
53 |
|
|
54 |
def __lt__(self, other):
|
|
55 |
if type(self) == type(other):
|
|
56 |
return self.data < other.data
|
|
57 |
else:
|
|
58 |
return False
|
|
59 |
|
|
60 |
class MockReaderBase(plugin.ReaderBase):
|
|
61 |
@classmethod
|
|
62 |
def read_impl(cls, resource_ref, configuration, root_elem):
|
|
63 |
data = [cls.__name__, resource_ref]
|
|
64 |
for elem in root_elem.findall('{%s}elem' % cls.NAMESPACE):
|
|
65 |
data.append(elem.attrib)
|
|
66 |
return MockImpl.create(resource_ref, configuration, data)
|
|
67 |
|
|
68 |
class MockReader(MockReaderBase):
|
|
69 |
NAMESPACE = "http://www.test.com/xml/1"
|
|
70 |
NAMESPACE_ID = "mock"
|
|
71 |
ROOT_ELEMENT_NAME = "impl"
|
|
72 |
FILE_EXTENSIONS = ['mockml']
|
|
73 |
|
0
|
74 |
class ImplTest(plugin.ImplBase):
|
|
75 |
def __init__(self,ref,configuration):
|
|
76 |
plugin.ImplBase.__init__(self,ref,configuration)
|
|
77 |
self.generate_invoked = False
|
|
78 |
self.refs = ["dummy1.too"]
|
|
79 |
self.output_files = []
|
|
80 |
def generate(self, context=None):
|
|
81 |
self.generate_invoked = True
|
|
82 |
if context and hasattr(context, 'objects'):
|
|
83 |
context.objects.append(self)
|
|
84 |
|
|
85 |
def get_refs(self):
|
|
86 |
return self.refs
|
|
87 |
|
|
88 |
def list_output_files(self):
|
|
89 |
return self.output_files
|
|
90 |
|
|
91 |
|
|
92 |
class TestPluginReader(unittest.TestCase):
|
|
93 |
def setUp(self):
|
|
94 |
pass
|
|
95 |
|
|
96 |
class TestCommonNamespaceHandling(unittest.TestCase):
|
|
97 |
|
|
98 |
def setUp(self):
|
3
|
99 |
plugin.ImplFactory.set_reader_classes_override([MockReader])
|
|
100 |
|
0
|
101 |
def tearDown(self):
|
3
|
102 |
plugin.ImplFactory.set_reader_classes_override(None)
|
0
|
103 |
|
|
104 |
def test_implcontainer_reader_get_condition(self):
|
|
105 |
root = utils.etree.fromstring("<container/>")
|
|
106 |
self.assertEquals(plugin.ImplContainerReader.get_condition(root), None)
|
|
107 |
|
|
108 |
root = utils.etree.fromstring("<container condition='test'/>")
|
|
109 |
condition = plugin.ImplContainerReader.get_condition(root)
|
|
110 |
self.assertTrue(isinstance(condition, rules.SimpleCondition))
|
|
111 |
self.assertEquals(condition.left.expression, "test")
|
|
112 |
self.assertEquals(condition.right.expression, "true")
|
|
113 |
|
|
114 |
root = utils.etree.fromstring("<container condition='${feature.one}' value='2'/>")
|
|
115 |
condition = plugin.ImplContainerReader.get_condition(root)
|
|
116 |
self.assertTrue(isinstance(condition, rules.SimpleCondition))
|
|
117 |
self.assertEquals(condition.left.expression, "${feature.one}")
|
|
118 |
self.assertEquals(condition.right.expression, "2")
|
|
119 |
|
|
120 |
|
|
121 |
def test_implcontainer_reader_get_reader_classes(self):
|
|
122 |
classes = plugin.ImplContainerReader.get_reader_classes()
|
|
123 |
self.assertTrue(classes.has_key('http://www.symbianfoundation.org/xml/implml/1'))
|
|
124 |
|
|
125 |
def test_get_test_container(self):
|
|
126 |
xml_data = """<?xml version="1.0"?>
|
|
127 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
128 |
</container>
|
|
129 |
"""
|
|
130 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
131 |
self.assertTrue(isinstance(container, plugin.ImplContainer))
|
3
|
132 |
|
|
133 |
def test_get_reader_for_namespace(self):
|
|
134 |
self.assertEquals(plugin.ReaderBase.get_reader_for_namespace('http://www.symbianfoundation.org/Foo'), None)
|
|
135 |
self.assertEquals(plugin.ReaderBase.get_reader_for_namespace('http://www.symbianfoundation.org/xml/implml/1'),
|
|
136 |
plugin.ImplContainerReader)
|
|
137 |
|
|
138 |
def test_read_container_via_common_readerbase(self):
|
|
139 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'testdata')))
|
|
140 |
config = prj.create_configuration("test.confml", True)
|
|
141 |
container = plugin.read_impl_from_location('layer1/implml/test.implml', config, 4)
|
|
142 |
self.assertEquals(container.invocation_phase(), 'normal')
|
|
143 |
self.assertEquals(container.path, 'layer1/implml/test.implml')
|
|
144 |
self.assertEquals(container.lineno, 4)
|
|
145 |
self.assertEquals(container[0].invocation_phase(), 'normal')
|
|
146 |
self.assertEquals(container[0].path, 'layer1/implml/test.implml')
|
|
147 |
self.assertEquals(container[0].lineno, 5)
|
|
148 |
|
|
149 |
|
|
150 |
def test_read_containers_from_location(self):
|
|
151 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'testdata')))
|
|
152 |
config = prj.create_configuration("test.confml", True)
|
|
153 |
|
|
154 |
container = plugin.ImplContainerReader.read_impl_from_location('layer1/implml/test.implml', config, 4)
|
|
155 |
self.assertEquals(container.invocation_phase(), 'normal')
|
|
156 |
self.assertEquals(container.path, 'layer1/implml/test.implml')
|
|
157 |
self.assertEquals(container.lineno, 4)
|
|
158 |
self.assertEquals(container[0].invocation_phase(), 'normal')
|
|
159 |
self.assertEquals(container[0].path, 'layer1/implml/test.implml')
|
|
160 |
self.assertEquals(container[0].lineno, 5)
|
0
|
161 |
|
|
162 |
def test_get_test_container_with_sub_containers(self):
|
|
163 |
xml_data = """<?xml version="1.0"?>
|
|
164 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
165 |
<container />
|
|
166 |
<container />
|
|
167 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
168 |
<container />
|
|
169 |
</container>
|
|
170 |
</container>
|
|
171 |
"""
|
|
172 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
173 |
self.assertTrue(isinstance(container, plugin.ImplContainer))
|
|
174 |
self.assertEquals(len(container), 3)
|
|
175 |
|
|
176 |
def test_containers_with_phases(self):
|
|
177 |
xml_data = """<?xml version="1.0"?>
|
3
|
178 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
179 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
180 |
<container>
|
|
181 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
182 |
</container>
|
0
|
183 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
184 |
<phase name="post"/>
|
3
|
185 |
<mock xmlns="http://www.test.com/xml/1"/>
|
0
|
186 |
</container>
|
3
|
187 |
</container>
|
0
|
188 |
"""
|
|
189 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
3
|
190 |
self.assertEquals(container[0].invocation_phase(), 'normal')
|
|
191 |
self.assertEquals(container[1][0].invocation_phase(), 'normal')
|
|
192 |
self.assertEquals(container[2][0].invocation_phase(), 'post')
|
0
|
193 |
|
|
194 |
def test_containers_with_tags(self):
|
|
195 |
xml_data = """<?xml version="1.0"?>
|
|
196 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
197 |
<tag name="target" value="rofs2"/>
|
|
198 |
<tag name="foobar" value="test"/>
|
3
|
199 |
|
|
200 |
<container>
|
|
201 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
202 |
</container>
|
|
203 |
|
0
|
204 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
205 |
<tag name="target" value="rofs3"/>
|
3
|
206 |
<mock xmlns="http://www.test.com/xml/1"/>
|
0
|
207 |
</container>
|
|
208 |
</container>
|
|
209 |
"""
|
|
210 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
3
|
211 |
self.assertEquals(container[0][0].get_tags(), {'target': ['rofs2'],
|
|
212 |
'foobar': ['test']})
|
|
213 |
self.assertEquals(container[1][0].get_tags(), {'target': ['rofs3']})
|
|
214 |
|
|
215 |
def test_read_container_impl_line_numbers(self):
|
|
216 |
xml_data = """<?xml version="1.0"?>
|
|
217 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
218 |
<container>
|
|
219 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
220 |
</container>
|
|
221 |
|
|
222 |
<container>
|
|
223 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
224 |
<container>
|
|
225 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
226 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
227 |
</container>
|
|
228 |
</container>
|
|
229 |
</container>
|
|
230 |
"""
|
|
231 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
232 |
self.assertEquals(container[0].lineno, 3)
|
|
233 |
self.assertEquals(container[0][0].lineno, 4)
|
|
234 |
self.assertEquals(container[1].lineno, 7)
|
|
235 |
self.assertEquals(container[1][0].lineno, 8)
|
|
236 |
self.assertEquals(container[1][1].lineno, 9)
|
|
237 |
self.assertEquals(container[1][1][0].lineno, 10)
|
|
238 |
self.assertEquals(container[1][1][1].lineno, 11)
|
|
239 |
|
|
240 |
def test_container_common_element_inheritance(self):
|
|
241 |
xml_data = """<?xml version="1.0"?>
|
|
242 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
243 |
|
|
244 |
<!-- [0] -->
|
|
245 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
246 |
|
|
247 |
<!-- [1] -->
|
|
248 |
<container>
|
|
249 |
<tag name="target" value="rofs2"/>
|
|
250 |
<tag name="target" value="rofs3"/>
|
|
251 |
<tag name="foo" value="bar"/>
|
|
252 |
<phase name="post"/>
|
|
253 |
<settingRefsOverride>
|
|
254 |
<settingRef value="Foo.Bar"/>
|
|
255 |
<settingRef value="Foo.Baz"/>
|
|
256 |
</settingRefsOverride>
|
|
257 |
<outputRootDir value="/foo/root"/>
|
|
258 |
<outputSubDir value="foosubdir"/>
|
|
259 |
|
|
260 |
<!-- [1][0] -->
|
|
261 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
262 |
|
|
263 |
<!-- [1][1] -->
|
|
264 |
<container>
|
|
265 |
<!-- [1][1][0] -->
|
|
266 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
267 |
|
|
268 |
<!-- [1][1][1] -->
|
|
269 |
<container>
|
|
270 |
<!-- [1][1][1][0] -->
|
|
271 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
272 |
</container>
|
|
273 |
</container>
|
|
274 |
|
|
275 |
<!-- [1][2] -->
|
|
276 |
<container>
|
|
277 |
<tag name="target" value="core"/>
|
|
278 |
<tag name="foo" value="baz"/>
|
|
279 |
<phase name="pre"/>
|
|
280 |
<settingRefsOverride refsIrrelevant="true"/>
|
|
281 |
<outputRootDir value="/foo/root2"/>
|
|
282 |
<outputSubDir value="foosubdir2"/>
|
|
283 |
|
|
284 |
<!-- [1][2][0] -->
|
|
285 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
286 |
|
|
287 |
<!-- [1][2][1] -->
|
|
288 |
<container>
|
|
289 |
<!-- [1][2][1][0] -->
|
|
290 |
<mock xmlns="http://www.test.com/xml/1"/>
|
|
291 |
</container>
|
|
292 |
</container>
|
|
293 |
</container>
|
|
294 |
</container>
|
|
295 |
"""
|
|
296 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
297 |
|
|
298 |
# First impl, with all defaults
|
|
299 |
impl = container[0]
|
|
300 |
self.assertEquals(impl.get_tags(), {})
|
|
301 |
self.assertEquals(impl.invocation_phase(), 'normal')
|
|
302 |
self.assertEquals(impl.get_refs(), None)
|
|
303 |
self.assertEquals(impl.output, '')
|
|
304 |
|
|
305 |
# The sub-container has things overridden, check that they
|
|
306 |
# are all inherited correctly downwards in the implementation
|
|
307 |
# tree
|
|
308 |
def assert_is_expected(impl):
|
|
309 |
self.assertEquals(impl.get_tags(), {'target': ['rofs2', 'rofs3'], 'foo': ['bar']})
|
|
310 |
self.assertEquals(impl.invocation_phase(), 'post')
|
|
311 |
self.assertEquals(impl.get_refs(), ['Foo.Bar', 'Foo.Baz'])
|
|
312 |
self.assertEquals(impl.output, '/foo/root/foosubdir')
|
|
313 |
self.assertEquals(impl.output_subdir, 'foosubdir')
|
|
314 |
assert_is_expected(container[1][0])
|
|
315 |
assert_is_expected(container[1][1][0])
|
|
316 |
assert_is_expected(container[1][1][1][0])
|
|
317 |
|
|
318 |
# The sub-container's second sub-container has things overridden
|
|
319 |
# again, so check that those are correct
|
|
320 |
def assert_is_expected_2(impl):
|
|
321 |
self.assertEquals(impl.get_tags(), {'target': ['core'], 'foo': ['baz']})
|
|
322 |
self.assertEquals(impl.invocation_phase(), 'pre')
|
|
323 |
self.assertEquals(impl.get_refs(), None)
|
|
324 |
self.assertEquals(impl.output, '/foo/root2/foosubdir2')
|
|
325 |
assert_is_expected_2(container[1][2][0])
|
|
326 |
assert_is_expected_2(container[1][2][1][0])
|
0
|
327 |
|
|
328 |
def test_tempfeature_definitions(self):
|
|
329 |
xml_data = """<?xml version="1.0"?>
|
|
330 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1">
|
|
331 |
<tempVariable ref="TempFeature.root" value="true"/>
|
|
332 |
<container>
|
|
333 |
<tempVariable ref="TempFeature.String" type="string" value="testing"/>
|
|
334 |
<tempVariable ref="TempFeature.Int" type="int" value="500"/>
|
|
335 |
<tempVariable ref="TempFeature.Real" type="real" value="1.5"/>
|
|
336 |
<tempVariable ref="TempFeature.Boolean" type="boolean" value="true"/>
|
|
337 |
<tempVariable ref="TempFeature.Defaults"/>
|
|
338 |
|
|
339 |
<tempVariableSequence ref="TempFeature.Seq">
|
|
340 |
<tempVariable ref="String" type="string"/>
|
|
341 |
<tempVariable ref="Int" type="int"/>
|
|
342 |
<tempVariable ref="Real" type="real"/>
|
|
343 |
<tempVariable ref="Boolean" type="boolean"/>
|
|
344 |
<tempVariable ref="DefaultType"/>
|
|
345 |
</tempVariableSequence>
|
|
346 |
</container>
|
|
347 |
</container>
|
|
348 |
"""
|
|
349 |
|
|
350 |
Tfd = _plugin_reader.TempVariableDefinition
|
|
351 |
Tsfd = _plugin_reader.TempVariableSequenceDefinition
|
|
352 |
expected_1 = [
|
|
353 |
Tfd('TempFeature.String', 'string', 'testing'),
|
|
354 |
Tfd('TempFeature.Int', 'int', '500'),
|
|
355 |
Tfd('TempFeature.Real', 'real', '1.5'),
|
|
356 |
Tfd('TempFeature.Boolean', 'boolean', 'true'),
|
|
357 |
Tfd('TempFeature.Defaults', 'string', ''),
|
|
358 |
Tsfd('TempFeature.Seq', [('String', 'string'),
|
|
359 |
('Int', 'int',),
|
|
360 |
('Real', 'real'),
|
|
361 |
('Boolean', 'boolean'),
|
|
362 |
('DefaultType', 'string')]),
|
|
363 |
]
|
|
364 |
expected_2 = [Tfd('TempFeature.root', 'string', value='true')] + expected_1
|
|
365 |
|
|
366 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
367 |
self.assertEquals(container[0].get_temp_variable_definitions(), expected_1)
|
|
368 |
self.assertEquals(container.get_temp_variable_definitions(), expected_2)
|
|
369 |
|
|
370 |
def test_get_test_container_with_condition(self):
|
|
371 |
xml_data = """<?xml version="1.0"?>
|
|
372 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1"
|
|
373 |
condition="${feature.test}">
|
|
374 |
</container>
|
|
375 |
"""
|
|
376 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
377 |
self.assertTrue(isinstance(container.condition, rules.SimpleCondition))
|
|
378 |
self.assertEquals(container.condition.left.expression, "${feature.test}")
|
|
379 |
self.assertEquals(container.condition.right.expression, "true")
|
|
380 |
|
|
381 |
xml_data = """<?xml version="1.0"?>
|
|
382 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1"
|
|
383 |
condition="${feature.test}"
|
|
384 |
value="false">
|
|
385 |
</container>
|
|
386 |
"""
|
|
387 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
388 |
self.assertTrue(isinstance(container.condition, rules.SimpleCondition))
|
|
389 |
self.assertEquals(container.condition.left.expression, "${feature.test}")
|
|
390 |
self.assertEquals(container.condition.right.expression, "false")
|
|
391 |
|
|
392 |
def test_impl_container_with_condition(self):
|
|
393 |
context = plugin.GenerationContext()
|
|
394 |
context.configuration = api.Configuration()
|
|
395 |
context.configuration.add_feature(api.Feature("test"))
|
|
396 |
context.configuration.get_default_view().test.value = True
|
|
397 |
|
|
398 |
xml_data = """<?xml version="1.0"?>
|
|
399 |
<container xmlns="http://www.symbianfoundation.org/xml/implml/1"
|
|
400 |
condition="${test}"
|
|
401 |
value="false">
|
|
402 |
</container>
|
|
403 |
"""
|
|
404 |
container = plugin.ImplContainerReader.read_implementation(xml_data)
|
|
405 |
imp1 = ImplTest("implml/test.content",None)
|
|
406 |
container.append(imp1)
|
|
407 |
container.generate(context)
|
|
408 |
self.assertFalse(imp1.generate_invoked)
|
|
409 |
context.configuration.get_default_view().test.value = False
|
|
410 |
container.generate(context)
|
|
411 |
self.assertTrue(imp1.generate_invoked)
|