Index: src/libchcore/Tests/TestsTSQLiteTransaction.cpp =================================================================== diff -u -N -rd18db617f4727a237c94b59af9b4328f829eda16 -ra4635addad389b9e117679437a3e1b64a739ea96 --- src/libchcore/Tests/TestsTSQLiteTransaction.cpp (.../TestsTSQLiteTransaction.cpp) (revision d18db617f4727a237c94b59af9b4328f829eda16) +++ src/libchcore/Tests/TestsTSQLiteTransaction.cpp (.../TestsTSQLiteTransaction.cpp) (revision a4635addad389b9e117679437a3e1b64a739ea96) @@ -1,82 +1,82 @@ -#include "stdafx.h" -#include "gtest/gtest.h" -#include "gmock/gmock.h" -#include "../TSQLiteTransaction.h" -#include "../TSQLiteDatabase.h" -#include "../TSQLiteStatement.h" -#include "../TSQLiteException.h" - -using namespace chcore; -using namespace sqlite; - -TEST(SQLiteTransaction, BeginTransactionWithDefaultRollback_Empty) -{ - TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); - - // separate scope for the transaction - { - TSQLiteTransaction tran(spDB); - EXPECT_TRUE(spDB->GetInTransaction()); - } - EXPECT_FALSE(spDB->GetInTransaction()); -} - -TEST(SQLiteTransaction, BeginTransactionWithDefaultRollback_WithData) -{ - TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); - TSQLiteStatement tStatement(spDB); - - // separate scope for the transaction - { - TSQLiteTransaction tran(spDB); - - tStatement.Prepare(_T("CREATE TABLE test(col1 INTEGER, col2 VARCHAR(40))")); - tStatement.Step(); - - tStatement.Prepare(_T("INSERT INTO test(col1, col2) VALUES(?1, ?2)")); - tStatement.BindValue(1, 54); - tStatement.BindValue(2, _T("Some Value")); - tStatement.Step(); - } - - // rollback seem to revert the schema changes, so this statement can't be processed due to missing table - EXPECT_THROW(tStatement.Prepare(_T("SELECT count(*) FROM test")), TSQLiteException); -} - -TEST(SQLiteTransaction, BeginTransactionWithCommit) -{ - TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); - - // separate scope for the transaction - TSQLiteTransaction tran(spDB); - - tran.Commit(); - EXPECT_FALSE(spDB->GetInTransaction()); -} - -TEST(SQLiteTransaction, BeginTransactionWithCommit_WithData) -{ - TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); - TSQLiteStatement tStatement(spDB); - - // separate scope for the transaction - { - TSQLiteTransaction tran(spDB); - - tStatement.Prepare(_T("CREATE TABLE test(col1 INTEGER, col2 VARCHAR(40))")); - tStatement.Step(); - - tStatement.Prepare(_T("INSERT INTO test(col1, col2) VALUES(?1, ?2)")); - tStatement.BindValue(1, 54); - tStatement.BindValue(2, _T("Some Value")); - tStatement.Step(); - - tran.Commit(); - } - - // rollback seem to revert the schema changes, so this statement can't be processed due to missing table - tStatement.Prepare(_T("SELECT count(*) FROM test")); - tStatement.Step(); - - EXPECT_EQ(1, tStatement.GetInt(0)); -} +#include "stdafx.h" +#include "gtest/gtest.h" +#include "gmock/gmock.h" +#include "../TSQLiteTransaction.h" +#include "../TSQLiteDatabase.h" +#include "../TSQLiteStatement.h" +#include "../TSQLiteException.h" + +using namespace chcore; +using namespace sqlite; + +TEST(SQLiteTransaction, BeginTransactionWithDefaultRollback_Empty) +{ + TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); + + // separate scope for the transaction + { + TSQLiteTransaction tran(spDB); + EXPECT_TRUE(spDB->GetInTransaction()); + } + EXPECT_FALSE(spDB->GetInTransaction()); +} + +TEST(SQLiteTransaction, BeginTransactionWithDefaultRollback_WithData) +{ + TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); + TSQLiteStatement tStatement(spDB); + + // separate scope for the transaction + { + TSQLiteTransaction tran(spDB); + + tStatement.Prepare(_T("CREATE TABLE test(col1 INTEGER, col2 VARCHAR(40))")); + tStatement.Step(); + + tStatement.Prepare(_T("INSERT INTO test(col1, col2) VALUES(?1, ?2)")); + tStatement.BindValue(1, 54); + tStatement.BindValue(2, _T("Some Value")); + tStatement.Step(); + } + + // rollback seem to revert the schema changes, so this statement can't be processed due to missing table + EXPECT_THROW(tStatement.Prepare(_T("SELECT count(*) FROM test")), TSQLiteException); +} + +TEST(SQLiteTransaction, BeginTransactionWithCommit) +{ + TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); + + // separate scope for the transaction + TSQLiteTransaction tran(spDB); + + tran.Commit(); + EXPECT_FALSE(spDB->GetInTransaction()); +} + +TEST(SQLiteTransaction, BeginTransactionWithCommit_WithData) +{ + TSQLiteDatabasePtr spDB(new TSQLiteDatabase(PathFromString(_T(":memory:")))); + TSQLiteStatement tStatement(spDB); + + // separate scope for the transaction + { + TSQLiteTransaction tran(spDB); + + tStatement.Prepare(_T("CREATE TABLE test(col1 INTEGER, col2 VARCHAR(40))")); + tStatement.Step(); + + tStatement.Prepare(_T("INSERT INTO test(col1, col2) VALUES(?1, ?2)")); + tStatement.BindValue(1, 54); + tStatement.BindValue(2, _T("Some Value")); + tStatement.Step(); + + tran.Commit(); + } + + // rollback seem to revert the schema changes, so this statement can't be processed due to missing table + tStatement.Prepare(_T("SELECT count(*) FROM test")); + tStatement.Step(); + + EXPECT_EQ(1, tStatement.GetInt(0)); +}