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, shutil
|
|
19 |
import sys
|
|
20 |
import logging
|
3
|
21 |
|
0
|
22 |
from cone.public import exceptions,plugin,api,container
|
|
23 |
from cone.storage import filestorage
|
|
24 |
from contentplugin import contentml
|
|
25 |
|
|
26 |
# Hardcoded value of testdata folder that must be under the current working dir
|
|
27 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
28 |
testdata = os.path.join(ROOT_PATH,'contentproject')
|
|
29 |
|
|
30 |
|
|
31 |
class TestContentPlugin(unittest.TestCase):
|
|
32 |
|
|
33 |
def test_create_copy_list_from_datacontainer_with_test(self):
|
|
34 |
'''
|
|
35 |
Test that the loading of the plugins works
|
|
36 |
'''
|
|
37 |
data = container.DataContainer()
|
|
38 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
39 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
40 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
41 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
42 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
43 |
impl = contentml.ContentImpl("foo",None)
|
|
44 |
copylist = impl.create_copy_list(content=data, input='test',output='content')
|
|
45 |
self.assertEquals(copylist[0][1],'content/test.txt')
|
|
46 |
|
|
47 |
def test_create_copy_list_from_datacontainer_with_defauls(self):
|
|
48 |
'''
|
|
49 |
Test that the loading of the plugins works
|
|
50 |
'''
|
|
51 |
data = container.DataContainer()
|
|
52 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
53 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
54 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
55 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
56 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
57 |
impl = contentml.ContentImpl("foo",None)
|
|
58 |
copylist = impl.create_copy_list(content=data)
|
|
59 |
self.assertEquals(copylist[0][0],'/bar/content/test/test.txt')
|
|
60 |
self.assertEquals(copylist[0][1],'test/test.txt')
|
|
61 |
self.assertEquals(copylist[1][0],'/bar/content/include/hide.iby')
|
|
62 |
self.assertEquals(copylist[1][1],'include/hide.iby')
|
|
63 |
|
|
64 |
def test_create_copy_list_from_datacontainer_with_filters(self):
|
|
65 |
'''
|
|
66 |
Test that the loading of the plugins works
|
|
67 |
'''
|
|
68 |
data = container.DataContainer()
|
|
69 |
data.add_value('test/test.txt','/foo/content/test/test.txt')
|
|
70 |
data.add_value('test/test.txt','/bar/content/test/test.txt')
|
|
71 |
data.add_value('product/aaa.txt','/foo/content/product/aaa.txt')
|
|
72 |
data.add_value('images/kuva.jpg','/foo/content/images/kuva.jpg')
|
|
73 |
data.add_value('include/hide.iby','/bar/content/include/hide.iby')
|
|
74 |
impl = contentml.ContentImpl("foo",None)
|
|
75 |
copylist = impl.create_copy_list(content=data,input='include',include_filter='*.iby')
|
|
76 |
self.assertEquals(copylist[0][0],'/bar/content/include/hide.iby')
|
|
77 |
self.assertEquals(copylist[0][1],'hide.iby')
|
|
78 |
|
|
79 |
class TestContentPluginOnFileStorage(unittest.TestCase):
|
|
80 |
def setUp(self):
|
|
81 |
self.curdir = os.getcwd()
|
|
82 |
self.output = 'output'
|
|
83 |
self.workdir = 'workdir'
|
|
84 |
if not os.path.exists(self.workdir):
|
|
85 |
os.mkdir(self.workdir)
|
|
86 |
os.chdir(self.workdir)
|
|
87 |
pass
|
|
88 |
|
|
89 |
def tearDown(self):
|
|
90 |
os.chdir(self.curdir)
|
|
91 |
if os.path.exists(self.workdir):
|
|
92 |
shutil.rmtree(self.workdir)
|
|
93 |
pass
|
|
94 |
|
|
95 |
def load_config(self, config='product.confml'):
|
|
96 |
fs = filestorage.FileStorage(testdata)
|
|
97 |
p = api.Project(fs)
|
|
98 |
return p.get_configuration(config)
|
|
99 |
|
|
100 |
def load_impl(self, resource_ref, config='product.confml'):
|
|
101 |
configuration = self.load_config(config)
|
|
102 |
impls = plugin.ImplFactory.get_impls_from_file(resource_ref, configuration)
|
|
103 |
self.assertEquals(len(impls), 1)
|
|
104 |
impl = impls[0]
|
|
105 |
return impl
|
|
106 |
|
|
107 |
def test_configuration_parse_resource(self):
|
|
108 |
impl = self.load_impl('assets/s60/implml/test_filter_both.content')
|
|
109 |
self.assertEquals(impl.outputs[0].dir,'content')
|
|
110 |
self.assertEquals(impl.outputs[0].inputs[0].include,{'pattern': ['prod']})
|
|
111 |
self.assertEquals(impl.outputs[0].inputs[0].exclude,{'pattern': ['.svn']})
|
|
112 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3', 'uda']})
|
|
113 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
114 |
|
|
115 |
|
|
116 |
def test_configuration_parse_content2(self):
|
|
117 |
impl = self.load_impl('assets/s60/implml/content2_with_tags.content')
|
|
118 |
self.assertEquals(impl.outputs[0].dir,'content')
|
|
119 |
self.assertEquals(impl.outputs[0].inputs[0].include,{'files': ['test/override.txt, test/s60.txt']})
|
|
120 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3', 'uda']})
|
|
121 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
122 |
|
|
123 |
def test_configuration_parse_content2_with_tag_refs(self):
|
|
124 |
impl = self.load_impl('assets/s60/implml/content2_with_tags_refs.content')
|
|
125 |
self.assertEquals(impl.get_tags(), {'target': ['rofs3']})
|
|
126 |
self.assertEquals(impl.has_tag({'target':['rofs3']}), True)
|
|
127 |
|
|
128 |
def test_configuration_parse_and_filter_implementation_with_tags(self):
|
|
129 |
fs = filestorage.FileStorage(testdata)
|
|
130 |
p = api.Project(fs)
|
|
131 |
config = p.get_configuration('product.confml')
|
|
132 |
impls = plugin.get_impl_set(config,'\.content$')
|
|
133 |
impls_rofs3 = impls.filter_implementations(tags={'target':['rofs3']})
|
|
134 |
self.assertEquals(len(list(impls_rofs3)),3)
|
|
135 |
|
|
136 |
def test_configuration_parse_content_with_include_files(self):
|
|
137 |
impl = self.load_impl('assets/s60/implml/copy_files.content')
|
|
138 |
self.assertEquals(impl.outputs[0].inputs[0].include['files'],['test/override.txt, test/s60.txt'])
|
|
139 |
|
|
140 |
def test_configuration_content_get_full_copy_list(self):
|
|
141 |
impl = self.load_impl('assets/s60/implml/copy_files.content')
|
|
142 |
files = impl.get_full_copy_list()
|
3
|
143 |
self.assertEquals(files,
|
|
144 |
[('assets/s60/content/test/s60.txt', 'content/test/s60.txt', False),
|
|
145 |
('family/content/test/override.txt', 'content/test/override.txt', False)])
|
0
|
146 |
|
|
147 |
def test_configuration_content_list_output_files(self):
|
|
148 |
config = self.load_config()
|
|
149 |
impls = plugin.get_impl_set(config,'\.content$')
|
|
150 |
files = impls.list_output_files()
|
3
|
151 |
self.assertTrue('content/test/override.txt' in files)
|
0
|
152 |
|
|
153 |
def test_configuration_content_list_output_files_with_refs_filter(self):
|
|
154 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
|
155 |
files = impl.list_output_files()
|
3
|
156 |
self.assertEquals(files[0],'content/override.txt')
|
0
|
157 |
|
|
158 |
def test_configuration_content_list_output_files_with_exclude_filter(self):
|
|
159 |
impl = self.load_impl('assets/s60/implml/test_filter_both.content')
|
|
160 |
files = impl.list_output_files()
|
3
|
161 |
self.assertEquals(files[0],'content/prodX/jee/ProdX_specific.txt')
|
0
|
162 |
#
|
|
163 |
def test_configuration_get_input_with_ref(self):
|
|
164 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs.content')
|
|
165 |
self.assertEquals(impl.outputs[0].dir, 'content')
|
|
166 |
self.assertEquals(impl.outputs[0].inputs[0].dir, 'content')
|
|
167 |
|
|
168 |
def test_configuration_get_include_with_refs(self):
|
|
169 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
|
170 |
self.assertEquals(impl.outputs[0].inputs[0].include['files'], ['test/override.txt'])
|
3
|
171 |
self.assertEquals(impl.list_output_files(), ['content/override.txt'])
|
0
|
172 |
|
3
|
173 |
def test_configuration_get_include_with_refs2(self):
|
0
|
174 |
impl = self.load_impl('assets/s60/implml/copy.content')
|
3
|
175 |
expected = ['content/prodX/jee/ProdX_specific.txt',
|
|
176 |
'content/test/shout.txt',
|
|
177 |
'content/test/override.txt',
|
|
178 |
'content/test/s60.txt',
|
5
|
179 |
'content/test/test_CAP_letters.txt',
|
|
180 |
'content/wallpapers/wallpaper1.png',
|
|
181 |
'content/wallpapers/wallpaper2.png',
|
|
182 |
'content/wallpapers/wallpaper3.png']
|
0
|
183 |
actual = impl.list_output_files()
|
|
184 |
self.assertEquals(sorted(actual), sorted(expected))
|
|
185 |
|
|
186 |
def test_configuration_content_create_output(self):
|
|
187 |
impl = self.load_impl('assets/s60/implml/copy.content')
|
|
188 |
impl.logger.setLevel(logging.DEBUG)
|
|
189 |
impl.create_output()
|
3
|
190 |
self.assertTrue(os.path.exists(os.path.join(self.output,'content/prodX/jee/ProdX_specific.txt')))
|
0
|
191 |
|
|
192 |
def test_configuration_content_generate(self):
|
|
193 |
config = self.load_config()
|
|
194 |
impls = plugin.get_impl_set(config,'\.content$')
|
3
|
195 |
context = plugin.GenerationContext(output=self.output)
|
|
196 |
results = impls.generate(context)
|
0
|
197 |
self.assertTrue(os.path.exists(impls.output))
|
3
|
198 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content/prodX/jee/ProdX_specific.txt')))
|
0
|
199 |
|
|
200 |
def test_configuration_content_generate_with_include_refs(self):
|
|
201 |
impl = self.load_impl('assets/s60/implml/test_content_with_sequence_refs.content')
|
3
|
202 |
context = plugin.GenerationContext(output=self.output)
|
|
203 |
results = impl.generate(context)
|
|
204 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content/override.txt')))
|
|
205 |
|
|
206 |
def test_configuration_content_generate_with_external_input(self):
|
|
207 |
impl = self.load_impl('assets/s60/implml/test_external_input.content')
|
|
208 |
context = plugin.GenerationContext(output=self.output)
|
|
209 |
results = impl.generate(context)
|
|
210 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content_external/abc.txt')))
|
|
211 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content_external/folder1/data.txt')))
|
|
212 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content_external2/folder2/setting.txt')))
|
0
|
213 |
|
|
214 |
def test_configuration_content_generate_with_multi_output(self):
|
|
215 |
impl = self.load_impl('assets/s60/implml/content2_with_multi_outputs.content')
|
3
|
216 |
context = plugin.GenerationContext(output=self.output)
|
|
217 |
results = impl.generate(context)
|
|
218 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content/test/override.txt')))
|
|
219 |
self.assertTrue(os.path.exists(os.path.join(context.output,'include/s60.txt')))
|
0
|
220 |
|
|
221 |
def test_configuration_content_generate_with_refs(self):
|
|
222 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs2.content')
|
3
|
223 |
context = plugin.GenerationContext(output=self.output)
|
|
224 |
results = impl.generate(context)
|
|
225 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content2p1/content2p2/override.txt')))
|
0
|
226 |
|
|
227 |
def test_configuration_content_generate_with_refs2(self):
|
|
228 |
impl = self.load_impl('assets/s60/implml/test_content_with_refs3.content')
|
3
|
229 |
context = plugin.GenerationContext(output=self.output)
|
|
230 |
results = impl.generate(context)
|
|
231 |
self.assertTrue(os.path.exists(os.path.join(self.output,'example/content2p2/override.txt')))
|
0
|
232 |
|
|
233 |
def test_configuration_content_generate_capital_letters(self):
|
|
234 |
impl = self.load_impl('assets/s60/implml/test_content_capital_file_input.content')
|
3
|
235 |
context = plugin.GenerationContext(output=self.output)
|
|
236 |
results = impl.generate(context)
|
|
237 |
self.assertTrue(os.path.exists(context.output))
|
|
238 |
self.assertTrue(os.path.exists(os.path.join(context.output,'content/test_CAP_letters.txt')))
|
0
|
239 |
|
|
240 |
def test_get_refs(self):
|
|
241 |
def check(filename, expected_refs):
|
|
242 |
impl = self.load_impl('assets/s60/implml/' + filename)
|
|
243 |
actual_refs = impl.get_refs()
|
|
244 |
|
|
245 |
if expected_refs is None:
|
|
246 |
self.assertEquals(actual_refs, None)
|
|
247 |
else:
|
|
248 |
self.assertTrue(actual_refs is not None)
|
|
249 |
self.assertEquals(sorted(actual_refs), sorted(expected_refs))
|
|
250 |
|
|
251 |
check('content2_with_multi_outputs.content', None)
|
|
252 |
check('content2_with_tags_refs.content', None)
|
|
253 |
check('content2_with_tags.content', None)
|
|
254 |
check('copy_files.content', None)
|
|
255 |
check('copy.content', None)
|
|
256 |
check('test_content_with_refs.content', ['content.inputdir'])
|
|
257 |
check('test_content_with_refs2.content', ['content.inputdir2'])
|
|
258 |
check('test_content_with_refs3.content', ['content.inputdir2'])
|
|
259 |
check('test_content_with_sequence_refs.content', ['ContentFiles.contentfile.fileelem.localPath'])
|
|
260 |
check('test_external_input.content', None)
|
|
261 |
check('test_external_with_ref.content', ['CTD_Special.InputPath'])
|
|
262 |
check('test_filter_both.content', None)
|
|
263 |
|
3
|
264 |
def test_uses_layer(self):
|
|
265 |
project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'contentproject')))
|
|
266 |
root_config = project.get_configuration('product.confml')
|
|
267 |
|
|
268 |
impl = self.load_impl('assets/s60/implml/test_content_capital_file_input.content')
|
|
269 |
self.assertFalse(impl.uses_layer(root_config.get_configuration_by_index(0)))
|
|
270 |
self.assertFalse(impl.uses_layer(root_config.get_configuration_by_index(1)))
|
|
271 |
self.assertTrue(impl.uses_layer(root_config.get_configuration_by_index(2)))
|
|
272 |
|
|
273 |
def test_get_copy_list_with_empty_file_input_from_sequence(self):
|
|
274 |
impl = self.load_impl('assets/s60/implml/empty_input_file_from_sequence.content')
|
|
275 |
copylist = impl.get_full_copy_list()
|
|
276 |
# There should be nothing in the copy list
|
|
277 |
self.assertEquals(copylist, [])
|
|
278 |
|
5
|
279 |
def test_get_copy_list_with_multiple_includes_from_sequence(self):
|
|
280 |
impl = self.load_impl('assets/s60/implml/multiple_input_includes_from_sequence.content')
|
|
281 |
copylist = impl.get_full_copy_list()
|
|
282 |
self.assertEquals(sorted(copylist),
|
|
283 |
sorted(
|
|
284 |
[('assets/s60/content/test/foo.txt', 'widget/temp/foo.txt', False),
|
|
285 |
('assets/s60/content/test/bar.txt', 'widget/temp/bar.txt', False),
|
|
286 |
('assets/s60/content/test/baz.txt', 'widget/temp/baz.txt', False),
|
|
287 |
('assets/s60/content/test/s60.txt', 'widget/temp/s60.txt', False)]))
|
|
288 |
|
|
289 |
def test_get_copy_list_with_multiple_input_from_sequence_with_flatten(self):
|
|
290 |
impl = self.load_impl('assets/s60/implml/multiple_input_from_sequence_with_flatten.content')
|
|
291 |
copylist = impl.get_full_copy_list()
|
|
292 |
self.assertEquals(sorted(copylist),
|
|
293 |
sorted(
|
|
294 |
[('family/product/content/wallpapers/wallpaper1.png', 'content/wallpapers/1_wallpaper1.png', False),
|
|
295 |
('family/product/content/wallpapers/wallpaper2.png', 'content/wallpapers/2_wallpaper2.png', False),
|
|
296 |
('family/product/content/wallpapers/wallpaper3.png', 'content/wallpapers/3_wallpaper3.png', False)]))
|
|
297 |
|
0
|
298 |
if __name__ == '__main__':
|
|
299 |
unittest.main()
|