| Index: tools/tests/gyp_to_android_tests.py
|
| diff --git a/tools/tests/gyp_to_android_tests.py b/tools/tests/gyp_to_android_tests.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9c9f1bf2a6f7089b2e4fa33dd9b799ab09327477
|
| --- /dev/null
|
| +++ b/tools/tests/gyp_to_android_tests.py
|
| @@ -0,0 +1,103 @@
|
| +#!/usr/bin/python
|
| +
|
| +# Copyright 2014 Google Inc.
|
| +#
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +"""
|
| +Test gyp_to_android.py
|
| +"""
|
| +
|
| +import os
|
| +import shutil
|
| +import sys
|
| +import tempfile
|
| +import unittest
|
| +
|
| +# Find this file so we can find the Skia trunk.
|
| +SCRIPT_DIR = os.path.dirname(__file__)
|
| +SKIA_TRUNK = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
|
| +
|
| +# Path to gyp_to_android
|
| +# TODO (scroggo): Run this test inside platform_tools, instead of here.
|
| +sys.path.append(os.path.join(SKIA_TRUNK, 'platform_tools', 'android', 'bin'))
|
| +
|
| +import gyp_to_android
|
| +
|
| +class VarsDictTest(unittest.TestCase):
|
| + """
|
| + Tests for the VarsDict class.
|
| + """
|
| +
|
| + def setUp(self):
|
| + self.__vars_dict = gyp_to_android.VarsDict()
|
| +
|
| + def test_block_insertion(self):
|
| + # Inserting new dictionary entries should throw an exception.
|
| + with self.assertRaises(AssertionError):
|
| + self.__vars_dict['c'] = None
|
| +
|
| + def test_ConvertDefines(self):
|
| + # convert_defines() should append all 'defines' to 'cflags' with '-D'.
|
| +
|
| + # 'cflags' starts off empty.
|
| + self.assertEqual(len(self.__vars_dict['cflags']), 0)
|
| +
|
| + self.__vars_dict['defines'].extend(['foo', 'bar', 'c++'])
|
| + self.__vars_dict.convert_defines()
|
| +
|
| + self.assertEqual(len(self.__vars_dict['cflags']),
|
| + len(self.__vars_dict['defines']))
|
| +
|
| + for define in self.__vars_dict['defines']:
|
| + self.assertIn(('-D' + define), self.__vars_dict['cflags'])
|
| +
|
| + # convert_defines() can only be called once.
|
| + with self.assertRaises(AssertionError):
|
| + self.__vars_dict.convert_defines()
|
| +
|
| +class AddToListTest(unittest.TestCase):
|
| +
|
| + def setUp(self):
|
| + self.__li = []
|
| +
|
| + def test_add(self):
|
| + dummy_var = 'dummy_var'
|
| + # Add to the list. This should succeed.
|
| + gyp_to_android.add_to_list(self.__li, dummy_var)
|
| + self.assertEqual(len(self.__li), 1)
|
| + self.assertEqual(self.__li[0], dummy_var)
|
| +
|
| + # Now attempt to add it again. This should fail.
|
| + gyp_to_android.add_to_list(self.__li, dummy_var)
|
| + self.assertEqual(len(self.__li), 1)
|
| + self.assertEqual(self.__li[0], dummy_var)
|
| +
|
| +class AndroidMkCreationTest(unittest.TestCase):
|
| +
|
| + def setUp(self):
|
| + # Create a temporary directory for storing the output (Android.mk)
|
| + self.__tmp_dir = tempfile.mkdtemp()
|
| +
|
| + def test_create(self):
|
| + gyp_to_android.main(self.__tmp_dir)
|
| +
|
| + # Now there should be a file named 'Android.mk' inside __tmp_dir
|
| + path_to_android_mk = os.path.join(self.__tmp_dir, 'Android.mk')
|
| + self.assertTrue(os.path.exists(path_to_android_mk))
|
| +
|
| + def tearDown(self):
|
| + # Remove self.__tmp_dir, which is no longer needed.
|
| + shutil.rmtree(self.__tmp_dir)
|
| +
|
| +
|
| +def main():
|
| + loader = unittest.TestLoader()
|
| + suite = loader.loadTestsFromTestCase(VarsDictTest)
|
| + suite.addTest(loader.loadTestsFromTestCase(AddToListTest))
|
| + suite.addTest(loader.loadTestsFromTestCase(AndroidMkCreationTest))
|
| + unittest.TextTestRunner(verbosity=2).run(suite)
|
| +
|
| +if __name__ == "__main__":
|
| + main()
|
|
|