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