1 /* 2 * Copyright (c) 2025 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 #include <gmock/gmock.h> 18 19 // mock 20 #include "alarm_timer_manager.h" 21 #include "setting_data_manager.h" 22 23 #define private public 24 #include "smart_gesture_manager.h" 25 #undef private 26 27 using namespace testing; 28 using namespace testing::ext; 29 30 namespace OHOS::ArkUi::UiAppearance { 31 namespace { 32 const std::string SETTING_SMART_GESTURE_SWITCH_KEY = "persist.gesture.smart_gesture_enable"; 33 } 34 35 class SmartGestureManagerTest : public Test { 36 protected: SetUp()37 void SetUp() override 38 { 39 SmartGestureManager& manager = SmartGestureManager::GetInstance(); 40 EXPECT_EQ(manager.Initialize([this](const bool isAutoMode, const int32_t userId) { 41 UpdateCallback(isAutoMode, userId); 42 }), ERR_OK); 43 } 44 TearDown()45 void TearDown() override 46 { 47 SmartGestureManager& manager = SmartGestureManager::GetInstance(); 48 manager.updateCallback_ = nullptr; 49 } 50 UpdateCallback(bool isAutoMode,int32_t userId)51 void UpdateCallback(bool isAutoMode, int32_t userId) {} 52 }; 53 54 /** 55 * @tc.name: LoadSettingDataObserver_0100 56 * @tc.desc: Test LoadSettingDataObserversCallback 57 * @tc.type: FUNC 58 */ 59 HWTEST_F(SmartGestureManagerTest, LoadSettingDataObserver_0100, TestSize.Level1) 60 { 61 SmartGestureManager& manager = SmartGestureManager::GetInstance(); 62 manager.observer_.first = ""; 63 manager.LoadSettingDataObserversCallback(); 64 manager.UpdateSmartGestureInitialValue(); 65 manager.UpdateSmartGestureValue(SETTING_SMART_GESTURE_SWITCH_KEY, INVALID_USER_ID); 66 EXPECT_EQ(manager.observer_.first, SETTING_SMART_GESTURE_SWITCH_KEY); 67 } 68 69 /** 70 * @tc.name: RegisterSettingDataObserver_0100 71 * @tc.desc: Test OnChangeSmartGestureMode after register observer 72 * @tc.type: FUNC 73 */ 74 HWTEST_F(SmartGestureManagerTest, RegisterSettingDataObserver_0100, TestSize.Level1) 75 { 76 SmartGestureManager& manager = SmartGestureManager::GetInstance(); 77 auto result = manager.RegisterSettingDataObserver(); 78 manager.OnChangeSmartGestureMode(SmartGestureManager::SmartGestureMode::SMART_GESTURE_DISABLE, INVALID_USER_ID); 79 manager.updateCallback_ = nullptr; 80 manager.OnChangeSmartGestureMode(SmartGestureManager::SmartGestureMode::SMART_GESTURE_DISABLE, INVALID_USER_ID); 81 EXPECT_EQ(result, ERR_OK); 82 } 83 84 /** 85 * @tc.name: RegisterSettingDataObserver_0100 86 * @tc.desc: Test register setting data observer registration failure exception 87 * @tc.type: FUNC 88 */ 89 HWTEST_F(SmartGestureManagerTest, RegisterSettingDataObserver_0200, TestSize.Level1) 90 { 91 SettingDataManager& settingDataManager = SettingDataManager::GetInstance(); 92 ExpectationSet expectSet; 93 expectSet += EXPECT_CALL( 94 settingDataManager, MockRegisterObserver(SETTING_SMART_GESTURE_SWITCH_KEY, _, INVALID_USER_ID)) 95 .Times(1).After(expectSet).WillOnce(Return(ERR_INVALID_OPERATION)); 96 SmartGestureManager& manager = SmartGestureManager::GetInstance(); 97 auto result = manager.RegisterSettingDataObserver(); 98 EXPECT_EQ(result, ERR_NO_INIT); 99 } 100 } // namespace OHOS::ArkUi::UiAppearance 101