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 |
"""
|
|
18 |
Test the configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
|
21 |
import string
|
|
22 |
import sys,os
|
|
23 |
|
|
24 |
from cone.public import api, plugin
|
|
25 |
from cone.core import *
|
|
26 |
|
|
27 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
28 |
test_project = os.path.join(ROOT_PATH,"testdata/test_project.cpf")
|
|
29 |
multiroot_project = os.path.join(ROOT_PATH,"testdata/multiroot_test.zip")
|
3
|
30 |
LAYERED_RES_PROJECT = os.path.join(ROOT_PATH,"testdata/layered_res_test.zip")
|
|
31 |
|
0
|
32 |
|
|
33 |
class TestConfiguration(unittest.TestCase):
|
|
34 |
def setUp(self):
|
|
35 |
pass
|
|
36 |
|
3
|
37 |
def test_layered_resources_invalid_resource_type(self):
|
|
38 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
39 |
config = p.get_configuration('root.confml')
|
|
40 |
self.assertRaises(ValueError, config.layered_resources, resource_type='foo')
|
|
41 |
|
|
42 |
def test_layered_resource_invalid_params(self):
|
|
43 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
44 |
config = p.get_configuration('root.confml')
|
|
45 |
|
|
46 |
# Both folder and resource_type specified
|
|
47 |
self.assertRaises(ValueError, config.layered_resources, folder='foo', resource_type='implml')
|
|
48 |
|
|
49 |
# Neither folder nor resource_type specified
|
|
50 |
self.assertRaises(ValueError, config.layered_resources, folder=None, resource_type=None)
|
|
51 |
|
|
52 |
def test_layered_resources(self):
|
|
53 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
54 |
config = p.get_configuration('root.confml')
|
|
55 |
|
|
56 |
data = config.layered_resources(resource_type='confml').data
|
|
57 |
self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml',
|
|
58 |
'layer2/confml/test.confml']})
|
|
59 |
|
|
60 |
data = config.layered_resources(resource_type='implml').data
|
|
61 |
self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml',
|
|
62 |
'layer2/implml/test.implml']})
|
|
63 |
|
|
64 |
data = config.layered_resources(resource_type='content').data
|
|
65 |
self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt',
|
|
66 |
'layer2/content/foo.txt']})
|
|
67 |
|
|
68 |
data = config.layered_resources(resource_type='doc').data
|
|
69 |
self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt',
|
|
70 |
'layer2/doc/bar.txt']})
|
|
71 |
|
|
72 |
def test_layered_resources_custom_folder(self):
|
|
73 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
74 |
config = p.get_configuration('root.confml')
|
|
75 |
|
|
76 |
data = config.layered_resources(folder='foo').data
|
|
77 |
self.assertEquals(data, {'bar.txt': ['layer1/foo/bar.txt',
|
|
78 |
'layer2/foo/bar.txt']})
|
|
79 |
|
|
80 |
def test_layered_resources_directly_from_layer(self):
|
|
81 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
82 |
config = p.get_configuration('layer1/root.confml')
|
|
83 |
|
|
84 |
self.assertEquals(config.layered_resources(resource_type='confml').data,
|
|
85 |
{'test.confml': ['layer1/confml/test.confml']})
|
|
86 |
|
|
87 |
self.assertEquals(config.layered_resources(resource_type='implml').data,
|
|
88 |
{'test.implml': ['layer1/implml/test.implml']})
|
|
89 |
|
|
90 |
def test_layered_resources_with_empty_folders(self):
|
|
91 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
92 |
config = p.get_configuration('root.confml')
|
|
93 |
|
|
94 |
data = config.layered_resources(empty_folders=True, resource_type='confml').data
|
|
95 |
self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml',
|
|
96 |
'layer2/confml/test.confml'],
|
|
97 |
'empty': ['layer1/confml/empty',
|
|
98 |
'layer2/confml/empty']})
|
|
99 |
|
|
100 |
data = config.layered_resources(empty_folders=True, resource_type='implml').data
|
|
101 |
self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml',
|
|
102 |
'layer2/implml/test.implml'],
|
|
103 |
'empty': ['layer1/implml/empty',
|
|
104 |
'layer2/implml/empty']})
|
|
105 |
|
|
106 |
data = config.layered_resources(empty_folders=True, resource_type='content').data
|
|
107 |
self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt',
|
|
108 |
'layer2/content/foo.txt'],
|
|
109 |
'empty': ['layer1/content/empty',
|
|
110 |
'layer2/content/empty']})
|
|
111 |
|
|
112 |
data = config.layered_resources(empty_folders=True, resource_type='doc').data
|
|
113 |
self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt',
|
|
114 |
'layer2/doc/bar.txt'],
|
|
115 |
'empty': ['layer1/doc/empty',
|
|
116 |
'layer2/doc/empty']})
|
|
117 |
|
|
118 |
def test_layered_resources_specific_layers(self):
|
|
119 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
120 |
config = p.get_configuration('root.confml')
|
|
121 |
|
|
122 |
self.assertEquals(config.layered_resources(layers=[-1], resource_type='confml').data,
|
|
123 |
{'test.confml': ['layer2/confml/test.confml']})
|
|
124 |
self.assertEquals(config.layered_resources(layers=[0], resource_type='confml').data,
|
|
125 |
{'test.confml': ['layer1/confml/test.confml']})
|
|
126 |
|
|
127 |
def test_layered_resources_shortcuts(self):
|
|
128 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
129 |
config = p.get_configuration('root.confml')
|
|
130 |
|
|
131 |
data = config.layered_confml().data
|
|
132 |
self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml',
|
|
133 |
'layer2/confml/test.confml']})
|
|
134 |
|
|
135 |
data = config.layered_implml().data
|
|
136 |
self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml',
|
|
137 |
'layer2/implml/test.implml']})
|
|
138 |
|
|
139 |
data = config.layered_content().data
|
|
140 |
self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt',
|
|
141 |
'layer2/content/foo.txt']})
|
|
142 |
|
|
143 |
data = config.layered_doc().data
|
|
144 |
self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt',
|
|
145 |
'layer2/doc/bar.txt']})
|
|
146 |
|
|
147 |
|
|
148 |
def test_implml_override(self):
|
|
149 |
p = api.Project(api.Storage.open(LAYERED_RES_PROJECT))
|
|
150 |
config = p.get_configuration('root.confml')
|
|
151 |
|
|
152 |
impl_set = plugin.get_impl_set(config)
|
|
153 |
self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml'])
|
|
154 |
|
|
155 |
impl_set = plugin.filtered_impl_set(config)
|
|
156 |
self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml'])
|
|
157 |
|
|
158 |
|
0
|
159 |
def test_create_configuration(self):
|
|
160 |
conf = api.Configuration("foobar/testmee.confml")
|
|
161 |
self.assertTrue(conf)
|
|
162 |
|
|
163 |
def test_get_root(self):
|
|
164 |
conf = api.Configuration("foobar/testmee.confml")
|
|
165 |
self.assertEquals(conf.get_path(),"foobar/testmee.confml")
|
|
166 |
|
|
167 |
def test_add_layer(self):
|
|
168 |
conf = api.Configuration("data/simple.confml")
|
|
169 |
conf.add_configuration(api.Configuration("foo.confml",namespace="foo"))
|
|
170 |
self.assertEquals(conf.list_configurations(),["foo.confml"])
|
|
171 |
|
|
172 |
def test_meta_desc(self):
|
|
173 |
conf = api.Configuration("test.confml")
|
|
174 |
conf.meta = {'test':'data','test2':'value'}
|
|
175 |
conf.desc = "Description osos"
|
|
176 |
self.assertEquals(conf.meta['test'],"data")
|
|
177 |
self.assertEquals(conf.meta['test2'],"value")
|
|
178 |
self.assertEquals(conf.desc,"Description osos")
|
|
179 |
|
|
180 |
|
|
181 |
def test_project_list_all_sequence_features(self):
|
|
182 |
fs = api.Storage.open(test_project)
|
|
183 |
p = api.Project(fs)
|
|
184 |
config = p.get_configuration('root5.confml')
|
|
185 |
view = config.get_default_view()
|
|
186 |
print "Fealist %s." % len(view.list_all_features())
|
3
|
187 |
self.assertEquals(len(view.list_all_features()), 99)
|
0
|
188 |
for feaname in view.list_all_features():
|
|
189 |
fea = view.get_feature(feaname)
|
|
190 |
if fea.get_type() == 'sequence':
|
|
191 |
print "%s" % feaname,
|
3
|
192 |
print "Value = %s" % fea.get_value()
|
|
193 |
print "RFS = %s" % fea.get_value(attr='rfs')
|
0
|
194 |
|
|
195 |
def test_get_implml_container(self):
|
|
196 |
fs = api.Storage.open(test_project)
|
|
197 |
p = api.Project(fs)
|
|
198 |
config = p.get_configuration('root5.confml')
|
|
199 |
implcont = plugin.get_impl_set(config, 'foo$')
|
|
200 |
self.assertEquals(implcont.list_implementation(),[])
|
|
201 |
|
|
202 |
def test_multiple_open_configurations_in_one_project(self):
|
|
203 |
prj = api.Project(api.Storage.open(multiroot_project, "r"))
|
|
204 |
|
|
205 |
conf1 = prj.get_configuration('root1.confml')
|
|
206 |
|
|
207 |
# Getting the same configuration again should return the same object
|
|
208 |
self.assertTrue(conf1 is prj.get_configuration('root1.confml'))
|
|
209 |
|
|
210 |
conf2 = prj.get_configuration('root2.confml')
|
|
211 |
self.assertFalse(conf1 is conf2)
|
|
212 |
|
|
213 |
# Test getting default views
|
|
214 |
dview1 = conf1.get_default_view()
|
|
215 |
dview2 = conf2.get_default_view()
|
|
216 |
dview3 = prj.get_configuration('root3.confml').get_default_view()
|
|
217 |
dview4 = prj.get_configuration('root4.confml').get_default_view()
|
|
218 |
dview5 = prj.get_configuration('root5.confml').get_default_view()
|
|
219 |
self.assertFalse(dview1 is dview2)
|
|
220 |
self.assertFalse(dview2 is dview3)
|
|
221 |
self.assertFalse(dview3 is dview4)
|
|
222 |
self.assertFalse(dview4 is dview5)
|
|
223 |
self.assertTrue(dview1 is conf1.get_default_view())
|
|
224 |
|
|
225 |
# Test listing features from different configurations
|
|
226 |
self.assertEquals(dview1.list_all_features(), dview2.list_all_features())
|
|
227 |
self.assertEquals(dview2.list_all_features(), dview3.list_all_features())
|
|
228 |
# Layer 4 introduces a new feature
|
|
229 |
self.assertNotEquals(dview3.list_all_features(), dview4.list_all_features())
|
|
230 |
self.assertTrue('Layer4Feature' in dview4.list_all_features())
|
|
231 |
self.assertTrue('Layer4Feature.RealSetting' in dview4.list_all_features())
|
|
232 |
self.assertEquals(dview4.list_all_features(), dview5.list_all_features())
|
|
233 |
|
|
234 |
# Test getting the same feature from different configurations
|
|
235 |
FEATURE_REF = 'Feature1.StringSetting'
|
|
236 |
ss1 = dview1.get_feature(FEATURE_REF)
|
|
237 |
ss2 = dview2.get_feature(FEATURE_REF)
|
|
238 |
ss3 = dview3.get_feature(FEATURE_REF)
|
|
239 |
ss4 = dview4.get_feature(FEATURE_REF)
|
|
240 |
ss5 = dview5.get_feature(FEATURE_REF)
|
|
241 |
self.assertFalse(ss1 is ss2)
|
|
242 |
self.assertFalse(ss2 is ss3)
|
|
243 |
self.assertFalse(ss3 is ss4)
|
|
244 |
self.assertFalse(ss4 is ss5)
|
|
245 |
|
|
246 |
# Test getting values for the features
|
|
247 |
self.assertEquals(ss1.get_value(), 'default string')
|
|
248 |
self.assertEquals(ss2.get_value(), 'layer 2 string')
|
|
249 |
self.assertEquals(ss3.get_value(), 'layer 3 string')
|
|
250 |
self.assertEquals(ss4.get_value(), 'layer 4 string')
|
|
251 |
# Layer 5 contains no data, so the value should be the same as on layer 4
|
|
252 |
self.assertEquals(ss5.get_value(), 'layer 4 string')
|
|
253 |
|
|
254 |
|
|
255 |
#if __name__ == '__main__':
|
|
256 |
# unittest.main()
|
|
257 |
|
|
258 |
|
|
259 |
def profile_project_list_all_features():
|
|
260 |
fs = api.Storage.open(configproject)
|
|
261 |
p = api.Project(fs)
|
|
262 |
config = p.get_configuration('s60.confml')
|
|
263 |
view = config.get_default_view()
|
|
264 |
print "Fealist %s." % len(view.list_all_features())
|
|
265 |
#for fea in view.list_all_features():
|
|
266 |
# if view.get_feature(fea).get_type() == 'sequence':
|
|
267 |
# print "%s" % fea
|
|
268 |
# print " = %s" % view.get_feature(fea).get_value()
|
|
269 |
if __name__ == '__main__':
|
|
270 |
|
|
271 |
import cProfile
|
|
272 |
cProfile.run('profile_project_list_all_features()',None,'time')
|