• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
17 #include "gtest/gtest.h"
18 
19 #define private public
20 #define protected public
21 #include "reminder_affected.h"
22 #include "string_utils.h"
23 #undef private
24 #undef protected
25 
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace Notification {
29 class ReminderAffectedTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {};
TearDownTestCase()32     static void TearDownTestCase() {};
SetUp()33     void SetUp() {};
TearDown()34     void TearDown() {};
35 };
36 
37 /**
38  * @tc.name: Test FromJson
39  * @tc.desc: Test FromJson
40  * @tc.type: FUNC
41  */
42 HWTEST_F(ReminderAffectedTest, FromJson_00001, Function | SmallTest | Level1)
43 {
44     ReminderAffected reminderAffected;
45     nlohmann::json jsonObject = nlohmann::json{
46         "test", "test"
47     };
48     auto res = reminderAffected.FromJson(jsonObject);
49     ASSERT_FALSE(res);
50 }
51 
52 /**
53  * @tc.name: Test ValidAndGetAffectedBy
54  * @tc.desc: Test ValidAndGetAffectedBy
55  * @tc.type: FUNC
56  */
57 HWTEST_F(ReminderAffectedTest, ValidAndGetAffectedBy_00001, Function | SmallTest | Level1)
58 {
59     ReminderAffected reminderAffected;
60     nlohmann::json jsonObject = nlohmann::json{
61         ReminderAffected::AFFECTED_BY, "test"
62     };
63 
64     std::vector<std::pair<std::string, std::string>> affectedBy;
65     auto res = reminderAffected.ValidAndGetAffectedBy(jsonObject, affectedBy);
66     ASSERT_FALSE(res);
67 }
68 
69 /**
70  * @tc.name: Test ValidAndGetAffectedBy
71  * @tc.desc: Test ValidAndGetAffectedBy
72  * @tc.type: FUNC
73  */
74 HWTEST_F(ReminderAffectedTest, ValidAndGetAffectedBy_00002, Function | SmallTest | Level1)
75 {
76     ReminderAffected reminderAffected;
77     nlohmann::json jsonObject = nlohmann::json{
78         ReminderAffected::AFFECTED_BY, {{"test", "test"}, {ReminderAffected::DEVICE_TYPE, ""}}
79     };
80     std::vector<std::pair<std::string, std::string>> affectedBy;
81     auto res = reminderAffected.ValidAndGetAffectedBy(jsonObject, affectedBy);
82     ASSERT_FALSE(res);
83 
84     jsonObject = nlohmann::json{
85         ReminderAffected::AFFECTED_BY, {}
86     };
87     res = reminderAffected.ValidAndGetAffectedBy(jsonObject, affectedBy);
88     ASSERT_FALSE(res);
89 }
90 
91 /**
92  * @tc.name: Test ValidStatus
93  * @tc.desc: Test ValidStatus
94  * @tc.type: FUNC
95  */
96 HWTEST_F(ReminderAffectedTest, ValidStatus_00001, Function | SmallTest | Level1)
97 {
98     ReminderAffected reminderAffected;
99     nlohmann::json jsonObject = nlohmann::json{
100         {ReminderAffected::DEVICE_TYPE, "test"}, {ReminderAffected::STATUS, 1}
101     };
102 
103     std::string status = "test1";
104     auto res = reminderAffected.ValidStatus(jsonObject, status);
105     ASSERT_FALSE(res);
106     ASSERT_EQ(status, "test1");
107 
108     jsonObject = nlohmann::json{
109         {ReminderAffected::DEVICE_TYPE, "test"}, {ReminderAffected::STATUS, ""}
110     };
111     res = reminderAffected.ValidStatus(jsonObject, status);
112     ASSERT_TRUE(res);
113     ASSERT_EQ(status, "test1");
114 
115     jsonObject = nlohmann::json{
116         {ReminderAffected::DEVICE_TYPE, "test"}, {ReminderAffected::STATUS, "123"}
117     };
118     res = reminderAffected.ValidStatus(jsonObject, status);
119     ASSERT_FALSE(res);
120     ASSERT_EQ(status, "test1");
121 
122     jsonObject = nlohmann::json{
123         {ReminderAffected::DEVICE_TYPE, "test"}, {ReminderAffected::STATUS, "xxx1"}
124     };
125     res = reminderAffected.ValidStatus(jsonObject, status);
126     ASSERT_TRUE(res);
127     ASSERT_EQ(status, "xxx1");
128 }
129 
130 /**
131  * @tc.name: Test StringUtils
132  * @tc.desc: Test StringUtils
133  * @tc.type: FUNC
134  */
135 HWTEST_F(ReminderAffectedTest, StringUtils_00001, Function | SmallTest | Level1)
136 {
137     const std::string str = "test, test";
138     const std::string splitFlag = ",";
139     std::vector<std::string> res;
140 
141     StringUtils::Split("", splitFlag, res);
142     ASSERT_EQ(res.size(), 0);
143 
144     StringUtils::Split(str, splitFlag, res);
145     ASSERT_EQ(res.size(), 2);
146 }
147 }  // namespace Notification
148 }  // namespace OHOS
149 #endif