0
|
1 |
# *-* coding: utf-8 *-*
|
|
2 |
#
|
|
3 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
# All rights reserved.
|
|
5 |
# This component and the accompanying materials are made available
|
|
6 |
# under the terms of "Eclipse Public License v1.0"
|
|
7 |
# which accompanies this distribution, and is available
|
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
9 |
#
|
|
10 |
# Initial Contributors:
|
|
11 |
# Nokia Corporation - initial contribution.
|
|
12 |
#
|
|
13 |
# Contributors:
|
|
14 |
#
|
|
15 |
# Description:
|
|
16 |
#
|
|
17 |
##
|
|
18 |
# @author Lasse Salo
|
|
19 |
|
|
20 |
import sys, os, shutil, unittest
|
3
|
21 |
|
0
|
22 |
from testautomation.base_testcase import BaseTestCase
|
|
23 |
from testautomation import zip_dir
|
|
24 |
|
|
25 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
26 |
|
|
27 |
if sys.platform == "win32":
|
|
28 |
CONE_SCRIPT = "cone.cmd"
|
|
29 |
else:
|
3
|
30 |
CONE_SCRIPT = "cone"
|
0
|
31 |
|
|
32 |
def get_cmd(action='generate'):
|
|
33 |
"""Return the command used to run the ConE sub-action"""
|
|
34 |
if 'CONE_PATH' in os.environ:
|
|
35 |
CONE_CMD = os.path.join(os.environ['CONE_PATH'], CONE_SCRIPT)
|
|
36 |
if not os.path.exists(CONE_CMD):
|
|
37 |
raise RuntimeError("'%s' does not exist!" % CONE_CMD)
|
|
38 |
return '"%s" %s' % (CONE_CMD, action)
|
|
39 |
else:
|
|
40 |
SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..'))
|
|
41 |
assert os.path.split(SOURCE_ROOT)[1] == 'source'
|
|
42 |
cmd = 'python "%s" %s' % (os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts/cone_tool.py')), action)
|
|
43 |
return cmd
|
|
44 |
|
3
|
45 |
def get_uses_layer_test_project():
|
|
46 |
# If running from the working copy
|
|
47 |
dir1 = os.path.normpath(os.path.join(ROOT_PATH, '../ConeRulePlugin/ruleplugin/evals/tests/layer_filtering_project'))
|
|
48 |
if os.path.isdir(dir1): return dir1
|
|
49 |
|
|
50 |
# If running from standalone
|
|
51 |
dir2 = os.path.normpath(os.path.join(ROOT_PATH, 'testdata/uses_layer_test_project'))
|
|
52 |
if os.path.isdir(dir2): return dir2
|
|
53 |
|
|
54 |
raise RuntimeError("layers_used() test project found neither in '%s' nor '%s'!" % (dir1, dir2))
|
|
55 |
|
0
|
56 |
class TestCommonGenerateAllImplsOnLastLayer(BaseTestCase):
|
|
57 |
|
|
58 |
def _prepare_workdir(self, workdir):
|
|
59 |
workdir = os.path.join(ROOT_PATH, workdir)
|
|
60 |
self.recreate_dir(workdir)
|
|
61 |
|
|
62 |
# Any needed extra preparation can be done here
|
|
63 |
|
|
64 |
return workdir
|
|
65 |
|
|
66 |
def test_generate_all_impls_on_last_layer_on_file_storage(self):
|
|
67 |
project_dir = os.path.join(ROOT_PATH, "testdata/generate/project")
|
|
68 |
self.assert_exists_and_contains_something(project_dir)
|
|
69 |
self._run_test_generate_all_impls_on_last_layer('temp/gen_ll1', project_dir)
|
|
70 |
|
|
71 |
def test_generate_all_impls_on_last_layer_on_zip_storage(self):
|
|
72 |
project_dir = os.path.join(ROOT_PATH, "testdata/generate/project")
|
|
73 |
self.assert_exists_and_contains_something(project_dir)
|
|
74 |
|
|
75 |
project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip")
|
|
76 |
self.remove_if_exists(project_zip)
|
|
77 |
zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN])
|
|
78 |
self.assert_exists_and_contains_something(project_zip)
|
|
79 |
|
|
80 |
self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip)
|
3
|
81 |
|
|
82 |
def test_uses_layers_rule(self):
|
|
83 |
project_dir = get_uses_layer_test_project()
|
|
84 |
self.assert_exists_and_contains_something(project_dir)
|
|
85 |
|
|
86 |
orig_workdir = os.getcwd()
|
|
87 |
workdir = self._prepare_workdir("temp/uses_layers_test")
|
|
88 |
os.chdir(workdir)
|
|
89 |
|
|
90 |
try:
|
|
91 |
cmd = '%s -p "%s" --output output --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project_dir)
|
|
92 |
self.run_command(cmd)
|
|
93 |
|
|
94 |
self.assert_file_contents_equal(
|
|
95 |
os.path.join(ROOT_PATH, "testdata/uses_layers_test_expected.txt"),
|
|
96 |
"output/uses_layers_test.txt",
|
|
97 |
ignore_endline_style=True)
|
|
98 |
finally:
|
|
99 |
os.chdir(orig_workdir)
|
|
100 |
|
|
101 |
def test_override_templateml_outputattribs_from_cmd_line(self):
|
|
102 |
project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project')
|
|
103 |
|
|
104 |
#Added because of known bug #1018 (test data missing)
|
|
105 |
# Remove after fix ->
|
|
106 |
if os.path.isdir(project_dir):
|
|
107 |
if len(os.listdir(project_dir)) == 0:
|
|
108 |
self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir)
|
|
109 |
elif os.path.isfile(project_dir):
|
|
110 |
if os.stat(project_dir).st_size == 0:
|
|
111 |
self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir)
|
|
112 |
else:
|
|
113 |
self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir)
|
|
114 |
# Remove after fix <-
|
|
115 |
|
|
116 |
self.assert_exists_and_contains_something(project_dir)
|
|
117 |
|
|
118 |
workdir = os.getcwd()
|
|
119 |
workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_cmd_line'))
|
|
120 |
|
|
121 |
logfile = os.path.join(workdir, 'cone.log')
|
|
122 |
|
|
123 |
file1 = os.path.join(workdir,'setdir','setfile1.txt')
|
|
124 |
file2 = os.path.join(workdir,'setdir','setfile2.txt')
|
|
125 |
|
|
126 |
cmd = ['%(cone_cmd)s',
|
|
127 |
'-p "%(project)s"',
|
|
128 |
'-c root.confml',
|
|
129 |
'--output "%(output)s"',
|
|
130 |
'--log-file="%(log_file)s"',
|
|
131 |
'--all-layers',
|
|
132 |
'--set=Tempfeature.Outputfile1=setfile1.txt',
|
|
133 |
'--set=Tempfeature.Outputfile2=setfile2.txt',
|
|
134 |
'--set=Tempfeature.Outputdir=setdir',
|
|
135 |
'--set=Tempfeature.Encoding=UTF-16',
|
|
136 |
'--set=Tempfeature.BOM=false',
|
|
137 |
'--set=Tempfeature.Newline=unix',]
|
|
138 |
cmd = ' '.join(cmd) % {'cone_cmd': get_cmd(),
|
|
139 |
'project': project_dir,
|
|
140 |
'output': workdir,
|
|
141 |
'log_file': logfile}
|
|
142 |
|
|
143 |
self.run_command(cmd)
|
|
144 |
|
|
145 |
self.assert_exists_and_contains_something(os.path.join(workdir,'setdir'))
|
|
146 |
self.assert_file_contains(file1, ['TempFeature.Outputfile1: setfile1.txt',
|
|
147 |
'TempFeature.Outputdir: setdir',
|
|
148 |
'TempFeature.Encoding: UTF-16',
|
|
149 |
'TempFeature.BOM: false',
|
|
150 |
'TempFeature.Newline: unix'],
|
|
151 |
encoding='UTF-16')
|
|
152 |
self.assert_file_contains(file2, ['TempFeature.Outputfile2: setfile2.txt',
|
|
153 |
'TempFeature.Outputdir: setdir',
|
|
154 |
'TempFeature.Encoding: UTF-8',
|
|
155 |
'TempFeature.BOM: true',
|
|
156 |
'TempFeature.Newline: win'])
|
|
157 |
|
|
158 |
|
|
159 |
def test_set_tempvariables_as_templateml_outputattribs(self):
|
|
160 |
project_dir = os.path.join(ROOT_PATH, 'testdata', 'templateml_test_project')
|
|
161 |
|
|
162 |
#Added because of known bug #1018 (test data missing)
|
|
163 |
# Remove after fix ->
|
|
164 |
if os.path.isdir(project_dir):
|
|
165 |
if len(os.listdir(project_dir)) == 0:
|
|
166 |
self.fail("Path '%s' exists (is a directory) but does not contain anything)" % project_dir)
|
|
167 |
elif os.path.isfile(project_dir):
|
|
168 |
if os.stat(project_dir).st_size == 0:
|
|
169 |
self.fail("Path '%s' exists (is a file) but does not contain anything)" % project_dir)
|
|
170 |
else:
|
|
171 |
self.fail("Known bug #1018: Test data missing. Path '%s' does not exist" % project_dir)
|
|
172 |
# Remove after fix <-
|
|
173 |
|
|
174 |
self.assert_exists_and_contains_something(project_dir)
|
|
175 |
|
|
176 |
workdir = os.getcwd()
|
|
177 |
workdir = self._prepare_workdir(os.path.join('temp','gen_tmplml_out_from_ref'))
|
|
178 |
|
|
179 |
logfile = os.path.join(workdir, 'cone.log')
|
|
180 |
|
|
181 |
file1 = os.path.join(workdir,'origdir','orig1.txt')
|
|
182 |
file2 = os.path.join(workdir,'origdir','orig2.txt')
|
|
183 |
|
|
184 |
cmd = ['%(cone_cmd)s',
|
|
185 |
'-p "%(project)s"',
|
|
186 |
'-c root.confml',
|
|
187 |
'--output "%(output)s"',
|
|
188 |
'--log-file="%(log_file)s"',
|
|
189 |
'--all-layers',]
|
|
190 |
cmd = ' '.join(cmd) % {'cone_cmd': get_cmd(),
|
|
191 |
'project': project_dir,
|
|
192 |
'output': workdir,
|
|
193 |
'log_file': logfile}
|
|
194 |
|
|
195 |
self.run_command(cmd)
|
|
196 |
|
|
197 |
self.assert_exists_and_contains_something(os.path.join(workdir,'origdir'))
|
|
198 |
self.assert_file_contains(file1, ['TempFeature.Outputfile1: orig1.txt',
|
|
199 |
'TempFeature.Outputdir: origdir',
|
|
200 |
'TempFeature.Encoding: ASCII',
|
|
201 |
'TempFeature.BOM: true',
|
|
202 |
'TempFeature.Newline: win'])
|
|
203 |
self.assert_file_contains(file2, ['TempFeature.Outputfile2: orig2.txt',
|
|
204 |
'TempFeature.Outputdir: origdir',
|
|
205 |
'TempFeature.Encoding: UTF-8',
|
|
206 |
'TempFeature.BOM: true',
|
|
207 |
'TempFeature.Newline: win'])
|
0
|
208 |
|
|
209 |
def _run_test_generate_all_impls_on_last_layer(self, workdir, project):
|
|
210 |
# Create a temp workdir and go there to run the test
|
|
211 |
orig_workdir = os.getcwd()
|
|
212 |
workdir = self._prepare_workdir(workdir)
|
|
213 |
os.chdir(workdir)
|
|
214 |
|
|
215 |
try:
|
|
216 |
cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project)
|
|
217 |
self.run_command(cmd)
|
|
218 |
|
|
219 |
EXPECTED_DIR = os.path.join(ROOT_PATH, "testdata/generate/expected")
|
|
220 |
self.assert_dir_contents_equal('output', EXPECTED_DIR, ['.svn'])
|
|
221 |
finally:
|
|
222 |
os.chdir(orig_workdir)
|
|
223 |
|
3
|
224 |
|
|
225 |
|
|
226 |
|
0
|
227 |
if __name__ == '__main__':
|
|
228 |
unittest.main()
|