2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
11 BUILD_TOOLS_DIR
= os
.path
.dirname(SCRIPT_DIR
)
12 CHROME_SRC
= os
.path
.dirname(os
.path
.dirname(os
.path
.dirname(BUILD_TOOLS_DIR
)))
13 MOCK_DIR
= os
.path
.join(CHROME_SRC
, "third_party", "pymock")
15 # For the mock library
16 sys
.path
.append(MOCK_DIR
)
19 sys
.path
.append(BUILD_TOOLS_DIR
)
23 class TestPartition(unittest
.TestCase
):
26 os
.path
.join('ppapi', 'c', 'ppb_foo.h'),
27 os
.path
.join('ppapi', 'cpp', 'foo.h'),
28 os
.path
.join('ppapi', 'cpp', 'foo.cc'),
30 result
= verify_ppapi
.PartitionFiles(filenames
)
31 self
.assertTrue(filenames
[0] in result
['ppapi'])
32 self
.assertTrue(filenames
[1] in result
['ppapi_cpp'])
33 self
.assertTrue(filenames
[2] in result
['ppapi_cpp'])
34 self
.assertEqual(0, len(result
['ppapi_cpp_private']))
36 def testIgnoreDocumentation(self
):
38 os
.path
.join('ppapi', 'c', 'documentation', 'Doxyfile'),
39 os
.path
.join('ppapi', 'c', 'documentation', 'index.dox'),
40 os
.path
.join('ppapi', 'cpp', 'documentation', 'footer.html'),
42 result
= verify_ppapi
.PartitionFiles(filenames
)
43 self
.assertEqual(0, len(result
['ppapi']))
44 self
.assertEqual(0, len(result
['ppapi_cpp']))
45 self
.assertEqual(0, len(result
['ppapi_cpp_private']))
47 def testIgnoreTrusted(self
):
49 os
.path
.join('ppapi', 'c', 'trusted', 'ppb_broker_trusted.h'),
50 os
.path
.join('ppapi', 'cpp', 'trusted', 'file_chooser_trusted.cc'),
52 result
= verify_ppapi
.PartitionFiles(filenames
)
53 self
.assertEqual(0, len(result
['ppapi']))
54 self
.assertEqual(0, len(result
['ppapi_cpp']))
55 self
.assertEqual(0, len(result
['ppapi_cpp_private']))
57 def testIgnoreIfNotSourceOrHeader(self
):
59 os
.path
.join('ppapi', 'c', 'DEPS'),
60 os
.path
.join('ppapi', 'c', 'blah', 'foo.xml'),
61 os
.path
.join('ppapi', 'cpp', 'DEPS'),
62 os
.path
.join('ppapi', 'cpp', 'foobar.py'),
64 result
= verify_ppapi
.PartitionFiles(filenames
)
65 self
.assertEqual(0, len(result
['ppapi']))
66 self
.assertEqual(0, len(result
['ppapi_cpp']))
67 self
.assertEqual(0, len(result
['ppapi_cpp_private']))
69 def testIgnoreOtherDirectories(self
):
70 ignored_directories
= ['api', 'examples', 'generators', 'host', 'lib',
71 'native_client', 'proxy', 'shared_impl', 'tests', 'thunk']
73 # Generate some random files in the ignored directories.
75 for dirname
in ignored_directories
:
76 filenames
= os
.path
.join('ppapi', dirname
, 'foo.cc')
77 filenames
= os
.path
.join('ppapi', dirname
, 'subdir', 'foo.h')
78 filenames
= os
.path
.join('ppapi', dirname
, 'DEPS')
80 result
= verify_ppapi
.PartitionFiles(filenames
)
81 self
.assertEqual(0, len(result
['ppapi']))
82 self
.assertEqual(0, len(result
['ppapi_cpp']))
83 self
.assertEqual(0, len(result
['ppapi_cpp_private']))
86 class TestGetChangedAndRemoved(unittest
.TestCase
):
88 modified_filenames
= [
89 os
.path
.join('ppapi', 'cpp', 'audio.cc'),
90 os
.path
.join('ppapi', 'cpp', 'graphics_2d.cc'),
91 os
.path
.join('ppapi', 'cpp', 'foobar.cc'),
92 os
.path
.join('ppapi', 'cpp', 'var.cc'),
95 os
.path
.join('ppapi', 'cpp', 'audio.cc'),
96 os
.path
.join('ppapi', 'cpp', 'graphics_2d.cc'),
98 changed
, removed
= verify_ppapi
.GetChangedAndRemovedFilenames(
99 modified_filenames
, directory_list
)
100 self
.assertTrue(modified_filenames
[0] in changed
)
101 self
.assertTrue(modified_filenames
[1] in changed
)
102 self
.assertTrue(modified_filenames
[2] in removed
)
103 self
.assertTrue(modified_filenames
[3] in removed
)
106 class TestVerify(unittest
.TestCase
):
108 dsc_filename
= 'native_client_sdk/src/libraries/ppapi/library.dsc'
109 # The .dsc files typically uses basenames, not full paths.
110 dsc_sources_and_headers
= [
117 changed_filenames
= [
118 os
.path
.join('ppapi', 'c', 'ppb_audio.h'),
119 os
.path
.join('ppapi', 'c', 'ppb_console.h'),
121 removed_filenames
= []
123 verify_ppapi
.Verify(dsc_filename
, dsc_sources_and_headers
,
124 changed_filenames
, removed_filenames
)
126 # Raise, because we removed ppp_zoom_dev.h.
127 removed_filenames
= [
128 os
.path
.join('ppapi', 'c', 'ppb_console.h'),
130 self
.assertRaises(verify_ppapi
.VerifyException
, verify_ppapi
.Verify
,
131 dsc_filename
, dsc_sources_and_headers
, changed_filenames
,
134 # Raise, because we added ppb_foo.h.
135 removed_filenames
= []
136 changed_filenames
= [
137 os
.path
.join('ppapi', 'c', 'ppb_audio.h'),
138 os
.path
.join('ppapi', 'c', 'ppb_console.h'),
139 os
.path
.join('ppapi', 'c', 'ppb_foo.h'),
141 self
.assertRaises(verify_ppapi
.VerifyException
, verify_ppapi
.Verify
,
142 dsc_filename
, dsc_sources_and_headers
, changed_filenames
,
145 def testVerifyPrivate(self
):
147 'native_client_sdk/src/libraries/ppapi_cpp_private/library.dsc'
148 # The .dsc files typically uses basenames, not full paths.
149 dsc_sources_and_headers
= [
150 'ext_crx_file_system_private.cc',
151 'file_io_private.cc',
152 'ppb_ext_crx_file_system_private.h',
153 'ppb_file_io_private.h',
154 'host_resolver_private.h',
155 'net_address_private.h',
157 changed_filenames
= [
158 os
.path
.join('ppapi', 'c', 'private', 'ppb_foo_private.h'),
160 removed_filenames
= []
162 with mock
.patch('sys.stderr') as sys_stderr
:
163 # When a new private file is added, just print to stderr, but don't fail.
164 result
= verify_ppapi
.VerifyOrPrintError(
165 dsc_filename
, dsc_sources_and_headers
, changed_filenames
,
166 removed_filenames
, is_private
=True)
167 self
.assertTrue(result
)
168 self
.assertTrue(sys_stderr
.write
.called
)
170 # If is_private is False, then adding a new interface without updating the
172 sys_stderr
.reset_mock()
173 result
= verify_ppapi
.VerifyOrPrintError(
174 dsc_filename
, dsc_sources_and_headers
, changed_filenames
,
175 removed_filenames
, is_private
=False)
176 self
.assertFalse(result
)
177 self
.assertTrue(sys_stderr
.write
.called
)
179 # Removing a file without updating the .dsc is always an error.
180 sys_stderr
.reset_mock()
181 changed_filenames
= []
182 removed_filenames
= [
183 os
.path
.join('ppapi', 'c', 'private', 'net_address_private.h'),
185 result
= verify_ppapi
.VerifyOrPrintError(
186 dsc_filename
, dsc_sources_and_headers
, changed_filenames
,
187 removed_filenames
, is_private
=True)
188 self
.assertFalse(result
)
189 self
.assertTrue(sys_stderr
.write
.called
)
192 if __name__
== '__main__':