2014-02-21 12 views
2

다음 파일을 컴파일하고 실행 한 후 실행 파일을 실행하는 동안 위의 오류가 발생합니다.부스트 테스트 설정 오류 : 메모리 액세스 위반

#define BOOST_TEST_MAIN 
#define BOOST_TEST_DYN_LINK 
#include <iostream> 
#include <boost/shared_ptr.hpp> 
#include <boost/test/unit_test.hpp> 
#include <boost/bind.hpp> 
#include <boost/test/unit_test_log.hpp> 
#include <boost/filesystem/fstream.hpp> 
#include "index/DatabaseGroup.hpp" 

using namespace boost::unit_test; 

namespace indexing { 

class ForwardDBTest { 

    /// A pointer to the database group object. 
    DatabaseGroup& databaseGroup; 

    std::string databaseName; 
public: 

    ~ForwardDBTest() { 
    } 
    ; 

    ForwardDBTest(DatabaseGroup& databaseGroup_, std::string dbName) : 
      databaseGroup(databaseGroup_), databaseName(dbName) { 
    } 

    void boostTestCreateDB() { 
     databaseGroup.createDatabase(databaseName, databaseName); 
    } 

}; 

class testSuites: public test_suite { 
public: 
    testSuites() : 
      test_suite("test_suite") { 
     std::string db_location = "home/girijag/ripe/ripe_db"; 
     std::cout << "hello" << std::endl; 
     int concurrency = 0; 
     std::string db_cache_policy = "AllMem"; 
     boost::shared_ptr<DatabaseGroup> db = boost::shared_ptr<DatabaseGroup>(
       new DatabaseGroup(db_location, concurrency, db_cache_policy)); 
     std::string dbName = "DB1"; 
     boost::shared_ptr<ForwardDBTest> instance(
       new ForwardDBTest(*db, dbName)); 
     test_case* boostTestCreateDB_test_case = BOOST_CLASS_TEST_CASE(
       &ForwardDBTest::boostTestCreateDB, instance); 
     add(boostTestCreateDB_test_case); 
    } 

    ~testSuites() { 
    } 
    ; 

}; 

test_suite* init_unit_test_suite(int argc, char** argv) { 

    test_suite* suite(BOOST_TEST_SUITE("Master Suite")); 
    suite->add(new testSuites()); 
    return suite; 
} 

}' 

어떻게 해결해야합니까? 나는 아래와 같은 오류를 얻고있다 : -

Test setup error: memory access violation at address: 0x00000021: no mapping at fault address

내가

답변

1

코드에 방해 가지가 있습니다 뭐죠 내 문제를 알아 내기 위해 지난 이일에서 고전을 면치 못하고 있고, 일부 서식이있는 것 같다 질문을 게시 할 때 잃어 버렸습니다. 그렇지 않으면 컴파일 할 기회가 없습니다. 우선 들어

, 당신은 색인 네임 스페이스에 init_unit_test_suite(int, char**)을 배치해서는 안되며, 이후 BOOST_TEST_MAIN을 정의 아무 소용이 없다 (예를 들어, }’ 들어?!) - 당신은 말했다 init_unit_test_suite(int, char**) 방법의 여러 정의로 끝날 것 .

귀하의 경우 스위트는 마스터 테스트 모음에 등록되어 있어야하며, 메소드에서 포인터를 반환 할 필요가 없습니다.

여기에 목적을 위해 연장으로 작업 할 수있는 최소 예가 있습니다. 귀하의 구조를 따르지만 관련이없는 세부 사항은 생략합니다 :

#include <boost/test/included/unit_test.hpp> 
#include <iostream> 

using namespace boost::unit_test; 

namespace indexing { 

class ForwardDBTest { 
public: 
    void boostTestCreateDB() { std::cout << __FUNCTION__ << std::endl; } 
}; 

class TestSuite : public test_suite { 
public: 
    TestSuite() : test_suite("test_suite") { 
     boost::shared_ptr<ForwardDBTest> instance(new ForwardDBTest); 
     add(BOOST_CLASS_TEST_CASE(&ForwardDBTest::boostTestCreateDB, instance)); 
    } 
}; 

} // namespace indexing 

test_suite* init_unit_test_suite(int, char**) { 
    framework::master_test_suite().add(new indexing::TestSuite); 
    return 0; 
} 
/* Output: 
Running 1 test case... 
boostTestCreateDB 

*** No errors detected 
*/