googletest-list-tests-unittest_.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "gtest/gtest.h"
  38. // Several different test cases and tests that will be listed.
  39. TEST(Foo, Bar1) {
  40. }
  41. TEST(Foo, Bar2) {
  42. }
  43. TEST(Foo, DISABLED_Bar3) {
  44. }
  45. TEST(Abc, Xyz) {
  46. }
  47. TEST(Abc, Def) {
  48. }
  49. TEST(FooBar, Baz) {
  50. }
  51. class FooTest : public testing::Test {
  52. };
  53. TEST_F(FooTest, Test1) {
  54. }
  55. TEST_F(FooTest, DISABLED_Test2) {
  56. }
  57. TEST_F(FooTest, Test3) {
  58. }
  59. TEST(FooDeathTest, Test1) {
  60. }
  61. // A group of value-parameterized tests.
  62. class MyType {
  63. public:
  64. explicit MyType(const std::string& a_value) : value_(a_value) {}
  65. const std::string& value() const { return value_; }
  66. private:
  67. std::string value_;
  68. };
  69. // Teaches Google Test how to print a MyType.
  70. void PrintTo(const MyType& x, std::ostream* os) {
  71. *os << x.value();
  72. }
  73. class ValueParamTest : public testing::TestWithParam<MyType> {
  74. };
  75. TEST_P(ValueParamTest, TestA) {
  76. }
  77. TEST_P(ValueParamTest, TestB) {
  78. }
  79. INSTANTIATE_TEST_CASE_P(
  80. MyInstantiation, ValueParamTest,
  81. testing::Values(MyType("one line"),
  82. MyType("two\nlines"),
  83. MyType("a very\nloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line"))); // NOLINT
  84. // A group of typed tests.
  85. // A deliberately long type name for testing the line-truncating
  86. // behavior when printing a type parameter.
  87. class VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName { // NOLINT
  88. };
  89. template <typename T>
  90. class TypedTest : public testing::Test {
  91. };
  92. template <typename T, int kSize>
  93. class MyArray {
  94. };
  95. typedef testing::Types<VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName, // NOLINT
  96. int*, MyArray<bool, 42> > MyTypes;
  97. TYPED_TEST_CASE(TypedTest, MyTypes);
  98. TYPED_TEST(TypedTest, TestA) {
  99. }
  100. TYPED_TEST(TypedTest, TestB) {
  101. }
  102. // A group of type-parameterized tests.
  103. template <typename T>
  104. class TypeParamTest : public testing::Test {
  105. };
  106. TYPED_TEST_CASE_P(TypeParamTest);
  107. TYPED_TEST_P(TypeParamTest, TestA) {
  108. }
  109. TYPED_TEST_P(TypeParamTest, TestB) {
  110. }
  111. REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB);
  112. INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes);
  113. int main(int argc, char **argv) {
  114. ::testing::InitGoogleTest(&argc, argv);
  115. return RUN_ALL_TESTS();
  116. }