|
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 |
|
20 import __init__ |
|
21 from cone.public import * |
|
22 from cone.public import _plugin_reader |
|
23 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
24 |
|
25 class ImplTest(plugin.ImplBase): |
|
26 def __init__(self,ref,configuration): |
|
27 plugin.ImplBase.__init__(self,ref,configuration) |
|
28 self.generate_invoked = False |
|
29 self.refs = ["dummy1.too"] |
|
30 self.output_files = [] |
|
31 def generate(self, context=None): |
|
32 self.generate_invoked = True |
|
33 if context and hasattr(context, 'objects'): |
|
34 context.objects.append(self) |
|
35 |
|
36 def get_refs(self): |
|
37 return self.refs |
|
38 |
|
39 def list_output_files(self): |
|
40 return self.output_files |
|
41 |
|
42 |
|
43 class TestPluginReader(unittest.TestCase): |
|
44 def setUp(self): |
|
45 pass |
|
46 |
|
47 class TestCommonNamespaceHandling(unittest.TestCase): |
|
48 |
|
49 def setUp(self): |
|
50 pass |
|
51 |
|
52 |
|
53 def tearDown(self): |
|
54 pass |
|
55 |
|
56 def test_implcontainer_reader_get_condition(self): |
|
57 root = utils.etree.fromstring("<container/>") |
|
58 self.assertEquals(plugin.ImplContainerReader.get_condition(root), None) |
|
59 |
|
60 root = utils.etree.fromstring("<container condition='test'/>") |
|
61 condition = plugin.ImplContainerReader.get_condition(root) |
|
62 self.assertTrue(isinstance(condition, rules.SimpleCondition)) |
|
63 self.assertEquals(condition.left.expression, "test") |
|
64 self.assertEquals(condition.right.expression, "true") |
|
65 |
|
66 root = utils.etree.fromstring("<container condition='${feature.one}' value='2'/>") |
|
67 condition = plugin.ImplContainerReader.get_condition(root) |
|
68 self.assertTrue(isinstance(condition, rules.SimpleCondition)) |
|
69 self.assertEquals(condition.left.expression, "${feature.one}") |
|
70 self.assertEquals(condition.right.expression, "2") |
|
71 |
|
72 |
|
73 def test_implcontainer_reader_get_reader_classes(self): |
|
74 classes = plugin.ImplContainerReader.get_reader_classes() |
|
75 self.assertTrue(classes.has_key('http://www.symbianfoundation.org/xml/implml/1')) |
|
76 |
|
77 def test_get_test_container(self): |
|
78 xml_data = """<?xml version="1.0"?> |
|
79 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
80 </container> |
|
81 """ |
|
82 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
83 self.assertTrue(isinstance(container, plugin.ImplContainer)) |
|
84 |
|
85 def test_get_test_container_with_sub_containers(self): |
|
86 xml_data = """<?xml version="1.0"?> |
|
87 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
88 <container /> |
|
89 <container /> |
|
90 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
91 <container /> |
|
92 </container> |
|
93 </container> |
|
94 """ |
|
95 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
96 self.assertTrue(isinstance(container, plugin.ImplContainer)) |
|
97 self.assertEquals(len(container), 3) |
|
98 |
|
99 def test_containers_with_phases(self): |
|
100 xml_data = """<?xml version="1.0"?> |
|
101 <implml:container xmlns:implml="http://www.symbianfoundation.org/xml/implml/1"> |
|
102 <implml:container /> |
|
103 <implml:container /> |
|
104 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
105 <phase name="post"/> |
|
106 </container> |
|
107 </implml:container> |
|
108 """ |
|
109 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
110 self.assertEquals(container.invocation_phase(), ['post','normal']) |
|
111 self.assertEquals(container[2].invocation_phase(), ['post']) |
|
112 |
|
113 def test_containers_with_tags(self): |
|
114 xml_data = """<?xml version="1.0"?> |
|
115 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
116 <tag name="target" value="rofs2"/> |
|
117 <tag name="foobar" value="test"/> |
|
118 <container /> |
|
119 <container /> |
|
120 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
121 <tag name="target" value="rofs3"/> |
|
122 <phase name="post"/> |
|
123 </container> |
|
124 </container> |
|
125 """ |
|
126 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
127 self.assertEquals(container[2].get_tags(), {'target': ['rofs3']}) |
|
128 self.assertEquals(container.get_tags(), {'target': ['rofs2','rofs3'], |
|
129 'foobar': ['test']}) |
|
130 |
|
131 def test_tempfeature_definitions(self): |
|
132 xml_data = """<?xml version="1.0"?> |
|
133 <container xmlns="http://www.symbianfoundation.org/xml/implml/1"> |
|
134 <tempVariable ref="TempFeature.root" value="true"/> |
|
135 <container> |
|
136 <tempVariable ref="TempFeature.String" type="string" value="testing"/> |
|
137 <tempVariable ref="TempFeature.Int" type="int" value="500"/> |
|
138 <tempVariable ref="TempFeature.Real" type="real" value="1.5"/> |
|
139 <tempVariable ref="TempFeature.Boolean" type="boolean" value="true"/> |
|
140 <tempVariable ref="TempFeature.Defaults"/> |
|
141 |
|
142 <tempVariableSequence ref="TempFeature.Seq"> |
|
143 <tempVariable ref="String" type="string"/> |
|
144 <tempVariable ref="Int" type="int"/> |
|
145 <tempVariable ref="Real" type="real"/> |
|
146 <tempVariable ref="Boolean" type="boolean"/> |
|
147 <tempVariable ref="DefaultType"/> |
|
148 </tempVariableSequence> |
|
149 </container> |
|
150 </container> |
|
151 """ |
|
152 |
|
153 Tfd = _plugin_reader.TempVariableDefinition |
|
154 Tsfd = _plugin_reader.TempVariableSequenceDefinition |
|
155 expected_1 = [ |
|
156 Tfd('TempFeature.String', 'string', 'testing'), |
|
157 Tfd('TempFeature.Int', 'int', '500'), |
|
158 Tfd('TempFeature.Real', 'real', '1.5'), |
|
159 Tfd('TempFeature.Boolean', 'boolean', 'true'), |
|
160 Tfd('TempFeature.Defaults', 'string', ''), |
|
161 Tsfd('TempFeature.Seq', [('String', 'string'), |
|
162 ('Int', 'int',), |
|
163 ('Real', 'real'), |
|
164 ('Boolean', 'boolean'), |
|
165 ('DefaultType', 'string')]), |
|
166 ] |
|
167 expected_2 = [Tfd('TempFeature.root', 'string', value='true')] + expected_1 |
|
168 |
|
169 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
170 self.assertEquals(container[0].get_temp_variable_definitions(), expected_1) |
|
171 self.assertEquals(container.get_temp_variable_definitions(), expected_2) |
|
172 |
|
173 def test_get_test_container_with_condition(self): |
|
174 xml_data = """<?xml version="1.0"?> |
|
175 <container xmlns="http://www.symbianfoundation.org/xml/implml/1" |
|
176 condition="${feature.test}"> |
|
177 </container> |
|
178 """ |
|
179 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
180 self.assertTrue(isinstance(container.condition, rules.SimpleCondition)) |
|
181 self.assertEquals(container.condition.left.expression, "${feature.test}") |
|
182 self.assertEquals(container.condition.right.expression, "true") |
|
183 |
|
184 xml_data = """<?xml version="1.0"?> |
|
185 <container xmlns="http://www.symbianfoundation.org/xml/implml/1" |
|
186 condition="${feature.test}" |
|
187 value="false"> |
|
188 </container> |
|
189 """ |
|
190 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
191 self.assertTrue(isinstance(container.condition, rules.SimpleCondition)) |
|
192 self.assertEquals(container.condition.left.expression, "${feature.test}") |
|
193 self.assertEquals(container.condition.right.expression, "false") |
|
194 |
|
195 def test_impl_container_with_condition(self): |
|
196 context = plugin.GenerationContext() |
|
197 context.configuration = api.Configuration() |
|
198 context.configuration.add_feature(api.Feature("test")) |
|
199 context.configuration.get_default_view().test.value = True |
|
200 |
|
201 xml_data = """<?xml version="1.0"?> |
|
202 <container xmlns="http://www.symbianfoundation.org/xml/implml/1" |
|
203 condition="${test}" |
|
204 value="false"> |
|
205 </container> |
|
206 """ |
|
207 container = plugin.ImplContainerReader.read_implementation(xml_data) |
|
208 imp1 = ImplTest("implml/test.content",None) |
|
209 container.append(imp1) |
|
210 container.generate(context) |
|
211 self.assertFalse(imp1.generate_invoked) |
|
212 context.configuration.get_default_view().test.value = False |
|
213 container.generate(context) |
|
214 self.assertTrue(imp1.generate_invoked) |