summaryrefslogtreecommitdiffstats
path: root/base/gtest_prod_util.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/gtest_prod_util.h')
-rw-r--r--base/gtest_prod_util.h46
1 files changed, 45 insertions, 1 deletions
diff --git a/base/gtest_prod_util.h b/base/gtest_prod_util.h
index a54235a..2db5853 100644
--- a/base/gtest_prod_util.h
+++ b/base/gtest_prod_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -25,4 +25,48 @@
FRIEND_TEST(test_case_name, FLAKY_##test_name); \
FRIEND_TEST(test_case_name, FAILS_##test_name)
+// C++ compilers will refuse to compile the following code:
+//
+// namespace foo {
+// class MyClass {
+// private:
+// FRIEND_TEST_ALL_PREFIXES(MyClassTest, TestMethod);
+// bool private_var;
+// };
+// } // namespace foo
+//
+// class MyClassTest::TestMethod() {
+// foo::MyClass foo_class;
+// foo_class.private_var = true;
+// }
+//
+// Unless you forward declare MyClassTest::TestMethod outside of namespace foo.
+// Use FORWARD_DECLARE_TEST_ALL_PREFIXES to do so for all possible prefixes.
+//
+// Example usage:
+//
+// FORWARD_DECLARE_TEST_ALL_PREFIXES(MyClassTest, TestMethod);
+//
+// namespace foo {
+// class MyClass {
+// private:
+// FRIEND_TEST_ALL_PREFIXES(::MyClassTest, TestMethod); // NOTE use of ::
+// bool private_var;
+// };
+// } // namespace foo
+//
+// class MyClassTest::TestMethod() {
+// foo::MyClass foo_class;
+// foo_class.private_var = true;
+// }
+
+#define FORWARD_DECLARE_TEST(test_case_name, test_name) \
+class test_case_name##_##test_name##_Test\
+
+#define FORWARD_DECLARE_TEST_ALL_PREFIXES(test_case_name, test_name) \
+ FORWARD_DECLARE_TEST(test_case_name, test_name); \
+ FORWARD_DECLARE_TEST(test_case_name, DISABLED_##test_name); \
+ FORWARD_DECLARE_TEST(test_case_name, FLAKY_##test_name); \
+ FORWARD_DECLARE_TEST(test_case_name, FAILS_##test_name)
+
#endif // BASE_GTEST_PROD_UTIL_H_