0

I've been struggling with this and so far couldn't make it work. A simple main using botan works fine, but when i put the same code in a unittest it fails.

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

I then tried putting the init in the main entry point like this:

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

They both show the same error:

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.

Just for the record, a simple test for compression that i tried or whatever i did works fine, but when i try to create a test with botan initialization it fails no matter what i try.


Edit: I've tried with Qt Test and the same happens. Its is really weird. Has anyone experienced something like this? Could anyone reproduce this?

Sebastian
  • 1,243
  • 1
  • 18
  • 34

1 Answers1

0

Found the annoying problem. Code Generation was set to Multi-threaded DEBUG DLL. For some reason changing to Multi-threaded DLL makes it work. I guess maybe because botan was compiled for release. (it would be nice to have a hint or suggestion from the compiler...)

Sebastian
  • 1,243
  • 1
  • 18
  • 34