1 /* 2 * Copyright (c) 2023 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 "iconsumer_surface.h" 18 #include "ohos_adapter_helper.h" 19 #include "window.h" 20 21 using testing::ext::TestSize; 22 23 namespace OHOS::NWeb { 24 /** 25 * @tc.name: NormalTest. 26 * @tc.desc: test WindowAdapterImpl class function. 27 * @tc.type: FUNC. 28 * @tc.require: 29 */ 30 HWTEST(WindowAdapterImplTest, NormalTest, TestSize.Level1) 31 { 32 auto cSurface = IConsumerSurface::Create("test"); 33 auto producer = cSurface->GetProducer(); 34 auto pSurface = Surface::CreateSurfaceAsProducer(producer); 35 auto window = OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().CreateNativeWindowFromSurface(nullptr); 36 EXPECT_EQ(window, nullptr); 37 window = OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().CreateNativeWindowFromSurface(&pSurface); 38 EXPECT_NE(window, nullptr); 39 EXPECT_EQ(OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowSetBufferGeometry( 40 window, 0, 0), OHOS::GSERROR_OK); 41 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowSurfaceCleanCache(window); 42 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowSurfaceCleanCacheWithPara(window, false); 43 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().DestroyNativeWindow(window); 44 window = nullptr; 45 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowSurfaceCleanCacheWithPara(window, false); 46 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().AddNativeWindowRef(window); 47 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowUnRef(window); 48 cSurface = IConsumerSurface::Create("test1"); 49 producer = cSurface->GetProducer(); 50 pSurface = Surface::CreateSurfaceAsProducer(producer); 51 window = OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().CreateNativeWindowFromSurface(&pSurface); 52 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().AddNativeWindowRef(window); 53 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().NativeWindowUnRef(window); 54 window = nullptr; 55 } 56 57 /** 58 * @tc.name: NormalTest. 59 * @tc.desc: test AshmemAdapterImplTest class function. 60 * @tc.type: FUNC. 61 * @tc.require: 62 */ 63 HWTEST(AshmemAdapterImplTest, NormalTest, TestSize.Level1) 64 { 65 size_t size = 1024; 66 EXPECT_GE(AshmemAdapter::AshmemCreate("test", size), 0); 67 } 68 69 /** 70 * @tc.name: WindowAdapterImplTest_001 71 * @tc.desc: test WindowAdapterImpl class function. 72 * @tc.type: FUNC. 73 * @tc.require: 74 */ 75 HWTEST(WindowAdapterImplTest, WindowAdapterImplTest_001, TestSize.Level1) 76 { 77 auto cSurface = IConsumerSurface::Create("test"); 78 auto producer = cSurface->GetProducer(); 79 auto pSurface = Surface::CreateSurfaceAsProducer(producer); 80 auto window = OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().CreateNativeWindowFromSurface(&pSurface); 81 uint32_t angle = 0; 82 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 83 angle = 90; 84 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 85 angle = 180; 86 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 87 angle = 270; 88 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 89 angle = 300; 90 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 91 window = nullptr; 92 OhosAdapterHelper::GetInstance().GetWindowAdapterInstance().SetTransformHint(angle, window); 93 } 94 } // namespace OHOS::NWeb 95