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_10.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 WMClientNativeTest10 : public WMClientNativeTest1 { 32 public: GetDescription() const33 std::string GetDescription() const override 34 { 35 constexpr const char *desc = "move"; 36 return desc; 37 } 38 GetID() const39 int32_t GetID() const override 40 { 41 constexpr int32_t id = 10; 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 std::vector<struct WMDisplayInfo> displays; 55 WindowManager::GetInstance()->GetDisplays(displays); 56 if (displays.size() <= 0) { 57 printf("GetDisplays return no screen\n"); 58 ExitTest(); 59 return; 60 } 61 maxWidth = displays[0].width; 62 maxHeight = displays[0].height; 63 WMClientNativeTest1::Run(argc, argv); 64 65 window->Resize(maxWidth / 0x2, maxHeight / 0x2); 66 AfterRun(); 67 } 68 AfterRun()69 void AfterRun() 70 { 71 constexpr int32_t step = 37; 72 constexpr int32_t minWidthHeight = 100; 73 static int32_t width = maxWidth; 74 static int32_t height = maxHeight; 75 width -= step; 76 height -= step; 77 if (width < minWidthHeight) { 78 width += maxWidth; 79 } 80 if (height < minWidthHeight) { 81 height += maxHeight; 82 } 83 window->Move(width, height); 84 85 constexpr uint32_t delayTime = 100; 86 PostTask(std::bind(&WMClientNativeTest10::AfterRun, this), delayTime); 87 } 88 89 private: 90 uint32_t maxWidth = 0; 91 uint32_t maxHeight = 0; 92 } g_autoload; 93 } // namespace 94