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