Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 """Unit test utilities for Google C++ Mocking Framework."""
00033
00034 __author__ = 'wan@google.com (Zhanyong Wan)'
00035
00036 import os
00037 import sys
00038
00039
00040
00041 SCRIPT_DIR = os.path.dirname(__file__) or '.'
00042
00043
00044 gtest_tests_util_dir = os.path.join(SCRIPT_DIR, '../gtest/test')
00045 if os.path.isdir(gtest_tests_util_dir):
00046 GTEST_TESTS_UTIL_DIR = gtest_tests_util_dir
00047 else:
00048 GTEST_TESTS_UTIL_DIR = os.path.join(SCRIPT_DIR, '../../gtest/test')
00049
00050 sys.path.append(GTEST_TESTS_UTIL_DIR)
00051 import gtest_test_utils
00052
00053
00054 def GetSourceDir():
00055 """Returns the absolute path of the directory where the .py files are."""
00056
00057 return gtest_test_utils.GetSourceDir()
00058
00059
00060 def GetTestExecutablePath(executable_name):
00061 """Returns the absolute path of the test binary given its name.
00062
00063 The function will print a message and abort the program if the resulting file
00064 doesn't exist.
00065
00066 Args:
00067 executable_name: name of the test binary that the test script runs.
00068
00069 Returns:
00070 The absolute path of the test binary.
00071 """
00072
00073 return gtest_test_utils.GetTestExecutablePath(executable_name)
00074
00075
00076 def GetExitStatus(exit_code):
00077 """Returns the argument to exit(), or -1 if exit() wasn't called.
00078
00079 Args:
00080 exit_code: the result value of os.system(command).
00081 """
00082
00083 if os.name == 'nt':
00084
00085
00086 return exit_code
00087 else:
00088
00089
00090 if os.WIFEXITED(exit_code):
00091 return os.WEXITSTATUS(exit_code)
00092 else:
00093 return -1
00094
00095
00096
00097
00098
00099
00100 Subprocess = gtest_test_utils.Subprocess
00101 TestCase = gtest_test_utils.TestCase
00102 environ = gtest_test_utils.environ
00103 SetEnvVar = gtest_test_utils.SetEnvVar
00104 PREMATURE_EXIT_FILE_ENV_VAR = gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR
00105
00106
00107
00108
00109 def Main():
00110 """Runs the unit test."""
00111
00112 gtest_test_utils.Main()