• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "object_service_proxy.h"
19 #include "objectstore_errors.h"
20 
21 using namespace testing::ext;
22 using namespace OHOS::ObjectStore;
23 using namespace OHOS::DistributedObject;
24 using namespace OHOS;
25 using namespace std;
26 
27 namespace {
28 class ObjectServiceProxyTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34 };
35 
SetUpTestCase(void)36 void ObjectServiceProxyTest::SetUpTestCase(void)
37 {
38     // input testsuit setup step,setup invoked before all testcases
39 }
40 
TearDownTestCase(void)41 void ObjectServiceProxyTest::TearDownTestCase(void)
42 {
43     // input testsuit teardown step,teardown invoked after all testcases
44 }
45 
SetUp(void)46 void ObjectServiceProxyTest::SetUp(void)
47 {
48     // input testcase setup step,setup invoked before each testcases
49 }
50 
TearDown(void)51 void ObjectServiceProxyTest::TearDown(void)
52 {
53     // input testcase teardown step,teardown invoked after each testcases
54 }
55 
56 /**
57  * @tc.name: OnAssetChanged_001
58  * @tc.desc: Abnormal test for OnAssetChanged, impl is nullptr
59  * @tc.type: FUNC
60  */
61 HWTEST_F(ObjectServiceProxyTest, OnAssetChanged_001, TestSize.Level1)
62 {
63     string bundleName = "com.example.myapplication";
64     string sessionId = "123456";
65     string deviceId = "devideId";
66     Asset assetValue = {
67             .version = 0,
68             .status = 0,
69             .id = "id",
70             .name = "1.txt",
71             .uri = "file://com.example.myapp/data/dir/1.txt",
72             .createTime = "2024/10/26 19:48:00",
73             .modifyTime = "2024/10/26 20:10:00",
74             .size = "1",
75             .hash = "hash",
76             .path = "/dir/1.txt",
77     };
78     sptr<IRemoteObject> impl;
79     ObjectServiceProxy objectServiceProxy(impl);
80     int32_t ret = objectServiceProxy.OnAssetChanged(bundleName, sessionId, deviceId, assetValue);
81     EXPECT_EQ(ret, OHOS::ObjectStore::ERR_IPC);
82 }
83 
84 /**
85  * @tc.name: BindAssetStore_001
86  * @tc.desc: Abnormal test for BindAssetStore, impl is nullptr
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ObjectServiceProxyTest, BindAssetStore_001, TestSize.Level1)
90 {
91     string bundleName = "com.example.myapplication";
92     string sessionId = "123456";
93     Asset asset = {
94             .version = 0,
95             .status = 0,
96             .id = "id",
97             .name = "1.txt",
98             .uri = "file://com.example.myapp/data/dir/1.txt",
99             .createTime = "2024/10/26 19:48:00",
100             .modifyTime = "2024/10/26 20:10:00",
101             .size = "1",
102             .hash = "hash",
103             .path = "/dir/1.txt",
104     };
105     AssetBindInfo bindInfo = {
106         .storeName = "storeName",
107         .tableName = "tableName",
108         .primaryKey = {
109             {"data1", 123},
110             {"data2", "test1"}
111         },
112         .field = "field",
113         .assetName = "assetName"
114     };
115     sptr<IRemoteObject> impl;
116     ObjectServiceProxy objectServiceProxy(impl);
117     int32_t ret = objectServiceProxy.BindAssetStore(bundleName, sessionId, asset, bindInfo);
118     EXPECT_EQ(ret, OHOS::ObjectStore::ERR_IPC);
119 }
120 }
121