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