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 <gtest/gtest.h>
17 #include <unistd.h>
18
19 #include "flat_object_store.h"
20
21 #include "accesstoken_kit.h"
22 #include "block_data.h"
23 #include "bytes_utils.h"
24 #include "client_adaptor.h"
25 #include "distributed_objectstore_impl.h"
26 #include "ipc_skeleton.h"
27 #include "logger.h"
28 #include "object_callback_impl.h"
29 #include "object_radar_reporter.h"
30 #include "object_service_proxy.h"
31 #include "objectstore_errors.h"
32 #include "softbus_adapter.h"
33 #include "string_utils.h"
34
35 #define OMIT_MULTI_VER
36
37 using namespace testing::ext;
38 using namespace OHOS::ObjectStore;
39 using namespace OHOS;
40 using namespace std;
41
42 namespace {
43 class FlatObjectStoreTest : public testing::Test {
44 public:
45 static void SetUpTestCase(void);
46 static void TearDownTestCase(void);
47 void SetUp();
48 void TearDown();
49 };
50
SetUpTestCase(void)51 void FlatObjectStoreTest::SetUpTestCase(void)
52 {
53 // input testsuit setup step,setup invoked before all testcases
54 }
55
TearDownTestCase(void)56 void FlatObjectStoreTest::TearDownTestCase(void)
57 {
58 // input testsuit teardown step,teardown invoked after all testcases
59 }
60
SetUp(void)61 void FlatObjectStoreTest::SetUp(void)
62 {
63 // input testcase setup step,setup invoked before each testcases
64 }
65
TearDown(void)66 void FlatObjectStoreTest::TearDown(void)
67 {
68 // input testcase teardown step,teardown invoked after each testcases
69 }
70
71 /**
72 * @tc.name: BindAssetStore_001
73 * @tc.desc: Abnormal test for BindAssetStore, data is not stored
74 * @tc.type: FUNC
75 */
76
77 HWTEST_F(FlatObjectStoreTest, BindAssetStore_001, TestSize.Level1)
78 {
79 string sessionId = "123";
80 AssetBindInfo bindInfo = {
81 .storeName = "storeName",
82 .tableName = "tableName",
83 .primaryKey = {
84 {"data1", 123},
85 {"data2", "test1"}
86 },
87 .field = "field",
88 .assetName = "assetName"
89 };
90 Asset assetValue = {
91 .version = 0,
92 .status = 0,
93 .id = "id",
94 .name = "1.txt",
95 .uri = "file://com.example.myapp/data/dir/1.txt",
96 .createTime = "2024/10/26 19:48:00",
97 .modifyTime = "2024/10/26 20:10:00",
98 .size = "1",
99 .hash = "hash",
100 .path = "/dir/1.txt",
101 };
102 std::string bundleName = "default";
103 FlatObjectStore flatObjectStore = FlatObjectStore(bundleName);
104 uint32_t ret = flatObjectStore.BindAssetStore(sessionId, bindInfo, assetValue);
105 EXPECT_NE(ret, SUCCESS);
106 }
107
108 /**
109 * @tc.name: GetBundleName_001
110 * @tc.desc: Normal test for GetBundleName
111 * @tc.type: FUNC
112 */
113
114 HWTEST_F(FlatObjectStoreTest, GetBundleName_001, TestSize.Level1)
115 {
116 std::string bundleName = "default";
117 FlatObjectStore flatObjectStore = FlatObjectStore(bundleName);
118 flatObjectStore.bundleName_ = bundleName;
119 std::string ret = flatObjectStore.GetBundleName();
120 EXPECT_EQ(ret, bundleName);
121 }
122 }
123