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..dcd874e37c1ae7d5d67a97ac49d7d4e75724cc9c |
--- /dev/null |
+++ b/tools/tests/gyp_to_android_tests.py |
@@ -0,0 +1,102 @@ |
+#!/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 sys |
+ |
+# Find this file so we can find the Skia trunk. |
+script_dir = os.path.dirname(__file__) |
epoger
2014/01/21 20:00:51
all caps for these constants
scroggo
2014/01/22 16:36:48
Done.
|
+skia_trunk = os.path.normpath(os.path.join(script_dir, os.pardir, os.pardir)) |
+ |
+# Path to gyp_to_android |
+sys.path.append(os.path.join('platform_tools', 'android', 'bin')) |
epoger
2014/01/21 20:00:51
It worries me that tools/ is running the unittests
scroggo
2014/01/22 16:36:48
I've added a TODO. I think it's fine to move it in
|
+ |
+import gyp_to_android |
+ |
+def AssertFunctionAsserts(f): |
epoger
2014/01/21 20:00:51
Please make the self-test extend unittest.TestCase
scroggo
2014/01/22 16:36:48
Done.
|
+ """ |
+ Assert that the passed in function asserts. |
+ """ |
+ try: |
+ f() |
+ except AssertionError: |
+ # Nothing to see here; this is the intended behavior. |
+ pass |
+ else: |
+ assert False |
+ |
+def TestVarsDict(): |
+ """ |
+ Tests for the VarsDict class. |
+ """ |
+ vars_dict = gyp_to_android.VarsDict() |
epoger
2014/01/21 20:00:51
Using unittest.TestCase and its assertRaises() wil
scroggo
2014/01/22 16:36:48
Done.
|
+ |
+ # Inserting new dictionary entries should throw an exception. |
+ def f(): |
+ vars_dict['c'] = None |
+ |
+ AssertFunctionAsserts(f) |
+ |
+ # ConvertDefines() should append all 'defines' to 'cflags' with '-D'. |
epoger
2014/01/21 20:00:51
When you convert this to unittest.TestCase, I thin
scroggo
2014/01/22 16:36:48
Done.
|
+ |
+ # 'cflags' starts off empty. |
+ assert len(vars_dict['cflags']) == 0 |
+ |
+ vars_dict['defines'].extend(['foo', 'bar', 'c++']) |
+ |
+ vars_dict.ConvertDefines() |
+ |
+ assert len(vars_dict['cflags']) == len(vars_dict['defines']) |
+ |
+ for define in vars_dict['defines']: |
+ assert ('-D' + define) in vars_dict['cflags'] |
+ |
+ # ConvertDefines() can only be called once. |
+ def g(): |
+ vars_dict.ConvertDefines() |
+ |
+ AssertFunctionAsserts(g) |
+ |
+def TestAddToList(): |
+ li = [] |
+ foo = 'foo' |
+ gyp_to_android.AddToList(li, foo) |
+ assert len(li) == 1 |
+ assert li[0] == foo |
+ |
+ # Now attempt to add it again |
+ gyp_to_android.AddToList(li, foo) |
+ assert len(li) == 1 |
+ assert li[0] == foo |
+ |
+def TestAndroidMkCreation(): |
+ if gyp_to_android.main() != 0: |
+ raise Exception('gyp_to_android failed!') |
+ # Now there should be a file named 'Android.mk' at the root level. |
+ path_to_android_mk = os.path.join(skia_trunk, 'Android.mk') |
epoger
2014/01/21 20:00:51
I think it's dangerous for unittests to write into
scroggo
2014/01/22 16:36:48
Done.
For what it's worth, gyp_to_android calls g
scroggo
2014/01/22 19:32:50
Actually it wasn't so hard. In patch set 5 (and be
|
+ if not os.path.exists(path_to_android_mk): |
+ raise Exception('Failed to create Android.mk!') |
+ # Remove Android.mk, which is no longer needed. |
+ os.remove(path_to_android_mk) |
+ |
+ # gypd files should have been removed. |
+ for filename in os.listdir(os.path.join(skia_trunk, 'gyp')): |
+ assert not filename.endswith('gypd') |
+ |
+def main(): |
+ print 'Running gyp_to_android tests...' |
+ TestAndroidMkCreation() |
+ TestVarsDict() |
+ TestAddToList() |
+ print 'gyp_to_android tests succeeded!' |
+ |
+if __name__ == "__main__": |
+ main() |