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
|
|
20 |
import __init__
|
|
21 |
from cone.public import *
|
|
22 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
class TestPluginImplContainer(unittest.TestCase):
|
|
27 |
class ImplTest(plugin.ImplBase):
|
|
28 |
def __init__(self,ref,configuration):
|
|
29 |
plugin.ImplBase.__init__(self,ref,configuration)
|
|
30 |
self.generate_invoked = False
|
|
31 |
self.refs = ["dummy1.too"]
|
|
32 |
self.output_files = []
|
|
33 |
def generate(self, context=None):
|
|
34 |
self.generate_invoked = True
|
|
35 |
if context and hasattr(context, 'objects'):
|
|
36 |
context.objects.append(self)
|
|
37 |
|
|
38 |
def get_refs(self):
|
|
39 |
return self.refs
|
|
40 |
|
|
41 |
def list_output_files(self):
|
|
42 |
return self.output_files
|
|
43 |
|
|
44 |
def test_impl_container_add(self):
|
|
45 |
container = plugin.ImplContainer("norm", None)
|
|
46 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
47 |
imp2a = plugin.ImplBase("implml/copy:21.content",None)
|
|
48 |
imp2b = plugin.ImplBase("implml/copy:24.content",None)
|
|
49 |
container.append(imp1)
|
|
50 |
container.append(imp2a)
|
|
51 |
container.append(imp2b)
|
|
52 |
self.assertEquals(container.impls, [imp1,imp2a, imp2b])
|
|
53 |
|
|
54 |
def test_impl_container_sub_container(self):
|
|
55 |
container = plugin.ImplContainer("norm", None)
|
|
56 |
imp1 = plugin.ImplBase("implml/test.content",None)
|
|
57 |
container.append(imp1)
|
|
58 |
subcontainer = plugin.ImplContainer("implml/sub.implml", None)
|
|
59 |
imp2a = plugin.ImplBase("implml/sub.implml:21.content",None)
|
|
60 |
imp2b = plugin.ImplBase("implml/sub.implml:24.content",None)
|
|
61 |
subcontainer.append(imp2a)
|
|
62 |
subcontainer.append(imp2b)
|
|
63 |
container.append(subcontainer)
|
|
64 |
self.assertEquals(container.get_all_implementations(),[imp1,imp2a,imp2b])
|
|
65 |
for sub in container:
|
|
66 |
print sub
|
|
67 |
self.assertEquals(container.impls, [imp1,subcontainer])
|
|
68 |
container[0] = subcontainer
|
|
69 |
self.assertEquals(container.impls, [subcontainer,subcontainer])
|
|
70 |
del container[0]
|
|
71 |
self.assertEquals(container.impls, [subcontainer])
|
|
72 |
|
|
73 |
def test_impl_container_with_condition(self):
|
|
74 |
context = plugin.GenerationContext()
|
|
75 |
context.configuration = api.Configuration()
|
|
76 |
context.configuration.add_feature(api.Feature("test"))
|
|
77 |
context.configuration.add_feature(api.Feature("stringsub"),"test")
|
|
78 |
context.configuration.add_feature(api.Feature("intsub"),"test")
|
|
79 |
context.configuration.get_default_view().test.value = True
|
|
80 |
context.configuration.get_default_view().test.stringsub.value = "stringval"
|
|
81 |
context.configuration.get_default_view().test.intsub.value = 2
|
|
82 |
|
|
83 |
condition = rules.SimpleCondition("${test}", "true")
|
|
84 |
container = plugin.ImplContainer("norm", None)
|
|
85 |
container.condition = condition
|
|
86 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
87 |
container.append(imp1)
|
|
88 |
container.generate(context)
|
|
89 |
self.assertTrue(imp1.generate_invoked)
|
|
90 |
imp1.generate_invoked = False
|
|
91 |
context.configuration.get_default_view().test.value = False
|
|
92 |
container.generate(context)
|
|
93 |
self.assertFalse(imp1.generate_invoked)
|
|
94 |
|
|
95 |
imp1.generate_invoked = False
|
|
96 |
condition = rules.SimpleCondition("${test}", "false")
|
|
97 |
container.condition = condition
|
|
98 |
container.append(imp1)
|
|
99 |
container.generate(context)
|
|
100 |
self.assertTrue(imp1.generate_invoked)
|
|
101 |
imp1.generate_invoked = False
|
|
102 |
context.configuration.get_default_view().test.value = True
|
|
103 |
container.generate(context)
|
|
104 |
self.assertFalse(imp1.generate_invoked)
|
|
105 |
|
|
106 |
|
|
107 |
def test_impl_container_generate(self):
|
|
108 |
container = plugin.ImplContainer("norm", None)
|
|
109 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
110 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
111 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
112 |
container.append(imp1)
|
|
113 |
container.append(imp2a)
|
|
114 |
container.append(imp2b)
|
|
115 |
container.generate()
|
|
116 |
self.assertTrue(imp1.generate_invoked)
|
|
117 |
self.assertTrue(imp2a.generate_invoked)
|
|
118 |
self.assertTrue(imp2a.generate_invoked)
|
|
119 |
|
|
120 |
def test_impl_container_get_tags(self):
|
|
121 |
container = plugin.ImplContainer("norm", None)
|
|
122 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
123 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
124 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
125 |
subcontainer = plugin.ImplContainer("sub", None)
|
|
126 |
container.append(imp1)
|
|
127 |
container.append(imp2a)
|
|
128 |
container.append(imp2b)
|
|
129 |
container.append(subcontainer)
|
|
130 |
self.assertEquals(container.get_tags(), {})
|
|
131 |
container.set_tags({'test':['foobar']})
|
|
132 |
self.assertEquals(container.get_tags(), {'test':['foobar']})
|
|
133 |
imp1.set_tags({'foo':['bar']})
|
|
134 |
self.assertEquals(container.get_tags(), {'test':['foobar'],
|
|
135 |
'foo':['bar']})
|
|
136 |
imp2a.set_tags({'test':['bar'], 'one' :['more']})
|
|
137 |
|
|
138 |
self.assertEquals(container.get_tags(), {'test':['foobar', 'bar'],
|
|
139 |
'foo':['bar'],
|
|
140 |
'one' :['more']})
|
|
141 |
subcontainer.set_tags({'test':['bar1']})
|
|
142 |
self.assertEquals(container.get_tags(), {'test':['foobar', 'bar', 'bar1'],
|
|
143 |
'foo':['bar'],
|
|
144 |
'one' :['more']})
|
|
145 |
|
|
146 |
def test_impl_container_get_phase(self):
|
|
147 |
container = plugin.ImplContainer("norm", None)
|
|
148 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
149 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
150 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
151 |
subcontainer1 = plugin.ImplContainer("norm", None)
|
|
152 |
container.append(subcontainer1)
|
|
153 |
subcontainer1.append(imp1)
|
|
154 |
subcontainer1.append(imp2a)
|
|
155 |
subcontainer1.append(imp2b)
|
|
156 |
subcontainer1.set_invocation_phase("normal")
|
|
157 |
self.assertEquals(container.invocation_phase(), ["normal"])
|
|
158 |
imp1.set_invocation_phase('pre')
|
|
159 |
self.assertEquals(container.invocation_phase(), ["normal"])
|
|
160 |
subcontainer2 = plugin.ImplContainer("norm", None)
|
|
161 |
subimp = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
162 |
subimp.set_invocation_phase('post')
|
|
163 |
subcontainer2.append(subimp)
|
|
164 |
subcontainer2.set_invocation_phase('post')
|
|
165 |
container.append(subcontainer2)
|
|
166 |
self.assertEquals(container.invocation_phase(), ['post','normal'])
|
|
167 |
|
|
168 |
def test_impl_container_get_refs(self):
|
|
169 |
container = plugin.ImplContainer("norm", None)
|
|
170 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
171 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
172 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
173 |
container.append(imp1)
|
|
174 |
container.append(imp2a)
|
|
175 |
container.append(imp2b)
|
|
176 |
self.assertEquals(container.get_refs(), ["dummy1.too"])
|
|
177 |
imp2b.refs = ['dummy2.foo']
|
|
178 |
self.assertEquals(container.get_refs(), ["dummy1.too",
|
|
179 |
"dummy2.foo",])
|
|
180 |
|
|
181 |
def test_impl_container_list_output_files(self):
|
|
182 |
container = plugin.ImplContainer("norm", None)
|
|
183 |
subcontainer = plugin.ImplContainer("norm", None)
|
|
184 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
185 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
186 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
187 |
container.append(subcontainer)
|
|
188 |
subcontainer.append(imp1)
|
|
189 |
subcontainer.append(imp2a)
|
|
190 |
subcontainer.append(imp2b)
|
|
191 |
self.assertEquals(container.list_output_files(), [])
|
|
192 |
imp2b.output_files= ['output/dummy2.txt']
|
|
193 |
self.assertEquals(container.list_output_files(), ['output/dummy2.txt'])
|
|
194 |
imp1.output_files= ['output/foobar/hee.txt']
|
|
195 |
self.assertEquals(container.list_output_files(), ['output/foobar/hee.txt',
|
|
196 |
'output/dummy2.txt'])
|
|
197 |
|
|
198 |
def test_impl_container_set_output_root(self):
|
|
199 |
container = plugin.ImplContainer("norm", None)
|
|
200 |
subcontainer = plugin.ImplContainer("norm", None)
|
|
201 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
202 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
203 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
204 |
container.append(subcontainer)
|
|
205 |
subcontainer.append(imp1)
|
|
206 |
subcontainer.append(imp2a)
|
|
207 |
subcontainer.append(imp2b)
|
|
208 |
self.assertEquals(imp1.get_output_root(), 'output')
|
|
209 |
container.set_output_root('foobar/test')
|
|
210 |
self.assertEquals(imp1.get_output_root(), 'foobar/test')
|
|
211 |
|
|
212 |
def test_impl_container_sub_container_generate(self):
|
|
213 |
container = plugin.ImplContainer("norm", None)
|
|
214 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
215 |
container.append(imp1)
|
|
216 |
subcontainer = plugin.ImplContainer("implml/sub.implml", None)
|
|
217 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
218 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
219 |
subcontainer.append(imp2a)
|
|
220 |
subcontainer.append(imp2b)
|
|
221 |
container.append(subcontainer)
|
|
222 |
self.assertEquals(container.impls, [imp1,subcontainer])
|
|
223 |
container.append(subcontainer)
|
|
224 |
container.generate()
|
|
225 |
self.assertTrue(imp1.generate_invoked)
|
|
226 |
self.assertTrue(imp2a.generate_invoked)
|
|
227 |
self.assertTrue(imp2a.generate_invoked)
|
|
228 |
|
|
229 |
def test_impl_container_sub_container_generate_with_generation_contexts(self):
|
|
230 |
container = plugin.ImplContainer("norm", None)
|
|
231 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
232 |
container.append(imp1)
|
|
233 |
subcontainer = plugin.ImplContainer("implml/sub.implml", None)
|
|
234 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
235 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
236 |
subcontainer.append(imp2a)
|
|
237 |
subcontainer.append(imp2b)
|
|
238 |
container.append(subcontainer)
|
|
239 |
self.assertEquals(container.impls, [imp1,subcontainer])
|
|
240 |
context = plugin.GenerationContext()
|
|
241 |
context.objects = []
|
|
242 |
container.generate(context)
|
|
243 |
self.assertTrue(imp1.generate_invoked)
|
|
244 |
self.assertTrue(imp2a.generate_invoked)
|
|
245 |
self.assertTrue(imp2a.generate_invoked)
|
|
246 |
self.assertEquals(len(context.objects), 3)
|
|
247 |
self.assertEquals(context.objects, [imp1,imp2a,imp2b])
|
|
248 |
|
|
249 |
def test_impl_container_generate_with_generation_contexts_tags(self):
|
|
250 |
container = plugin.ImplContainer("norm", None)
|
|
251 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
252 |
subcontainer1 = plugin.ImplContainer("implml/sub1.implml", None)
|
|
253 |
subcontainer1.append(imp1)
|
|
254 |
|
|
255 |
subcontainer2 = plugin.ImplContainer("implml/sub2.implml", None)
|
|
256 |
subcontainer2.set_tags({'target': ['rofs3','uda']})
|
|
257 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
258 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
259 |
subcontainer2.append(imp2a)
|
|
260 |
subcontainer2.append(imp2b)
|
|
261 |
container.append(subcontainer1)
|
|
262 |
container.append(subcontainer2)
|
|
263 |
|
|
264 |
context = plugin.GenerationContext()
|
|
265 |
context.tags = {'target': ['rofs3'], 'foobar' :['test']}
|
|
266 |
context.objects = []
|
|
267 |
container.generate(context)
|
|
268 |
self.assertFalse(imp1.generate_invoked)
|
|
269 |
self.assertTrue(imp2a.generate_invoked)
|
|
270 |
self.assertTrue(imp2a.generate_invoked)
|
|
271 |
self.assertEquals(len(context.objects), 2)
|
|
272 |
self.assertEquals(context.objects, [imp2a,imp2b])
|
|
273 |
|
|
274 |
def test_impl_container_generate_with_generation_phase(self):
|
|
275 |
container = plugin.ImplContainer("norm", None)
|
|
276 |
imp1 = TestPluginImplContainer.ImplTest("implml/test.content",None)
|
|
277 |
subcontainer1 = plugin.ImplContainer("implml/sub1.implml", None)
|
|
278 |
subcontainer1.append(imp1)
|
|
279 |
|
|
280 |
subcontainer2 = plugin.ImplContainer("implml/sub2.implml", None)
|
|
281 |
subcontainer2.set_invocation_phase("post")
|
|
282 |
imp2a = TestPluginImplContainer.ImplTest("implml/copy:21.content",None)
|
|
283 |
imp2b = TestPluginImplContainer.ImplTest("implml/copy:24.content",None)
|
|
284 |
subcontainer2.append(imp2a)
|
|
285 |
subcontainer2.append(imp2b)
|
|
286 |
container.append(subcontainer1)
|
|
287 |
container.append(subcontainer2)
|
|
288 |
|
|
289 |
context = plugin.GenerationContext()
|
|
290 |
context.phase = "post"
|
|
291 |
context.objects = []
|
|
292 |
container.generate(context)
|
|
293 |
self.assertFalse(imp1.generate_invoked)
|
|
294 |
self.assertTrue(imp2a.generate_invoked)
|
|
295 |
self.assertTrue(imp2a.generate_invoked)
|
|
296 |
self.assertEquals(len(context.objects), 2)
|
|
297 |
self.assertEquals(context.objects, [imp2a,imp2b])
|
|
298 |
|