1 /*
2  * Copyright (c) 2021-2022 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 
19 #define private public
20 #define protected public
21 #include "user_object_wrapper.h"
22 #include "user_object_base.h"
23 #undef private
24 #undef protected
25 
26 using namespace OHOS;
27 using namespace OHOS::AAFwk;
28 using testing::ext::TestSize;
29 
30 namespace OHOS {
31 namespace AAFwk {
32 namespace {
33 const std::string SPLIT = "#";
34 };
35 class AAfWKUserObjectWrapperTest : public testing::Test {
36 public:
SetUpTestCase()37     static void SetUpTestCase() {};
TearDownTestCase()38     static void TearDownTestCase() {};
SetUp()39     void SetUp() {};
TearDown()40     void TearDown() {};
41 };
42 
43 /**
44  * @tc.number: UserObjectWrapperTest_GetValue_001
45  * @tc.name: GetValue
46  * @tc.desc:
47  */
48 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_GetValue_001, TestSize.Level1)
49 {
50     std::shared_ptr<UserObjectBase> value = nullptr;
51     UserObject useObjectValue(value);
52     ErrCode result = useObjectValue.GetValue(value);
53     EXPECT_EQ(ERR_OK, result);
54 }
55 
56 /**
57  * @tc.number: UserObjectWrapperTest_ToString_001
58  * @tc.name: ToString
59  * @tc.desc:
60  */
61 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_ToString_001, TestSize.Level1)
62 {
63     std::shared_ptr<UserObjectBase> value = nullptr;
64     UserObject useObjectValue(value);
65     EXPECT_EQ("", useObjectValue.ToString());
66 }
67 
68 /**
69  * @tc.number: UserObjectWrapperTest_Box_001
70  * @tc.name: Box
71  * @tc.desc:
72  */
73 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_Box_001, TestSize.Level1)
74 {
75     std::shared_ptr<UserObjectBase> value = nullptr;
76     UserObject useObjectValue(value);
77     EXPECT_EQ(nullptr, useObjectValue.Box(value));
78 }
79 
80 /**
81  * @tc.number: UserObjectWrapperTest_Unbox_001
82  * @tc.name: Unbox
83  * @tc.desc:
84  */
85 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_Unbox_001, TestSize.Level1)
86 {
87     std::shared_ptr<UserObjectBase> value = nullptr;
88     UserObject useObjectValue(value);
89     sptr<IUserObject> object = new (std::nothrow) UserObject(value);
90     EXPECT_EQ(value, useObjectValue.Unbox(object));
91 }
92 
93 /**
94  * @tc.number: UserObjectWrapperTest_Unbox_002
95  * @tc.name: Unbox
96  * @tc.desc:
97  */
98 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_Unbox_002, TestSize.Level1)
99 {
100     std::shared_ptr<UserObjectBase> value = nullptr;
101     UserObject useObjectValue(value);
102     sptr<IUserObject> object = new (std::nothrow) UserObject(value);
103     object = nullptr;
104     EXPECT_EQ(nullptr, useObjectValue.Unbox(object));
105 }
106 
107 /**
108  * @tc.number: UserObjectWrapperTest_Parse_001
109  * @tc.name: Parse
110  * @tc.desc:
111  */
112 HWTEST_F(AAfWKUserObjectWrapperTest, UserObjectWrapperTest_Parse_001, TestSize.Level1)
113 {
114     std::string str = "";
115     std::shared_ptr<UserObjectBase> value = nullptr;
116     UserObject useObjectValue(value);
117     EXPECT_EQ(nullptr, useObjectValue.Parse(str));
118 }
119 }
120 }