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 |
import __init__
|
|
25 |
from cone.public import api, plugin
|
|
26 |
from cone.core import *
|
|
27 |
|
|
28 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
29 |
test_project = os.path.join(ROOT_PATH,"testdata/test_project.cpf")
|
|
30 |
multiroot_project = os.path.join(ROOT_PATH,"testdata/multiroot_test.zip")
|
|
31 |
|
|
32 |
class TestConfiguration(unittest.TestCase):
|
|
33 |
def setUp(self):
|
|
34 |
pass
|
|
35 |
|
|
36 |
# @test
|
|
37 |
def test_create_configuration(self):
|
|
38 |
conf = api.Configuration("foobar/testmee.confml")
|
|
39 |
self.assertTrue(conf)
|
|
40 |
|
|
41 |
def test_get_root(self):
|
|
42 |
conf = api.Configuration("foobar/testmee.confml")
|
|
43 |
self.assertEquals(conf.get_path(),"foobar/testmee.confml")
|
|
44 |
|
|
45 |
def test_add_layer(self):
|
|
46 |
conf = api.Configuration("data/simple.confml")
|
|
47 |
conf.add_configuration(api.Configuration("foo.confml",namespace="foo"))
|
|
48 |
self.assertEquals(conf.list_configurations(),["foo.confml"])
|
|
49 |
|
|
50 |
def test_meta_desc(self):
|
|
51 |
conf = api.Configuration("test.confml")
|
|
52 |
conf.meta = {'test':'data','test2':'value'}
|
|
53 |
conf.desc = "Description osos"
|
|
54 |
self.assertEquals(conf.meta['test'],"data")
|
|
55 |
self.assertEquals(conf.meta['test2'],"value")
|
|
56 |
self.assertEquals(conf.desc,"Description osos")
|
|
57 |
|
|
58 |
|
|
59 |
def test_project_list_all_sequence_features(self):
|
|
60 |
fs = api.Storage.open(test_project)
|
|
61 |
p = api.Project(fs)
|
|
62 |
config = p.get_configuration('root5.confml')
|
|
63 |
view = config.get_default_view()
|
|
64 |
print "Fealist %s." % len(view.list_all_features())
|
|
65 |
self.assertEquals(len(view.list_all_features()), 62)
|
|
66 |
for feaname in view.list_all_features():
|
|
67 |
fea = view.get_feature(feaname)
|
|
68 |
if fea.get_type() == 'sequence':
|
|
69 |
print "%s" % feaname,
|
|
70 |
print " = %s" % fea.get_value()
|
|
71 |
|
|
72 |
def test_get_implml_container(self):
|
|
73 |
fs = api.Storage.open(test_project)
|
|
74 |
p = api.Project(fs)
|
|
75 |
config = p.get_configuration('root5.confml')
|
|
76 |
implcont = plugin.get_impl_set(config, 'foo$')
|
|
77 |
self.assertEquals(implcont.list_implementation(),[])
|
|
78 |
|
|
79 |
def test_multiple_open_configurations_in_one_project(self):
|
|
80 |
prj = api.Project(api.Storage.open(multiroot_project, "r"))
|
|
81 |
|
|
82 |
conf1 = prj.get_configuration('root1.confml')
|
|
83 |
|
|
84 |
# Getting the same configuration again should return the same object
|
|
85 |
self.assertTrue(conf1 is prj.get_configuration('root1.confml'))
|
|
86 |
|
|
87 |
conf2 = prj.get_configuration('root2.confml')
|
|
88 |
self.assertFalse(conf1 is conf2)
|
|
89 |
|
|
90 |
# Test getting default views
|
|
91 |
dview1 = conf1.get_default_view()
|
|
92 |
dview2 = conf2.get_default_view()
|
|
93 |
dview3 = prj.get_configuration('root3.confml').get_default_view()
|
|
94 |
dview4 = prj.get_configuration('root4.confml').get_default_view()
|
|
95 |
dview5 = prj.get_configuration('root5.confml').get_default_view()
|
|
96 |
self.assertFalse(dview1 is dview2)
|
|
97 |
self.assertFalse(dview2 is dview3)
|
|
98 |
self.assertFalse(dview3 is dview4)
|
|
99 |
self.assertFalse(dview4 is dview5)
|
|
100 |
self.assertTrue(dview1 is conf1.get_default_view())
|
|
101 |
|
|
102 |
# Test listing features from different configurations
|
|
103 |
self.assertEquals(dview1.list_all_features(), dview2.list_all_features())
|
|
104 |
self.assertEquals(dview2.list_all_features(), dview3.list_all_features())
|
|
105 |
# Layer 4 introduces a new feature
|
|
106 |
self.assertNotEquals(dview3.list_all_features(), dview4.list_all_features())
|
|
107 |
self.assertTrue('Layer4Feature' in dview4.list_all_features())
|
|
108 |
self.assertTrue('Layer4Feature.RealSetting' in dview4.list_all_features())
|
|
109 |
self.assertEquals(dview4.list_all_features(), dview5.list_all_features())
|
|
110 |
|
|
111 |
# Test getting the same feature from different configurations
|
|
112 |
FEATURE_REF = 'Feature1.StringSetting'
|
|
113 |
ss1 = dview1.get_feature(FEATURE_REF)
|
|
114 |
ss2 = dview2.get_feature(FEATURE_REF)
|
|
115 |
ss3 = dview3.get_feature(FEATURE_REF)
|
|
116 |
ss4 = dview4.get_feature(FEATURE_REF)
|
|
117 |
ss5 = dview5.get_feature(FEATURE_REF)
|
|
118 |
self.assertFalse(ss1 is ss2)
|
|
119 |
self.assertFalse(ss2 is ss3)
|
|
120 |
self.assertFalse(ss3 is ss4)
|
|
121 |
self.assertFalse(ss4 is ss5)
|
|
122 |
|
|
123 |
# Test getting values for the features
|
|
124 |
self.assertEquals(ss1.get_value(), 'default string')
|
|
125 |
self.assertEquals(ss2.get_value(), 'layer 2 string')
|
|
126 |
self.assertEquals(ss3.get_value(), 'layer 3 string')
|
|
127 |
self.assertEquals(ss4.get_value(), 'layer 4 string')
|
|
128 |
# Layer 5 contains no data, so the value should be the same as on layer 4
|
|
129 |
self.assertEquals(ss5.get_value(), 'layer 4 string')
|
|
130 |
|
|
131 |
|
|
132 |
#if __name__ == '__main__':
|
|
133 |
# unittest.main()
|
|
134 |
|
|
135 |
|
|
136 |
def profile_project_list_all_features():
|
|
137 |
fs = api.Storage.open(configproject)
|
|
138 |
p = api.Project(fs)
|
|
139 |
config = p.get_configuration('s60.confml')
|
|
140 |
view = config.get_default_view()
|
|
141 |
print "Fealist %s." % len(view.list_all_features())
|
|
142 |
#for fea in view.list_all_features():
|
|
143 |
# if view.get_feature(fea).get_type() == 'sequence':
|
|
144 |
# print "%s" % fea
|
|
145 |
# print " = %s" % view.get_feature(fea).get_value()
|
|
146 |
if __name__ == '__main__':
|
|
147 |
|
|
148 |
import cProfile
|
|
149 |
cProfile.run('profile_project_list_all_features()',None,'time')
|