*/
#include <gmock/gmock.h>
-
#include <gtest/gtest.h>
#include <cstdio>
+#include <fstream>
#include "appinfo_db_handler.hh"
#include "create_db_handler.hh"
#include "parcel_utils.hh"
#include "pkg_get_db_handler.hh"
#include "pkg_set_db_handler.hh"
-
-#include "mock/file_mock.h"
#include "mock/test_fixture.h"
#include "mock/system_info_mock.h"
-
#include "pkgmgr-info.h"
#include "pkgmgr_query_index.h"
#include "pkgmgrinfo_basic.h"
+#include "server/pkgmgrinfo_internal.h"
#define TEST_PARSER_DB "test.pkgmgr_parser.db"
: psd::CreateDBHandler(uid, pid) {}
MOCK_METHOD0(Connect, bool());
- MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+ MOCK_METHOD0(GetConnection, const std::vector<std::pair<tizen_base::Database,
+ uid_t>>&());
};
class PkgSetDBHandlerMock : public psd::PkgSetDBHandler {
PkgSetDBHandlerMock(uid_t uid, int pid) : psd::PkgSetDBHandler(uid, pid) {}
MOCK_METHOD0(Connect, bool());
- MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+ MOCK_METHOD0(GetConnection, const std::vector<std::pair<tizen_base::Database,
+ uid_t>>&());
};
class PkgGetDBHandlerMock : public psd::PkgGetDBHandler {
PkgGetDBHandlerMock(uid_t uid, int pid) : psd::PkgGetDBHandler(uid, pid) {}
MOCK_METHOD0(Connect, bool());
- MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+ MOCK_METHOD0(GetConnection, const std::vector<std::pair<tizen_base::Database,
+ uid_t>>&());
};
class AppInfoDBHandlerMock : public psd::AppInfoDBHandler {
AppInfoDBHandlerMock(uid_t uid, int pid) : psd::AppInfoDBHandler(uid, pid) {}
MOCK_METHOD0(Connect, bool());
- MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+ MOCK_METHOD0(GetConnection, const std::vector<std::pair<tizen_base::Database,
+ uid_t>>&());
};
class DepInfoGetDBHandlerMock : public psd::DepInfoGetDBHandler {
psd::DepInfoGetDBHandler(uid, pid) {}
MOCK_METHOD0(Connect, bool());
- MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+ MOCK_METHOD0(GetConnection, const std::vector<std::pair<tizen_base::Database,
+ uid_t>>&());
};
class Mocks : public ::testing::NiceMock<SystemInfoMock> {};
virtual ~ParserDBHandlerTest() {}
virtual void SetUp() {
- sqlite3* db;
-
- int ret = sqlite3_open_v2(TEST_PARSER_DB, &db,
- SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
- if (ret != SQLITE_OK)
- sqlite3_close_v2(db);
-
- ASSERT_EQ(ret, SQLITE_OK);
-
- SetDBHandles(
- std::vector<std::pair<sqlite3*, uid_t>> { std::make_pair(db, 0) });
+ tizen_base::Database db(TEST_PARSER_DB, SQLITE_OPEN_READWRITE |
+ SQLITE_OPEN_CREATE);
+ db_handles_.emplace_back(std::move(db), 0);
CreateParserDBHandlerMock create_db_handler(0, 0);
EXPECT_CALL(create_db_handler, Connect())
.Times(2).WillRepeatedly(testing::Return(true));
EXPECT_CALL(create_db_handler, GetConnection())
- .Times(2).WillRepeatedly(testing::Return(GetDBHandles()));
+ .Times(2).WillRepeatedly(testing::ReturnRef(db_handles_));
EXPECT_CALL(GetMock<SystemInfoMock>(),
system_info_get_platform_int(testing::_, testing::_))
.WillRepeatedly(testing::DoAll(
testing::SetArgPointee<1>(120), testing::Return(0)));
- fopen_mock_setup(true);
+ MakeVersionFile();
+ pkgmgr_server::internal::SetEnableUnitTest(true);
ASSERT_EQ(create_db_handler.Execute(), 0);
- fopen_mock_setup(false);
+ pkgmgr_server::internal::SetEnableUnitTest(false);
}
virtual void TearDown() {
- for (auto& handle : db_handles_)
- sqlite3_close_v2(handle.first);
-
+ db_handles_.clear();
ASSERT_EQ(remove(TEST_PARSER_DB), 0);
std::string journal_path(TEST_PARSER_DB);
journal_path += "-journal";
ASSERT_EQ(remove(journal_path.c_str()), 0);
}
- const std::vector<std::pair<sqlite3*, uid_t>>& GetDBHandles() {
- return db_handles_;
- }
-
private:
- void SetDBHandles(std::vector<std::pair<sqlite3*, uid_t>>&& db_handles) {
- db_handles_ = db_handles;
+ void MakeVersionFile() {
+ std::remove("./pkg_db_version.txt");
+ std::ofstream ofs("./pkg_db_version.txt");
+ ofs << "30005";
}
- std::vector<std::pair<sqlite3*, uid_t>> db_handles_;
+ protected:
+ std::vector<std::pair<tizen_base::Database, uid_t>> db_handles_;
};
TEST_F(ParserDBHandlerTest, PkgSetDBHandlerTest_Install) {
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
}
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
}
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
pkgmgrinfo_pkginfo_filter_h filter;
EXPECT_CALL(pkg_get_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_get_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_get_db_handler.Execute(), PMINFO_R_ENOENT);
}
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
pkgmgrinfo_pkginfo_filter_h filter;
EXPECT_CALL(pkg_get_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_get_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_get_db_handler.Execute(), 0);
auto lpkginfo_list = pkg_get_db_handler.GetPkgHandle();
auto test_pkginfo = GetTestPackage(pkgid);
std::vector<std::shared_ptr<package_x>> rpkginfo_list;
- rpkginfo_list.emplace_back(test_pkginfo);
+ rpkginfo_list.emplace_back(test_pkginfo, pkgmgrinfo_basic_free_package);
ASSERT_EQ(IsEqualPackagesInfo(lpkginfo_list, rpkginfo_list), true);
}
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
pkgmgrinfo_appinfo_filter_h filter;
EXPECT_CALL(appinfo_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(appinfo_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
appinfo_db_handler.SetLocale("test_lang");
ASSERT_EQ(appinfo_db_handler.Execute(), 0);
auto test_appinfo = GetTestApplication(appid);
std::vector<std::shared_ptr<application_x>> rappinfo_list;
- rappinfo_list.emplace_back(test_appinfo);
+ rappinfo_list.emplace_back(test_appinfo, std::free);
ASSERT_EQ(IsEqualApplicationsInfo(lappinfo_list, rappinfo_list), true);
}
EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(pkg_set_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
DepInfoGetDBHandlerMock depinfo_get_db_handler(0, 0);
EXPECT_CALL(depinfo_get_db_handler,
Connect()).WillOnce(testing::Return(true));
EXPECT_CALL(depinfo_get_db_handler, GetConnection())
- .WillOnce(testing::Return(GetDBHandles()));
+ .WillOnce(testing::ReturnRef(db_handles_));
ASSERT_EQ(depinfo_get_db_handler.Execute(), 0);
auto depinfo_from_db = depinfo_get_db_handler.GetDependencyList();