OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 | |
3 # Copyright 2014 Google Inc. | |
4 # | |
5 # Use of this source code is governed by a BSD-style license that can be | |
6 # found in the LICENSE file. | |
7 | |
8 """ | |
9 Test gyp_to_android.py | |
epoger
2014/02/03 17:26:32
Thanks for the unittests!
scroggo
2014/02/03 23:22:31
Haha, sure thing!
... they're out of date though.
| |
10 """ | |
11 | |
12 import os | |
13 import shutil | |
14 import sys | |
15 import tempfile | |
16 import unittest | |
17 | |
18 # Find this file so we can find the Skia trunk. | |
19 SCRIPT_DIR = os.path.dirname(__file__) | |
20 SKIA_TRUNK = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir)) | |
21 | |
22 # Path to gyp_to_android | |
23 # TODO (scroggo): Run this test inside platform_tools, instead of here. | |
24 sys.path.append(os.path.join(SKIA_TRUNK, 'platform_tools', 'android', 'bin')) | |
25 | |
26 import gyp_to_android | |
27 | |
28 class VarsDictTest(unittest.TestCase): | |
29 """ | |
30 Tests for the VarsDict class. | |
31 """ | |
32 | |
33 def setUp(self): | |
34 self.__vars_dict = gyp_to_android.VarsDict() | |
35 | |
36 def test_block_insertion(self): | |
37 # Inserting new dictionary entries should throw an exception. | |
38 with self.assertRaises(AssertionError): | |
39 self.__vars_dict['c'] = None | |
40 | |
41 def test_ConvertDefines(self): | |
42 # convert_defines() should append all 'defines' to 'cflags' with '-D'. | |
43 | |
44 # 'cflags' starts off empty. | |
45 self.assertEqual(len(self.__vars_dict['cflags']), 0) | |
46 | |
47 self.__vars_dict['defines'].extend(['foo', 'bar', 'c++']) | |
48 self.__vars_dict.convert_defines() | |
49 | |
50 self.assertEqual(len(self.__vars_dict['cflags']), | |
51 len(self.__vars_dict['defines'])) | |
52 | |
53 for define in self.__vars_dict['defines']: | |
54 self.assertIn(('-D' + define), self.__vars_dict['cflags']) | |
55 | |
56 # convert_defines() can only be called once. | |
57 with self.assertRaises(AssertionError): | |
58 self.__vars_dict.convert_defines() | |
59 | |
60 class AddToListTest(unittest.TestCase): | |
61 | |
62 def setUp(self): | |
63 self.__li = [] | |
64 | |
65 def test_add(self): | |
66 dummy_var = 'dummy_var' | |
67 # Add to the list. This should succeed. | |
68 gyp_to_android.add_to_list(self.__li, dummy_var) | |
69 self.assertEqual(len(self.__li), 1) | |
70 self.assertEqual(self.__li[0], dummy_var) | |
71 | |
72 # Now attempt to add it again. This should fail. | |
73 gyp_to_android.add_to_list(self.__li, dummy_var) | |
74 self.assertEqual(len(self.__li), 1) | |
75 self.assertEqual(self.__li[0], dummy_var) | |
76 | |
77 class AndroidMkCreationTest(unittest.TestCase): | |
78 | |
79 def setUp(self): | |
80 # Create a temporary directory for storing the output (Android.mk) | |
81 self.__tmp_dir = tempfile.mkdtemp() | |
82 | |
83 def test_create(self): | |
84 gyp_to_android.main(self.__tmp_dir) | |
85 | |
86 # Now there should be a file named 'Android.mk' inside __tmp_dir | |
87 path_to_android_mk = os.path.join(self.__tmp_dir, 'Android.mk') | |
88 self.assertTrue(os.path.exists(path_to_android_mk)) | |
89 | |
90 def tearDown(self): | |
91 # Remove self.__tmp_dir, which is no longer needed. | |
92 shutil.rmtree(self.__tmp_dir) | |
93 | |
94 | |
95 def main(): | |
96 loader = unittest.TestLoader() | |
97 suite = loader.loadTestsFromTestCase(VarsDictTest) | |
98 suite.addTest(loader.loadTestsFromTestCase(AddToListTest)) | |
99 suite.addTest(loader.loadTestsFromTestCase(AndroidMkCreationTest)) | |
100 unittest.TextTestRunner(verbosity=2).run(suite) | |
101 | |
102 if __name__ == "__main__": | |
103 main() | |
OLD | NEW |