blob: 3ebed93578dea700bf03748f78928b78d5ee1892 [file] [log] [blame]
commit-bot@chromium.org11f15622014-01-07 17:03:40 +00001#!/usr/bin/python
2
3"""
4Copyright 2014 Google Inc.
5
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
8
9Test the render_pictures binary.
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000010"""
11
12# System-level imports
13import json
14import os
15import shutil
16import tempfile
17
18# Imports from within Skia
19import base_unittest
20
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000021# Maximum length of text diffs to show when tests fail
22MAX_DIFF_LENGTH = 30000
23
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000024EXPECTED_HEADER_CONTENTS = {
25 "type" : "ChecksummedImages",
26 "revision" : 1,
27}
28
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000029
30class RenderPicturesTest(base_unittest.TestCase):
31
32 def setUp(self):
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000033 self._input_skp_dir = tempfile.mkdtemp()
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000034 self._temp_dir = tempfile.mkdtemp()
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000035 self.maxDiff = MAX_DIFF_LENGTH
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000036
37 def tearDown(self):
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000038 shutil.rmtree(self._input_skp_dir)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000039 shutil.rmtree(self._temp_dir)
40
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000041 def test_tiled_whole_image(self):
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000042 """Run render_pictures with tiles and --writeWholeImage flag."""
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000043 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000044 self._generate_skps()
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000045 # TODO(epoger): I noticed that when this is run without --writePath being
46 # specified, this test writes red_skp.png and green_skp.png to the current
47 # directory. We should fix that... if --writePath is not specified, this
48 # probably shouldn't write out red_skp.png and green_skp.png at all!
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000049 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000050 '--bbh', 'grid', '256', '256',
51 '--mode', 'tile', '256', '256',
52 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000053 '--writePath', self._temp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000054 '--writeWholeImage'])
55 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000056 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000057 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000058 "red.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000059 # Manually verified: 640x400 red rectangle with black border
60 "whole-image": {
61 "checksumAlgorithm" : "bitmap-64bitMD5",
62 "checksumValue" : 11092453015575919668,
63 "comparisonResult" : "no-comparison",
64 "filepath" : "red_skp.png",
65 },
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000066 },
67 "green.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000068 # Manually verified: 640x400 green rectangle with black border
69 "whole-image": {
70 "checksumAlgorithm" : "bitmap-64bitMD5",
71 "checksumValue" : 8891695120562235492,
72 "comparisonResult" : "no-comparison",
73 "filepath" : "green_skp.png",
74 },
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000075 }
76 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000077 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000078 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +000079 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000080 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000081
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000082 def test_untiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000083 """Run without tiles."""
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000084 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +000085 self._generate_skps()
86 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000087 '--writePath', self._temp_dir,
88 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000089 # TODO(epoger): These expectations are the same as for above unittest.
90 # Define the expectations once, and share them.
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000091 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000092 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +000093 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +000094 "red.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +000095 # Manually verified: 640x400 red rectangle with black border
96 "whole-image": {
97 "checksumAlgorithm" : "bitmap-64bitMD5",
98 "checksumValue" : 11092453015575919668,
99 "comparisonResult" : "no-comparison",
100 "filepath" : "red_skp.png",
101 },
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000102 },
103 "green.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000104 # Manually verified: 640x400 green rectangle with black border
105 "whole-image": {
106 "checksumAlgorithm" : "bitmap-64bitMD5",
107 "checksumValue" : 8891695120562235492,
108 "comparisonResult" : "no-comparison",
109 "filepath" : "green_skp.png",
110 },
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000111 }
112 }
113 }
114 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000115 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000116 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000117
118 def test_untiled_writeChecksumBasedFilenames(self):
119 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
120 output_json_path = os.path.join(self._temp_dir, 'output.json')
121 self._generate_skps()
122 self._run_render_pictures(['-r', self._input_skp_dir,
123 '--writeChecksumBasedFilenames',
124 '--writePath', self._temp_dir,
125 '--writeJsonSummaryPath', output_json_path])
126 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000127 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000128 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000129 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000130 # Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000131 "whole-image": {
132 "checksumAlgorithm" : "bitmap-64bitMD5",
133 "checksumValue" : 11092453015575919668,
134 "comparisonResult" : "no-comparison",
135 "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png",
136 },
137 },
138 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000139 # Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000140 "whole-image": {
141 "checksumAlgorithm" : "bitmap-64bitMD5",
142 "checksumValue" : 8891695120562235492,
143 "comparisonResult" : "no-comparison",
144 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png",
145 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000146 }
147 }
148 }
149 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000150 self._assert_directory_contents(self._temp_dir, [
151 'red_skp', 'green_skp', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000152 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000153 os.path.join(self._temp_dir, 'red_skp'),
154 ['bitmap-64bitMD5_11092453015575919668.png'])
155 self._assert_directory_contents(
156 os.path.join(self._temp_dir, 'green_skp'),
157 ['bitmap-64bitMD5_8891695120562235492.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000158
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000159 def test_untiled_validate(self):
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000160 """Same as test_untiled, but with --validate.
161
162 TODO(epoger): This test generates undesired results! The call
163 to render_pictures should succeed, and generate the same output as
164 test_untiled.
165 See https://code.google.com/p/skia/issues/detail?id=2044 ('render_pictures:
166 --validate fails')
167 """
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000168 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000169 self._generate_skps()
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000170 with self.assertRaises(Exception):
171 self._run_render_pictures(['-r', self._input_skp_dir,
172 '--validate',
173 '--writePath', self._temp_dir,
174 '--writeJsonSummaryPath', output_json_path])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000175
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000176 def test_untiled_without_writePath(self):
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000177 """Same as test_untiled, but without --writePath.
178
179 TODO(epoger): This test generates undesired results!
180 See https://code.google.com/p/skia/issues/detail?id=2043 ('render_pictures:
181 --writeJsonSummaryPath fails unless --writePath is specified')
182 """
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000183 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000184 self._generate_skps()
185 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000186 '--writeJsonSummaryPath', output_json_path])
187 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000188 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000189 "actual-results" : None,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000190 }
191 self._assert_json_contents(output_json_path, expected_summary_dict)
192
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000193 def test_tiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000194 """Generate individual tiles."""
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000195 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000196 self._generate_skps()
197 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000198 '--bbh', 'grid', '256', '256',
199 '--mode', 'tile', '256', '256',
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000200 '--writePath', self._temp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000201 '--writeJsonSummaryPath', output_json_path])
202 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000203 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000204 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000205 "red.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000206 # Manually verified these 6 images, all 256x256 tiles,
207 # consistent with a tiled version of the 640x400 red rect
208 # with black borders.
209 "tiled-images": [{
210 "checksumAlgorithm" : "bitmap-64bitMD5",
211 "checksumValue" : 5815827069051002745,
212 "comparisonResult" : "no-comparison",
213 "filepath" : "red_skp-tile0.png",
214 }, {
215 "checksumAlgorithm" : "bitmap-64bitMD5",
216 "checksumValue" : 9323613075234140270,
217 "comparisonResult" : "no-comparison",
218 "filepath" : "red_skp-tile1.png",
219 }, {
220 "checksumAlgorithm" : "bitmap-64bitMD5",
221 "checksumValue" : 16670399404877552232,
222 "comparisonResult" : "no-comparison",
223 "filepath" : "red_skp-tile2.png",
224 }, {
225 "checksumAlgorithm" : "bitmap-64bitMD5",
226 "checksumValue" : 2507897274083364964,
227 "comparisonResult" : "no-comparison",
228 "filepath" : "red_skp-tile3.png",
229 }, {
230 "checksumAlgorithm" : "bitmap-64bitMD5",
231 "checksumValue" : 7325267995523877959,
232 "comparisonResult" : "no-comparison",
233 "filepath" : "red_skp-tile4.png",
234 }, {
235 "checksumAlgorithm" : "bitmap-64bitMD5",
236 "checksumValue" : 2181381724594493116,
237 "comparisonResult" : "no-comparison",
238 "filepath" : "red_skp-tile5.png",
239 }],
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000240 },
241 "green.skp": {
commit-bot@chromium.orgcced37d2014-04-28 14:07:10 +0000242 # Manually verified these 6 images, all 256x256 tiles,
243 # consistent with a tiled version of the 640x400 green rect
244 # with black borders.
245 "tiled-images": [{
246 "checksumAlgorithm" : "bitmap-64bitMD5",
247 "checksumValue" : 12587324416545178013,
248 "comparisonResult" : "no-comparison",
249 "filepath" : "green_skp-tile0.png",
250 }, {
251 "checksumAlgorithm" : "bitmap-64bitMD5",
252 "checksumValue" : 7624374914829746293,
253 "comparisonResult" : "no-comparison",
254 "filepath" : "green_skp-tile1.png",
255 }, {
256 "checksumAlgorithm" : "bitmap-64bitMD5",
257 "checksumValue" : 5686489729535631913,
258 "comparisonResult" : "no-comparison",
259 "filepath" : "green_skp-tile2.png",
260 }, {
261 "checksumAlgorithm" : "bitmap-64bitMD5",
262 "checksumValue" : 7980646035555096146,
263 "comparisonResult" : "no-comparison",
264 "filepath" : "green_skp-tile3.png",
265 }, {
266 "checksumAlgorithm" : "bitmap-64bitMD5",
267 "checksumValue" : 17817086664365875131,
268 "comparisonResult" : "no-comparison",
269 "filepath" : "green_skp-tile4.png",
270 }, {
271 "checksumAlgorithm" : "bitmap-64bitMD5",
272 "checksumValue" : 10673669813016809363,
273 "comparisonResult" : "no-comparison",
274 "filepath" : "green_skp-tile5.png",
275 }],
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000276 }
277 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000278 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000279 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000280 self._assert_directory_contents(
281 self._temp_dir,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000282 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
283 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
284 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
285 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
286 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000287
288 def test_tiled_writeChecksumBasedFilenames(self):
289 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
290 output_json_path = os.path.join(self._temp_dir, 'output.json')
291 self._generate_skps()
292 self._run_render_pictures(['-r', self._input_skp_dir,
293 '--bbh', 'grid', '256', '256',
294 '--mode', 'tile', '256', '256',
295 '--writeChecksumBasedFilenames',
296 '--writePath', self._temp_dir,
297 '--writeJsonSummaryPath', output_json_path])
298 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000299 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000300 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000301 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000302 # Manually verified these 6 images, all 256x256 tiles,
303 # consistent with a tiled version of the 640x400 red rect
304 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000305 "tiled-images": [{
306 "checksumAlgorithm" : "bitmap-64bitMD5",
307 "checksumValue" : 5815827069051002745,
308 "comparisonResult" : "no-comparison",
309 "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png",
310 }, {
311 "checksumAlgorithm" : "bitmap-64bitMD5",
312 "checksumValue" : 9323613075234140270,
313 "comparisonResult" : "no-comparison",
314 "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png",
315 }, {
316 "checksumAlgorithm" : "bitmap-64bitMD5",
317 "checksumValue" : 16670399404877552232,
318 "comparisonResult" : "no-comparison",
319 "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png",
320 }, {
321 "checksumAlgorithm" : "bitmap-64bitMD5",
322 "checksumValue" : 2507897274083364964,
323 "comparisonResult" : "no-comparison",
324 "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png",
325 }, {
326 "checksumAlgorithm" : "bitmap-64bitMD5",
327 "checksumValue" : 7325267995523877959,
328 "comparisonResult" : "no-comparison",
329 "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png",
330 }, {
331 "checksumAlgorithm" : "bitmap-64bitMD5",
332 "checksumValue" : 2181381724594493116,
333 "comparisonResult" : "no-comparison",
334 "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png",
335 }],
336 },
337 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000338 # Manually verified these 6 images, all 256x256 tiles,
339 # consistent with a tiled version of the 640x400 green rect
340 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000341 "tiled-images": [{
342 "checksumAlgorithm" : "bitmap-64bitMD5",
343 "checksumValue" : 12587324416545178013,
344 "comparisonResult" : "no-comparison",
345 "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png",
346 }, {
347 "checksumAlgorithm" : "bitmap-64bitMD5",
348 "checksumValue" : 7624374914829746293,
349 "comparisonResult" : "no-comparison",
350 "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png",
351 }, {
352 "checksumAlgorithm" : "bitmap-64bitMD5",
353 "checksumValue" : 5686489729535631913,
354 "comparisonResult" : "no-comparison",
355 "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png",
356 }, {
357 "checksumAlgorithm" : "bitmap-64bitMD5",
358 "checksumValue" : 7980646035555096146,
359 "comparisonResult" : "no-comparison",
360 "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png",
361 }, {
362 "checksumAlgorithm" : "bitmap-64bitMD5",
363 "checksumValue" : 17817086664365875131,
364 "comparisonResult" : "no-comparison",
365 "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png",
366 }, {
367 "checksumAlgorithm" : "bitmap-64bitMD5",
368 "checksumValue" : 10673669813016809363,
369 "comparisonResult" : "no-comparison",
370 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png",
371 }],
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000372 }
373 }
374 }
375 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000376 self._assert_directory_contents(self._temp_dir, [
377 'red_skp', 'green_skp', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000378 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000379 os.path.join(self._temp_dir, 'red_skp'),
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000380 ['bitmap-64bitMD5_5815827069051002745.png',
381 'bitmap-64bitMD5_9323613075234140270.png',
382 'bitmap-64bitMD5_16670399404877552232.png',
383 'bitmap-64bitMD5_2507897274083364964.png',
384 'bitmap-64bitMD5_7325267995523877959.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000385 'bitmap-64bitMD5_2181381724594493116.png'])
386 self._assert_directory_contents(
387 os.path.join(self._temp_dir, 'green_skp'),
388 ['bitmap-64bitMD5_12587324416545178013.png',
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000389 'bitmap-64bitMD5_7624374914829746293.png',
390 'bitmap-64bitMD5_5686489729535631913.png',
391 'bitmap-64bitMD5_7980646035555096146.png',
392 'bitmap-64bitMD5_17817086664365875131.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000393 'bitmap-64bitMD5_10673669813016809363.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000394
395 def _run_render_pictures(self, args):
396 binary = self.find_path_to_program('render_pictures')
397 return self.run_command([binary,
398 '--clone', '1',
399 '--config', '8888',
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000400 ] + args)
401
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000402 def _generate_skps(self):
403 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
404 self._run_skpmaker(
405 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
406 self._run_skpmaker(
407 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
408
409 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
410 width=640, height=400):
411 """Runs the skpmaker binary to generate SKP with known characteristics.
412
413 Args:
414 output_path: Filepath to write the SKP into.
415 red: Value of red color channel in image, 0-255.
416 green: Value of green color channel in image, 0-255.
417 blue: Value of blue color channel in image, 0-255.
418 width: Width of canvas to create.
419 height: Height of canvas to create.
420 """
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000421 binary = self.find_path_to_program('skpmaker')
422 return self.run_command([binary,
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000423 '--red', str(red),
424 '--green', str(green),
425 '--blue', str(blue),
426 '--width', str(width),
427 '--height', str(height),
428 '--writePath', str(output_path),
429 ])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000430
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000431 def _assert_directory_contents(self, dir_path, expected_filenames):
432 """Asserts that files found in a dir are identical to expected_filenames.
433
434 Args:
435 dir_path: Path to a directory on local disk.
436 expected_filenames: Set containing the expected filenames within the dir.
437
438 Raises:
439 AssertionError: contents of the directory are not identical to
440 expected_filenames.
441 """
442 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
443
444
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000445 def _assert_json_contents(self, json_path, expected_dict):
446 """Asserts that contents of a JSON file are identical to expected_dict.
447
448 Args:
449 json_path: Path to a JSON file.
450 expected_dict: Dictionary indicating the expected contents of the JSON
451 file.
452
453 Raises:
454 AssertionError: contents of the JSON file are not identical to
455 expected_dict.
456 """
457 file_contents = open(json_path, 'r').read()
458 actual_dict = json.loads(file_contents)
459 self.assertEqual(actual_dict, expected_dict)
460
461
462def main():
463 base_unittest.main(RenderPicturesTest)
464
465
466if __name__ == '__main__':
467 main()