diff options
Diffstat (limited to 'src/components/resumption/test/last_state_test.cc')
-rw-r--r-- | src/components/resumption/test/last_state_test.cc | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/src/components/resumption/test/last_state_test.cc b/src/components/resumption/test/last_state_test.cc index d2b7f10ce4..78acc68c90 100644 --- a/src/components/resumption/test/last_state_test.cc +++ b/src/components/resumption/test/last_state_test.cc @@ -30,66 +30,86 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <string> + #include "gtest/gtest.h" + #include "resumption/last_state.h" -#include "config_profile/profile.h" #include "utils/file_system.h" namespace test { namespace components { -namespace resumption { +namespace resumption_test { using namespace ::resumption; using namespace ::Json; +const std::string kAppStorageFolder = "app_storage_folder"; +const std::string kAppInfoStorageFile = "app_info_storage"; class LastStateTest : public ::testing::Test { - public: - virtual void SetUp() { - ASSERT_TRUE(::file_system::CreateFile("./app_info.dat")); - ::profile::Profile::instance()->UpdateValues(); + protected: + LastStateTest() + : empty_dictionary_("null\n") + , app_info_dat_file_("app_info.dat") + , last_state_(kAppStorageFolder, kAppInfoStorageFile) {} + + static void SetUpTestCase() { + file_system::DeleteFile(kAppInfoStorageFile); + file_system::RemoveDirectory(kAppStorageFolder); } - virtual void TearDown() { - EXPECT_TRUE(::file_system::DeleteFile("./app_info.dat")); + void SetUp() OVERRIDE { + ASSERT_TRUE(file_system::CreateFile(app_info_dat_file_)); } + + void TearDown() OVERRIDE { + EXPECT_TRUE(file_system::DeleteFile((app_info_dat_file_))); + } + + const std::string empty_dictionary_; + const std::string app_info_dat_file_; + + resumption::LastState last_state_; }; TEST_F(LastStateTest, Basic) { - Value& dictionary = LastState::instance()->dictionary; - EXPECT_EQ("null\n", dictionary.toStyledString()); + const Value& dictionary = last_state_.dictionary; + EXPECT_EQ(empty_dictionary_, dictionary.toStyledString()); } TEST_F(LastStateTest, SetGetData) { { - Value& dictionary = LastState::instance()->dictionary; - Value bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; - EXPECT_EQ("null\n", bluetooth_info.toStyledString()); + const Value& dictionary = last_state_.dictionary; + const Value& bluetooth_info = + dictionary["TransportManager"]["BluetoothAdapter"]; + EXPECT_EQ(empty_dictionary_, bluetooth_info.toStyledString()); - Value tcp_adapter_info = + const Value& tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]["devices"]; - EXPECT_EQ("null\n", tcp_adapter_info.toStyledString()); + EXPECT_EQ(empty_dictionary_, tcp_adapter_info.toStyledString()); - Value resumption_time = dictionary["resumption"]["last_ign_off_time"]; + const Value& resumption_time = + dictionary["resumption"]["last_ign_off_time"]; EXPECT_EQ("null\n", resumption_time.toStyledString()); - Value resumption_list = dictionary["resumption"]["resume_app_list"]; + const Value& resumption_list = dictionary["resumption"]["resume_app_list"]; EXPECT_EQ("null\n", resumption_list.toStyledString()); Value test_value; test_value["name"] = "test_device"; - LastState::instance() - ->dictionary["TransportManager"]["TcpAdapter"]["devices"] = test_value; - LastState::instance() - ->dictionary["TransportManager"]["BluetoothAdapter"]["devices"] = + last_state_.dictionary["TransportManager"]["TcpAdapter"]["devices"] = + test_value; + last_state_.dictionary["TransportManager"]["BluetoothAdapter"]["devices"] = "bluetooth_device"; - LastState::instance()->SaveToFileSystem(); + last_state_.SaveToFileSystem(); } - Value& dictionary = LastState::instance()->dictionary; + const Value& dictionary = last_state_.dictionary; - Value bluetooth_info = dictionary["TransportManager"]["BluetoothAdapter"]; - Value tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]; + const Value& bluetooth_info = + dictionary["TransportManager"]["BluetoothAdapter"]; + const Value& tcp_adapter_info = dictionary["TransportManager"]["TcpAdapter"]; EXPECT_EQ("{\n \"devices\" : \"bluetooth_device\"\n}\n", bluetooth_info.toStyledString()); EXPECT_EQ( @@ -97,6 +117,6 @@ TEST_F(LastStateTest, SetGetData) { tcp_adapter_info.toStyledString()); } -} // namespace resumption +} // namespace resumption_test } // namespace components } // namespace test |