123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include <catch2/catch.hpp>
- class DBConnection
- {
- public:
- static DBConnection createConnection( std::string const & ) {
- return DBConnection();
- }
- bool executeSQL( std::string const & , int const , std::string const & arg ) {
- if ( arg.length() == 0 ) {
- throw std::logic_error("empty SQL query argument");
- }
- return true;
- }
- };
- class UniqueTestsFixture
- {
- protected:
- UniqueTestsFixture()
- : conn( DBConnection::createConnection( "myDB" ) )
- {}
- int getID() {
- return ++uniqueID;
- }
- protected:
- DBConnection conn;
- private:
- static int uniqueID;
- };
- int UniqueTestsFixture::uniqueID = 0;
- TEST_CASE_METHOD( UniqueTestsFixture, "Create Employee/No Name", "[create]" ) {
- REQUIRE_THROWS( conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "") );
- }
- TEST_CASE_METHOD( UniqueTestsFixture, "Create Employee/Normal", "[create]" ) {
- REQUIRE( conn.executeSQL( "INSERT INTO employee (id, name) VALUES (?, ?)", getID(), "Joe Bloggs" ) );
- }
|