googletest-list-tests-unittest_.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Unit test for Google Test's --gtest_list_tests flag.
  30. //
  31. // A user can ask Google Test to list all tests that will run
  32. // so that when using a filter, a user will know what
  33. // tests to look for. The tests will not be run after listing.
  34. //
  35. // This program will be invoked from a Python unit test.
  36. // Don't run it directly.
  37. #include <ostream>
  38. #include <string>
  39. #include "gtest/gtest.h"
  40. // Several different test cases and tests that will be listed.
  41. TEST(Foo, Bar1) {}
  42. TEST(Foo, Bar2) {}
  43. TEST(Foo, DISABLED_Bar3) {}
  44. TEST(Abc, Xyz) {}
  45. TEST(Abc, Def) {}
  46. TEST(FooBar, Baz) {}
  47. class FooTest : public testing::Test {};
  48. TEST_F(FooTest, Test1) {}
  49. TEST_F(FooTest, DISABLED_Test2) {}
  50. TEST_F(FooTest, Test3) {}
  51. TEST(FooDeathTest, Test1) {}
  52. // A group of value-parameterized tests.
  53. class MyType {
  54. public:
  55. explicit MyType(const std::string& a_value) : value_(a_value) {}
  56. const std::string& value() const { return value_; }
  57. private:
  58. std::string value_;
  59. };
  60. // Teaches Google Test how to print a MyType.
  61. void PrintTo(const MyType& x, std::ostream* os) { *os << x.value(); }
  62. class ValueParamTest : public testing::TestWithParam<MyType> {};
  63. TEST_P(ValueParamTest, TestA) {}
  64. TEST_P(ValueParamTest, TestB) {}
  65. INSTANTIATE_TEST_SUITE_P(
  66. MyInstantiation, ValueParamTest,
  67. testing::Values(
  68. MyType("one line"), MyType("two\nlines"),
  69. MyType("a "
  70. "very\nloooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
  71. "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
  72. "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
  73. "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
  74. "ooooong line"))); // NOLINT
  75. // A group of typed tests.
  76. // A deliberately long type name for testing the line-truncating
  77. // behavior when printing a type parameter.
  78. class
  79. VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName { // NOLINT
  80. };
  81. template <typename T>
  82. class TypedTest : public testing::Test {};
  83. template <typename T, int kSize>
  84. class MyArray {};
  85. typedef testing::Types<
  86. VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT
  87. int*, MyArray<bool, 42> >
  88. MyTypes;
  89. TYPED_TEST_SUITE(TypedTest, MyTypes);
  90. TYPED_TEST(TypedTest, TestA) {}
  91. TYPED_TEST(TypedTest, TestB) {}
  92. // A group of type-parameterized tests.
  93. template <typename T>
  94. class TypeParamTest : public testing::Test {};
  95. TYPED_TEST_SUITE_P(TypeParamTest);
  96. TYPED_TEST_P(TypeParamTest, TestA) {}
  97. TYPED_TEST_P(TypeParamTest, TestB) {}
  98. REGISTER_TYPED_TEST_SUITE_P(TypeParamTest, TestA, TestB);
  99. INSTANTIATE_TYPED_TEST_SUITE_P(My, TypeParamTest, MyTypes);
  100. int main(int argc, char** argv) {
  101. ::testing::InitGoogleTest(&argc, argv);
  102. return RUN_ALL_TESTS();
  103. }