69 return workdir |
69 return workdir |
70 |
70 |
71 def test_generate_all_impls_on_last_layer_on_file_storage(self): |
71 def test_generate_all_impls_on_last_layer_on_file_storage(self): |
72 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
72 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
73 self.assert_exists_and_contains_something(project_dir) |
73 self.assert_exists_and_contains_something(project_dir) |
74 self._run_test_generate_all_impls_on_last_layer('temp/gen_ll1', project_dir) |
74 self._run_test_generate_all_impls_on_last_layer( |
|
75 workdir = 'temp/gen_ll1', |
|
76 project = project_dir, |
|
77 expected = os.path.join(ROOT_PATH, 'testdata/generate/expected_last_layer'), |
|
78 args = '--layer -1', |
|
79 linux_ignores = ['anim1.mbm', 'anim2.mif', '20000000.txt', '10207114', 'themepackage.mbm', 'themepackage.mif', '12340001', '12340002']) |
|
80 |
|
81 def test_generate_all_impls_target_rofs2_file_storage(self): |
|
82 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
|
83 self.assert_exists_and_contains_something(project_dir) |
|
84 self._run_test_generate_all_impls_on_last_layer( |
|
85 workdir = 'temp/gen_ll_rofs2', |
|
86 project = project_dir, |
|
87 expected = os.path.join(ROOT_PATH, 'testdata/generate/expected_rofs2'), |
|
88 args = '--all-layers --impl-tag target:rofs2') |
75 |
89 |
76 def test_generate_all_impls_on_last_layer_on_zip_storage(self): |
90 def test_generate_all_impls_on_last_layer_on_zip_storage(self): |
77 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
91 project_dir = os.path.join(ROOT_PATH, "testdata/generate/project") |
78 self.assert_exists_and_contains_something(project_dir) |
92 self.assert_exists_and_contains_something(project_dir) |
79 |
93 |
80 project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip") |
94 project_zip = os.path.join(ROOT_PATH, "temp/generation_test_project.zip") |
81 self.remove_if_exists(project_zip) |
95 self.remove_if_exists(project_zip) |
82 zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN]) |
96 zip_dir.zip_dir(project_dir, project_zip, [zip_dir.SVN_IGNORE_PATTERN]) |
83 self.assert_exists_and_contains_something(project_zip) |
97 self.assert_exists_and_contains_something(project_zip) |
84 |
98 |
85 self._run_test_generate_all_impls_on_last_layer('temp/gen_ll2', project_zip) |
99 self._run_test_generate_all_impls_on_last_layer( |
|
100 workdir = 'temp/gen_ll2', |
|
101 project = project_zip, |
|
102 expected = os.path.join(ROOT_PATH, 'testdata/generate/expected_last_layer'), |
|
103 args = '--layer -1', |
|
104 linux_ignores = ['anim1.mbm', 'anim2.mif', '20000000.txt', '10207114', 'themepackage.mbm', 'themepackage.mif', '12340001', '12340002' ]) |
86 |
105 |
87 def _run_test_generate_all_impls_on_last_layer(self, workdir, project): |
106 def _run_test_generate_all_impls_on_last_layer(self, workdir, project, expected, args='', linux_ignores=[]): |
88 # Create a temp workdir and go there to run the test |
107 # Create a temp workdir and go there to run the test |
89 orig_workdir = os.getcwd() |
108 orig_workdir = os.getcwd() |
90 workdir = self._prepare_workdir(workdir) |
109 workdir = self._prepare_workdir(workdir) |
91 os.chdir(workdir) |
110 os.chdir(workdir) |
92 |
111 |
93 try: |
112 try: |
94 # Run the generation command |
113 # Run the generation command |
95 cmd = '%s -p "%s" --output output --layer -1 --add-setting-file imaker_variantdir.cfg' % (get_cmd(), project) |
114 cmd = '%s -p "%s" --output output --add-setting-file imaker_variantdir.cfg %s' % (get_cmd(), project, args) |
96 self.run_command(cmd) |
115 self.run_command(cmd) |
97 |
116 |
98 # Check that all expected output files are generated |
117 self.assert_dir_contents_equal('output', expected, ['.svn'] + linux_ignores) |
99 def check(path): |
118 finally: |
100 self.assert_exists_and_contains_something("output/" + path) |
119 os.chdir(orig_workdir) |
|
120 |
|
121 class TestDeltaCenrepGeneration(BaseTestCase): |
|
122 |
|
123 def test_generate_deltacenreps(self): |
|
124 self._run_test_generation( |
|
125 workdir = 'temp/deltacenrep/deltacenrep', |
|
126 expected_dir = 'testdata/deltacenrep/deltacenrep_expected', |
|
127 tag_args = '--impl-tag target:rofs3 --impl-tag crml:deltacenrep') |
|
128 |
|
129 def test_generate_normal_cenreps_from_deltacenrep_project(self): |
|
130 self._run_test_generation( |
|
131 workdir = 'temp/deltacenrep/normalcenrep', |
|
132 expected_dir = 'testdata/deltacenrep/normalcenrep_expected', |
|
133 tag_args = '--impl-tag target:rofs3') |
|
134 |
|
135 def _run_test_generation(self, workdir, expected_dir, tag_args): |
|
136 PROJECT_DIR = os.path.join(ROOT_PATH, 'testdata/deltacenrep/project') |
|
137 EXPECTED_DIR = os.path.join(ROOT_PATH, expected_dir) |
|
138 |
|
139 # Create a temp workdir and go there to run the test |
|
140 orig_workdir = os.getcwd() |
|
141 workdir = os.path.join(ROOT_PATH, workdir) |
|
142 self.recreate_dir(workdir) |
|
143 os.chdir(workdir) |
|
144 |
|
145 try: |
|
146 # Run the generation command |
|
147 cmd = '%(cmd)s -p "%(project)s" --output output --layer -1 '\ |
|
148 '--add-setting-file imaker_variantdir.cfg %(args)s'\ |
|
149 % {'cmd' : get_cmd(), |
|
150 'project' : PROJECT_DIR, |
|
151 'args' : tag_args} |
|
152 self.run_command(cmd) |
|
153 OUTPUT_DIR = os.path.abspath('output') |
101 |
154 |
102 try: |
155 # Assert that the CenRep files are equal |
103 check("content/animations/anim1.mbm") |
156 self.assert_dir_contents_equal(OUTPUT_DIR, EXPECTED_DIR, ignore=['.svn', 'include']) |
104 check("content/animations/anim2.mif") |
|
105 except AssertionError: |
|
106 if ' ' in ROOT_PATH: |
|
107 self.fail("Known bug (#177)") |
|
108 else: |
|
109 raise |
|
110 |
157 |
111 check("content/data/sounds/test.mp3") |
158 # If generating delta CenReps, check also the iby file |
112 check("content/data/sequence_setting_test.txt") |
159 OUTPUT_IBY = os.path.join(OUTPUT_DIR, 'include/deltacenreps.iby') |
113 check("content/private/10202BE9/10000000.txt") |
160 EXPECTED_IBY = os.path.join(EXPECTED_DIR, 'include/deltacenreps.iby') |
114 check("content/private/10202BE9/12341001.txt") |
161 if os.path.exists(EXPECTED_IBY): |
115 check("content/private/10202BE9/12341002.txt") |
162 self.assert_file_contents_equal(OUTPUT_IBY, EXPECTED_IBY, |
116 check("content/private/10202BE9/20000000.txt") |
163 ignore_patterns = [r'(\w:)?[\\/].*output[\\/]deltacenreps[\\/]'], |
117 check("content/sound_folder/test2.mp3") |
164 ignore_endline_style = True) |
118 check("hcr_test.h") |
|
119 check("content/private/10207114/import/12340001/themepackage.mbm") |
|
120 check("content/private/10207114/import/12340001/themepackage.mif") |
|
121 check("content/private/10207114/import/12340001/themepackage.skn") |
|
122 |
|
123 # Check that files that should not have been generated are not |
|
124 def check_not_gen(path): |
|
125 self.assertFalse(os.path.exists("output/" + path), |
|
126 "'%s' was generated when it should not have been!" % path) |
|
127 check_not_gen("content/private/10202BE9/ABCD0000.txt") |
|
128 check_not_gen("content/private/10202BE9/12341000.txt") |
|
129 |
|
130 # Check that the data has been generated correctly |
|
131 self.assert_file_contains( |
|
132 "output/content/private/10202BE9/12341002.txt", |
|
133 "0x1 int 42 0 cap_rd=alwayspass cap_wr=WriteDeviceData", |
|
134 encoding='utf-16') |
|
135 self.assert_file_contains( |
|
136 "output/content/private/10202BE9/10000000.txt", |
|
137 r'0x1 string "Z:\\data\\sounds\\test.mp3" 0 cap_rd=alwayspass cap_wr=WriteDeviceData', |
|
138 encoding='utf-16') |
|
139 self.assert_file_contains( |
|
140 "output/content/private/10202BE9/12341001.txt", |
|
141 u'0x1 string "default string カタカナ <&> カタカナ" 0 cap_rd=alwayspass cap_wr=WriteDeviceData', |
|
142 encoding='utf-16') |
|
143 self.assert_file_contains( |
|
144 "output/content/private/10202BE9/20000000.txt", |
|
145 ['0x11 string "305397761" 0', |
|
146 '0x12 string "305397761" 0', |
|
147 '0x13 string "305397761" 0', |
|
148 '0x21 string "305397762" 0', |
|
149 '0x22 string "305397762" 0'], |
|
150 encoding='utf-16') |
|
151 finally: |
165 finally: |
152 os.chdir(orig_workdir) |
166 os.chdir(orig_workdir) |
153 |
167 |
154 if __name__ == '__main__': |
168 if __name__ == '__main__': |
155 unittest.main() |
169 unittest.main() |