dpapad@chromium.org | 3062e6b | 2012-02-11 03:38:30 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
phajdan.jr@chromium.org | dd43b73 | 2010-06-01 23:30:51 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_GTEST_PROD_UTIL_H_ |
| 6 | #define BASE_GTEST_PROD_UTIL_H_ |
phajdan.jr@chromium.org | dd43b73 | 2010-06-01 23:30:51 +0900 | [diff] [blame] | 7 | |
pwnall | 4bc4713 | 2017-05-05 09:44:27 +0900 | [diff] [blame] | 8 | #include "testing/gtest/include/gtest/gtest_prod.h" // nogncheck |
phajdan.jr@chromium.org | dd43b73 | 2010-06-01 23:30:51 +0900 | [diff] [blame] | 9 | |
| 10 | // This is a wrapper for gtest's FRIEND_TEST macro that friends |
| 11 | // test with all possible prefixes. This is very helpful when changing the test |
| 12 | // prefix, because the friend declarations don't need to be updated. |
| 13 | // |
| 14 | // Example usage: |
| 15 | // |
| 16 | // class MyClass { |
| 17 | // private: |
| 18 | // void MyMethod(); |
| 19 | // FRIEND_TEST_ALL_PREFIXES(MyClassTest, MyMethod); |
| 20 | // }; |
| 21 | #define FRIEND_TEST_ALL_PREFIXES(test_case_name, test_name) \ |
| 22 | FRIEND_TEST(test_case_name, test_name); \ |
| 23 | FRIEND_TEST(test_case_name, DISABLED_##test_name); \ |
phajdan.jr@chromium.org | 1231059 | 2012-11-02 02:32:30 +0900 | [diff] [blame] | 24 | FRIEND_TEST(test_case_name, FLAKY_##test_name) |
phajdan.jr@chromium.org | dd43b73 | 2010-06-01 23:30:51 +0900 | [diff] [blame] | 25 | |
dpapad@chromium.org | 3062e6b | 2012-02-11 03:38:30 +0900 | [diff] [blame] | 26 | // C++ compilers will refuse to compile the following code: |
| 27 | // |
| 28 | // namespace foo { |
| 29 | // class MyClass { |
| 30 | // private: |
| 31 | // FRIEND_TEST_ALL_PREFIXES(MyClassTest, TestMethod); |
| 32 | // bool private_var; |
| 33 | // }; |
| 34 | // } // namespace foo |
| 35 | // |
| 36 | // class MyClassTest::TestMethod() { |
| 37 | // foo::MyClass foo_class; |
| 38 | // foo_class.private_var = true; |
| 39 | // } |
| 40 | // |
| 41 | // Unless you forward declare MyClassTest::TestMethod outside of namespace foo. |
dpapad@chromium.org | ac7a385 | 2012-02-14 10:19:07 +0900 | [diff] [blame] | 42 | // Use FORWARD_DECLARE_TEST to do so for all possible prefixes. |
dpapad@chromium.org | 3062e6b | 2012-02-11 03:38:30 +0900 | [diff] [blame] | 43 | // |
| 44 | // Example usage: |
| 45 | // |
dpapad@chromium.org | ac7a385 | 2012-02-14 10:19:07 +0900 | [diff] [blame] | 46 | // FORWARD_DECLARE_TEST(MyClassTest, TestMethod); |
dpapad@chromium.org | 3062e6b | 2012-02-11 03:38:30 +0900 | [diff] [blame] | 47 | // |
| 48 | // namespace foo { |
| 49 | // class MyClass { |
| 50 | // private: |
| 51 | // FRIEND_TEST_ALL_PREFIXES(::MyClassTest, TestMethod); // NOTE use of :: |
| 52 | // bool private_var; |
| 53 | // }; |
| 54 | // } // namespace foo |
| 55 | // |
| 56 | // class MyClassTest::TestMethod() { |
| 57 | // foo::MyClass foo_class; |
| 58 | // foo_class.private_var = true; |
| 59 | // } |
| 60 | |
| 61 | #define FORWARD_DECLARE_TEST(test_case_name, test_name) \ |
dpapad@chromium.org | ac7a385 | 2012-02-14 10:19:07 +0900 | [diff] [blame] | 62 | class test_case_name##_##test_name##_Test; \ |
| 63 | class test_case_name##_##DISABLED_##test_name##_Test; \ |
phajdan.jr@chromium.org | 1231059 | 2012-11-02 02:32:30 +0900 | [diff] [blame] | 64 | class test_case_name##_##FLAKY_##test_name##_Test |
dpapad@chromium.org | 3062e6b | 2012-02-11 03:38:30 +0900 | [diff] [blame] | 65 | |
phajdan.jr@chromium.org | dd43b73 | 2010-06-01 23:30:51 +0900 | [diff] [blame] | 66 | #endif // BASE_GTEST_PROD_UTIL_H_ |