boost unit test失败并显示错误 - 未知位置(0):“MyCheckTest”中的致命错误:

时间:2014-04-24 07:40:02

标签: c++ serialization boost boost-serialization

我尝试使用提升运行单元测试,但是当我运行测试时它会给我错误 - > 的"未知位置(0):" MyCheckTest"中的致命错误:"

错误甚至没有提到测试失败的行。我无法弄明白并因此共享代码:

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

}

在maintest.cpp文件中,我试图测试它并且它给出了如下所示的错误消息:

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

不知道为什么它会给MyCheckTest带来致命错误。如果丢失任何拼写错误或头文件,请告诉我。

至少它应该给出如下所述的错误simialr:

maintest.cpp(10):&#34; my_test&#34;中的错误:检查m1-&gt; id == m2-&gt; id失败。  在测试套件中检测到 1次失败&#34; MyCheckTest&#34;

0 个答案:

没有答案