2015-03-31 100 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是爲了發佈而編譯的。 (從編譯器獲得提示或建議將會很好...)