Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / testing / gmock / test / gmock_test_utils.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006, Google Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9 #
10 #     * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
15 # distribution.
16 #     * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 """Unit test utilities for Google C++ Mocking Framework."""
33
34 __author__ = 'wan@google.com (Zhanyong Wan)'
35
36 import os
37 import sys
38
39
40 # Determines path to gtest_test_utils and imports it.
41 SCRIPT_DIR = os.path.dirname(__file__) or '.'
42
43 # isdir resolves symbolic links.
44 gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test')
45 if os.path.isdir(gtest_tests_util_dir):
46   GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
47 else:
48   GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test')
49
50 sys.path.append(GTEST_TESTS_UTIL_DIR)
51 import gtest_test_utils  # pylint: disable-msg=C6204
52
53
54 def GetSourceDir():
55   """Returns the absolute path of the directory where the .py files are."""
56
57   return gtest_test_utils.GetSourceDir()
58
59
60 def GetTestExecutablePath(executable_name):
61   """Returns the absolute path of the test binary given its name.
62
63   The function will print a message and abort the program if the resulting file
64   doesn't exist.
65
66   Args:
67     executable_name: name of the test binary that the test script runs.
68
69   Returns:
70     The absolute path of the test binary.
71   """
72
73   return gtest_test_utils.GetTestExecutablePath(executable_name)
74
75
76 def GetExitStatus(exit_code):
77   """Returns the argument to exit(), or -1 if exit() wasn't called.
78
79   Args:
80     exit_code: the result value of os.system(command).
81   """
82
83   if os.name == 'nt':
84     # On Windows, os.WEXITSTATUS() doesn't work and os.system() returns
85     # the argument to exit() directly.
86     return exit_code
87   else:
88     # On Unix, os.WEXITSTATUS() must be used to extract the exit status
89     # from the result of os.system().
90     if os.WIFEXITED(exit_code):
91       return os.WEXITSTATUS(exit_code)
92     else:
93       return -1
94
95
96 # Suppresses the "Invalid const name" lint complaint
97 # pylint: disable-msg=C6409
98
99 # Exposes utilities from gtest_test_utils.
100 Subprocess = gtest_test_utils.Subprocess
101 TestCase = gtest_test_utils.TestCase
102 environ = gtest_test_utils.environ
103 SetEnvVar = gtest_test_utils.SetEnvVar
104 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
105
106 # pylint: enable-msg=C6409
107
108
109 def Main():
110   """Runs the unit test."""
111
112   gtest_test_utils.Main()