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 "wmclient_native_test_26.h" 17 18 #include <cstdio> 19 #include <securec.h> 20 21 #include <display_type.h> 22 #include <window_manager.h> 23 24 #include "native_test_class.h" 25 #include "util.h" 26 #include "wmclient_native_test_1.h" 27 28 using namespace OHOS; 29 30 namespace { 31 class WMClientNativeTest26 : public WMClientNativeTest1 { 32 public: GetDescription() const33 std::string GetDescription() const override 34 { 35 constexpr const char *desc = "scaleto"; 36 return desc; 37 } 38 GetID() const39 int32_t GetID() const override 40 { 41 constexpr int32_t id = 26; 42 return id; 43 } 44 Run(int32_t argc,const char ** argv)45 void Run(int32_t argc, const char **argv) override 46 { 47 auto initRet = WindowManager::GetInstance()->Init(); 48 if (initRet) { 49 printf("init failed with %s\n", GSErrorStr(initRet).c_str()); 50 ExitTest(); 51 return; 52 } 53 54 WMClientNativeTest1::Run(argc, argv); 55 std::vector<struct WMDisplayInfo> displays; 56 WindowManager::GetInstance()->GetDisplays(displays); 57 if (displays.size() <= 0) { 58 printf("GetDisplays return no screen\n"); 59 ExitTest(); 60 return; 61 } 62 maxWidth = displays[0].width; 63 maxHeight = displays[0].height; 64 AfterRun(); 65 } 66 AfterRun()67 void AfterRun() 68 { 69 constexpr int32_t step = 37; 70 constexpr int32_t minWidthHeight = 100; 71 static int32_t width = maxWidth; 72 static int32_t height = maxHeight; 73 width -= step; 74 height -= step; 75 if (width < minWidthHeight) { 76 width += maxWidth; 77 } 78 if (height < minWidthHeight) { 79 height += maxHeight; 80 } 81 window->ScaleTo(width, height); 82 83 constexpr uint32_t delayTime = 100; 84 PostTask(std::bind(&WMClientNativeTest26::AfterRun, this), delayTime); 85 } 86 87 private: 88 uint32_t maxWidth = 0; 89 uint32_t maxHeight = 0; 90 } g_autoload; 91 } // namespace 92