1 /* 2 * Copyright (c) 2021 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 <cstdio> 17 #include <gtest/gtest.h> 18 19 #include "volume/notification.h" 20 21 namespace { 22 using namespace std; 23 using namespace OHOS; 24 using namespace StorageManager; 25 class NotificationTest : public testing::Test { 26 public: SetUpTestCase(void)27 static void SetUpTestCase(void) {}; TearDownTestCase()28 static void TearDownTestCase() {}; SetUp()29 void SetUp() {}; TearDown()30 void TearDown() {}; 31 }; 32 33 /** 34 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0000 35 * @tc.name: Notification_NotifyVolumeChange_0000 36 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 37 * @tc.size: MEDIUM 38 * @tc.type: FUNC 39 * @tc.level Level 1 40 * @tc.require: SR000GGUPF 41 */ 42 43 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0000, testing::ext::TestSize.Level1) 44 { 45 GTEST_LOG_(INFO) << "NotificationTest-begin Notification_NotifyVolumeChange_0000"; 46 std::string volumeId = "vol-1-1"; 47 int32_t fsType = 1; 48 std::string diskId = "disk-1-1"; 49 VolumeCore vc(volumeId, fsType, diskId); 50 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 51 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 52 notification->NotifyVolumeChange(VolumeState::REMOVED, volume); 53 EXPECT_EQ(vc.GetDiskId(), diskId); 54 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0000"; 55 } 56 57 /** 58 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0001 59 * @tc.name: Notification_NotifyVolumeChange_0001 60 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 61 * @tc.size: MEDIUM 62 * @tc.type: FUNC 63 * @tc.level Level 1 64 * @tc.require: SR000GGUPF 65 */ 66 67 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0001, testing::ext::TestSize.Level1) 68 { 69 GTEST_LOG_(INFO) << "NotificationTestt-begin Notification_NotifyVolumeChange_0001"; 70 std::string volumeId = "vol-1-1"; 71 int32_t fsType = 1; 72 std::string diskId = "disk-1-1"; 73 VolumeCore vc(volumeId, fsType, diskId); 74 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 75 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 76 notification->NotifyVolumeChange(VolumeState::UNMOUNTED, volume); 77 EXPECT_EQ(vc.GetDiskId(), diskId); 78 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0001"; 79 } 80 81 /** 82 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0002 83 * @tc.name: Notification_NotifyVolumeChange_0002 84 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 85 * @tc.size: MEDIUM 86 * @tc.type: FUNC 87 * @tc.level Level 1 88 * @tc.require: SR000GGUPF 89 */ 90 91 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0002, testing::ext::TestSize.Level1) 92 { 93 GTEST_LOG_(INFO) << "NotificationTest-begin Notification_NotifyVolumeChange_0002"; 94 std::string volumeId = "vol-1-1"; 95 int32_t fsType = 1; 96 std::string diskId = "disk-1-1"; 97 VolumeCore vc(volumeId, fsType, diskId); 98 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 99 volume->SetFsUuid("uuid1"); 100 volume->SetPath("path1"); 101 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 102 notification->NotifyVolumeChange(VolumeState::MOUNTED, volume); 103 EXPECT_EQ(vc.GetDiskId(), diskId); 104 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0002"; 105 } 106 107 /** 108 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0003 109 * @tc.name: Notification_NotifyVolumeChange_0003 110 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 111 * @tc.size: MEDIUM 112 * @tc.type: FUNC 113 * @tc.level Level 1 114 * @tc.require: SR000GGUPF 115 */ 116 117 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0003, testing::ext::TestSize.Level1) 118 { 119 GTEST_LOG_(INFO) << "NotificationTest-begin Notification_NotifyVolumeChange_0003"; 120 std::string volumeId = "vol-1-1"; 121 int32_t fsType = 1; 122 std::string diskId = "disk-1-1"; 123 VolumeCore vc(volumeId, fsType, diskId); 124 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 125 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 126 notification->NotifyVolumeChange(VolumeState::BAD_REMOVAL, volume); 127 EXPECT_EQ(vc.GetDiskId(), diskId); 128 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0003"; 129 } 130 131 /** 132 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0004 133 * @tc.name: Notification_NotifyVolumeChange_0004 134 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 135 * @tc.size: MEDIUM 136 * @tc.type: FUNC 137 * @tc.level Level 1 138 * @tc.require: SR000GGUPF 139 */ 140 141 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0004, testing::ext::TestSize.Level1) 142 { 143 GTEST_LOG_(INFO) << "NotificationTest-begin Notification_NotifyVolumeChange_0004"; 144 std::string volumeId = "vol-1-1"; 145 int32_t fsType = 1; 146 std::string diskId = "disk-1-1"; 147 VolumeCore vc(volumeId, fsType, diskId); 148 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 149 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 150 notification->NotifyVolumeChange(VolumeState::EJECTING, volume); 151 EXPECT_EQ(vc.GetDiskId(), diskId); 152 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0004"; 153 } 154 155 /** 156 * @tc.number: SUB_STORAGE_Notification_NotifyVolumeChange_0005 157 * @tc.name: Notification_NotifyVolumeChange_0005 158 * @tc.desc: Test function of NotifyVolumeChange interface for SUCCESS. 159 * @tc.size: MEDIUM 160 * @tc.type: FUNC 161 * @tc.level Level 1 162 * @tc.require: SR000GGUPF 163 */ 164 165 HWTEST_F(NotificationTest, Notification_NotifyVolumeChange_0005, testing::ext::TestSize.Level1) 166 { 167 GTEST_LOG_(INFO) << "NotificationTest-begin Notification_NotifyVolumeChange_0005"; 168 std::string volumeId = "vol-1-1"; 169 int32_t fsType = 1; 170 std::string diskId = "disk-1-1"; 171 VolumeCore vc(volumeId, fsType, diskId); 172 std::shared_ptr<VolumeExternal> volume = make_shared<VolumeExternal>(vc); 173 std::shared_ptr<Notification> notification = DelayedSingleton<Notification>::GetInstance(); 174 notification->NotifyVolumeChange(VolumeState::CHECKING, volume); 175 EXPECT_EQ(vc.GetDiskId(), diskId); 176 GTEST_LOG_(INFO) << "NotificationTest-end Notification_NotifyVolumeChange_0005"; 177 } 178 } 179