Skip to content

Unittesting a bool operator fails #119

Closed
@grahamreeds

Description

@grahamreeds

I detailed the issue I am having here:
http://stackoverflow.com/questions/38330348/continuous-error-21-library-routine-called-out-of-sequence
I have since narrowed it down to a piece of code. This passes:

    TEST_FIXTURE(DatabaseFixture, TryToCreateATable)
    {
        database db(test);
        CHECK(db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
    }

But this fails (normally it is REQUIRE CHECK(db) but I removed it to make sure it isn't REQUIRE causing issues).

    TEST_FIXTURE(DatabaseFixture, TryToCreateATable)
    {
        database db(test);
        CHECK(db);
        CHECK(db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
    }

The db boolean check is

operator bool() const { return connected_; }

If you replace the CHECK(db); line with the following:

if (!db) std::cout << "Not connected! " << db.error() << std::endl;

It passes. You can see the bool operator is called by placing a cout in there just to acknowledge the call.

While I initially thought it was Sqlite3 related it appears it is the boolean operator causing the issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions