Skip to content

Commit 1416d01

Browse files
Ulmo-Fkris-jusiak
authored andcommitted
Update GTest-friend.md
1 parent 7390e02 commit 1416d01

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

docs/GTest-friend.md

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@ If you want to make make your classes friend with their test, here are some ways
44

55
* <font size="1">Add `#define private public` & `#define protected public` before including production headers to your test sources. But I never said this.</font>
66

7-
* You can declare your test with an existing class instead of a string :
7+
* Note that you can declare your test with an existing class instead of a string :
88
`GTEST(SomeClass) { ... }`
9-
With this syntax, the test will inherit from `SomeClass`, so you can access to protected members.
10-
11-
This is the least intrusive way, as there is nothing added to the tested class - apart from maybe replace private by protected.
129

1310
* You can declare your class `friend` with the test class `GTEST(SomeClass)` :
14-
```// Forward declare some GUnit classes
11+
```#include <GUnit/Detail/StringUtils.h>
12+
// Forward declare some GUnit classes
1513
template <typename ...> struct GTEST;
16-
namespace testing::detail { template <char ...> struct string; }
1714
1815
class SomeClass {
19-
friend struct GTEST<SomeClass, testing::detail::string<> >;
16+
friend struct GTEST<SomeTest, testing::detail::string<> >;
2017
};
2118
22-
GTEST(Game) { ... }
19+
GTEST(SomeTest) { ... }
2320
```
2421
* You can also declare friend with the test class `GTEST("SomeTest")`, it is more cumbersome :
25-
```// Forward declare some GUnit classes
22+
```#include <GUnit/Detail/StringUtils.h>
23+
// Forward declare some GUnit classes
2624
template <typename ...> struct GTEST;
27-
namespace testing::detail { template <char ...> struct string; }
2825
2926
class SomeClass {
3027
friend struct GTEST<testing::detail::string<'\"', 'S', 'o', 'm', 'e', 'T', ,'e', 's', 't', '\"', '\000'>, testing::detail::string<> >;
@@ -33,17 +30,9 @@ With this syntax, the test will inherit from `SomeClass`, so you can access to p
3330
GTEST("SomeTest") { ... }
3431
```
3532
36-
* You can even declare friendness with `GTEST("SomeTest")` by importing some GUnit magic - but we're polluting our production code:
37-
```
38-
#ifndef __GUNIT_CAT
39-
#define __GUNIT_PRIMITIVE_CAT(arg, ...) arg##__VA_ARGS__
40-
#define __GUNIT_CAT(arg, ...) __GUNIT_PRIMITIVE_CAT(arg, __VA_ARGS__)
41-
#endif
42-
namespace {
43-
template <char ...> struct string {};
44-
template <class TStr, std::size_t N, char... Chrs> struct make_string : make_string<TStr, N - 1, TStr().chrs[N - 1], Chrs...> {};
45-
template <class TStr, char... Chrs> struct make_string<TStr, 0, Chrs...> { using type = string<Chrs...>; };
46-
}
33+
* You can even declare friendness with `GTEST("SomeTest")` by importing some GUnit magic
34+
```#include <GUnit/Detail/Preprocessor.h>
35+
#include <GUnit/Detail/StringUtils.h>
4736
4837
#define FRIEND_GTEST(name) \
4938
struct __GUNIT_CAT(GTEST_STRING_, __LINE__) { static constexpr const char* chrs = #name; }; \

0 commit comments

Comments
 (0)