gtest_list_tests_unittest_.cc 4.6 KB

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