[英]boost test case from dll access violation
I want to start Boost test case from dll under Windows RT. 我想从Windows RT下的dll启动Boost测试用例。 I built test case as dll via the Visual Studio command prompt using the following comandline: 我使用以下命令通过Visual Studio命令提示符将测试用例构建为dll:
cl.exe /EHsc /D_USRDLL /D_WINDLL /LDd ~location\\testcase.cpp ~library location\\libboost_unit_test_framework-vc110-mt-sgd-1_53.lib /link /DLL /OUT:~output directory\\testcase.dll cl.exe / EHsc / D_USRDLL / D_WINDLL / LDd〜location \\ testcase.cpp〜库位置\\ libboost_unit_test_framework-vc110-mt-sgd-1_53.lib / link / DLL / OUT:〜输出目录\\ testcase.dll
placed it into my application's folder and set property "Content" to "true". 将其放入我的应用程序的文件夹中,并将属性“ Content”设置为“ true”。 After launching of my application I have the following error: 启动我的应用程序后,出现以下错误:
Unhadled exception at the 0x00B9AF16 in TestApp.exe: 0xC0000005: Access violation reading location 0x00000000 TestApp.exe中0x00B9AF16处未隐藏的异常:0xC0000005:访问冲突读取位置0x00000000
Top of the call stack is below: 调用堆栈的顶部如下:
> TestApp.exe!boost::unit_test::framework::get(unsigned long id, boost::unit_test::test_unit_type t) Line 388 C++ TestApp.exe!boost::unit_test::framework::get(unsigned long id) Line 73 C++ TestApp.exe!boost::unit_test::traverse_test_tree(unsigned long id, boost::unit_test::test_tree_visitor & V) Line 232 C++ TestApp.exe!boost::unit_test::traverse_test_tree(const boost::unit_test::test_suite & suite, boost::unit_test::test_tree_visitor & V) Line 207 C++ TestApp.exe!boost::unit_test::traverse_test_tree(unsigned long id, boost::unit_test::test_tree_visitor & V) Line 234 C++ TestApp.exe!boost::unit_test::framework::run(unsigned long id, bool continue_test) Line 403 C++ TestApp.exe!boost::unit_test::unit_test_main(boost::unit_test::test_suite * (int, char * *) * init_func, int argc, char * * argv) Line 185 C++
Here is the dll code (NOTE: If I place the same code directly into my source, it works fine): 这是dll代码(注意:如果我将相同的代码直接放入源代码,则可以正常工作):
void test_stat()
{
//some code there
}
extern "C" {
__declspec (dllexport) test_suite* init_unit_test_suite( int argc, char* argv[] )
{
test_suite *test = BOOST_TEST_SUITE("test name");
test->add(BOOST_TEST_CASE(&test_stat));
return test;
}
}
Code of the application for launching of the test case: 用于启动测试用例的应用程序代码:
boost::unit_test::test_suite* main_global_test_suite;
test_suite* init_unit_test_suite( int argc, char* argv[] ) {
return NULL; }
test_suite* run_global_test_suite (int, char* []) {
return main_global_test_suite;
}
HINSTANCE hMyDll;
typedef test_suite* (*PFN_MyFunction)(int,const char*);
PFN_MyFunction pfnMyFunction;
test_suite* rPtr;
if((hMyDll=::LoadPackagedLibrary(L"testcase", 0))==NULL)
{
return;
}
pfnMyFunction=(PFN_MyFunction)GetProcAddress(hMyDll,"init_unit_test_suite");
if (pfnMyFunction != NULL)
{
//just create fake arguments for the boost::unit_test::unit_test_main function call
char* argv[1024];
argv[0] = "Text";
rPtr = pfnMyFunction(1, NULL);
main_global_test_suite = rPtr;
const int error =
boost::unit_test::unit_test_main(&run_global_test_suite, 1, argv );
}
else
{
//handling code
}
FreeLibrary(hMyDll);
Is there any ideas how to solve the problem? 有什么想法可以解决问题吗?
Check what console_test_runner is doing. 检查console_test_runner在做什么。 This is command line application (part of Boost.Test), which intended to do just that - load and execute test units implemented in shared library. 这是命令行应用程序(Boost.Test的一部分),旨在完成该任务-加载和执行在共享库中实现的测试单元。 Also please make sure you tell UTF that you want to build dll: define BOOST_TEST_DYN_LINK. 另外,请确保您告诉UTF您要构建dll:定义BOOST_TEST_DYN_LINK。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.