skia2/platform_tools/android/tests/var_dict_tests.py
commit-bot@chromium.org ba0c5ea90d Updates to Android.mk generation.
Generate SkUserConfig.
Include arm64 as another build flavor.
Add tests.

gyp/common_conditions.gypi:
Add conditions for Android framework. These will get written into the generated SkUserConfig.

include/core/SkUserConfig.h:
Generated version that will ultimately be checked into Android (but not here).

platform_tools/android/bin/gyp_to_android.py:
Generate SkUserConfig.
Add arm64 (note that arm64 is not currently respected by our gyp files, so it results in use _none.cpp for the various opts).
Reset the common defines, which are now passed to the generated SkUserConfig.

platform_tools/android/gyp_gen/generate_user_config.py:
New script to generate SkUserConfig.h.

platform_tools/android/gyp_gen/gypd_parser.py:
Fix a lint error (unused import).

platform_tools/android/gyp_gen/makefile_writer.py:
Append any remaining DEFINES to LOCAL_CFLAGS (previously this was done during parsing).
Add a warning for arm64 (corresponds to downstream Android.mk).

platform_tools/android/gyp_gen/vars_dict_lib.py:
Add OrderedSet.reset().
Add DEFINES to VarsDict.

platform_tools/android/tests/expectations/:
Add and update expectations files.

platform_tools/android/tests/generate_user_config_tests.py:
New test for generate_user_config.py

platform_tools/android/tests/inputs/SkUserConfig.h:
Input to the new test, so we don't have to update the expectations each time the real SkUserConfig.h changes.

platform_tools/android/tests/makefile_writer_tests.py:
Add a way to rebaseline test_write_local_vars, which has changed.
Refactor EXPECTATIONS_DIR and compare_files into a separate file for sharing with generate_user_config_tests.py.

platform_tools/android/tests/utils.py:
Common code for tests.

platform_tools/android/tests/var_dict_tests.py:
Use a for loop to test the new key (DEFINES) and future proof this test to test any new keys in the future.

BUG=skia:1975
R=djsollen@google.com, halcanary@google.com

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/198063002

git-svn-id: http://skia.googlecode.com/svn/trunk@13975 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-03-28 15:59:04 +00:00

91 lines
2.6 KiB
Python

#!/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 the VarsDict.
"""
import sys
import test_variables
import unittest
sys.path.append(test_variables.GYP_GEN_DIR)
import vars_dict_lib
from vars_dict_lib import OrderedSet
from vars_dict_lib import VarsDict
from vars_dict_lib import VAR_NAMES
class VarsDictTest(unittest.TestCase):
"""
Tests for the VarsDict class.
"""
# May not be needed.
def setUp(self):
self.__vars_dict = VarsDict()
def assert_consistency(self, v_dict):
self.assertIs(v_dict.LOCAL_CFLAGS, v_dict['LOCAL_CFLAGS'])
self.assertIs(v_dict.LOCAL_CPPFLAGS, v_dict['LOCAL_CPPFLAGS'])
self.assertIs(v_dict.LOCAL_SRC_FILES, v_dict['LOCAL_SRC_FILES'])
self.assertIs(v_dict.LOCAL_SHARED_LIBRARIES,
v_dict['LOCAL_SHARED_LIBRARIES'])
self.assertIs(v_dict.LOCAL_STATIC_LIBRARIES,
v_dict['LOCAL_STATIC_LIBRARIES'])
self.assertIs(v_dict.LOCAL_C_INCLUDES, v_dict['LOCAL_C_INCLUDES'])
self.assertIs(v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS,
v_dict['LOCAL_EXPORT_C_INCLUDE_DIRS'])
self.assertIs(v_dict.KNOWN_TARGETS, v_dict['KNOWN_TARGETS'])
def test_creation(self):
v_dict = VarsDict()
# VarsDict has one entry for each label in VAR_NAMES
self.assertEqual(len(v_dict.keys()), len(VAR_NAMES))
for key in v_dict.keys():
self.assertIn(key, VAR_NAMES)
# Each entry is an empty OrderedSet
self.assertIsNotNone(v_dict[key])
self.assertIsInstance(v_dict[key], OrderedSet)
self.assertEqual(len(v_dict[key]), 0)
self.assert_consistency(v_dict)
def test_intersection(self):
v_dict_list = []
RANGE = 10
for i in range(RANGE):
v_dict = VarsDict()
# Add something common to each field, as well as a unique entry
for key in v_dict.keys():
v_dict[key].add(key.lower())
v_dict[key].add(str(i))
self.assert_consistency(v_dict)
v_dict_list.append(v_dict)
intersection = vars_dict_lib.intersect(v_dict_list)
self.assert_consistency(intersection)
for key in intersection.keys():
# Each field had one common item
self.assertEqual(len(intersection[key]), 1)
for item in intersection[key]:
for other_v_dict in v_dict_list:
self.assertNotIn(item, other_v_dict[key])
def main():
loader = unittest.TestLoader()
suite = loader.loadTestsFromTestCase(VarsDictTest)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == "__main__":
main()