Skip to content
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

Met different access of __xfer_bufptrs while setting GoogleTest under CppUTest #1652

Open
gary1994613 opened this issue Oct 27, 2022 · 4 comments

Comments

@gary1994613
Copy link

gary1994613 commented Oct 27, 2022

I tried to set up GoogleTest under CppUTest framework in order to support parameterized tests (https://groups.google.com/g/cpputest/c/FuPTZm5_nqg). So I followed the description from the manual (https://cpputest.github.io/manual.html#gtest), but it failed to compile even for only the easiest TEST_GROUP HelloWorld in the example directory in CppUTest. I got stuck in the error:

compiling AllTests.cpp
In file included from /usr/local/include/gtest/internal/gtest-port.h:271:0,
from /usr/local/include/gtest/internal/gtest-internal.h:40,
from /usr/local/include/gtest/gtest.h:62,
from ../include/CppUTestExt/GTest.h:37,
from ../include/CppUTestExt/GTestConvertor.h:95,
from AllTests/AllTests.cpp:34:
/usr/include/c++/7/sstream:300:7: error: ‘struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::__xfer_bufptrs’ redeclared with different access
struct __xfer_bufptrs
^~~~~~
compilation terminated due to -Wfatal-errors.

After a little bit of explorations about the problem, I guessed that this problem seemed to be caused by the #define access hack in the include/CppUTestExt/GTestConvertor.h: 92
#define private public
#define protected public
which makes the __xfer_bufptrs public, but it is defined as private in class basic_stringbuf. The action of #define access hack maybe cause the problem in GoogleTest because that GoogleTest used sstream (Not sure, just as my guess...).
I have tried some suggestions from others discussions, ex: changing the #include order in examples/AllTests/AllTests.cpp, but it doesn't work (which make sense in my opinion). something like:

#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/TestPlugin.h"
#include "CppUTest/TestRegistry.h"
#include "CppUTestExt/IEEE754ExceptionsPlugin.h"
#include "CppUTestExt/MockSupportPlugin.h"
#include "CppUTestExt/GTestConvertor.h" // <-- changing this one up or down

I also tried to use some more ugly hacks like
#undef private
#define private private
somewhere in GTestConvertor.h, but I still failed.

I would like to know what should I do to handle this problem?

Some refs:

Not sure if these helps:

@basvodde
Copy link
Member

Thanks. I do not know if CppUTest works with the latest version of gtest, so that might be the problem. Which GTest version did you use here ?

@gary1994613
Copy link
Author

I followed the instructions from here: https://github.com/google/googletest/tree/main/googletest

git clone https://github.com/google/googletest.git -b release-1.12.1
cd googletest # Main directory of the cloned repository.
mkdir build # Create a directory to hold the build output.
cd build
cmake .. # Generate native build scripts for GoogleTest.

@basvodde
Copy link
Member

basvodde commented Nov 8, 2022

Yes, at the moment, we've only tested CppUTest with max gtest 1.8. @thetic was checking if he can also get other version to work (and add it to the CppUTest automated build) but I suspect it might still need some work.

@thetic
Copy link
Contributor

thetic commented Nov 12, 2022

I was able to work around this by building with gtest 1.8 and C++ 98. I'm starting to doubt that this can be made to work reliably across gtest and C++ versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants