#include "parcel_utils.hh"
#include "pkg_get_db_handler.hh"
#include "pkg_set_db_handler.hh"
+#include "query_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"
#define TEST_PARSER_DB "test.pkgmgr_parser.db"
MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
};
+class QueryHandlerMock : public psd::QueryHandler {
+ public:
+ QueryHandlerMock(uid_t uid, int pid) :
+ psd::QueryHandler(uid, pid) {}
+
+ MOCK_METHOD0(Connect, bool());
+ MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+};
+
class Mocks : public ::testing::NiceMock<SystemInfoMock> {};
class ParserDBHandlerTest : public TestFixture {
EXPECT_TRUE(IsEqualDepInfo(depinfo_list, depinfo_from_db));
}
+
+TEST_F(ParserDBHandlerTest, QueryDBHandler_PluginInfoTest) {
+ const std::string pkgid = "test_pkgid";
+ const std::string appid = "test_appid";
+ const std::string plugin_type = "test_plugin_type";
+ const std::string plugin_name = "test_plugin_name";
+
+ QueryHandlerMock set_query_handler(0, 0);
+ set_query_handler.SetQueryArgs(
+ std::vector<std::pair<int, std::vector<std::string>>>{
+ std::make_pair(
+ QUERY_INDEX_INSERT_PACKAGE_PLUGIN_EXECUTION_INFO,
+ std::vector<std::string>{
+ pkgid, appid, plugin_type, plugin_name})});
+ set_query_handler.SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+ set_query_handler.SetOpType(
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
+
+ EXPECT_CALL(set_query_handler,
+ Connect()).WillOnce(testing::Return(true));
+ EXPECT_CALL(set_query_handler, GetConnection())
+ .WillOnce(testing::Return(GetDBHandles()));
+ ASSERT_EQ(set_query_handler.Execute(), 0);
+
+ QueryHandlerMock get_query_handler(0, 0);
+ get_query_handler.SetQueryArgs(
+ std::vector<std::pair<int, std::vector<std::string>>>{
+ std::make_pair(
+ QUERY_INDEX_PLUGININFO_GET_APPIDS,
+ std::vector<std::string>{pkgid, plugin_type, plugin_name})});
+ get_query_handler.SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+ get_query_handler.SetOpType(
+ pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+
+ EXPECT_CALL(get_query_handler,
+ Connect()).WillOnce(testing::Return(true));
+ EXPECT_CALL(get_query_handler, GetConnection())
+ .WillOnce(testing::Return(GetDBHandles()));
+ ASSERT_EQ(get_query_handler.Execute(), 0);
+ auto result = get_query_handler.GetResult();
+ ASSERT_EQ(result.size(), 1);
+ ASSERT_EQ(result[0].size(), 1);
+ ASSERT_EQ(appid, result[0][0]);
+}