I've set up a project in Visual Studio 2010 to write unit tests against an existing MFC DLL. I'm using a single-header unit test framework, and linked to the MFC DLL's lib wrapper from the unit test project. I'm trying to construct a class that takes a std::wstring
in it's constructor. Here's what my test looks like:
TEST_CASE("MyProject/MyTest", "Do the test.")
{
MockDbService mockDbService;
Foobar foo(L"{F00DFACE-FEED-DEAD-BEEF-C0FFEEDECADE}", mockDbService);
foo.loadObject();
REQUIRE(mockDbService.getMethodInvokeCount("query()") >= 1);
}
Where Foobar
is the class exported from the MFC DLL under test. However, the test framework reports an unexpected exception. I tracked it down to std::wstring
's copy constructor when copying the string to Foobar
's constructor. The MSVC debugger reports the source string as <Bad Ptr>
.
I created a dummy constructor, Foobar::Foobar(long num, IDbService& db)
and all the values (including the IDbService&
) come across just fine.
Both the MFC DLL and my unit test EXE are sharing a property sheet which should keep the compiler flags equivalent. I'm building and running the test in debug mode. Any ideas why the std::wstring
can't copy across the DLL?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…