1 /*
2 * Copyright (c) 2023 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 #include "dk_database.h"
16
17 #include <functional>
18 #include <iostream>
19 #include <thread>
20
21 #include <gtest/gtest.h>
22
23 #include "dk_context.h"
24
25 namespace DriveKit {
SaveRecords(std::shared_ptr<DKContext> context,std::vector<DKRecord> && records,DKSavePolicy policy,SaveRecordsCallback callback)26 DKLocalErrorCode DKDatabase::SaveRecords(std::shared_ptr<DKContext> context,
27 std::vector<DKRecord> &&records,
28 DKSavePolicy policy,
29 SaveRecordsCallback callback)
30 {
31 return DKLocalErrorCode::NO_ERROR;
32 }
SaveRecord(std::shared_ptr<DKContext> context,DKRecord && record,DKSavePolicy policy,SaveRecordCallback callback)33 DKLocalErrorCode DKDatabase::SaveRecord(std::shared_ptr<DKContext> context,
34 DKRecord &&record,
35 DKSavePolicy policy,
36 SaveRecordCallback callback)
37 {
38 return DKLocalErrorCode::NO_ERROR;
39 }
FetchRecords(std::shared_ptr<DKContext> context,DKRecordType recordType,DKFieldKeyArray & desiredKeys,int resultLimit,DKQueryCursor cursor,FetchRecordsCallback callback)40 DKLocalErrorCode DKDatabase::FetchRecords(std::shared_ptr<DKContext> context,
41 DKRecordType recordType,
42 DKFieldKeyArray &desiredKeys,
43 int resultLimit,
44 DKQueryCursor cursor,
45 FetchRecordsCallback callback)
46 {
47 GTEST_LOG_(INFO) << "FetchRecords begin";
48 if (cursor == "err") {
49 return DKLocalErrorCode::IPC_CONNECT_FAILED;
50 }
51 return DKLocalErrorCode::NO_ERROR;
52 }
53
FetchRecordWithId(std::shared_ptr<DKContext> context,DKRecordType recordType,DKRecordId recordId,DKFieldKeyArray & desiredKeys,FetchRecordCallback callback)54 DKLocalErrorCode DKDatabase::FetchRecordWithId(std::shared_ptr<DKContext> context,
55 DKRecordType recordType,
56 DKRecordId recordId,
57 DKFieldKeyArray &desiredKeys,
58 FetchRecordCallback callback)
59 {
60 if (recordId == "err") {
61 return DKLocalErrorCode::IPC_CONNECT_FAILED;
62 }
63 return DKLocalErrorCode::NO_ERROR;
64 }
65
DeleteRecords(std::shared_ptr<DKContext> context,std::vector<DKRecord> && records,DKSavePolicy policy,DeleteRecordsCallback callback)66 DKLocalErrorCode DKDatabase::DeleteRecords(std::shared_ptr<DKContext> context,
67 std::vector<DKRecord> &&records,
68 DKSavePolicy policy,
69 DeleteRecordsCallback callback)
70 {
71 return DKLocalErrorCode::NO_ERROR;
72 }
73
ModifyRecords(std::shared_ptr<DKContext> context,std::vector<DKRecord> && recordsToSave,std::vector<DKRecord> && recordsToDelete,DKSavePolicy policy,bool atomically,ModifyRecordsCallback callback)74 DKLocalErrorCode DKDatabase::ModifyRecords(std::shared_ptr<DKContext> context,
75 std::vector<DKRecord> &&recordsToSave,
76 std::vector<DKRecord> &&recordsToDelete,
77 DKSavePolicy policy,
78 bool atomically,
79 ModifyRecordsCallback callback)
80 {
81 return DKLocalErrorCode::NO_ERROR;
82 }
83
FetchRecordsWithQuery(std::shared_ptr<DKContext> context,DKFieldKeyArray & desiredKeys,DKQuery query,int resultLimit,DKQueryCursor cursor,FetchRecordsCallback callback)84 DKLocalErrorCode DKDatabase::FetchRecordsWithQuery(std::shared_ptr<DKContext> context,
85 DKFieldKeyArray &desiredKeys,
86 DKQuery query,
87 int resultLimit,
88 DKQueryCursor cursor,
89 FetchRecordsCallback callback)
90 {
91 return DKLocalErrorCode::NO_ERROR;
92 }
93
FetchDatabaseChanges(std::shared_ptr<DKContext> context,DKRecordType recordType,DKFieldKeyArray & desiredKeys,int resultLimit,DKQueryCursor cursor,FetchDatabaseCallback callback)94 DKLocalErrorCode DKDatabase::FetchDatabaseChanges(std::shared_ptr<DKContext> context,
95 DKRecordType recordType,
96 DKFieldKeyArray &desiredKeys,
97 int resultLimit,
98 DKQueryCursor cursor,
99 FetchDatabaseCallback callback)
100 {
101 return DKLocalErrorCode::NO_ERROR;
102 }
103
GetStartCursor(DKRecordType recordType,DKQueryCursor & cursor)104 DKError DKDatabase::GetStartCursor(DKRecordType recordType, DKQueryCursor &cursor)
105 {
106 GTEST_LOG_(INFO) << "GetStartCursor begin";
107 DKError e;
108 if (recordType == "err") {
109 e.isLocalError = true;
110 return e;
111 }
112 return e;
113 }
GenerateIds(int count,std::vector<DKRecordId> & ids)114 DKError DKDatabase::GenerateIds(int count, std::vector<DKRecordId> &ids)
115 {
116 DKError e;
117 return e;
118 }
GetLock(DKLock & lock)119 DKError DKDatabase::GetLock(DKLock &lock)
120 {
121 DKError e;
122 if (lock.lockInterval == -1) {
123 e.isLocalError = true;
124 }
125 return e;
126 }
DeleteLock(DKLock lock)127 void DKDatabase::DeleteLock(DKLock lock) {}
GetAssetsDownloader()128 std::shared_ptr<DKAssetsDownloader> DKDatabase::GetAssetsDownloader()
129 {
130 return std::make_shared<DKAssetsDownloader>(shared_from_this());
131 }
NewAssetReadSession(DKRecordType recordType,DKRecordId recordId,DKFieldKey assetKey,DKAssetPath assetPath)132 std::shared_ptr<DKAssetReadSession> DKDatabase::NewAssetReadSession(DKRecordType recordType,
133 DKRecordId recordId,
134 DKFieldKey assetKey,
135 DKAssetPath assetPath)
136 {
137 return std::make_shared<DKAssetReadSession>();
138 }
DKDatabase(std::shared_ptr<DKContainer> container,DKDatabaseScope scope)139 DKDatabase::DKDatabase(std::shared_ptr<DKContainer> container, DKDatabaseScope scope) {}
Init()140 void DKDatabase::Init() {}
141 } // namespace DriveKit
142