1 /*
2 * Copyright (c) 2024 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 "lnn_kv_adapter_wrapper_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22 void *g_kvAdapterInterface;
LnnKvAdapterInterfaceMock()23 LnnKvAdapterInterfaceMock::LnnKvAdapterInterfaceMock()
24 {
25 g_kvAdapterInterface = reinterpret_cast<void *>(this);
26 }
27
~LnnKvAdapterInterfaceMock()28 LnnKvAdapterInterfaceMock::~LnnKvAdapterInterfaceMock()
29 {
30 g_kvAdapterInterface = nullptr;
31 }
32
GetKvAdapterInterface()33 static LnnKvAdapterInterface *GetKvAdapterInterface()
34 {
35 return reinterpret_cast<LnnKvAdapterInterface *>(g_kvAdapterInterface);
36 }
37
38 extern "C" {
LnnCreateKvAdapter(int32_t * dbId,const char * appId,int32_t appIdLen,const char * storeId,int32_t storeIdLen)39 int32_t LnnCreateKvAdapter(int32_t *dbId, const char *appId, int32_t appIdLen, const char *storeId, int32_t storeIdLen)
40 {
41 return GetKvAdapterInterface()->LnnCreateKvAdapter(dbId, appId, appIdLen, storeId, storeIdLen);
42 }
43
LnnDestroyKvAdapter(int32_t dbId)44 int32_t LnnDestroyKvAdapter(int32_t dbId)
45 {
46 return GetKvAdapterInterface()->LnnDestroyKvAdapter(dbId);
47 }
48
LnnRegisterDataChangeListener(int32_t dbId,const char * appId,int32_t appIdLen,const char * storeId,int32_t storeIdLen)49 void LnnRegisterDataChangeListener(
50 int32_t dbId, const char *appId, int32_t appIdLen, const char *storeId, int32_t storeIdLen)
51 {
52 return GetKvAdapterInterface()->LnnRegisterDataChangeListener(dbId, appId, appIdLen, storeId, storeIdLen);
53 }
54
LnnUnRegisterDataChangeListener(int32_t dbId)55 void LnnUnRegisterDataChangeListener(int32_t dbId)
56 {
57 return GetKvAdapterInterface()->LnnUnRegisterDataChangeListener(dbId);
58 }
59
LnnPutDBData(int32_t dbId,const char * key,int32_t keyLen,const char * value,int32_t valueLen)60 int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *value, int32_t valueLen)
61 {
62 return GetKvAdapterInterface()->LnnPutDBData(dbId, key, keyLen, value, valueLen);
63 }
64
LnnDeleteDBDataByPrefix(int32_t dbId,const char * keyPrefix,int32_t keyPrefixLen)65 int32_t LnnDeleteDBDataByPrefix(int32_t dbId, const char *keyPrefix, int32_t keyPrefixLen)
66 {
67 return GetKvAdapterInterface()->LnnDeleteDBDataByPrefix(dbId, keyPrefix, keyPrefixLen);
68 }
69
LnnCloudSync(int32_t dbId)70 int32_t LnnCloudSync(int32_t dbId)
71 {
72 return GetKvAdapterInterface()->LnnCloudSync(dbId);
73 }
74
LnnSetCloudAbilityInner(int32_t dbId,const bool isEnableCloud)75 int32_t LnnSetCloudAbilityInner(int32_t dbId, const bool isEnableCloud)
76 {
77 return GetKvAdapterInterface()->LnnSetCloudAbilityInner(dbId, isEnableCloud);
78 }
79 }
80 } // namespace OHOS