diff options
Diffstat (limited to 'src/components/policy/policy_external/test/sql_pt_representation_test.cc')
-rw-r--r-- | src/components/policy/policy_external/test/sql_pt_representation_test.cc | 62 |
1 files changed, 19 insertions, 43 deletions
diff --git a/src/components/policy/policy_external/test/sql_pt_representation_test.cc b/src/components/policy/policy_external/test/sql_pt_representation_test.cc index 2f85f8dc0a..2cb5ec1aaf 100644 --- a/src/components/policy/policy_external/test/sql_pt_representation_test.cc +++ b/src/components/policy/policy_external/test/sql_pt_representation_test.cc @@ -66,33 +66,22 @@ namespace test { namespace components { namespace policy_test { -namespace { -const int32_t kPolicyTablesNumber = 27; -} - class SQLPTRepresentationTest : public SQLPTRepresentation, public ::testing::Test { - public: - static const bool in_memory_; - protected: - static SQLPTRepresentation* reps; - static const std::string kDatabaseName; - static utils::dbms::SQLQuery* query_wrapper_; + static std::shared_ptr<SQLPTRepresentation> reps; + static std::shared_ptr<utils::dbms::SQLQuery> query_wrapper_; // Gtest can show message that this object doesn't destroyed - static std::unique_ptr<policy_handler_test::MockPolicySettings> + static std::shared_ptr<policy_handler_test::MockPolicySettings> policy_settings_; static void SetUpTestCase() { - const std::string kAppStorageFolder = "storage_SQLPTRepresentationTest"; - reps = new SQLPTRepresentation(in_memory_); + reps = std::make_shared<SQLPTRepresentation>(true); ASSERT_TRUE(reps != NULL); - policy_settings_ = std::unique_ptr<policy_handler_test::MockPolicySettings>( - new policy_handler_test::MockPolicySettings()); - ON_CALL(*policy_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kAppStorageFolder)); + policy_settings_ = + std::make_shared<policy_handler_test::MockPolicySettings>(); EXPECT_EQ(::policy::SUCCESS, reps->Init(policy_settings_.get())); - query_wrapper_ = new utils::dbms::SQLQuery(reps->db()); + query_wrapper_ = std::make_shared<utils::dbms::SQLQuery>(reps->db()); ASSERT_TRUE(query_wrapper_ != NULL); } @@ -101,12 +90,9 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, } static void TearDownTestCase() { - delete query_wrapper_; EXPECT_TRUE(reps->Drop()); EXPECT_TRUE(reps->Close()); reps->RemoveDB(); - delete reps; - policy_settings_.reset(); } virtual utils::dbms::SQLDatabase* db() const { @@ -343,16 +329,15 @@ class SQLPTRepresentationTest : public SQLPTRepresentation, } }; -SQLPTRepresentation* SQLPTRepresentationTest::reps = 0; -utils::dbms::SQLQuery* SQLPTRepresentationTest::query_wrapper_ = 0; -const std::string SQLPTRepresentationTest::kDatabaseName = ":memory:"; -const bool SQLPTRepresentationTest::in_memory_ = true; -std::unique_ptr<policy_handler_test::MockPolicySettings> - SQLPTRepresentationTest::policy_settings_; +std::shared_ptr<SQLPTRepresentation> SQLPTRepresentationTest::reps = NULL; +std::shared_ptr<utils::dbms::SQLQuery> SQLPTRepresentationTest::query_wrapper_ = + NULL; +std::shared_ptr<policy_handler_test::MockPolicySettings> + SQLPTRepresentationTest::policy_settings_ = NULL; class SQLPTRepresentationTest2 : public ::testing::Test { protected: - SQLPTRepresentation* reps; + std::shared_ptr<SQLPTRepresentation> reps; NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; virtual void SetUp() OVERRIDE { file_system::CreateDirectory(kAppStorageFolder); @@ -363,13 +348,14 @@ class SQLPTRepresentationTest2 : public ::testing::Test { .WillByDefault(Return(kOpenAttemptTimeoutMs)); ON_CALL(policy_settings_, attempts_to_open_policy_db()) .WillByDefault(Return(kAttemptsToOpenPolicyDB)); - reps = new SQLPTRepresentation; + reps = std::make_shared<SQLPTRepresentation>(); ASSERT_TRUE(reps != NULL); } virtual void TearDown() OVERRIDE { + chmod(kAppStorageFolder.c_str(), 755); file_system::RemoveDirectory(kAppStorageFolder, true); - delete reps; + reps.reset(); } const std::string kAppStorageFolder = "storage123"; const uint16_t kOpenAttemptTimeoutMs = 70u; @@ -1153,17 +1139,11 @@ TEST_F(SQLPTRepresentationTest, EXPECT_EQ("EMERGENCY", priority); } -namespace { -const std::string kAppStorageFolder = "storage"; -} TEST(SQLPTRepresentationTest3, Init_InitNewDataBase_ExpectResultSuccess) { // Arrange - const bool in_memory_ = true; NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; - SQLPTRepresentation reps(in_memory_); + SQLPTRepresentation reps(true); // Checks - ON_CALL(policy_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kAppStorageFolder)); EXPECT_EQ(::policy::SUCCESS, reps.Init(&policy_settings_)); EXPECT_EQ(::policy::EXISTS, reps.Init(&policy_settings_)); reps.RemoveDB(); @@ -1185,10 +1165,7 @@ TEST(SQLPTRepresentationTest3, Close_InitNewDataBaseThenClose_ExpectResultSuccess) { // Arrange NiceMock<policy_handler_test::MockPolicySettings> policy_settings_; - ON_CALL(policy_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kAppStorageFolder)); - const bool in_memory_ = true; - SQLPTRepresentation reps(in_memory_); + SQLPTRepresentation reps(true); EXPECT_EQ(::policy::SUCCESS, reps.Init(&policy_settings_)); EXPECT_TRUE(reps.Close()); utils::dbms::SQLError error(utils::dbms::Error::OK); @@ -1630,9 +1607,8 @@ TEST_F(SQLPTRepresentationTest, TEST(SQLPTRepresentationTest3, RemoveDB_RemoveDB_ExpectFileDeleted) { // Arrange - const bool in_memory_ = true; policy_handler_test::MockPolicySettings policy_settings_; - SQLPTRepresentation reps(in_memory_); + SQLPTRepresentation reps(true); EXPECT_EQ(::policy::SUCCESS, reps.Init(&policy_settings_)); EXPECT_EQ(::policy::EXISTS, reps.Init(&policy_settings_)); std::string path = (reps.db())->get_path(); |