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