使用Botan进行Boost测试和QtTest内存访问冲突

时间:2015-03-31 03:01:25

标签: boost-test botan qttest

我一直在努力解决这个问题,到目前为止还没有成功。使用botan的简单主要工作正常,但是当我将相同的代码放在单元测试中时,它就失败了。

// 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

然后我尝试将init放在主入口点,如下所示:

//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);
}

它们都显示相同的错误:

  

运行1个测试用例...未知位置(0):致命错误   “rsa_key_generation”:地址发生内存访问冲突   0x00141000,同时尝试读取无法访问的数据

     

***在测试套件中检测到失败“加密测试”检测到内存泄漏!转储对象 - &gt; {670}正常阻挡   0x0000000000221380,长度为16个字节。数据:78 EA 13   00 00 00 00 00 00 00 00 00 00 00 00 00对象转储完成。

仅仅是为了记录,我尝试的压缩的简单测试或我做的任何工作都很好,但是当我尝试使用botan初始化创建测试时,无论我尝试什么,它都会失败。 < / p>


编辑:我尝试过Qt测试,同样的事情发生了。它真的很奇怪。有没有人经历过这样的事情?有人可以重现这个吗?

1 个答案:

答案 0 :(得分:0)

发现了烦人的问题。代码生成设置为多线程DEBUG DLL。由于某种原因,更改为多线程DLL使其工作。我想也许是因为botan是为了发布而编译的。 (从编译器那里获得提示或建议会很好...)