I'm converting Google tests to Visual Studio Native unit tests. I'm running into an issue where the Visual Studio unit test isn't seeing variables of it's friend class. Any idea how to fix this?
In my VSUT-Br.cpp class (ported from Google unit test):
#include "DocFriendClass.h
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace VSUTBr
{
TEST_CLASS(BrTest)
{
public:
protected:
virtual ~BrTest();
virtual void SetUp();
virtual void TearDown();
std::unique_ptr<DocFriendClass> TestDoc;
...
TEST_METHOD_INITIALIZE(File_Initialize)
{
pP = CreateP();
TestDoc = std::make_unique<DocFriendClass>(OurString("Test"));
TestDoc->m_Parser.setParser(pP); //it can't see m_Parser either
...
OurString sColor(kszColor);//it's not seeing kszColor in friend
}
};
}
In my DocFriendClass.h:
...
private:
Parser m_Parser;
...
#ifdef UNIT_TEST
friend class BrTest;
#endif
Then I went to my VSUT-Br project and right clicked and selected properties, and edited the C/C++ Preprocessor settings; Preprocessor Definitions now include UNIT_TEST=1. I clean built and it still couldn't find the friend variable. I exited VS and went back in, and clean built and it's not finding the friend variable. It worked having that as a friend with the old Google test. Any ideas?
I looked at unit test friend but it's not the same problem. I found elsewhere and they were saying I can't have a friend to my VS Unit Test, but I have a feeling that's internet garbage (can't find link now).
Update: I added some info on a variable, m_Parser in DocFriendClass that it's not seeing. Error info:
C2248 'DocFriendClass::m_Parser': cannot access private member declared in class 'DocFriendClass'. File VSUT-Br.
It should be able to access this. The Google test could as a friend.