test.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2021 Project CHIP Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """
  16. Test for GN Java build rules. This test should be executed using ninja.
  17. """
  18. import json
  19. import os
  20. import unittest
  21. from os import path
  22. class JavaBuildTest(unittest.TestCase):
  23. chip_root = os.getenv('PW_PROJECT_ROOT')
  24. local_test_dir = '/build/chip/java/tests'
  25. test_dir = chip_root + local_test_dir
  26. jars_dir = 'lib' + local_test_dir
  27. configs_dir = 'gen' + local_test_dir
  28. # Target names in the BUILD.gn
  29. targets_to_check = [
  30. 'java_library',
  31. 'child_library',
  32. 'child_library_2',
  33. 'grandchild_library',
  34. ]
  35. prebuilt_targets_to_check = ['java_prebuilt', 'child_prebuilt']
  36. def testExpectedJarsCreated(self):
  37. jars_dir = JavaBuildTest.jars_dir
  38. for target in JavaBuildTest.targets_to_check:
  39. self.assertTrue(path.exists(jars_dir + '/' + target + '.jar'))
  40. # Prebuilt jars should have been copied to the output directory.
  41. self.assertTrue(path.exists(jars_dir + '/prebuilt_jar.jar'))
  42. self.assertTrue(path.exists(jars_dir + '/child_jar.jar'))
  43. def testBuildConfigMatchesExpected(self):
  44. self.maxDiff = None
  45. configs_dir = JavaBuildTest.configs_dir
  46. expected_dir = JavaBuildTest.test_dir + '/expected_output'
  47. for target in (JavaBuildTest.targets_to_check +
  48. JavaBuildTest.prebuilt_targets_to_check):
  49. with open(expected_dir + '/' + target + '_expected.json',
  50. 'r') as expected_config, open(
  51. configs_dir + '/' + target + '.json',
  52. 'r') as actual_config:
  53. expected_json = json.load(expected_config)['deps_info']
  54. actual_json = json.load(actual_config)['deps_info']
  55. self.assertEqual(expected_json['name'], actual_json['name'])
  56. self.assertEqual(expected_json['jar_path'],
  57. actual_json['jar_path'])
  58. self.assertCountEqual(expected_json['deps_configs'],
  59. actual_json['deps_configs'])
  60. self.assertCountEqual(expected_json['deps_jars'],
  61. actual_json['deps_jars'])
  62. if __name__ == '__main__':
  63. unittest.main()