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 "distributed_object_impl.h"
20
21 #include "hitrace.h"
22 #include "objectstore_errors.h"
23 #include "string_utils.h"
24 #include "dev_manager.h"
25 #include "bytes_utils.h"
26 #include "object_radar_reporter.h"
27
28 using namespace testing::ext;
29 using namespace OHOS::ObjectStore;
30 using namespace OHOS;
31 using namespace std;
32
33 namespace {
34 class DistributedObjectImplTest : public testing::Test {
35 public:
36 static void SetUpTestCase(void);
37 static void TearDownTestCase(void);
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase(void)42 void DistributedObjectImplTest::SetUpTestCase(void)
43 {
44 // input testsuit setup step,setup invoked before all testcases
45 }
46
TearDownTestCase(void)47 void DistributedObjectImplTest::TearDownTestCase(void)
48 {
49 // input testsuit teardown step,teardown invoked after all testcases
50 }
51
SetUp(void)52 void DistributedObjectImplTest::SetUp(void)
53 {
54 // input testcase setup step,setup invoked before each testcases
55 }
56
TearDown(void)57 void DistributedObjectImplTest::TearDown(void)
58 {
59 // input testcase teardown step,teardown invoked after each testcases
60 }
61
62 /**
63 * @tc.name: BindAssetStore_001
64 * @tc.desc: Abnormal test for BindAssetStore, data is not stored
65 * @tc.type: FUNC
66 */
67
68 HWTEST_F(DistributedObjectImplTest, BindAssetStore_001, TestSize.Level1)
69 {
70 string assetKey = "assetKey";
71 string sessionId = "123";
72 AssetBindInfo bindInfo = {
73 .storeName = "storeName",
74 .tableName = "tableName",
75 .primaryKey = {
76 {"data1", 123},
77 {"data2", "test1"}
78 },
79 .field = "field",
80 .assetName = "assetName"
81 };
82 std::string bundleName = "default";
83 FlatObjectStore *flatObjectStore = new FlatObjectStore(bundleName);
84 DistributedObjectImpl distributedObjectImpl(bundleName, flatObjectStore);
85 uint32_t ret = distributedObjectImpl.BindAssetStore(assetKey, bindInfo);
86 EXPECT_NE(ret, SUCCESS);
87 delete flatObjectStore;
88 }
89 }