2015-03-31 98 views
0

我一直在为此而苦苦挣扎,至今无法使它工作。一个简单的主要使用植物工作正常,但是当我把相同的代码在单元测试中失败。与Botan的升压测试和QtTest内存访问冲突

// keygeneration_test.cpp 

#define BOOST_TEST_DYN_LINK 
#include <boost/test/unit_test.hpp> // shuold use this one if using dynamic linking 
#include <botan\botan.h> 
#include <botan\rsa.h> 

BOOST_AUTO_TEST_SUITE(keygeneration_suite) 

BOOST_AUTO_TEST_CASE(rsa_key_generation) 
{ 
    BOOST_TEST_MESSAGE("generating key"); 
    try 
    { 
     Botan::LibraryInitializer init; 

     Botan::AutoSeeded_RNG rng; 
     rng.reseed(10096); 
     Botan::RSA_PrivateKey rsaPrivate(rng, 1024); 
    } 
    catch (std::exception& e) 
    { 
     BOOST_TEST_MESSAGE(e.what()); 
    } 
} 

BOOST_AUTO_TEST_SUITE_END() 

-

// main.cpp 

#define BOOST_TEST_DYN_LINK 
#define BOOST_TEST_MODULE cryptography test //module define should be only here, it takes care of creating entry point 

#include <boost/test/unit_test.hpp> // should use this one if using dynamic linking 

然后我试图把初始化主入口点是这样的:

//main.cpp 

#define BOOST_TEST_DYN_LINK // Make the exe link dynamically 
#define BOOST_TEST_NO_MAIN 

#include <boost/test/unit_test.hpp> // should use this one if using dynamic linking 

#include <botan\botan.h> 

bool init_function() 
{ 
    return true; 
} 

int main(int argc, char* argv[]) 
{ 
    Botan::LibraryInitializer init; 
    return boost::unit_test::unit_test_main(&init_function, argc, argv); 
} 

他们都表现出了同样的错误:

Running 1 test case... unknown location(0): fatal error in "rsa_key_generation": memory access violation occurred at address 0x00141000, while attempting to read inaccessible data

*** 1 failure detected in test suite "cryptography test" Detected memory leaks! Dumping objects -> {670} normal block at 0x0000000000221380, 16 bytes long. Data: 78 EA 13 00 00 00 00 00 00 00 00 00 00 00 00 00 Object dump complete.

只是为了记录,一个简单的压缩测试,我试过或任何我做的很好,但是当我尝试创建一个测试botan初始化失败,无论我尝试。


编辑:我试图使用Qt测试和同样的情况。它真的很奇怪。有没有人经历过这样的事情?任何人都可以重现吗?

回答

0

发现恼人的问题。代码生成被设置为多线程DEBUG DLL。出于某种原因改为多线程DLL使其工作。我想可能是因为botan是为了发布而编译的。 (从编译器获得提示或建议将会很好...)