• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2#
3#
4# Copyright 2011, The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18import sys
19import unittest
20sys.path.append('../..')
21
22from testrunner import android_mk
23
24
25class AndroidMKTest(unittest.TestCase):
26  """Unit tests for AndroidMK."""
27
28  def testHasGTest(self):
29    """Test for AndroidMK.HasGTest."""
30    mk_parser = android_mk.CreateAndroidMK(path='.',
31                                           filename='Android_native.mk')
32    self.assertTrue(mk_parser.HasGTest())
33
34  def testHasGTest_lib(self):
35    """Test for AndroidMK.HasGTest."""
36    mk_parser = android_mk.CreateAndroidMK(path='.',
37                                           filename='Android_gtestlib.mk')
38    self.assertTrue(mk_parser.HasGTest())
39
40  def testHasGTest_false(self):
41    """Negative test for AndroidMK.HasGTest."""
42    mk_parser = android_mk.CreateAndroidMK(path='.', filename='Android_java.mk')
43    self.assertFalse(mk_parser.HasGTest())
44
45  def testHasJavaLibrary(self):
46    """Test for AndroidMK.HasJavaLibrary."""
47    mk_parser = android_mk.CreateAndroidMK(path='.',
48                                           filename='Android_java.mk')
49    self.assertTrue(mk_parser.HasJavaLibrary('android.test.runner'))
50
51  def testHasJavaLibrary_missing(self):
52    """Negative test for AndroidMK.HasJavaLibrary.
53
54    Test behavior when LOCAL_JAVA_LIBARIES rule is not present in makefile.
55    """
56    mk_parser = android_mk.CreateAndroidMK(path='.',
57                                           filename='Android_native.mk')
58    self.assertFalse(mk_parser.HasJavaLibrary('android.test.runner'))
59
60  def testHasJavaLibrary_false(self):
61    """Negative test for AndroidMK.HasJavaLibrary.
62
63    Test behavior when LOCAL_JAVA_LIBARIES rule is present, but does not list
64    given library.
65    """
66    mk_parser = android_mk.CreateAndroidMK(path='.', filename='Android_java.mk')
67    self.assertFalse(mk_parser.HasJavaLibrary('doesntexist'))
68
69  def testGetExpandedVariable(self):
70    """Test for AndroidMK.GetExpandedVariable.
71    """
72    mk_parser = android_mk.CreateAndroidMK(path='.',
73                                           filename='Android_native.mk')
74    self.assertEquals('foo', mk_parser.GetExpandedVariable('LOCAL_MODULE'))
75
76  def testGetExpandedVariable_loop(self):
77    """Test for AndroidMK.GetExpandedVariable where variable expansion loops
78    """
79    mk_parser = android_mk.CreateAndroidMK(path='.',
80                                           filename='Android_native.mk')
81    try:
82      mk_parser.GetExpandedVariable('recursive_var')
83      self.assertTrue(False)
84    except RuntimeError:
85      # expected
86      pass
87
88
89if __name__ == '__main__':
90  unittest.main()
91