Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
6.8 KiB

  1. // Copyright 2007, 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: [email protected] (Zhanyong Wan)
  31. // This file is the input to a negative-compilation test for Google
  32. // Test. Code here is NOT supposed to compile. Its purpose is to
  33. // verify that certain incorrect usages of the Google Test API are
  34. // indeed rejected by the compiler.
  35. //
  36. // We still need to write the negative-compilation test itself, which
  37. // will be tightly coupled with the build environment.
  38. //
  39. // TODO([email protected]): finish the negative-compilation test.
  40. #ifdef TEST_CANNOT_IGNORE_RUN_ALL_TESTS_RESULT
  41. // Tests that the result of RUN_ALL_TESTS() cannot be ignored.
  42. #include <gtest/gtest.h>
  43. int main(int argc, char** argv) {
  44. testing::InitGoogleTest(&argc, argv);
  45. RUN_ALL_TESTS(); // This line shouldn't compile.
  46. }
  47. #elif defined(TEST_USER_CANNOT_INCLUDE_GTEST_INTERNAL_INL_H)
  48. // Tests that a user cannot include gtest-internal-inl.h in his code.
  49. #include "src/gtest-internal-inl.h"
  50. #elif defined(TEST_CATCHES_DECLARING_SETUP_IN_TEST_FIXTURE_WITH_TYPO)
  51. // Tests that the compiler catches the typo when a user declares a
  52. // Setup() method in a test fixture.
  53. #include <gtest/gtest.h>
  54. class MyTest : public testing::Test {
  55. protected:
  56. void Setup() {}
  57. };
  58. #elif defined(TEST_CATCHES_CALLING_SETUP_IN_TEST_WITH_TYPO)
  59. // Tests that the compiler catches the typo when a user calls Setup()
  60. // from a test fixture.
  61. #include <gtest/gtest.h>
  62. class MyTest : public testing::Test {
  63. protected:
  64. virtual void SetUp() {
  65. testing::Test::Setup(); // Tries to call SetUp() in the parent class.
  66. }
  67. };
  68. #elif defined(TEST_CATCHES_DECLARING_SETUP_IN_ENVIRONMENT_WITH_TYPO)
  69. // Tests that the compiler catches the typo when a user declares a
  70. // Setup() method in a subclass of Environment.
  71. #include <gtest/gtest.h>
  72. class MyEnvironment : public testing::Environment {
  73. public:
  74. void Setup() {}
  75. };
  76. #elif defined(TEST_CATCHES_CALLING_SETUP_IN_ENVIRONMENT_WITH_TYPO)
  77. // Tests that the compiler catches the typo when a user calls Setup()
  78. // in an Environment.
  79. #include <gtest/gtest.h>
  80. class MyEnvironment : public testing::Environment {
  81. protected:
  82. virtual void SetUp() {
  83. // Tries to call SetUp() in the parent class.
  84. testing::Environment::Setup();
  85. }
  86. };
  87. #elif defined(TEST_CATCHES_WRONG_CASE_IN_TYPED_TEST_P)
  88. // Tests that the compiler catches using the wrong test case name in
  89. // TYPED_TEST_P.
  90. #include <gtest/gtest.h>
  91. template <typename T>
  92. class FooTest : public testing::Test {
  93. };
  94. template <typename T>
  95. class BarTest : public testing::Test {
  96. };
  97. TYPED_TEST_CASE_P(FooTest);
  98. TYPED_TEST_P(BarTest, A) {} // Wrong test case name.
  99. REGISTER_TYPED_TEST_CASE_P(FooTest, A);
  100. INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>);
  101. #elif defined(TEST_CATCHES_WRONG_CASE_IN_REGISTER_TYPED_TEST_CASE_P)
  102. // Tests that the compiler catches using the wrong test case name in
  103. // REGISTER_TYPED_TEST_CASE_P.
  104. #include <gtest/gtest.h>
  105. template <typename T>
  106. class FooTest : public testing::Test {
  107. };
  108. template <typename T>
  109. class BarTest : public testing::Test {
  110. };
  111. TYPED_TEST_CASE_P(FooTest);
  112. TYPED_TEST_P(FooTest, A) {}
  113. REGISTER_TYPED_TEST_CASE_P(BarTest, A); // Wrong test case name.
  114. INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>);
  115. #elif defined(TEST_CATCHES_WRONG_CASE_IN_INSTANTIATE_TYPED_TEST_CASE_P)
  116. // Tests that the compiler catches using the wrong test case name in
  117. // INSTANTIATE_TYPED_TEST_CASE_P.
  118. #include <gtest/gtest.h>
  119. template <typename T>
  120. class FooTest : public testing::Test {
  121. };
  122. template <typename T>
  123. class BarTest : public testing::Test {
  124. };
  125. TYPED_TEST_CASE_P(FooTest);
  126. TYPED_TEST_P(FooTest, A) {}
  127. REGISTER_TYPED_TEST_CASE_P(FooTest, A);
  128. // Wrong test case name.
  129. INSTANTIATE_TYPED_TEST_CASE_P(My, BarTest, testing::Types<int>);
  130. #elif defined(TEST_CATCHES_INSTANTIATE_TYPED_TESET_CASE_P_WITH_SAME_NAME_PREFIX)
  131. // Tests that the compiler catches instantiating TYPED_TEST_CASE_P
  132. // twice with the same name prefix.
  133. #include <gtest/gtest.h>
  134. template <typename T>
  135. class FooTest : public testing::Test {
  136. };
  137. TYPED_TEST_CASE_P(FooTest);
  138. TYPED_TEST_P(FooTest, A) {}
  139. REGISTER_TYPED_TEST_CASE_P(FooTest, A);
  140. INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<int>);
  141. // Wrong name prefix: "My" has been used.
  142. INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, testing::Types<double>);
  143. #elif defined(TEST_STATIC_ASSERT_TYPE_EQ_IS_NOT_A_TYPE)
  144. #include <gtest/gtest.h>
  145. // Tests that StaticAssertTypeEq<T1, T2> cannot be used as a type.
  146. testing::StaticAssertTypeEq<int, int> dummy;
  147. #elif defined(TEST_STATIC_ASSERT_TYPE_EQ_WORKS_IN_NAMESPACE)
  148. #include <gtest/gtest.h>
  149. // Tests that StaticAssertTypeEq<T1, T2> works in a namespace scope.
  150. static bool dummy = testing::StaticAssertTypeEq<int, const int>();
  151. #elif defined(TEST_STATIC_ASSERT_TYPE_EQ_WORKS_IN_CLASS)
  152. #include <gtest/gtest.h>
  153. template <typename T>
  154. class Helper {
  155. public:
  156. // Tests that StaticAssertTypeEq<T1, T2> works in a class.
  157. Helper() { testing::StaticAssertTypeEq<int, T>(); }
  158. void DoSomething() {}
  159. };
  160. void Test() {
  161. Helper<bool> h;
  162. h.DoSomething(); // To avoid the "unused variable" warning.
  163. }
  164. #elif defined(TEST_STATIC_ASSERT_TYPE_EQ_WORKS_IN_FUNCTION)
  165. #include <gtest/gtest.h>
  166. void Test() {
  167. // Tests that StaticAssertTypeEq<T1, T2> works inside a function.
  168. testing::StaticAssertTypeEq<const int, int>();
  169. }
  170. #else
  171. // A sanity test. This should compile.
  172. #include <gtest/gtest.h>
  173. int main() {
  174. return RUN_ALL_TESTS();
  175. }
  176. #endif