1 /* 2 * Copyright (c) 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 #define private public 19 #define protected public 20 #include "reminder_store.h" 21 #undef private 22 #undef protected 23 #include "reminder_helper.h" 24 #include "notification_preferences.h" 25 26 using namespace testing::ext; 27 namespace OHOS { 28 namespace Notification { 29 namespace { 30 constexpr int32_t NON_SYSTEM_APP_UID = 1000; 31 const std::string TEST_DEFUALT_BUNDLE = "bundleName"; 32 const int32_t STATE_FAIL = -1; 33 } 34 class ReminderStoreTest : public testing::Test { 35 public: SetUpTestCase()36 static void SetUpTestCase() 37 { 38 ReminderHelper::CancelAllReminders(); 39 } TearDownTestCase()40 static void TearDownTestCase() {} SetUp()41 void SetUp() {} TearDown()42 void TearDown() 43 { 44 ReminderHelper::CancelAllReminders(); 45 } 46 static sptr<NotificationBundleOption> bundleOption_; 47 }; 48 49 sptr<NotificationBundleOption> ReminderStoreTest::bundleOption_ = 50 new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); 51 52 /** 53 * @tc.name: Init_00001 54 * @tc.desc: Test Init parameters. 55 * @tc.type: FUNC 56 * @tc.require: issueI5VB6V 57 */ 58 HWTEST_F(ReminderStoreTest, Init_00001, Function | SmallTest | Level1) 59 { 60 ReminderStore reminderStore; 61 int32_t ret = reminderStore.Init(); 62 EXPECT_EQ(ret, 0); 63 } 64 65 /** 66 * @tc.name: InitData_00001 67 * @tc.desc: Test InitData parameters. 68 * @tc.type: FUNC 69 * @tc.require: issueI5VB6V 70 */ 71 HWTEST_F(ReminderStoreTest, InitData_00001, Function | SmallTest | Level1) 72 { 73 ReminderStore reminderStore; 74 int32_t ret = reminderStore.InitData(); 75 EXPECT_EQ(ret, -1); 76 } 77 78 /** 79 * @tc.name: Delete_00001 80 * @tc.desc: Test Delete parameters. 81 * @tc.type: FUNC 82 * @tc.require: issueI5VB6V 83 */ 84 HWTEST_F(ReminderStoreTest, Delete_00001, Function | SmallTest | Level1) 85 { 86 int32_t reminderId = 1; 87 ReminderStore reminderStore; 88 int32_t ret = reminderStore.Delete(reminderId); 89 EXPECT_EQ(ret, -1); 90 } 91 92 /** 93 * @tc.name: Delete_00002 94 * @tc.desc: Test Delete parameters. 95 * @tc.type: FUNC 96 * @tc.require: issueI5VB6V 97 */ 98 HWTEST_F(ReminderStoreTest, Delete_00002, Function | SmallTest | Level1) 99 { 100 std::string pkg = "pkg"; 101 int32_t userId = 1; 102 ReminderStore reminderStore; 103 int32_t ret = reminderStore.Delete(pkg, userId); 104 EXPECT_EQ(ret, -1); 105 } 106 107 /** 108 * @tc.name: Delete_00003 109 * @tc.desc: Test Delete parameters. 110 * @tc.type: FUNC 111 * @tc.require: issueI5VB6V 112 */ 113 HWTEST_F(ReminderStoreTest, Delete_00003, Function | SmallTest | Level1) 114 { 115 std::string deleteCondition = "deleteCondition"; 116 ReminderStore reminderStore; 117 int32_t ret = reminderStore.Delete(deleteCondition); 118 EXPECT_EQ(ret, -1); 119 } 120 121 /** 122 * @tc.name: Insert_00001 123 * @tc.desc: Test Insert parameters. 124 * @tc.type: FUNC 125 * @tc.require: issueI5VB6V 126 */ 127 HWTEST_F(ReminderStoreTest, Insert_00001, Function | SmallTest | Level1) 128 { 129 sptr<ReminderRequest> reminder = nullptr; 130 ReminderStore reminderStore; 131 int64_t ret = reminderStore.Insert(reminder, bundleOption_); 132 EXPECT_EQ(ret, -1); 133 } 134 135 /** 136 * @tc.name: Update_00001 137 * @tc.desc: Test Update parameters. 138 * @tc.type: FUNC 139 * @tc.require: issueI5VB6V 140 */ 141 HWTEST_F(ReminderStoreTest, Update_00001, Function | SmallTest | Level1) 142 { 143 sptr<ReminderRequest> reminder = nullptr; 144 ReminderStore reminderStore; 145 int64_t ret = reminderStore.Update(reminder, bundleOption_); 146 EXPECT_EQ(ret, -1); 147 } 148 149 /** 150 * @tc.name: Query_00001 151 * @tc.desc: Test Query parameters. 152 * @tc.type: FUNC 153 * @tc.require: issueI5VB6V 154 */ 155 HWTEST_F(ReminderStoreTest, Query_00001, Function | SmallTest | Level1) 156 { 157 std::string queryCondition = "queryCondition"; 158 std::string name = "it"; 159 ReminderStore reminderStore; 160 reminderStore.GetColumnIndex(name); 161 std::shared_ptr<NativeRdb::AbsSharedResultSet> ret = reminderStore.Query(queryCondition); 162 EXPECT_EQ(ret, nullptr); 163 } 164 165 /** 166 * @tc.name: GetMaxId_00001 167 * @tc.desc: Test GetMaxId parameters. 168 * @tc.type: FUNC 169 * @tc.require: issueI5VB6V 170 */ 171 HWTEST_F(ReminderStoreTest, GetMaxId_00001, Function | SmallTest | Level1) 172 { 173 ReminderStore reminderStore; 174 int32_t ret = reminderStore.GetMaxId(); 175 EXPECT_EQ(ret, STATE_FAIL); 176 } 177 178 /** 179 * @tc.name: GetAllValidReminders_00001 180 * @tc.desc: Test GetAllValidReminders parameters. 181 * @tc.type: FUNC 182 * @tc.require: issueI5VB6V 183 */ 184 HWTEST_F(ReminderStoreTest, GetAllValidReminders_00001, Function | SmallTest | Level1) 185 { 186 ReminderStore reminderStore; 187 std::vector<sptr<ReminderRequest>> ret = reminderStore.GetAllValidReminders(); 188 EXPECT_EQ(ret.size(), 0); 189 } 190 191 /** 192 * @tc.name: GetReminders_00001 193 * @tc.desc: Test GetReminders parameters. 194 * @tc.type: FUNC 195 * @tc.require: issueI5VB6V 196 */ 197 HWTEST_F(ReminderStoreTest, GetReminders_00001, Function | SmallTest | Level1) 198 { 199 std::string queryCondition = "queryCondition"; 200 ReminderStore reminderStore; 201 std::vector<sptr<ReminderRequest>> ret = reminderStore.GetReminders(queryCondition); 202 EXPECT_EQ(ret.size(), 0); 203 } 204 } 205 }