1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <gmock/gmock.h>
18 #include "insight_intent_rdb_storage_mgr.h"
19
20 namespace OHOS {
21 namespace AbilityRuntime {
22 bool g_mockDeleteStorageInsightIntentDataRet = true;
23 bool g_mockDeleteStorageInsightIntentByUserIdRet = true;
24 bool g_mockSaveStorageInsightIntentDataRet = true;
25 bool g_mockLoadInsightIntentInfoRet = true;
26 bool g_mockLoadInsightIntentInfoByNameRet = true;
27 bool g_mockLoadInsightIntentInfosRet = true;
28
MockDeleteData(bool mockRet)29 void MockDeleteData(bool mockRet)
30 {
31 g_mockDeleteStorageInsightIntentDataRet = mockRet;
32 }
33
34
MockDeleteDataByUserId(bool mockRet)35 void MockDeleteDataByUserId(bool mockRet)
36 {
37 g_mockDeleteStorageInsightIntentByUserIdRet = mockRet;
38 }
39
MockSaveData(bool mockRet)40 void MockSaveData(bool mockRet)
41 {
42 g_mockSaveStorageInsightIntentDataRet = mockRet;
43 }
44
MockLoadInsightIntentInfo(bool mockRet)45 void MockLoadInsightIntentInfo(bool mockRet)
46 {
47 g_mockLoadInsightIntentInfoRet = mockRet;
48 }
49
MockLoadInsightIntentInfoByName(bool mockRet)50 void MockLoadInsightIntentInfoByName(bool mockRet)
51 {
52 g_mockLoadInsightIntentInfoByNameRet = mockRet;
53 }
54
MockLoadInsightIntentInfos(bool mockRet)55 void MockLoadInsightIntentInfos(bool mockRet)
56 {
57 g_mockLoadInsightIntentInfosRet = mockRet;
58 }
59
60 }
61 }
62
63 namespace OHOS {
64 namespace AbilityRuntime {
InsightRdbStorageMgr()65 InsightRdbStorageMgr::InsightRdbStorageMgr()
66 {
67 }
68
~InsightRdbStorageMgr()69 InsightRdbStorageMgr::~InsightRdbStorageMgr()
70 {
71 }
72
LoadInsightIntentInfos(const int32_t userId,std::vector<ExtractInsightIntentInfo> & totalInfos)73 int32_t InsightRdbStorageMgr::LoadInsightIntentInfos(const int32_t userId,
74 std::vector<ExtractInsightIntentInfo> &totalInfos)
75 {
76 ExtractInsightIntentInfo totalInfo;
77 totalInfos.push_back(totalInfo);
78 if (g_mockLoadInsightIntentInfosRet) {
79 return ERR_OK;
80 }
81 return ERR_INVALID_VALUE;
82 }
83
LoadInsightIntentInfoByName(const std::string & bundleName,const int32_t userId,std::vector<ExtractInsightIntentInfo> & totalInfos)84 int32_t InsightRdbStorageMgr::LoadInsightIntentInfoByName(const std::string &bundleName, const int32_t userId,
85 std::vector<ExtractInsightIntentInfo> &totalInfos)
86 {
87 ExtractInsightIntentInfo totalInfo;
88 totalInfos.push_back(totalInfo);
89 if (g_mockLoadInsightIntentInfoByNameRet) {
90 return ERR_OK;
91 }
92 return ERR_INVALID_VALUE;
93 }
94
LoadInsightIntentInfo(const std::string & bundleName,const std::string & moduleName,const std::string & intentName,const int32_t userId,ExtractInsightIntentInfo & totalInfo)95 int32_t InsightRdbStorageMgr::LoadInsightIntentInfo(const std::string &bundleName, const std::string &moduleName,
96 const std::string &intentName, const int32_t userId, ExtractInsightIntentInfo &totalInfo)
97 {
98 if (g_mockLoadInsightIntentInfoRet) {
99 return ERR_OK;
100 }
101 return ERR_INVALID_VALUE;
102 }
103
SaveStorageInsightIntentData(const std::string & bundleName,const std::string & moduleName,const int32_t userId,ExtractInsightIntentProfileInfoVec & profileInfos)104 int32_t InsightRdbStorageMgr::SaveStorageInsightIntentData(const std::string &bundleName,
105 const std::string &moduleName, const int32_t userId, ExtractInsightIntentProfileInfoVec &profileInfos)
106 {
107 if (g_mockSaveStorageInsightIntentDataRet) {
108 return ERR_OK;
109 }
110 return ERR_INVALID_VALUE;
111 }
112
DeleteStorageInsightIntentData(const std::string & bundleName,const std::string & moduleName,const int32_t userId)113 int32_t InsightRdbStorageMgr::DeleteStorageInsightIntentData(const std::string &bundleName,
114 const std::string &moduleName, const int32_t userId)
115 {
116 if (g_mockDeleteStorageInsightIntentDataRet) {
117 return ERR_OK;
118 }
119 return ERR_INVALID_VALUE;
120 }
121
DeleteStorageInsightIntentByUserId(const int32_t userId)122 int32_t InsightRdbStorageMgr::DeleteStorageInsightIntentByUserId(const int32_t userId)
123 {
124 if (g_mockDeleteStorageInsightIntentByUserIdRet) {
125 return ERR_OK;
126 }
127 return ERR_INVALID_VALUE;
128 }
129 }
130 }