简体   繁体   中英

boost test case from dll access violation

I want to start Boost test case from dll under Windows RT. I built test case as dll via the Visual Studio command prompt using the following comandline:

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

placed it into my application's folder and set property "Content" to "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

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):



    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. This is command line application (part of Boost.Test), which intended to do just that - load and execute test units implemented in shared library. Also please make sure you tell UTF that you want to build dll: define BOOST_TEST_DYN_LINK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM