创建表的EXPECT_EQ出错

时间:2017-07-04 05:48:08

标签: c++ sqlite unit-testing googletest

在Create Table API的单元测试期间,我收到了下面提到的错误:

pankaj:〜/ Downloads / googletest-release-1.8.0 / src $ ./Test.out

[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from AdditionTest
[ RUN      ] AdditionTest.twoValues
in sqliteDB constructor
in sqliteDB destructor

Pure virtual destructor is called from DBManager()
unknown file: Failure
C++ exception with description "basic_string::erase" thrown in the test body.
[  FAILED  ] AdditionTest.twoValues (0 ms)
[----------] 1 test from AdditionTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (2 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] AdditionTest.twoValues

 1 FAILED TEST

result: 1

下面提到的是测试 createTable API ::

的代码
TEST_F(AdditionTest,twoValues){
    sqliteDB obj_sql;  
    std::vector<std::string> colNames;
    colNames.push_back("id");
    colNames.push_back("name");    
    pair<std::string, int> p1, p2;
    map<std::string, pair<string, int> > m1;
    p1 = make_pair("varchar", 10);
    p2 = make_pair("varchar", 10);
    m1["id"] = p1;
    m1["name"] = p2;
    tableData["table1"] = m1;
    EXPECT_EQ(9,obj_sql.createTable(colNames,tableData));
    //EXPECT_EQ(6,addition.twoValues(2,3));
}

测试下面提到的API :::::

int sqliteDB::createTable(std::vector<std::string> tableName, tableStructure &tableContents)
{
    for(unsigned int i=0; i<tableName.size(); i++)
    {
        string s4;
        string query;

        for(auto it : tableContents[tableName[i]])
        {
            s4.append(it.first);
            s4.append(" ");
            s4.append(it.second.first);
            if(it.second.first == "varchar")
            {
                s4.append("(");
                s4.append(to_string(it.second.second));
                s4.append(")");
            }
            s4.append(",");
        }

        s4.pop_back();
        query.append("CREATE TABLE ");
        query.append(tableName[i]);
        query.append(" (");
        query.append(s4);
        query.append(")");
        cout<<"Create Query: "<<query<<endl;

        executeQuery(m_db, query);
    }
    return 0;   
}

我应该在EXPECT_EQ(9,obj_sql.createTable(colNames,tableData))中进行哪些更改以通过此测试,或者我应该在代码中的其他位置进行更改。

0 个答案:

没有答案