blob: 33c1e6a0469c8d70bf4fffe748c2a0ebb70da19f [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
21
22class RenderPicturesTest(base_unittest.TestCase):
23
24 def setUp(self):
25 self._temp_dir = tempfile.mkdtemp()
26
27 def tearDown(self):
28 shutil.rmtree(self._temp_dir)
29
30 def test_tiled_whole_image_no_comparison(self):
31 """Run render_pictures with tiles and --writeWholeImage flag."""
32 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
33 output_json_path = os.path.join(self._temp_dir, 'output.json')
34 self._run_skpmaker(['--writePath', input_skp_path])
35 self._run_render_pictures(['-r', input_skp_path,
36 '--bbh', 'grid', '256', '256',
37 '--mode', 'tile', '256', '256',
38 '--writeJsonSummaryPath', output_json_path,
39 '--writeWholeImage'])
40 expected_summary_dict = {
41 "actual-results" : {
42 "no-comparison" : {
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000043 # Manually verified: 640x400 red image with black border
44 "input.png" : [ "bitmap-64bitMD5", 11092453015575919668 ]
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000045 }
46 }
commit-bot@chromium.org238771c2014-01-15 16:33:31 +000047 }
commit-bot@chromium.org11f15622014-01-07 17:03:40 +000048 self._assert_json_contents(output_json_path, expected_summary_dict)
49
50 def test_tiled_no_comparison(self):
51 """Generate individual tiles.
52
53 TODO(epoger): The results of this test are currently broken!
54 The summary should contain a list of tiles, but for some reason, it is
55 empty."""
56 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
57 output_json_path = os.path.join(self._temp_dir, 'output.json')
58 self._run_skpmaker(['--writePath', input_skp_path])
59 self._run_render_pictures(['-r', input_skp_path,
60 '--bbh', 'grid', '256', '256',
61 '--mode', 'tile', '256', '256',
62 '--writeJsonSummaryPath', output_json_path])
63 expected_summary_dict = {
64 "actual-results" : {
65 "no-comparison" : None
66 }
67 }
68 self._assert_json_contents(output_json_path, expected_summary_dict)
69
70 def test_untiled_no_comparison(self):
71 """Run without tiles.
72
73 TODO(epoger): The results of this test are currently broken!
74 The summary should contain a single image, but for some reason, it is
75 empty."""
76 input_skp_path = os.path.join(self._temp_dir, 'input.skp')
77 output_json_path = os.path.join(self._temp_dir, 'output.json')
78 self._run_skpmaker(['--writePath', input_skp_path])
79 self._run_render_pictures(['-r', input_skp_path,
80 '--writeJsonSummaryPath', output_json_path])
81 expected_summary_dict = {
82 "actual-results" : {
83 "no-comparison" : None
84 }
85 }
86 self._assert_json_contents(output_json_path, expected_summary_dict)
87
88 def _run_render_pictures(self, args):
89 binary = self.find_path_to_program('render_pictures')
90 return self.run_command([binary,
91 '--clone', '1',
92 '--config', '8888',
93 '--validate'
94 ] + args)
95
96 def _run_skpmaker(self, args):
97 binary = self.find_path_to_program('skpmaker')
98 return self.run_command([binary,
99 '--red', '255',
100 '--green', '0',
101 '--blue', '0',
102 '--width', '640',
103 '--height', '400',
104 ] + args)
105
106 def _assert_json_contents(self, json_path, expected_dict):
107 """Asserts that contents of a JSON file are identical to expected_dict.
108
109 Args:
110 json_path: Path to a JSON file.
111 expected_dict: Dictionary indicating the expected contents of the JSON
112 file.
113
114 Raises:
115 AssertionError: contents of the JSON file are not identical to
116 expected_dict.
117 """
118 file_contents = open(json_path, 'r').read()
119 actual_dict = json.loads(file_contents)
120 self.assertEqual(actual_dict, expected_dict)
121
122
123def main():
124 base_unittest.main(RenderPicturesTest)
125
126
127if __name__ == '__main__':
128 main()