I'm trying to run the unit test using boost but it gives me error when I run test -> " unknown location(0): fatal error in "MyCheckTest":"
Error even does not mention the line which test is failing.. I'm not able to figure it out and hence sharing the code:
// Function.hpp
#pragma once
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/access.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/export.hpp>
struct Function
{
std::string id, name;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int /*version*/)
{
ar & id;
ar & name;
}
public:
Function(void);
typedef int parameter_strings;
Function(const parameter_strings & parms) { }
virtual ~Function(void);
};
BOOST_CLASS_EXPORT_KEY(Function);
// Function.cpp
#include "functions.hpp"
Function::~Function()
{
std::cout<< " destructor called \n";
}
Function::Function()
{
std::cout<<" constructor called \n";
}
BOOST_CLASS_EXPORT_IMPLEMENT(Function);
BOOST_CLASS_IMPLEMENTATION(Function, boost::serialization::object_serializable);
BOOST_CLASS_TRACKING(Function, boost::serialization::track_never);
// maintest.cpp
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include "functions.hpp"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
void set_data(Function *c1)
{
c1->id= "sheena";
c1->name="kurian";
}
void check_data(Function *m1,Function *m2)
{
BOOST_CHECK(m1->id==m2->id);
BOOST_CHECK(m1->name==m2->name);
BOOST_CHECK(m1->id.size() == m2->id.size());
BOOST_CHECK(m1->name.size() == m2->name.size());
}
BOOST_AUTO_TEST_CASE(MyCheckTest)
{
boost::archive::text_oarchive ao(std::cout);
Function c;
set_data(&c);
const Function & oc=c;
ao & oc; // serialize
std::stringstream ss;
boost::archive::text_iarchive ia(ss);
Function d;
ia >> d; // deserialize
check_data(&c,&d); // comparing data
}
In the maintest.cpp file, i'm trying to test it and it gives me error message as shown below:
Running 1 test case...
1> 22 serialization::archive 10 constructor called
1> 7 sheena 7 kurian destructor called
1>
1> unknown location(0): fatal error in "MyCheckTest": std::exception: invalid signature
1>
1> Test suite "Master Test Suite" failed with:
1> 1 assertion out of 1 failed
1> 1 test case out of 1 failed
1> 1 test case out of 1 aborted
Don't know why it is giving fatal error for MyCheckTest. If any typo mistake or header file missing please let me know.
atleast it should give error simialr to as stated below :
maintest.cpp(10): error in "my_test": check m1->id == m2->id failed. 1 failure detected in test suite "MyCheckTest"