|
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 os, unittest |
|
18 import __init__ |
|
19 from cone.public import plugin |
|
20 from hcrplugin.hcrml_parser import HcrmlReader |
|
21 |
|
22 def impl_from_resource(resource_ref, configuration): |
|
23 """ |
|
24 Read a HCRML implementation from the given resource in a configuration. |
|
25 """ |
|
26 doc_root = plugin.ReaderBase._read_xml_doc_from_resource(resource_ref, configuration) |
|
27 return HcrmlReader.read_impl(resource_ref, configuration, doc_root) |
|
28 |
|
29 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
30 |
|
31 NAMESPACE = 'http://www.symbianfoundation.org/xml/hcrml/1' |
|
32 |
|
33 TEST_HCRML_DATA = """<?xml version="1.0" encoding="UTF-8"?> |
|
34 <hcr xmlns="%s"> |
|
35 <output file="test.h" type="header"> |
|
36 <category name="KTestCategory" uid="0x11223344"> |
|
37 <setting ref="Feature1.Setting1" name="F1S1" type="int32" id="0"/> |
|
38 <setting ref="Feature1.Setting2" name="F1S2" type="int32" id="1"/> |
|
39 <setting ref="Feature2.Setting1" name="F2S1" type="int32" id="2"/> |
|
40 <setting ref="Feature2.Setting2" name="F2S2" type="int32" id="3"/> |
|
41 </category> |
|
42 </output> |
|
43 </hcr> |
|
44 """ % NAMESPACE |
|
45 |
|
46 HCR_DAT_HCRML_DATA = """<?xml version="1.0" encoding="UTF-8"?> |
|
47 <hcr xmlns="%s"> |
|
48 <output file="sys/data/hcr.dat" type="hcr"> |
|
49 <include ref="*.hcrml"/> |
|
50 </output> |
|
51 </hcr> |
|
52 """ % NAMESPACE |
|
53 |
|
54 NO_OUTPUT_HCRML_DATA = """<?xml version="1.0" encoding="UTF-8"?> |
|
55 <hcr xmlns="%s"> |
|
56 <category name="KTestCategory2" uid="0x44332211"> |
|
57 <setting ref="Feature3.Setting1" name="F3S1" type="int32" id="0x10"/> |
|
58 <setting ref="Feature3.Setting2" name="F3S2" type="int32" id="0x20"/> |
|
59 </category> |
|
60 </hcr> |
|
61 """ % NAMESPACE |
|
62 |
|
63 class Dummy(object): |
|
64 pass |
|
65 |
|
66 class DummyConfiguration(object): |
|
67 RESOURCES = { |
|
68 'layer1/test.hcrml' : TEST_HCRML_DATA, |
|
69 'layer2/no_output.hcrml' : NO_OUTPUT_HCRML_DATA, |
|
70 'layer4/hcr_dat.hcrml' : HCR_DAT_HCRML_DATA, |
|
71 } |
|
72 |
|
73 def list_resources(self): |
|
74 return sorted(self.RESOURCES.keys()) |
|
75 |
|
76 def get_resource(self, res_ref): |
|
77 res = Dummy() |
|
78 res.read = lambda: self.RESOURCES[res_ref] |
|
79 res.close = lambda: None |
|
80 return res |
|
81 |
|
82 def get_default_view(self): |
|
83 view = Dummy() |
|
84 feature = Dummy() |
|
85 feature.get_value = lambda: 0 |
|
86 view.get_feature = lambda ref: feature |
|
87 return view |
|
88 |
|
89 class TestHcrmlImpl(unittest.TestCase): |
|
90 |
|
91 def test_has_ref(self): |
|
92 impl = impl_from_resource('layer1/test.hcrml', DummyConfiguration()) |
|
93 self.assertTrue(impl.has_ref(['Feature1.Setting1'])) |
|
94 self.assertTrue(impl.has_ref(['Feature1.Setting2'])) |
|
95 self.assertTrue(impl.has_ref(['Feature2.Setting1'])) |
|
96 self.assertTrue(impl.has_ref(['Feature2.Setting2'])) |
|
97 self.assertTrue(impl.has_ref(['Feature1.Setting1', 'foo.bar'])) |
|
98 self.assertTrue(impl.has_ref(['Feature1.Setting1', 'Feature1.Setting2'])) |
|
99 |
|
100 self.assertFalse(impl.has_ref([])) |
|
101 self.assertFalse(impl.has_ref(['foo.bar'])) |
|
102 self.assertFalse(impl.has_ref(['Feature1.Setting3'])) |
|
103 self.assertFalse(impl.has_ref(['x.y.z', 'foo.bar'])) |
|
104 self.assertFalse(impl.has_ref(['Feature3.Setting1'])) |
|
105 self.assertFalse(impl.has_ref(['Feature3.Setting2'])) |
|
106 |
|
107 impl = impl_from_resource('layer2/no_output.hcrml', DummyConfiguration()) |
|
108 self.assertFalse(impl.has_ref([])) |
|
109 self.assertFalse(impl.has_ref(['foo.bar'])) |
|
110 self.assertFalse(impl.has_ref(['Feature1.Setting1'])) |
|
111 self.assertFalse(impl.has_ref(['Feature1.Setting2'])) |
|
112 self.assertFalse(impl.has_ref(['Feature2.Setting1'])) |
|
113 self.assertFalse(impl.has_ref(['Feature2.Setting2'])) |
|
114 self.assertTrue(impl.has_ref(['Feature3.Setting1'])) |
|
115 self.assertTrue(impl.has_ref(['Feature3.Setting2'])) |
|
116 |
|
117 |
|
118 # hcr_dat.hcrml includes test.hcrml and no_output.hcrml, but it should |
|
119 # not say that it has the setting references specified in those files |
|
120 impl = impl_from_resource('layer4/hcr_dat.hcrml', DummyConfiguration()) |
|
121 repo = impl.output_obj.get_hcr_repository() |
|
122 # Check that the hcr_dat.hcrml implementation does contain the |
|
123 # records |
|
124 self.assertEquals(len(repo.records), 6) |
|
125 # Check that it doesn't report that it has the references |
|
126 self.assertFalse(impl.has_ref([])) |
|
127 self.assertFalse(impl.has_ref(['foo.bar'])) |
|
128 self.assertFalse(impl.has_ref(['Feature1.Setting1'])) |
|
129 self.assertFalse(impl.has_ref(['Feature1.Setting2'])) |
|
130 self.assertFalse(impl.has_ref(['Feature2.Setting1'])) |
|
131 self.assertFalse(impl.has_ref(['Feature2.Setting2'])) |
|
132 self.assertFalse(impl.has_ref(['Feature3.Setting1'])) |
|
133 self.assertFalse(impl.has_ref(['Feature3.Setting2'])) |
|
134 |
|
135 |
|
136 def test_list_output_files(self): |
|
137 output_dir = 'some/test/output' |
|
138 |
|
139 impl = impl_from_resource('layer1/test.hcrml', DummyConfiguration()) |
|
140 impl.set_output_root(output_dir) |
|
141 self.assertEquals( |
|
142 impl.list_output_files(), |
|
143 [os.path.normpath(os.path.join(output_dir, 'test.h'))]) |
|
144 |
|
145 impl = impl_from_resource('layer4/hcr_dat.hcrml', DummyConfiguration()) |
|
146 impl.set_output_root(output_dir) |
|
147 self.assertEquals( |
|
148 impl.list_output_files(), |
|
149 [os.path.normpath(os.path.join(output_dir, 'sys/data/hcr.dat'))]) |
|
150 |
|
151 impl = impl_from_resource('layer2/no_output.hcrml', DummyConfiguration()) |
|
152 impl.set_output_root(output_dir) |
|
153 self.assertEquals(impl.list_output_files(), []) |