Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: tools/generate_stubs/generate_stubs_unittest.py

Issue 403493004: generate_stubs: Add a new option --export-macro. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/generate_stubs/generate_stubs.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unittest for the generate_stubs.py. 6 """Unittest for the generate_stubs.py.
7 7
8 Since generate_stubs.py is a code generator, it is hard to do a very good 8 Since generate_stubs.py is a code generator, it is hard to do a very good
9 test. Instead of creating a golden-file test, which might be flakey, this 9 test. Instead of creating a golden-file test, which might be flakey, this
10 test elects instead to verify that various components "exist" within the 10 test elects instead to verify that various components "exist" within the
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 '-c', 'print "line 1 and suffix\\nline 2"'], 158 '-c', 'print "line 1 and suffix\\nline 2"'],
159 filter='line 1', write_to=output) 159 filter='line 1', write_to=output)
160 self.assertEqual('line 2\n', output.getvalue()) 160 self.assertEqual('line 2\n', output.getvalue())
161 161
162 162
163 class PosixStubWriterUnittest(unittest.TestCase): 163 class PosixStubWriterUnittest(unittest.TestCase):
164 def setUp(self): 164 def setUp(self):
165 self.module_name = 'my_module-1' 165 self.module_name = 'my_module-1'
166 self.signatures = [sig[1] for sig in SIMPLE_SIGNATURES] 166 self.signatures = [sig[1] for sig in SIMPLE_SIGNATURES]
167 self.out_dir = 'out_dir' 167 self.out_dir = 'out_dir'
168 self.writer = gs.PosixStubWriter(self.module_name, self.signatures) 168 self.writer = gs.PosixStubWriter(self.module_name, '', self.signatures)
169 169
170 def testEnumName(self): 170 def testEnumName(self):
171 self.assertEqual('kModuleMy_module1', 171 self.assertEqual('kModuleMy_module1',
172 gs.PosixStubWriter.EnumName(self.module_name)) 172 gs.PosixStubWriter.EnumName(self.module_name))
173 173
174 def testIsInitializedName(self): 174 def testIsInitializedName(self):
175 self.assertEqual('IsMy_module1Initialized', 175 self.assertEqual('IsMy_module1Initialized',
176 gs.PosixStubWriter.IsInitializedName(self.module_name)) 176 gs.PosixStubWriter.IsInitializedName(self.module_name))
177 177
178 def testInitializeModuleName(self): 178 def testInitializeModuleName(self):
179 self.assertEqual( 179 self.assertEqual(
180 'InitializeMy_module1', 180 'InitializeMy_module1',
181 gs.PosixStubWriter.InitializeModuleName(self.module_name)) 181 gs.PosixStubWriter.InitializeModuleName(self.module_name))
182 182
183 def testUninitializeModuleName(self): 183 def testUninitializeModuleName(self):
184 self.assertEqual( 184 self.assertEqual(
185 'UninitializeMy_module1', 185 'UninitializeMy_module1',
186 gs.PosixStubWriter.UninitializeModuleName(self.module_name)) 186 gs.PosixStubWriter.UninitializeModuleName(self.module_name))
187 187
188 def testStubFunctionPointer(self): 188 def testStubFunctionPointer(self):
189 self.assertEqual( 189 self.assertEqual(
190 'static int (*foo_ptr)(int a) = NULL;', 190 'static int (*foo_ptr)(int a) = NULL;',
191 gs.PosixStubWriter.StubFunctionPointer(SIMPLE_SIGNATURES[0][1])) 191 gs.PosixStubWriter.StubFunctionPointer(SIMPLE_SIGNATURES[0][1]))
192 192
193 def testStubFunction(self): 193 def testStubFunction(self):
194 # Test for a signature with a return value and a parameter. 194 # Test for a signature with a return value and a parameter.
195 self.assertEqual("""extern int foo(int a) __attribute__((weak)); 195 self.assertEqual("""extern int foo(int a) __attribute__((weak));
196 int foo(int a) { 196 int foo(int a) {
197 return foo_ptr(a); 197 return foo_ptr(a);
198 }""", gs.PosixStubWriter.StubFunction(SIMPLE_SIGNATURES[0][1])) 198 }""", gs.PosixStubWriter.StubFunction(SIMPLE_SIGNATURES[0][1]))
199 199
200 # Test for a signature with a void return value and no parameters. 200 # Test for a signature with a void return value and no parameters.
201 self.assertEqual("""extern void waldo(void) __attribute__((weak)); 201 self.assertEqual("""extern void waldo(void) __attribute__((weak));
202 void waldo(void) { 202 void waldo(void) {
203 waldo_ptr(); 203 waldo_ptr();
204 }""", gs.PosixStubWriter.StubFunction(SIMPLE_SIGNATURES[4][1])) 204 }""", gs.PosixStubWriter.StubFunction(SIMPLE_SIGNATURES[4][1]))
205 205
206 # Test export macros.
207 sig = _MakeSignature('int*', 'foo', ['bool b'])
208 sig['export'] = 'TEST_EXPORT'
209 self.assertEqual("""extern int* foo(bool b) __attribute__((weak));
210 int* TEST_EXPORT foo(bool b) {
211 return foo_ptr(b);
212 }""", gs.PosixStubWriter.StubFunction(sig))
213
206 def testWriteImplemenationContents(self): 214 def testWriteImplemenationContents(self):
207 outfile = StringIO.StringIO() 215 outfile = StringIO.StringIO()
208 self.writer.WriteImplementationContents('my_namespace', outfile) 216 self.writer.WriteImplementationContents('my_namespace', outfile)
209 contents = outfile.getvalue() 217 contents = outfile.getvalue()
210 218
211 # Verify namespace exists somewhere. 219 # Verify namespace exists somewhere.
212 self.assertTrue(contents.find('namespace my_namespace {') != -1) 220 self.assertTrue(contents.find('namespace my_namespace {') != -1)
213 221
214 # Verify that each signature has an _ptr and a function call in the file. 222 # Verify that each signature has an _ptr and a function call in the file.
215 # Check that the signatures were exported. 223 # Check that the signatures were exported.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 msg='Expected "%s" in %s' % (decl, contents)) 300 msg='Expected "%s" in %s' % (decl, contents))
293 decl = gs.PosixStubWriter.InitializeModuleName(name) 301 decl = gs.PosixStubWriter.InitializeModuleName(name)
294 self.assertTrue(contents.find(decl) != -1, 302 self.assertTrue(contents.find(decl) != -1,
295 msg='Expected "%s" in %s' % (decl, contents)) 303 msg='Expected "%s" in %s' % (decl, contents))
296 decl = gs.PosixStubWriter.UninitializeModuleName(name) 304 decl = gs.PosixStubWriter.UninitializeModuleName(name)
297 self.assertTrue(contents.find(decl) != -1, 305 self.assertTrue(contents.find(decl) != -1,
298 msg='Expected "%s" in %s' % (decl, contents)) 306 msg='Expected "%s" in %s' % (decl, contents))
299 307
300 if __name__ == '__main__': 308 if __name__ == '__main__':
301 unittest.main() 309 unittest.main()
OLDNEW
« no previous file with comments | « tools/generate_stubs/generate_stubs.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698