Chromium Code Reviews| 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 | |
| 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 def setUp(self): | |
|
epoger
2014/01/22 21:35:03
please add newline before first method in each cla
scroggo
2014/01/22 23:33:08
Done.
| |
| 33 self.__vars_dict = gyp_to_android.VarsDict() | |
| 34 | |
| 35 def test_block_insertion(self): | |
| 36 # Inserting new dictionary entries should throw an exception. | |
| 37 with self.assertRaises(AssertionError): | |
| 38 self.__vars_dict['c'] = None | |
| 39 | |
| 40 def test_ConvertDefines(self): | |
| 41 # ConvertDefines() should append all 'defines' to 'cflags' with '-D'. | |
| 42 | |
| 43 # 'cflags' starts off empty. | |
| 44 self.assertTrue(len(self.__vars_dict['cflags']) == 0) | |
|
epoger
2014/01/22 21:35:03
Your error messages will be better if you use self
scroggo
2014/01/22 23:33:08
Done.
| |
| 45 | |
| 46 self.__vars_dict['defines'].extend(['foo', 'bar', 'c++']) | |
| 47 self.__vars_dict.ConvertDefines() | |
| 48 | |
| 49 self.assertTrue(len(self.__vars_dict['cflags']) == | |
| 50 len(self.__vars_dict['defines'])) | |
| 51 | |
| 52 for define in self.__vars_dict['defines']: | |
| 53 self.assertTrue(('-D' + define) in self.__vars_dict['cflags']) | |
| 54 | |
| 55 # ConvertDefines() can only be called once. | |
| 56 with self.assertRaises(AssertionError): | |
| 57 self.__vars_dict.ConvertDefines() | |
| 58 | |
| 59 class AddToListTest(unittest.TestCase): | |
| 60 def setUp(self): | |
| 61 self.__li = [] | |
| 62 | |
| 63 def test_add(self): | |
| 64 dummy_var = 'dummy_var' | |
| 65 # Add to the list. This should succeed. | |
| 66 gyp_to_android.AddToList(self.__li, dummy_var) | |
| 67 self.assertTrue(len(self.__li) == 1) | |
| 68 self.assertTrue(self.__li[0] == dummy_var) | |
| 69 | |
| 70 # Now attempt to add it again. This should fail. | |
| 71 gyp_to_android.AddToList(self.__li, dummy_var) | |
| 72 self.assertTrue(len(self.__li) == 1) | |
| 73 self.assertTrue(self.__li[0] == dummy_var) | |
| 74 | |
| 75 class AndroidMkCreationTest(unittest.TestCase): | |
| 76 def setUp(self): | |
| 77 # Create a temporary directory for storing the output (Android.mk) | |
| 78 self.__tmp_dir = tempfile.mkdtemp() | |
| 79 | |
| 80 def test_create(self): | |
| 81 gyp_to_android.main(self.__tmp_dir) | |
| 82 | |
| 83 # Now there should be a file named 'Android.mk' inside __tmp_dir | |
| 84 path_to_android_mk = os.path.join(self.__tmp_dir, 'Android.mk') | |
| 85 self.assertTrue(os.path.exists(path_to_android_mk)) | |
| 86 | |
| 87 def tearDown(self): | |
| 88 # Remove self.__tmp_dir, which is no longer needed. | |
| 89 shutil.rmtree(self.__tmp_dir) | |
| 90 | |
| 91 | |
| 92 def main(): | |
| 93 loader = unittest.TestLoader() | |
| 94 suite = loader.loadTestsFromTestCase(VarsDictTest) | |
| 95 suite.addTest(loader.loadTestsFromTestCase(AddToListTest)) | |
| 96 suite.addTest(loader.loadTestsFromTestCase(AndroidMkCreationTest)) | |
| 97 unittest.TextTestRunner(verbosity=2).run(suite) | |
| 98 | |
| 99 if __name__ == "__main__": | |
| 100 main() | |
| OLD | NEW |