-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Namespaces not working #5
Comments
Hi @et-nik, Unfortunately namespace foo {
int bar(std::string a) {
return 2;
}
}
namespace {
using namespace foo;
MOCK_GLOBAL_FUNC1(bar, int(std::string));
TEST(config_parse_test, Success) {
EXPECT_GLOBAL_CALL(bar, bar("baz")).WillOnce(Return(1));
int a = bar("baz");
ASSERT_EQ(a, 1);
}
} Another option is to provide a different macro that accepts namespace, for example: MOCK_GLOBAL_FUNC1_NS(foo, bar, int(std::string)); PR is welcomed! |
Hi Sergey, In the above test case, if we have foo namespace in a library and when we want to mock foo bar global function , mocking does not work. Lets consider a case here. foo namespace is used in static library "lib1". There is a method ( method 1) in this lib1 that calls foo bar function. Now to mock foo bar in method 1, i have done following.
Test code looks like this. namespace //using namespace foo; // removed // foo is in one of the cpp files of lib1, so not adding
} after doing this, i am getting original bar call not the mocked one |
Hi @Chandra123539 ,
You can set linker options to exploit a multiple definition issue and use the definition provided by mocks instead of the real one. Or it can be conditional compilation. Or linker scripts. Or function pointers. Whatever works best for you. I hope you've got the idea. |
How can I use calls with namespace? In my code I use different functions with namespaces (
filesystem::exists
etc.). But gmock-global not working correctly with namespaces.I will show what I want with an examples.
I want to mock function:
Works
Other mock I need. Not works
Error:
Other variant mock I also need. Not works
The text was updated successfully, but these errors were encountered: