blob: d378a546885d72221da8d9e5cf322730fd41e0a1 [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.org4610a462014-04-29 19:39:22 +000029# Manually verified: 640x400 red rectangle with black border
30RED_WHOLEIMAGE = {
31 "checksumAlgorithm" : "bitmap-64bitMD5",
32 "checksumValue" : 11092453015575919668,
33 "comparisonResult" : "no-comparison",
34 "filepath" : "red_skp.png",
35}
36
37# Manually verified: 640x400 green rectangle with black border
38GREEN_WHOLEIMAGE = {
39 "checksumAlgorithm" : "bitmap-64bitMD5",
40 "checksumValue" : 8891695120562235492,
41 "comparisonResult" : "no-comparison",
42 "filepath" : "green_skp.png",
43}
44
45# Manually verified these 6 images, all 256x256 tiles,
46# consistent with a tiled version of the 640x400 red rect
47# with black borders.
48RED_TILES = [{
49 "checksumAlgorithm" : "bitmap-64bitMD5",
50 "checksumValue" : 5815827069051002745,
51 "comparisonResult" : "no-comparison",
52 "filepath" : "red_skp-tile0.png",
53},{
54 "checksumAlgorithm" : "bitmap-64bitMD5",
55 "checksumValue" : 9323613075234140270,
56 "comparisonResult" : "no-comparison",
57 "filepath" : "red_skp-tile1.png",
58}, {
59 "checksumAlgorithm" : "bitmap-64bitMD5",
60 "checksumValue" : 16670399404877552232,
61 "comparisonResult" : "no-comparison",
62 "filepath" : "red_skp-tile2.png",
63}, {
64 "checksumAlgorithm" : "bitmap-64bitMD5",
65 "checksumValue" : 2507897274083364964,
66 "comparisonResult" : "no-comparison",
67 "filepath" : "red_skp-tile3.png",
68}, {
69 "checksumAlgorithm" : "bitmap-64bitMD5",
70 "checksumValue" : 7325267995523877959,
71 "comparisonResult" : "no-comparison",
72 "filepath" : "red_skp-tile4.png",
73}, {
74 "checksumAlgorithm" : "bitmap-64bitMD5",
75 "checksumValue" : 2181381724594493116,
76 "comparisonResult" : "no-comparison",
77 "filepath" : "red_skp-tile5.png",
78}]
79
80# Manually verified these 6 images, all 256x256 tiles,
81# consistent with a tiled version of the 640x400 green rect
82# with black borders.
83GREEN_TILES = [{
84 "checksumAlgorithm" : "bitmap-64bitMD5",
85 "checksumValue" : 12587324416545178013,
86 "comparisonResult" : "no-comparison",
87 "filepath" : "green_skp-tile0.png",
88}, {
89 "checksumAlgorithm" : "bitmap-64bitMD5",
90 "checksumValue" : 7624374914829746293,
91 "comparisonResult" : "no-comparison",
92 "filepath" : "green_skp-tile1.png",
93}, {
94 "checksumAlgorithm" : "bitmap-64bitMD5",
95 "checksumValue" : 5686489729535631913,
96 "comparisonResult" : "no-comparison",
97 "filepath" : "green_skp-tile2.png",
98}, {
99 "checksumAlgorithm" : "bitmap-64bitMD5",
100 "checksumValue" : 7980646035555096146,
101 "comparisonResult" : "no-comparison",
102 "filepath" : "green_skp-tile3.png",
103}, {
104 "checksumAlgorithm" : "bitmap-64bitMD5",
105 "checksumValue" : 17817086664365875131,
106 "comparisonResult" : "no-comparison",
107 "filepath" : "green_skp-tile4.png",
108}, {
109 "checksumAlgorithm" : "bitmap-64bitMD5",
110 "checksumValue" : 10673669813016809363,
111 "comparisonResult" : "no-comparison",
112 "filepath" : "green_skp-tile5.png",
113}]
114
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000115
116class RenderPicturesTest(base_unittest.TestCase):
117
118 def setUp(self):
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000119 self._input_skp_dir = tempfile.mkdtemp()
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000120 self._temp_dir = tempfile.mkdtemp()
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000121 self.maxDiff = MAX_DIFF_LENGTH
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000122
123 def tearDown(self):
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000124 shutil.rmtree(self._input_skp_dir)
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000125 shutil.rmtree(self._temp_dir)
126
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000127 def test_tiled_whole_image(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000128 """Run render_pictures with tiles and --writeWholeImage flag.
129
130 TODO(epoger): This test generates undesired results! The JSON summary
131 includes both whole-image and tiled-images (as it should), but only
132 whole-images are written out to disk. See http://skbug.com/2463
133
134 TODO(epoger): I noticed that when this is run without --writePath being
135 specified, this test writes red_skp.png and green_skp.png to the current
136 directory. We should fix that... if --writePath is not specified, this
137 probably shouldn't write out red_skp.png and green_skp.png at all!
138 See http://skbug.com/2464
139 """
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000140 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000141 self._generate_skps()
142 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000143 '--bbh', 'grid', '256', '256',
144 '--mode', 'tile', '256', '256',
145 '--writeJsonSummaryPath', output_json_path,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000146 '--writePath', self._temp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000147 '--writeWholeImage'])
148 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000149 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000150 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000151 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000152 "tiled-images": RED_TILES,
153 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000154 },
155 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000156 "tiled-images": GREEN_TILES,
157 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000158 }
159 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +0000160 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000161 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000162 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000163 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000164
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000165 def test_untiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000166 """Run without tiles."""
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000167 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000168 self._generate_skps()
169 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000170 '--writePath', self._temp_dir,
171 '--writeJsonSummaryPath', output_json_path])
172 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000173 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000174 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000175 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000176 "whole-image": RED_WHOLEIMAGE,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000177 },
178 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000179 "whole-image": GREEN_WHOLEIMAGE,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000180 }
181 }
182 }
183 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000184 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000185 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000186
187 def test_untiled_writeChecksumBasedFilenames(self):
188 """Same as test_untiled, but with --writeChecksumBasedFilenames."""
189 output_json_path = os.path.join(self._temp_dir, 'output.json')
190 self._generate_skps()
191 self._run_render_pictures(['-r', self._input_skp_dir,
192 '--writeChecksumBasedFilenames',
193 '--writePath', self._temp_dir,
194 '--writeJsonSummaryPath', output_json_path])
195 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000196 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000197 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000198 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000199 # Manually verified: 640x400 red rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000200 "whole-image": {
201 "checksumAlgorithm" : "bitmap-64bitMD5",
202 "checksumValue" : 11092453015575919668,
203 "comparisonResult" : "no-comparison",
204 "filepath" : "red_skp/bitmap-64bitMD5_11092453015575919668.png",
205 },
206 },
207 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000208 # Manually verified: 640x400 green rectangle with black border
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000209 "whole-image": {
210 "checksumAlgorithm" : "bitmap-64bitMD5",
211 "checksumValue" : 8891695120562235492,
212 "comparisonResult" : "no-comparison",
213 "filepath" : "green_skp/bitmap-64bitMD5_8891695120562235492.png",
214 },
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000215 }
216 }
217 }
218 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000219 self._assert_directory_contents(self._temp_dir, [
220 'red_skp', 'green_skp', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000221 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000222 os.path.join(self._temp_dir, 'red_skp'),
223 ['bitmap-64bitMD5_11092453015575919668.png'])
224 self._assert_directory_contents(
225 os.path.join(self._temp_dir, 'green_skp'),
226 ['bitmap-64bitMD5_8891695120562235492.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000227
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000228 def test_untiled_validate(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000229 """Same as test_untiled, but with --validate."""
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000230 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000231 self._generate_skps()
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000232 self._run_render_pictures(['-r', self._input_skp_dir,
233 '--validate',
234 '--writePath', self._temp_dir,
235 '--writeJsonSummaryPath', output_json_path])
236 expected_summary_dict = {
237 "header" : EXPECTED_HEADER_CONTENTS,
238 "actual-results" : {
239 "red.skp": {
240 "whole-image": RED_WHOLEIMAGE,
241 },
242 "green.skp": {
243 "whole-image": GREEN_WHOLEIMAGE,
244 }
245 }
246 }
247 self._assert_json_contents(output_json_path, expected_summary_dict)
248 self._assert_directory_contents(
249 self._temp_dir, ['red_skp.png', 'green_skp.png', 'output.json'])
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000250
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000251 def test_untiled_without_writePath(self):
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000252 """Same as test_untiled, but without --writePath."""
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000253 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000254 self._generate_skps()
255 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000256 '--writeJsonSummaryPath', output_json_path])
257 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000258 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000259 "actual-results" : {
260 "red.skp": {
261 "whole-image": RED_WHOLEIMAGE,
262 },
263 "green.skp": {
264 "whole-image": GREEN_WHOLEIMAGE,
265 }
266 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000267 }
268 self._assert_json_contents(output_json_path, expected_summary_dict)
269
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000270 def test_tiled(self):
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000271 """Generate individual tiles."""
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000272 output_json_path = os.path.join(self._temp_dir, 'output.json')
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000273 self._generate_skps()
274 self._run_render_pictures(['-r', self._input_skp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000275 '--bbh', 'grid', '256', '256',
276 '--mode', 'tile', '256', '256',
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000277 '--writePath', self._temp_dir,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000278 '--writeJsonSummaryPath', output_json_path])
279 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000280 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000281 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000282 "red.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000283 "tiled-images": RED_TILES,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000284 },
285 "green.skp": {
commit-bot@chromium.org4610a462014-04-29 19:39:22 +0000286 "tiled-images": GREEN_TILES,
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000287 }
288 }
commit-bot@chromium.orgc3147c62014-01-15 20:35:54 +0000289 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000290 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000291 self._assert_directory_contents(
292 self._temp_dir,
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000293 ['red_skp-tile0.png', 'red_skp-tile1.png', 'red_skp-tile2.png',
294 'red_skp-tile3.png', 'red_skp-tile4.png', 'red_skp-tile5.png',
295 'green_skp-tile0.png', 'green_skp-tile1.png', 'green_skp-tile2.png',
296 'green_skp-tile3.png', 'green_skp-tile4.png', 'green_skp-tile5.png',
297 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000298
299 def test_tiled_writeChecksumBasedFilenames(self):
300 """Same as test_tiled, but with --writeChecksumBasedFilenames."""
301 output_json_path = os.path.join(self._temp_dir, 'output.json')
302 self._generate_skps()
303 self._run_render_pictures(['-r', self._input_skp_dir,
304 '--bbh', 'grid', '256', '256',
305 '--mode', 'tile', '256', '256',
306 '--writeChecksumBasedFilenames',
307 '--writePath', self._temp_dir,
308 '--writeJsonSummaryPath', output_json_path])
309 expected_summary_dict = {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000310 "header" : EXPECTED_HEADER_CONTENTS,
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000311 "actual-results" : {
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000312 "red.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000313 # Manually verified these 6 images, all 256x256 tiles,
314 # consistent with a tiled version of the 640x400 red rect
315 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000316 "tiled-images": [{
317 "checksumAlgorithm" : "bitmap-64bitMD5",
318 "checksumValue" : 5815827069051002745,
319 "comparisonResult" : "no-comparison",
320 "filepath" : "red_skp/bitmap-64bitMD5_5815827069051002745.png",
321 }, {
322 "checksumAlgorithm" : "bitmap-64bitMD5",
323 "checksumValue" : 9323613075234140270,
324 "comparisonResult" : "no-comparison",
325 "filepath" : "red_skp/bitmap-64bitMD5_9323613075234140270.png",
326 }, {
327 "checksumAlgorithm" : "bitmap-64bitMD5",
328 "checksumValue" : 16670399404877552232,
329 "comparisonResult" : "no-comparison",
330 "filepath" : "red_skp/bitmap-64bitMD5_16670399404877552232.png",
331 }, {
332 "checksumAlgorithm" : "bitmap-64bitMD5",
333 "checksumValue" : 2507897274083364964,
334 "comparisonResult" : "no-comparison",
335 "filepath" : "red_skp/bitmap-64bitMD5_2507897274083364964.png",
336 }, {
337 "checksumAlgorithm" : "bitmap-64bitMD5",
338 "checksumValue" : 7325267995523877959,
339 "comparisonResult" : "no-comparison",
340 "filepath" : "red_skp/bitmap-64bitMD5_7325267995523877959.png",
341 }, {
342 "checksumAlgorithm" : "bitmap-64bitMD5",
343 "checksumValue" : 2181381724594493116,
344 "comparisonResult" : "no-comparison",
345 "filepath" : "red_skp/bitmap-64bitMD5_2181381724594493116.png",
346 }],
347 },
348 "green.skp": {
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000349 # Manually verified these 6 images, all 256x256 tiles,
350 # consistent with a tiled version of the 640x400 green rect
351 # with black borders.
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000352 "tiled-images": [{
353 "checksumAlgorithm" : "bitmap-64bitMD5",
354 "checksumValue" : 12587324416545178013,
355 "comparisonResult" : "no-comparison",
356 "filepath" : "green_skp/bitmap-64bitMD5_12587324416545178013.png",
357 }, {
358 "checksumAlgorithm" : "bitmap-64bitMD5",
359 "checksumValue" : 7624374914829746293,
360 "comparisonResult" : "no-comparison",
361 "filepath" : "green_skp/bitmap-64bitMD5_7624374914829746293.png",
362 }, {
363 "checksumAlgorithm" : "bitmap-64bitMD5",
364 "checksumValue" : 5686489729535631913,
365 "comparisonResult" : "no-comparison",
366 "filepath" : "green_skp/bitmap-64bitMD5_5686489729535631913.png",
367 }, {
368 "checksumAlgorithm" : "bitmap-64bitMD5",
369 "checksumValue" : 7980646035555096146,
370 "comparisonResult" : "no-comparison",
371 "filepath" : "green_skp/bitmap-64bitMD5_7980646035555096146.png",
372 }, {
373 "checksumAlgorithm" : "bitmap-64bitMD5",
374 "checksumValue" : 17817086664365875131,
375 "comparisonResult" : "no-comparison",
376 "filepath" : "green_skp/bitmap-64bitMD5_17817086664365875131.png",
377 }, {
378 "checksumAlgorithm" : "bitmap-64bitMD5",
379 "checksumValue" : 10673669813016809363,
380 "comparisonResult" : "no-comparison",
381 "filepath" : "green_skp/bitmap-64bitMD5_10673669813016809363.png",
382 }],
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000383 }
384 }
385 }
386 self._assert_json_contents(output_json_path, expected_summary_dict)
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000387 self._assert_directory_contents(self._temp_dir, [
388 'red_skp', 'green_skp', 'output.json'])
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000389 self._assert_directory_contents(
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000390 os.path.join(self._temp_dir, 'red_skp'),
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000391 ['bitmap-64bitMD5_5815827069051002745.png',
392 'bitmap-64bitMD5_9323613075234140270.png',
393 'bitmap-64bitMD5_16670399404877552232.png',
394 'bitmap-64bitMD5_2507897274083364964.png',
395 'bitmap-64bitMD5_7325267995523877959.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000396 'bitmap-64bitMD5_2181381724594493116.png'])
397 self._assert_directory_contents(
398 os.path.join(self._temp_dir, 'green_skp'),
399 ['bitmap-64bitMD5_12587324416545178013.png',
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000400 'bitmap-64bitMD5_7624374914829746293.png',
401 'bitmap-64bitMD5_5686489729535631913.png',
402 'bitmap-64bitMD5_7980646035555096146.png',
403 'bitmap-64bitMD5_17817086664365875131.png',
commit-bot@chromium.org24c568c2014-04-10 15:39:02 +0000404 'bitmap-64bitMD5_10673669813016809363.png'])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000405
406 def _run_render_pictures(self, args):
407 binary = self.find_path_to_program('render_pictures')
408 return self.run_command([binary,
409 '--clone', '1',
410 '--config', '8888',
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000411 ] + args)
412
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000413 def _generate_skps(self):
414 """Runs the skpmaker binary to generate files in self._input_skp_dir."""
415 self._run_skpmaker(
416 output_path=os.path.join(self._input_skp_dir, 'red.skp'), red=255)
417 self._run_skpmaker(
418 output_path=os.path.join(self._input_skp_dir, 'green.skp'), green=255)
419
420 def _run_skpmaker(self, output_path, red=0, green=0, blue=0,
421 width=640, height=400):
422 """Runs the skpmaker binary to generate SKP with known characteristics.
423
424 Args:
425 output_path: Filepath to write the SKP into.
426 red: Value of red color channel in image, 0-255.
427 green: Value of green color channel in image, 0-255.
428 blue: Value of blue color channel in image, 0-255.
429 width: Width of canvas to create.
430 height: Height of canvas to create.
431 """
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000432 binary = self.find_path_to_program('skpmaker')
433 return self.run_command([binary,
commit-bot@chromium.orgf11943f2014-03-12 20:09:46 +0000434 '--red', str(red),
435 '--green', str(green),
436 '--blue', str(blue),
437 '--width', str(width),
438 '--height', str(height),
439 '--writePath', str(output_path),
440 ])
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000441
commit-bot@chromium.orgf5e315c2014-03-19 17:26:07 +0000442 def _assert_directory_contents(self, dir_path, expected_filenames):
443 """Asserts that files found in a dir are identical to expected_filenames.
444
445 Args:
446 dir_path: Path to a directory on local disk.
447 expected_filenames: Set containing the expected filenames within the dir.
448
449 Raises:
450 AssertionError: contents of the directory are not identical to
451 expected_filenames.
452 """
453 self.assertEqual(set(os.listdir(dir_path)), set(expected_filenames))
454
455
commit-bot@chromium.org11f15622014-01-07 17:03:40 +0000456 def _assert_json_contents(self, json_path, expected_dict):
457 """Asserts that contents of a JSON file are identical to expected_dict.
458
459 Args:
460 json_path: Path to a JSON file.
461 expected_dict: Dictionary indicating the expected contents of the JSON
462 file.
463
464 Raises:
465 AssertionError: contents of the JSON file are not identical to
466 expected_dict.
467 """
468 file_contents = open(json_path, 'r').read()
469 actual_dict = json.loads(file_contents)
470 self.assertEqual(actual_dict, expected_dict)
471
472
473def main():
474 base_unittest.main(RenderPicturesTest)
475
476
477if __name__ == '__main__':
478 main()