|
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 __init__ |
|
21 try: |
|
22 from cElementTree import ElementTree |
|
23 except ImportError: |
|
24 try: |
|
25 from elementtree import ElementTree |
|
26 except ImportError: |
|
27 try: |
|
28 from xml.etree import cElementTree as ElementTree |
|
29 except ImportError: |
|
30 from xml.etree import ElementTree |
|
31 |
|
32 from imageplugin import imageml |
|
33 |
|
34 |
|
35 imageml_string = \ |
|
36 '''<?xml version="1.0" encoding="UTF-8"?> |
|
37 <imageml xmlns="http://www.s60.com/xml/imageml/1"> |
|
38 <output file="startup.mbm"> |
|
39 <input dir="UI/Start-up Animation"> |
|
40 <include pattern="bmb$"/> |
|
41 <exclude pattern=".svn"/> |
|
42 </input> |
|
43 </output> |
|
44 <output file="shutdown.mbm"> |
|
45 <input file="UI/graphics/icon1.bmb" depth="8" /> |
|
46 <input file="UI/graphics/icon2.bmb" depth="8" /> |
|
47 <input file="UI/graphics/icon3.bmb" depth="8" /> |
|
48 <input file="UI/graphics/icon4.bmb" depth="8" /> |
|
49 </output> |
|
50 </imageml> |
|
51 ''' |
|
52 |
|
53 imageml_with_refs = \ |
|
54 '''<?xml version="1.0" encoding="UTF-8"?> |
|
55 <imageml xmlns="http://www.s60.com/xml/imageml/1"> |
|
56 <output file="${features.outputref}"> |
|
57 <input dir="${features.inputref}"> |
|
58 <include pattern="${features.inputfilter}"/> |
|
59 </input> |
|
60 </output> |
|
61 <output file="${features.outputseqfile}"> |
|
62 <input file="${features.outputseq.file.localpath}"> |
|
63 </input> |
|
64 </output> |
|
65 </imageml> |
|
66 ''' |
|
67 input_dir= \ |
|
68 '''<output xmlns="http://www.s60.com/xml/imageml/1" file="test.mbm"> |
|
69 <input dir="UI/Start-up Animation" depth="8" test="foo"> |
|
70 <include pattern="bmb$"/> |
|
71 <exclude pattern=".svn"/> |
|
72 </input> |
|
73 <input dir="UI/Start-up Animation/masks" depth="2"> |
|
74 <include pattern="bmb$"/> |
|
75 </input> |
|
76 </output> |
|
77 ''' |
|
78 input_files = \ |
|
79 '''<output xmlns="http://www.s60.com/xml/imageml/1" file="test.mbm"> |
|
80 <input file="UI/graphics/icon1.bmb" depth="8" /> |
|
81 <input file="UI/graphics/icon2.bmb" depth="8" /> |
|
82 <input file="UI/graphics/icon3.bmb" depth="8" /> |
|
83 <input file="UI/graphics/icon4.bmb" depth="8" /> |
|
84 </output> |
|
85 ''' |
|
86 |
|
87 class TestImagemlParseimpl(unittest.TestCase): |
|
88 |
|
89 def test_parse_output(self): |
|
90 etree = ElementTree.fromstring(imageml_string) |
|
91 reader = imageml.ImageImplReader() |
|
92 outgens = reader.parse_outputs(etree) |
|
93 self.assertEquals(outgens[0].outputpath,'startup.mbm') |
|
94 |
|
95 def test_parse_input_include(self): |
|
96 etree = ElementTree.fromstring(input_dir) |
|
97 input = etree.find("{%s}input" % 'http://www.s60.com/xml/imageml/1') |
|
98 reader = imageml.ImageImplReader() |
|
99 include = reader.parse_input_include(input) |
|
100 self.assertEquals(include,{'pattern': ['bmb$']}) |
|
101 |
|
102 def test_parse_input_exclude(self): |
|
103 etree = ElementTree.fromstring(input_dir) |
|
104 input = etree.find("{%s}input" % 'http://www.s60.com/xml/imageml/1') |
|
105 reader = imageml.ImageImplReader() |
|
106 include = reader.parse_input_exclude(input) |
|
107 self.assertEquals(include,{'pattern': ['.svn']}) |
|
108 |
|
109 def test_parse_inputs_with_dir(self): |
|
110 etree = ElementTree.fromstring(input_dir) |
|
111 reader = imageml.ImageImplReader() |
|
112 inputs = reader.parse_inputs(etree) |
|
113 self.assertEquals(inputs[0].path,'UI/Start-up Animation') |
|
114 self.assertEquals(inputs[0].type,'dir') |
|
115 self.assertEquals(inputs[0].include, ['bmb$']) |
|
116 self.assertEquals(inputs[0].exclude, ['.svn']) |
|
117 self.assertEquals(inputs[0].depth,'8') |
|
118 self.assertEquals(inputs[0].test,'foo') |
|
119 self.assertEquals(inputs[1].path,'UI/Start-up Animation/masks') |
|
120 self.assertEquals(inputs[1].depth,'2') |
|
121 |
|
122 def test_parse_inputs_with_files(self): |
|
123 etree = ElementTree.fromstring(input_files) |
|
124 reader = imageml.ImageImplReader() |
|
125 inputs = reader.parse_inputs(etree) |
|
126 self.assertEquals(inputs[0].path,'UI/graphics/icon1.bmb') |
|
127 self.assertEquals(inputs[0].depth,'8') |
|
128 self.assertEquals(inputs[1].path,'UI/graphics/icon2.bmb') |
|
129 self.assertEquals(inputs[1].depth,'8') |
|
130 self.assertEquals(inputs[2].path,'UI/graphics/icon3.bmb') |
|
131 self.assertEquals(inputs[2].depth,'8') |
|
132 self.assertEquals(inputs[3].path,'UI/graphics/icon4.bmb') |
|
133 self.assertEquals(inputs[3].depth,'8') |
|
134 |
|
135 def test_parse_outputs(self): |
|
136 etree = ElementTree.fromstring(imageml_string) |
|
137 reader = imageml.ImageImplReader() |
|
138 outputs = reader.parse_outputs(etree) |
|
139 self.assertEquals(outputs[0].outputpath,'startup.mbm') |
|
140 self.assertEquals(outputs[0].inputs[0].path,'UI/Start-up Animation') |
|
141 self.assertEquals(outputs[0].inputs[0].type,'dir') |
|
142 self.assertEquals(outputs[0].inputs[0].include,['bmb$']) |
|
143 self.assertEquals(outputs[0].inputs[0].exclude,['.svn']) |
|
144 self.assertEquals(outputs[1].outputpath,'shutdown.mbm') |
|
145 self.assertEquals(outputs[1].inputs[0].type,'file') |
|
146 self.assertEquals(outputs[1].inputs[0].path,'UI/graphics/icon1.bmb') |
|
147 self.assertEquals(outputs[1].inputs[1].type,'file') |
|
148 self.assertEquals(outputs[1].inputs[1].path,'UI/graphics/icon2.bmb') |
|
149 self.assertEquals(outputs[1].inputs[2].type,'file') |
|
150 self.assertEquals(outputs[1].inputs[2].path,'UI/graphics/icon3.bmb') |
|
151 self.assertEquals(outputs[1].inputs[3].type,'file') |
|
152 self.assertEquals(outputs[1].inputs[3].path,'UI/graphics/icon4.bmb') |
|
153 |
|
154 def test_parse_from_string(self): |
|
155 reader = imageml.ImageImplReader() |
|
156 reader.fromstring(imageml_string) |
|
157 self.assertEquals(reader.desc,'') |
|
158 self.assertEquals(reader.outputgenerators[0].outputpath,'startup.mbm') |
|
159 self.assertEquals(reader.outputgenerators[0].inputs[0].path,'UI/Start-up Animation') |
|
160 self.assertEquals(reader.outputgenerators[0].inputs[0].type,'dir') |
|
161 self.assertEquals(reader.outputgenerators[0].inputs[0].include,['bmb$']) |
|
162 self.assertEquals(reader.outputgenerators[0].inputs[0].exclude,['.svn']) |
|
163 |
|
164 def test_parse_from_string_with_refs(self): |
|
165 reader = imageml.ImageImplReader() |
|
166 reader.fromstring(imageml_with_refs) |
|
167 self.assertEquals(reader.outputgenerators[0]._outputpath,'${features.outputref}') |
|
168 self.assertEquals(reader.outputgenerators[0].inputs[0]._path,'${features.inputref}') |
|
169 self.assertEquals(reader.outputgenerators[0].inputs[0].type,'dir') |
|
170 self.assertEquals(reader.outputgenerators[0].inputs[0].include,['${features.inputfilter}']) |
|
171 |
|
172 |
|
173 if __name__ == '__main__': |
|
174 unittest.main() |