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
|
3
|
18 |
import sys, os
|
0
|
19 |
|
3
|
20 |
from imageplugin import generators
|
|
21 |
from cone.public import api, exceptions, plugin, utils
|
0
|
22 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
23 |
|
|
24 |
def impl_from_resource(resource_ref, configuration):
|
|
25 |
impls = plugin.ImplFactory.get_impls_from_file(resource_ref, configuration)
|
|
26 |
assert len(impls) == 1
|
|
27 |
return impls[0]
|
|
28 |
|
|
29 |
class TestGenerator(unittest.TestCase):
|
|
30 |
def test_create_generator_with_output(self):
|
|
31 |
gen = generators.OutputGenerator('foo/bar')
|
|
32 |
self.assertEquals(gen.outputpath,'foo/bar')
|
|
33 |
gen.outputpath = 'foo/bar/test.confml'
|
|
34 |
self.assertEquals(gen.outputpath,'foo/bar/test.confml')
|
|
35 |
del gen.outputpath
|
|
36 |
self.assertEquals(gen.outputpath,None)
|
|
37 |
|
|
38 |
|
|
39 |
def test_generator_subpath_and_path(self):
|
|
40 |
gen = generators.OutputGenerator('foo/bar.mbm')
|
|
41 |
self.assertEquals(gen.subpath, '')
|
|
42 |
gen.subpath = 'test/foo'
|
|
43 |
self.assertEquals(gen.subpath, 'test/foo')
|
|
44 |
self.assertEquals(gen.path, 'test/foo/foo/bar.mbm')
|
|
45 |
self.assertTrue(isinstance(gen.get_command(), generators.BmconvCommand))
|
|
46 |
gen.outputpath = 'bar/test.mif'
|
|
47 |
self.assertTrue(isinstance(gen.get_command(), generators.MifconvCommand))
|
|
48 |
gen.outputpath = 'bar/test.gif'
|
|
49 |
self.assertTrue(isinstance(gen.get_command(), generators.CopyCommand))
|
|
50 |
|
|
51 |
|
|
52 |
class TestInputFile(unittest.TestCase):
|
|
53 |
def test_create_inputfile(self):
|
|
54 |
input = generators.InputFile('foo/bar.bmb')
|
|
55 |
self.assertEquals(input.path,'foo/bar.bmb')
|
|
56 |
self.assertEquals(input.files[0].filename, 'foo/bar.bmb')
|
|
57 |
input.path = 'foo/bar/test.confml'
|
|
58 |
self.assertEquals(input.path,'foo/bar/test.confml')
|
|
59 |
del input.path
|
|
60 |
self.assertEquals(input.path,None)
|
|
61 |
|
|
62 |
|
|
63 |
def test_create_inputfile_with_args(self):
|
|
64 |
input = generators.InputFile('foo/bar.bmb',depth="c8",test="juu")
|
|
65 |
self.assertEquals(input.path,'foo/bar.bmb')
|
|
66 |
self.assertEquals(input.depth,'c8')
|
|
67 |
self.assertEquals(input.test,'juu')
|
|
68 |
|
|
69 |
class TestInputDir(unittest.TestCase):
|
|
70 |
def test_create_inputdir(self):
|
|
71 |
dir = generators.InputDir('foo/bar', dir='foo/bar',depth="c8")
|
|
72 |
self.assertEquals(dir.path,'foo/bar')
|
|
73 |
self.assertEquals(dir.depth,'c8')
|
|
74 |
self.assertEquals(dir.files, [])
|
|
75 |
|
|
76 |
def test_create_inputdir_and_get_files(self):
|
|
77 |
dir = generators.InputDir('imageproject/variant/content/UI/Start-up Animation')
|
|
78 |
dir.include = {'pattern' : 'bmp$'}
|
|
79 |
self.assertEquals(dir.files, [])
|
|
80 |
|
|
81 |
class TestGeneratorFromProject(unittest.TestCase):
|
|
82 |
def test_create_generator_from_project(self):
|
|
83 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject")))
|
|
84 |
config = prj.get_configuration('product.confml')
|
|
85 |
impl = impl_from_resource('variant/implml/startup_animation.imageml', config)
|
|
86 |
self.assertEquals(impl.generators[0].outputpath, 'startup.mbm')
|
|
87 |
self.assertEquals(impl.generators[0].configuration, config)
|
|
88 |
self.assertEquals(impl.generators[0].palette, '../bin/ThirdPartyBitmap.pal')
|
|
89 |
self.assertEquals(impl.generators[0].inputs[0].configuration, config)
|
|
90 |
self.assertEquals(impl.generators[0].inputs[0].path, 'UI/Start-up Animation')
|
|
91 |
self.assertEquals(impl.generators[0].inputs[0].type, 'dir')
|
|
92 |
self.assertEquals(impl.generators[1].outputpath, 'nocompress.mbm')
|
|
93 |
self.assertEquals(impl.generators[1].get_command().compress, False)
|
|
94 |
self.assertEquals(impl.generators[1].inputs[0].configuration, config)
|
|
95 |
self.assertEquals(impl.generators[1].inputs[0].path, 'UI/Start-up Animation')
|
|
96 |
self.assertEquals(impl.generators[1].inputs[0].type, 'dir')
|
|
97 |
self.assertEquals(len(impl.generators[1].inputs[0].files),20)
|
|
98 |
self.assertEquals(impl.generators[1].inputs[0].files[0].filename,'variant/content/UI/Start-up Animation/frame01.bmp')
|
|
99 |
self.assertEquals(impl.generators[1].inputs[0].files[0].path,'UI/Start-up Animation/frame01.bmp')
|
|
100 |
self.assertEquals(impl.generators[1].inputs[0].files[0].depth,'c8')
|
|
101 |
self.assertEquals(impl.generators[1].inputs[0].files[19].filename,'variant/content/UI/Start-up Animation/frame20.bmp')
|
|
102 |
self.assertEquals(impl.generators[1].inputs[0].files[19].depth,'c8')
|
|
103 |
|
|
104 |
def test_create_generator_with_configurable_depth_from_project(self):
|
|
105 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject")))
|
|
106 |
config = prj.get_configuration('product.confml')
|
|
107 |
impl = impl_from_resource('variant/implml/depth_from_ref_test.imageml', config)
|
|
108 |
self.assertEquals(impl.generators[0].inputs[0].depth, 'c16')
|
|
109 |
self.assertEquals(impl.generators[1].inputs[0].depth, 'c16')
|
|
110 |
|
|
111 |
# Assert the the depth is actually used in the command
|
|
112 |
command_obj = impl.generators[0].get_command()
|
|
113 |
cmd = command_obj.get_command(command_obj._get_filtered_input_files())
|
|
114 |
self.assertEquals(len(cmd), 4)
|
|
115 |
self.assertEquals(cmd[3], r'/c16conversion_workdir\frame01.bmp')
|
|
116 |
|
|
117 |
command_obj = impl.generators[1].get_command()
|
|
118 |
cmd = command_obj.get_command(command_obj._get_filtered_input_files())
|
|
119 |
self.assertEquals(len(cmd), 5)
|
|
120 |
self.assertEquals(cmd[3], '/c16')
|
|
121 |
self.assertEquals(cmd[4], r'conversion_workdir\icon.svg')
|
3
|
122 |
|
|
123 |
def test_create_generator_with_extraparams(self):
|
|
124 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject")))
|
|
125 |
config = prj.get_configuration('product.confml')
|
|
126 |
dview = config.get_default_view()
|
|
127 |
impl = impl_from_resource('variant/implml/startupmif_animation_with_version.imageml', config)
|
|
128 |
|
|
129 |
# 1st impl
|
|
130 |
self.assertEquals(impl.generators[0].extraparams, '/V3')
|
|
131 |
|
|
132 |
# Assert the the extraparams is actually used in the command
|
|
133 |
command_obj = impl.generators[0].get_command()
|
|
134 |
cmd = command_obj.get_command(command_obj._get_filtered_input_files())
|
|
135 |
self.assertEquals(len(cmd), 6)
|
|
136 |
self.assertEquals(cmd[2], r'/V3')
|
|
137 |
|
|
138 |
# 2nd impl
|
|
139 |
self.assertEquals(impl.generators[1].extraparams, '${StartupSettings.PluginTimeout}')
|
|
140 |
self.assertEquals(utils.expand_refs_by_default_view(impl.generators[1].extraparams, dview), '30000')
|
|
141 |
|
|
142 |
# Assert the the extraparams is actually used in the command
|
|
143 |
command_obj = impl.generators[1].get_command()
|
|
144 |
cmd = command_obj.get_command(command_obj._get_filtered_input_files())
|
|
145 |
self.assertEquals(len(cmd), 6)
|
|
146 |
self.assertEquals(cmd[2], r'30000')
|
|
147 |
|
|
148 |
# 3rd impl
|
|
149 |
self.assertEquals(impl.generators[2].extraparams, '${StartupSettings.PluginTimeout}')
|
|
150 |
self.assertEquals(utils.expand_refs_by_default_view(impl.generators[1].extraparams, dview), '30000')
|
|
151 |
|
|
152 |
# Assert the the extraparams is actually used in the command
|
|
153 |
command_obj = impl.generators[2].get_command()
|
|
154 |
cmd = command_obj.get_command(command_obj._get_filtered_input_files())
|
|
155 |
self.assertEquals(len(cmd), 4)
|
|
156 |
self.assertEquals(cmd[1], r'30000')
|
|
157 |
|
0
|
158 |
|
|
159 |
def test_create_generator_with_invalid_output(self):
|
|
160 |
prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,"imageproject")))
|
|
161 |
config = prj.get_configuration('product.confml')
|
|
162 |
impl = impl_from_resource('variant/implml/startup_animation.imageml', config)
|
|
163 |
impl.generators[0].outputpath = '${KCRUidStartup.StartupOperatorAnimationPath}'
|
|
164 |
try:
|
|
165 |
self.assertEquals(impl.generators[0].outputpath, '${KCRUidStartup.StartupOperatorAnimationPath}')
|
|
166 |
self.fail("Output path value should be none")
|
|
167 |
except exceptions.NotFound:
|
|
168 |
pass
|
|
169 |
|
|
170 |
try:
|
|
171 |
self.assertEquals(impl.generators[0].outputpath, '${KCRUidStartup.foobar}')
|
|
172 |
self.fail("Output path ref is invalid!")
|
|
173 |
except exceptions.NotFound:
|
|
174 |
pass
|
|
175 |
|
3
|
176 |
# Only run these tests on Windows
|
|
177 |
if sys.platform != 'win32':
|
|
178 |
del TestGenerator
|
|
179 |
del TestInputFile
|
|
180 |
del TestInputDir
|
|
181 |
del TestGeneratorFromProject
|
|
182 |
|
0
|
183 |
if __name__ == '__main__':
|
|
184 |
unittest.main()
|