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

Unified Diff: tools/tests/gyp_to_android_tests.py

Issue 142173002: Add self tests for gyp_to_android. (Closed) Base URL: https://skia.googlesource.com/skia.git@GYP2
Patch Set: Rebase onto Patch Set 8 of https://codereview.chromium.org/140503007/ Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « platform_tools/android/bin/gyp_to_android.py ('k') | tools/tests/run_all.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f2620cee4bc935efac14188df1da124f5609bfa0
--- /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):
+ # ConvertDefines() 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.ConvertDefines()
+
+ 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'])
+
+ # ConvertDefines() can only be called once.
+ with self.assertRaises(AssertionError):
+ self.__vars_dict.ConvertDefines()
+
+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.AddToList(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.AddToList(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()
« no previous file with comments | « platform_tools/android/bin/gyp_to_android.py ('k') | tools/tests/run_all.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698