⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtest-internal.h

📁 Search s framework 老外写的
💻 H
📖 第 1 页 / 共 3 页
字号:
//   comment:          a comment on the test that will be included in the//                     test output//   fixture_class_id: ID of the test fixture class//   set_up_tc:        pointer to the function that sets up the test case//   tear_down_tc:     pointer to the function that tears down the test case//   factory:          pointer to the factory that creates a test object.//                     The newly created TestInfo instance will assume//                     ownership of the factory object.TestInfo* MakeAndRegisterTestInfo(    const char* test_case_name, const char* name,    const char* test_case_comment, const char* comment,    TypeId fixture_class_id,    SetUpTestCaseFunc set_up_tc,    TearDownTestCaseFunc tear_down_tc,    TestFactoryBase* factory);#if defined(GTEST_HAS_TYPED_TEST) || defined(GTEST_HAS_TYPED_TEST_P)// State of the definition of a type-parameterized test case.class TypedTestCasePState { public:  TypedTestCasePState() : registered_(false) {}  // Adds the given test name to defined_test_names_ and return true  // if the test case hasn't been registered; otherwise aborts the  // program.  bool AddTestName(const char* file, int line, const char* case_name,                   const char* test_name) {    if (registered_) {      fprintf(stderr, "%s Test %s must be defined before "              "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",              FormatFileLocation(file, line).c_str(), test_name, case_name);      abort();    }    defined_test_names_.insert(test_name);    return true;  }  // Verifies that registered_tests match the test names in  // defined_test_names_; returns registered_tests if successful, or  // aborts the program otherwise.  const char* VerifyRegisteredTestNames(      const char* file, int line, const char* registered_tests); private:  bool registered_;  ::std::set<const char*> defined_test_names_;};// Skips to the first non-space char after the first comma in 'str';// returns NULL if no comma is found in 'str'.inline const char* SkipComma(const char* str) {  const char* comma = strchr(str, ',');  if (comma == NULL) {    return NULL;  }  while (isspace(*(++comma))) {}  return comma;}// Returns the prefix of 'str' before the first comma in it; returns// the entire string if it contains no comma.inline String GetPrefixUntilComma(const char* str) {  const char* comma = strchr(str, ',');  return comma == NULL ? String(str) : String(str, comma - str);}// TypeParameterizedTest<Fixture, TestSel, Types>::Register()// registers a list of type-parameterized tests with Google Test.  The// return value is insignificant - we just need to return something// such that we can call this function in a namespace scope.//// Implementation note: The GTEST_TEMPLATE_ macro declares a template// template parameter.  It's defined in gtest-type-util.h.template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>class TypeParameterizedTest { public:  // 'index' is the index of the test in the type list 'Types'  // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,  // Types).  Valid values for 'index' are [0, N - 1] where N is the  // length of Types.  static bool Register(const char* prefix, const char* case_name,                       const char* test_names, int index) {    typedef typename Types::Head Type;    typedef Fixture<Type> FixtureClass;    typedef typename GTEST_BIND_(TestSel, Type) TestClass;    // First, registers the first type-parameterized test in the type    // list.    MakeAndRegisterTestInfo(        String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/",                       case_name, index).c_str(),        GetPrefixUntilComma(test_names).c_str(),        String::Format("TypeParam = %s", GetTypeName<Type>().c_str()).c_str(),        "",        GetTypeId<FixtureClass>(),        TestClass::SetUpTestCase,        TestClass::TearDownTestCase,        new TestFactoryImpl<TestClass>);    // Next, recurses (at compile time) with the tail of the type list.    return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>        ::Register(prefix, case_name, test_names, index + 1);  }};// The base case for the compile time recursion.template <GTEST_TEMPLATE_ Fixture, class TestSel>class TypeParameterizedTest<Fixture, TestSel, Types0> { public:  static bool Register(const char* /*prefix*/, const char* /*case_name*/,                       const char* /*test_names*/, int /*index*/) {    return true;  }};// TypeParameterizedTestCase<Fixture, Tests, Types>::Register()// registers *all combinations* of 'Tests' and 'Types' with Google// Test.  The return value is insignificant - we just need to return// something such that we can call this function in a namespace scope.template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>class TypeParameterizedTestCase { public:  static bool Register(const char* prefix, const char* case_name,                       const char* test_names) {    typedef typename Tests::Head Head;    // First, register the first test in 'Test' for each type in 'Types'.    TypeParameterizedTest<Fixture, Head, Types>::Register(        prefix, case_name, test_names, 0);    // Next, recurses (at compile time) with the tail of the test list.    return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>        ::Register(prefix, case_name, SkipComma(test_names));  }};// The base case for the compile time recursion.template <GTEST_TEMPLATE_ Fixture, typename Types>class TypeParameterizedTestCase<Fixture, Templates0, Types> { public:  static bool Register(const char* prefix, const char* case_name,                       const char* test_names) {    return true;  }};#endif  // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P// Returns the current OS stack trace as a String.//// The maximum number of stack frames to be included is specified by// the gtest_stack_trace_depth flag.  The skip_count parameter// specifies the number of top frames to be skipped, which doesn't// count against the number of frames to be included.//// For example, if Foo() calls Bar(), which in turn calls// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);// Returns the number of failed test parts in the given test result object.int GetFailedPartCount(const TestResult* result);}  // namespace internal}  // namespace testing#define GTEST_MESSAGE_(message, result_type) \  ::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, message) \    = ::testing::Message()#define GTEST_FATAL_FAILURE_(message) \  return GTEST_MESSAGE_(message, ::testing::TPRT_FATAL_FAILURE)#define GTEST_NONFATAL_FAILURE_(message) \  GTEST_MESSAGE_(message, ::testing::TPRT_NONFATAL_FAILURE)#define GTEST_SUCCESS_(message) \  GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS)#define GTEST_TEST_THROW_(statement, expected_exception, fail) \  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \  if (const char* gtest_msg = "") { \    bool gtest_caught_expected = false; \    try { \      statement; \    } \    catch (expected_exception const&) { \      gtest_caught_expected = true; \    } \    catch (...) { \      gtest_msg = "Expected: " #statement " throws an exception of type " \                  #expected_exception ".\n  Actual: it throws a different " \                  "type."; \      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \    } \    if (!gtest_caught_expected) { \      gtest_msg = "Expected: " #statement " throws an exception of type " \                  #expected_exception ".\n  Actual: it throws nothing."; \      goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \    } \  } else \    GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \      fail(gtest_msg)#define GTEST_TEST_NO_THROW_(statement, fail) \  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \  if (const char* gtest_msg = "") { \    try { \      statement; \    } \    catch (...) { \      gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \                  "  Actual: it throws."; \      goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \    } \  } else \    GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \      fail(gtest_msg)#define GTEST_TEST_ANY_THROW_(statement, fail) \  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \  if (const char* gtest_msg = "") { \    bool gtest_caught_any = false; \    try { \      statement; \    } \    catch (...) { \      gtest_caught_any = true; \    } \    if (!gtest_caught_any) { \      gtest_msg = "Expected: " #statement " throws an exception.\n" \                  "  Actual: it doesn't."; \      goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \    } \  } else \    GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \      fail(gtest_msg)#define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \  if (boolexpr) \    ; \  else \    fail("Value of: " booltext "\n  Actual: " #actual "\nExpected: " #expected)#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \  if (const char* gtest_msg = "") { \    ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \    { statement; } \    if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \      gtest_msg = "Expected: " #statement " doesn't generate new fatal " \                  "failures in the current thread.\n" \                  "  Actual: it does."; \      goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \    } \  } else \    GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \      fail(gtest_msg)// Expands to the name of the class that implements the given test.#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \  test_case_name##_##test_name##_Test// Helper macro for defining tests.#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ public:\  GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ private:\  virtual void TestBody();\  static ::testing::TestInfo* const test_info_;\  GTEST_DISALLOW_COPY_AND_ASSIGN_(\      GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\};\\::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\  ::test_info_ =\    ::testing::internal::MakeAndRegisterTestInfo(\        #test_case_name, #test_name, "", "", \        (parent_id), \        parent_class::SetUpTestCase, \        parent_class::TearDownTestCase, \        new ::testing::internal::TestFactoryImpl<\            GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -