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,
40 int32_t storeIdLen)
41 {
42 return GetKvAdapterInterface()->LnnCreateKvAdapter(dbId, appId, appIdLen, storeId, storeIdLen);
43 }
44
LnnDestroyKvAdapter(int32_t dbId)45 int32_t LnnDestroyKvAdapter(int32_t dbId)
46 {
47 return GetKvAdapterInterface()->LnnDestroyKvAdapter(dbId);
48 }
49
LnnRegisterDataChangeListener(int32_t dbId,const char * appId,int32_t appIdLen,const char * storeId,int32_t storeIdLen)50 void LnnRegisterDataChangeListener(int32_t dbId, const char *appId, int32_t appIdLen,
51 const char *storeId, int32_t storeIdLen)
52 {
53 return GetKvAdapterInterface()->LnnRegisterDataChangeListener(dbId, appId, appIdLen, storeId, storeIdLen);
54 }
55
LnnUnRegisterDataChangeListener(int32_t dbId)56 void LnnUnRegisterDataChangeListener(int32_t dbId)
57 {
58 return GetKvAdapterInterface()->LnnUnRegisterDataChangeListener(dbId);
59 }
60
LnnPutDBData(int32_t dbId,const char * key,int32_t keyLen,const char * value,int32_t valueLen)61 int32_t LnnPutDBData(int32_t dbId, const char *key, int32_t keyLen, const char *value, int32_t valueLen)
62 {
63 return GetKvAdapterInterface()->LnnPutDBData(dbId, key, keyLen, value, valueLen);
64 }
65
LnnDeleteDBDataByPrefix(int32_t dbId,const char * keyPrefix,int32_t keyPrefixLen)66 int32_t LnnDeleteDBDataByPrefix(int32_t dbId, const char *keyPrefix, int32_t keyPrefixLen)
67 {
68 return GetKvAdapterInterface()->LnnDeleteDBDataByPrefix(dbId, keyPrefix, keyPrefixLen);
69 }
70
LnnCloudSync(int32_t dbId)71 int32_t LnnCloudSync(int32_t dbId)
72 {
73 return GetKvAdapterInterface()->LnnCloudSync(dbId);
74 }
75
LnnSetCloudAbilityInner(int32_t dbId,const bool isEnableCloud)76 int32_t LnnSetCloudAbilityInner(int32_t dbId, const bool isEnableCloud)
77 {
78 return GetKvAdapterInterface()->LnnSetCloudAbilityInner(dbId, isEnableCloud);
79 }
80 }
81 } // namespace OHOS