132a6e48fSopenharmony_ci/*
232a6e48fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
332a6e48fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
432a6e48fSopenharmony_ci * you may not use this file except in compliance with the License.
532a6e48fSopenharmony_ci * You may obtain a copy of the License at
632a6e48fSopenharmony_ci *
732a6e48fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
832a6e48fSopenharmony_ci *
932a6e48fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1032a6e48fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1132a6e48fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232a6e48fSopenharmony_ci * See the License for the specific language governing permissions and
1332a6e48fSopenharmony_ci * limitations under the License.
1432a6e48fSopenharmony_ci */
1532a6e48fSopenharmony_ci#include <gtest/gtest.h>
1632a6e48fSopenharmony_ci#include "iconsumer_surface.h"
1732a6e48fSopenharmony_ci#include <iservice_registry.h>
1832a6e48fSopenharmony_ci#include <native_window.h>
1932a6e48fSopenharmony_ci#include <securec.h>
2032a6e48fSopenharmony_ci#include <ctime>
2132a6e48fSopenharmony_ci#include "buffer_log.h"
2232a6e48fSopenharmony_ci#include "external_window.h"
2332a6e48fSopenharmony_ci#include "surface_utils.h"
2432a6e48fSopenharmony_ci#include "sync_fence.h"
2532a6e48fSopenharmony_ci#include "ipc_inner_object.h"
2632a6e48fSopenharmony_ci#include "ipc_cparcel.h"
2732a6e48fSopenharmony_ci
2832a6e48fSopenharmony_ciusing namespace std;
2932a6e48fSopenharmony_ciusing namespace testing;
3032a6e48fSopenharmony_ciusing namespace testing::ext;
3132a6e48fSopenharmony_ci
3232a6e48fSopenharmony_cinamespace OHOS::Rosen {
3332a6e48fSopenharmony_ciclass BufferConsumerListener : public IBufferConsumerListener {
3432a6e48fSopenharmony_cipublic:
3532a6e48fSopenharmony_ci    void OnBufferAvailable() override
3632a6e48fSopenharmony_ci    {
3732a6e48fSopenharmony_ci    }
3832a6e48fSopenharmony_ci};
3932a6e48fSopenharmony_ci
4032a6e48fSopenharmony_cistatic OHExtDataHandle *AllocOHExtDataHandle(uint32_t reserveInts)
4132a6e48fSopenharmony_ci{
4232a6e48fSopenharmony_ci    size_t handleSize = sizeof(OHExtDataHandle) + (sizeof(int32_t) * reserveInts);
4332a6e48fSopenharmony_ci    OHExtDataHandle *handle = static_cast<OHExtDataHandle *>(malloc(handleSize));
4432a6e48fSopenharmony_ci    if (handle == nullptr) {
4532a6e48fSopenharmony_ci        BLOGE("AllocOHExtDataHandle malloc %zu failed", handleSize);
4632a6e48fSopenharmony_ci        return nullptr;
4732a6e48fSopenharmony_ci    }
4832a6e48fSopenharmony_ci    auto ret = memset_s(handle, handleSize, 0, handleSize);
4932a6e48fSopenharmony_ci    if (ret != EOK) {
5032a6e48fSopenharmony_ci        BLOGE("AllocOHExtDataHandle memset_s failed");
5132a6e48fSopenharmony_ci        free(handle);
5232a6e48fSopenharmony_ci        return nullptr;
5332a6e48fSopenharmony_ci    }
5432a6e48fSopenharmony_ci    handle->fd = -1;
5532a6e48fSopenharmony_ci    handle->reserveInts = reserveInts;
5632a6e48fSopenharmony_ci    for (uint32_t i = 0; i < reserveInts; i++) {
5732a6e48fSopenharmony_ci        handle->reserve[i] = -1;
5832a6e48fSopenharmony_ci    }
5932a6e48fSopenharmony_ci    return handle;
6032a6e48fSopenharmony_ci}
6132a6e48fSopenharmony_ci
6232a6e48fSopenharmony_cistatic void FreeOHExtDataHandle(OHExtDataHandle *handle)
6332a6e48fSopenharmony_ci{
6432a6e48fSopenharmony_ci    if (handle == nullptr) {
6532a6e48fSopenharmony_ci        BLOGW("FreeOHExtDataHandle with nullptr handle");
6632a6e48fSopenharmony_ci        return ;
6732a6e48fSopenharmony_ci    }
6832a6e48fSopenharmony_ci    if (handle->fd >= 0) {
6932a6e48fSopenharmony_ci        close(handle->fd);
7032a6e48fSopenharmony_ci        handle->fd = -1;
7132a6e48fSopenharmony_ci    }
7232a6e48fSopenharmony_ci    free(handle);
7332a6e48fSopenharmony_ci}
7432a6e48fSopenharmony_ci
7532a6e48fSopenharmony_ciclass NativeWindowTest : public testing::Test {
7632a6e48fSopenharmony_cipublic:
7732a6e48fSopenharmony_ci    static void SetUpTestCase();
7832a6e48fSopenharmony_ci    static void TearDownTestCase();
7932a6e48fSopenharmony_ci
8032a6e48fSopenharmony_ci    static inline BufferRequestConfig requestConfig = {};
8132a6e48fSopenharmony_ci    static inline BufferFlushConfig flushConfig = {};
8232a6e48fSopenharmony_ci    static inline sptr<OHOS::IConsumerSurface> cSurface = nullptr;
8332a6e48fSopenharmony_ci    static inline sptr<OHOS::IBufferProducer> producer = nullptr;
8432a6e48fSopenharmony_ci    static inline sptr<OHOS::Surface> pSurface = nullptr;
8532a6e48fSopenharmony_ci    static inline sptr<OHOS::SurfaceBuffer> sBuffer = nullptr;
8632a6e48fSopenharmony_ci    static inline NativeWindow* nativeWindow = nullptr;
8732a6e48fSopenharmony_ci    static inline NativeWindowBuffer* nativeWindowBuffer = nullptr;
8832a6e48fSopenharmony_ci    static inline uint32_t firstSeqnum = 0;
8932a6e48fSopenharmony_ci};
9032a6e48fSopenharmony_ci
9132a6e48fSopenharmony_civoid NativeWindowTest::SetUpTestCase()
9232a6e48fSopenharmony_ci{
9332a6e48fSopenharmony_ci    requestConfig = {
9432a6e48fSopenharmony_ci        .width = 0x100,  // small
9532a6e48fSopenharmony_ci        .height = 0x100, // small
9632a6e48fSopenharmony_ci        .strideAlignment = 0x8,
9732a6e48fSopenharmony_ci        .format = GRAPHIC_PIXEL_FMT_RGBA_8888,
9832a6e48fSopenharmony_ci        .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
9932a6e48fSopenharmony_ci        .timeout = 0,
10032a6e48fSopenharmony_ci    };
10132a6e48fSopenharmony_ci
10232a6e48fSopenharmony_ci    cSurface = IConsumerSurface::Create();
10332a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
10432a6e48fSopenharmony_ci    cSurface->RegisterConsumerListener(listener);
10532a6e48fSopenharmony_ci    producer = cSurface->GetProducer();
10632a6e48fSopenharmony_ci    pSurface = Surface::CreateSurfaceAsProducer(producer);
10732a6e48fSopenharmony_ci    int32_t fence;
10832a6e48fSopenharmony_ci    pSurface->RequestBuffer(sBuffer, fence, requestConfig);
10932a6e48fSopenharmony_ci    firstSeqnum = sBuffer->GetSeqNum();
11032a6e48fSopenharmony_ci}
11132a6e48fSopenharmony_ci
11232a6e48fSopenharmony_civoid NativeWindowTest::TearDownTestCase()
11332a6e48fSopenharmony_ci{
11432a6e48fSopenharmony_ci    flushConfig = { .damage = {
11532a6e48fSopenharmony_ci        .w = 0x100,
11632a6e48fSopenharmony_ci        .h = 0x100,
11732a6e48fSopenharmony_ci    } };
11832a6e48fSopenharmony_ci    pSurface->FlushBuffer(sBuffer, -1, flushConfig);
11932a6e48fSopenharmony_ci    sBuffer = nullptr;
12032a6e48fSopenharmony_ci    cSurface = nullptr;
12132a6e48fSopenharmony_ci    producer = nullptr;
12232a6e48fSopenharmony_ci    pSurface = nullptr;
12332a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindow);
12432a6e48fSopenharmony_ci    nativeWindow = nullptr;
12532a6e48fSopenharmony_ci    nativeWindowBuffer = nullptr;
12632a6e48fSopenharmony_ci}
12732a6e48fSopenharmony_ci
12832a6e48fSopenharmony_ci/*
12932a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindow
13032a6e48fSopenharmony_ci* Type: Function
13132a6e48fSopenharmony_ci* Rank: Important(2)
13232a6e48fSopenharmony_ci* EnvConditions: N/A
13332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow by abnormal input
13432a6e48fSopenharmony_ci*                  2. check ret
13532a6e48fSopenharmony_ci */
13632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindow001, Function | MediumTest | Level2)
13732a6e48fSopenharmony_ci{
13832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_CreateNativeWindow(nullptr), nullptr);
13932a6e48fSopenharmony_ci}
14032a6e48fSopenharmony_ci
14132a6e48fSopenharmony_ci/*
14232a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindow
14332a6e48fSopenharmony_ci* Type: Function
14432a6e48fSopenharmony_ci* Rank: Important(2)
14532a6e48fSopenharmony_ci* EnvConditions: N/A
14632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
14732a6e48fSopenharmony_ci*                  2. check ret
14832a6e48fSopenharmony_ci */
14932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindow002, Function | MediumTest | Level2)
15032a6e48fSopenharmony_ci{
15132a6e48fSopenharmony_ci    nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
15232a6e48fSopenharmony_ci    ASSERT_NE(nativeWindow, nullptr);
15332a6e48fSopenharmony_ci}
15432a6e48fSopenharmony_ci
15532a6e48fSopenharmony_ci/*
15632a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindow
15732a6e48fSopenharmony_ci* Type: Function
15832a6e48fSopenharmony_ci* Rank: Important(2)
15932a6e48fSopenharmony_ci* EnvConditions: N/A
16032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
16132a6e48fSopenharmony_ci*                  2. check ret
16232a6e48fSopenharmony_ci */
16332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindow003, Function | MediumTest | Level2)
16432a6e48fSopenharmony_ci{
16532a6e48fSopenharmony_ci    uint64_t surfaceId = 0;
16632a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_GetSurfaceId(nativeWindow, &surfaceId);
16732a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_OK);
16832a6e48fSopenharmony_ci    ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
16932a6e48fSopenharmony_ci}
17032a6e48fSopenharmony_ci
17132a6e48fSopenharmony_ci/*
17232a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindow
17332a6e48fSopenharmony_ci* Type: Function
17432a6e48fSopenharmony_ci* Rank: Important(2)
17532a6e48fSopenharmony_ci* EnvConditions: N/A
17632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindow
17732a6e48fSopenharmony_ci*                  2. check ret
17832a6e48fSopenharmony_ci */
17932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindow004, Function | MediumTest | Level2)
18032a6e48fSopenharmony_ci{
18132a6e48fSopenharmony_ci    sptr<OHOS::Surface> surfaceTmp = nullptr;
18232a6e48fSopenharmony_ci    auto nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&surfaceTmp);
18332a6e48fSopenharmony_ci    ASSERT_EQ(nativeWindowTmp, nullptr);
18432a6e48fSopenharmony_ci}
18532a6e48fSopenharmony_ci
18632a6e48fSopenharmony_ci/*
18732a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
18832a6e48fSopenharmony_ci* Type: Function
18932a6e48fSopenharmony_ci* Rank: Important(2)
19032a6e48fSopenharmony_ci* EnvConditions: N/A
19132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
19232a6e48fSopenharmony_ci*                  2. check ret
19332a6e48fSopenharmony_ci */
19432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId001, Function | MediumTest | Level2)
19532a6e48fSopenharmony_ci{
19632a6e48fSopenharmony_ci    uint64_t surfaceId = static_cast<uint64_t>(pSurface->GetUniqueId());
19732a6e48fSopenharmony_ci    OHNativeWindow *window = nullptr;
19832a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &window);
19932a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_OK);
20032a6e48fSopenharmony_ci    surfaceId = 0;
20132a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetSurfaceId(window, &surfaceId);
20232a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_OK);
20332a6e48fSopenharmony_ci    ASSERT_EQ(surfaceId, pSurface->GetUniqueId());
20432a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(window);
20532a6e48fSopenharmony_ci}
20632a6e48fSopenharmony_ci
20732a6e48fSopenharmony_ci/*
20832a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
20932a6e48fSopenharmony_ci* Type: Function
21032a6e48fSopenharmony_ci* Rank: Important(2)
21132a6e48fSopenharmony_ci* EnvConditions: N/A
21232a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
21332a6e48fSopenharmony_ci*                  2. check ret
21432a6e48fSopenharmony_ci */
21532a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId002, Function | MediumTest | Level2)
21632a6e48fSopenharmony_ci{
21732a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0, nullptr);
21832a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
21932a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetSurfaceId(nullptr, nullptr);
22032a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
22132a6e48fSopenharmony_ci}
22232a6e48fSopenharmony_ci
22332a6e48fSopenharmony_ci/*
22432a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowFromSurfaceId
22532a6e48fSopenharmony_ci* Type: Function
22632a6e48fSopenharmony_ci* Rank: Important(2)
22732a6e48fSopenharmony_ci* EnvConditions: N/A
22832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowFromSurfaceId
22932a6e48fSopenharmony_ci*                  2. check ret
23032a6e48fSopenharmony_ci */
23132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowFromSurfaceId003, Function | MediumTest | Level2)
23232a6e48fSopenharmony_ci{
23332a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
23432a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
23532a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
23632a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
23732a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
23832a6e48fSopenharmony_ci
23932a6e48fSopenharmony_ci    uint64_t surfaceId = static_cast<uint64_t>(pSurfaceTmp->GetUniqueId());
24032a6e48fSopenharmony_ci    auto utils = SurfaceUtils::GetInstance();
24132a6e48fSopenharmony_ci    utils->Add(surfaceId, pSurfaceTmp);
24232a6e48fSopenharmony_ci    OHNativeWindow *nativeWindowTmp = nullptr;
24332a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(0xFFFFFFFF, &nativeWindowTmp);
24432a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_INVALID_ARGUMENTS);
24532a6e48fSopenharmony_ci    ret = OH_NativeWindow_CreateNativeWindowFromSurfaceId(surfaceId, &nativeWindowTmp);
24632a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_OK);
24732a6e48fSopenharmony_ci    surfaceId = 0;
24832a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetSurfaceId(nativeWindowTmp, &surfaceId);
24932a6e48fSopenharmony_ci    ASSERT_EQ(ret, OHOS::GSERROR_OK);
25032a6e48fSopenharmony_ci    ASSERT_EQ(surfaceId, pSurfaceTmp->GetUniqueId());
25132a6e48fSopenharmony_ci
25232a6e48fSopenharmony_ci    cSurfaceTmp = nullptr;
25332a6e48fSopenharmony_ci    producerTmp = nullptr;
25432a6e48fSopenharmony_ci    pSurfaceTmp = nullptr;
25532a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
25632a6e48fSopenharmony_ci}
25732a6e48fSopenharmony_ci
25832a6e48fSopenharmony_ci/*
25932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
26032a6e48fSopenharmony_ci* Type: Function
26132a6e48fSopenharmony_ci* Rank: Important(2)
26232a6e48fSopenharmony_ci* EnvConditions: N/A
26332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by abnormal input
26432a6e48fSopenharmony_ci*                  2. check ret
26532a6e48fSopenharmony_ci */
26632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt001, Function | MediumTest | Level2)
26732a6e48fSopenharmony_ci{
26832a6e48fSopenharmony_ci    int code = SET_USAGE;
26932a6e48fSopenharmony_ci    uint64_t usage = BUFFER_USAGE_CPU_READ;
27032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nullptr, code, usage), OHOS::GSERROR_INVALID_ARGUMENTS);
27132a6e48fSopenharmony_ci}
27232a6e48fSopenharmony_ci
27332a6e48fSopenharmony_ci/*
27432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
27532a6e48fSopenharmony_ci* Type: Function
27632a6e48fSopenharmony_ci* Rank: Important(2)
27732a6e48fSopenharmony_ci* EnvConditions: N/A
27832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
27932a6e48fSopenharmony_ci*                  2. check ret
28032a6e48fSopenharmony_ci */
28132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt002, Function | MediumTest | Level2)
28232a6e48fSopenharmony_ci{
28332a6e48fSopenharmony_ci    int code = SET_USAGE;
28432a6e48fSopenharmony_ci    uint64_t usageSet = BUFFER_USAGE_CPU_READ;
28532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
28632a6e48fSopenharmony_ci
28732a6e48fSopenharmony_ci    code = GET_USAGE;
28832a6e48fSopenharmony_ci    uint64_t usageGet = BUFFER_USAGE_CPU_WRITE;
28932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
29032a6e48fSopenharmony_ci    ASSERT_EQ(usageSet, usageGet);
29132a6e48fSopenharmony_ci}
29232a6e48fSopenharmony_ci
29332a6e48fSopenharmony_ci/*
29432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
29532a6e48fSopenharmony_ci* Type: Function
29632a6e48fSopenharmony_ci* Rank: Important(2)
29732a6e48fSopenharmony_ci* EnvConditions: N/A
29832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
29932a6e48fSopenharmony_ci*                  2. check ret
30032a6e48fSopenharmony_ci */
30132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt003, Function | MediumTest | Level2)
30232a6e48fSopenharmony_ci{
30332a6e48fSopenharmony_ci    int code = SET_BUFFER_GEOMETRY;
30432a6e48fSopenharmony_ci    int32_t heightSet = 0x100;
30532a6e48fSopenharmony_ci    int32_t widthSet = 0x100;
30632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
30732a6e48fSopenharmony_ci
30832a6e48fSopenharmony_ci    code = GET_BUFFER_GEOMETRY;
30932a6e48fSopenharmony_ci    int32_t heightGet = 0;
31032a6e48fSopenharmony_ci    int32_t widthGet = 0;
31132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &heightGet, &widthGet), OHOS::GSERROR_OK);
31232a6e48fSopenharmony_ci    ASSERT_EQ(heightSet, heightGet);
31332a6e48fSopenharmony_ci    ASSERT_EQ(widthSet, widthGet);
31432a6e48fSopenharmony_ci}
31532a6e48fSopenharmony_ci
31632a6e48fSopenharmony_ci/*
31732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
31832a6e48fSopenharmony_ci* Type: Function
31932a6e48fSopenharmony_ci* Rank: Important(2)
32032a6e48fSopenharmony_ci* EnvConditions: N/A
32132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
32232a6e48fSopenharmony_ci*                  2. check ret
32332a6e48fSopenharmony_ci */
32432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt004, Function | MediumTest | Level2)
32532a6e48fSopenharmony_ci{
32632a6e48fSopenharmony_ci    int code = SET_FORMAT;
32732a6e48fSopenharmony_ci    int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
32832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
32932a6e48fSopenharmony_ci
33032a6e48fSopenharmony_ci    code = GET_FORMAT;
33132a6e48fSopenharmony_ci    int32_t formatGet = GRAPHIC_PIXEL_FMT_CLUT8;
33232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
33332a6e48fSopenharmony_ci    ASSERT_EQ(formatSet, formatGet);
33432a6e48fSopenharmony_ci}
33532a6e48fSopenharmony_ci
33632a6e48fSopenharmony_ci/*
33732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
33832a6e48fSopenharmony_ci* Type: Function
33932a6e48fSopenharmony_ci* Rank: Important(2)
34032a6e48fSopenharmony_ci* EnvConditions: N/A
34132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
34232a6e48fSopenharmony_ci*                  2. check ret
34332a6e48fSopenharmony_ci */
34432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt005, Function | MediumTest | Level2)
34532a6e48fSopenharmony_ci{
34632a6e48fSopenharmony_ci    int code = SET_STRIDE;
34732a6e48fSopenharmony_ci    int32_t strideSet = 0x8;
34832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
34932a6e48fSopenharmony_ci
35032a6e48fSopenharmony_ci    code = GET_STRIDE;
35132a6e48fSopenharmony_ci    int32_t strideGet = 0;
35232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &strideGet), OHOS::GSERROR_OK);
35332a6e48fSopenharmony_ci    ASSERT_EQ(strideSet, strideGet);
35432a6e48fSopenharmony_ci}
35532a6e48fSopenharmony_ci
35632a6e48fSopenharmony_ci/*
35732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
35832a6e48fSopenharmony_ci* Type: Function
35932a6e48fSopenharmony_ci* Rank: Important(2)
36032a6e48fSopenharmony_ci* EnvConditions: N/A
36132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
36232a6e48fSopenharmony_ci*                  2. check ret
36332a6e48fSopenharmony_ci */
36432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt006, Function | MediumTest | Level2)
36532a6e48fSopenharmony_ci{
36632a6e48fSopenharmony_ci    int code = SET_COLOR_GAMUT;
36732a6e48fSopenharmony_ci    int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
36832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
36932a6e48fSopenharmony_ci
37032a6e48fSopenharmony_ci    code = GET_COLOR_GAMUT;
37132a6e48fSopenharmony_ci    int32_t colorGamutGet = 0;
37232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &colorGamutGet), OHOS::GSERROR_OK);
37332a6e48fSopenharmony_ci    ASSERT_EQ(colorGamutSet, colorGamutGet);
37432a6e48fSopenharmony_ci}
37532a6e48fSopenharmony_ci
37632a6e48fSopenharmony_ci/*
37732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
37832a6e48fSopenharmony_ci* Type: Function
37932a6e48fSopenharmony_ci* Rank: Important(2)
38032a6e48fSopenharmony_ci* EnvConditions: N/A
38132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
38232a6e48fSopenharmony_ci*                  2. check ret
38332a6e48fSopenharmony_ci */
38432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt007, Function | MediumTest | Level2)
38532a6e48fSopenharmony_ci{
38632a6e48fSopenharmony_ci    int code = SET_TIMEOUT;
38732a6e48fSopenharmony_ci    int32_t timeoutSet = 10;  // 10: for test
38832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
38932a6e48fSopenharmony_ci
39032a6e48fSopenharmony_ci    code = GET_TIMEOUT;
39132a6e48fSopenharmony_ci    int32_t timeoutGet = 0;
39232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &timeoutGet), OHOS::GSERROR_OK);
39332a6e48fSopenharmony_ci    ASSERT_EQ(timeoutSet, timeoutGet);
39432a6e48fSopenharmony_ci}
39532a6e48fSopenharmony_ci
39632a6e48fSopenharmony_ci/*
39732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
39832a6e48fSopenharmony_ci* Type: Function
39932a6e48fSopenharmony_ci* Rank: Important(2)
40032a6e48fSopenharmony_ci* EnvConditions: N/A
40132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
40232a6e48fSopenharmony_ci*                  2. check ret
40332a6e48fSopenharmony_ci */
40432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt008, Function | MediumTest | Level1)
40532a6e48fSopenharmony_ci{
40632a6e48fSopenharmony_ci    int code = GET_TRANSFORM;
40732a6e48fSopenharmony_ci    int32_t transform = 0;
40832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transform), OHOS::GSERROR_OK);
40932a6e48fSopenharmony_ci    transform = GraphicTransformType::GRAPHIC_ROTATE_90;
41032a6e48fSopenharmony_ci    code = SET_TRANSFORM;
41132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), OHOS::GSERROR_OK);
41232a6e48fSopenharmony_ci    int32_t transformTmp = 0;
41332a6e48fSopenharmony_ci    code = GET_TRANSFORM;
41432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), OHOS::GSERROR_OK);
41532a6e48fSopenharmony_ci    ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_90);
41632a6e48fSopenharmony_ci    nativeWindow->surface->SetTransform(GraphicTransformType::GRAPHIC_ROTATE_180);
41732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &transformTmp), OHOS::GSERROR_OK);
41832a6e48fSopenharmony_ci    ASSERT_EQ(transformTmp, GraphicTransformType::GRAPHIC_ROTATE_180);
41932a6e48fSopenharmony_ci}
42032a6e48fSopenharmony_ci
42132a6e48fSopenharmony_ci/*
42232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
42332a6e48fSopenharmony_ci* Type: Function
42432a6e48fSopenharmony_ci* Rank: Important(2)
42532a6e48fSopenharmony_ci* EnvConditions: N/A
42632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
42732a6e48fSopenharmony_ci*                  2. check ret
42832a6e48fSopenharmony_ci */
42932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt009, Function | MediumTest | Level1)
43032a6e48fSopenharmony_ci{
43132a6e48fSopenharmony_ci    int code = GET_BUFFERQUEUE_SIZE;
43232a6e48fSopenharmony_ci    int32_t queueSize = 0;
43332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), OHOS::GSERROR_OK);
43432a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
43532a6e48fSopenharmony_ci    nativeWindow->surface->SetQueueSize(5);
43632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &queueSize), OHOS::GSERROR_OK);
43732a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 5);
43832a6e48fSopenharmony_ci}
43932a6e48fSopenharmony_ci
44032a6e48fSopenharmony_ci/*
44132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
44232a6e48fSopenharmony_ci* Type: Function
44332a6e48fSopenharmony_ci* Rank: Important(2)
44432a6e48fSopenharmony_ci* EnvConditions: N/A
44532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
44632a6e48fSopenharmony_ci*                  2. check ret
44732a6e48fSopenharmony_ci */
44832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt010, Function | MediumTest | Level2)
44932a6e48fSopenharmony_ci{
45032a6e48fSopenharmony_ci    int code = SET_USAGE;
45132a6e48fSopenharmony_ci    uint64_t usageSet = NATIVEBUFFER_USAGE_HW_RENDER | NATIVEBUFFER_USAGE_HW_TEXTURE |
45232a6e48fSopenharmony_ci    NATIVEBUFFER_USAGE_CPU_READ_OFTEN | NATIVEBUFFER_USAGE_ALIGNMENT_512;
45332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
45432a6e48fSopenharmony_ci
45532a6e48fSopenharmony_ci    code = GET_USAGE;
45632a6e48fSopenharmony_ci    uint64_t usageGet = usageSet;
45732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &usageGet), OHOS::GSERROR_OK);
45832a6e48fSopenharmony_ci    ASSERT_EQ(usageSet, usageGet);
45932a6e48fSopenharmony_ci
46032a6e48fSopenharmony_ci    code = SET_FORMAT;
46132a6e48fSopenharmony_ci    int32_t formatSet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
46232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
46332a6e48fSopenharmony_ci
46432a6e48fSopenharmony_ci    code = GET_FORMAT;
46532a6e48fSopenharmony_ci    int32_t formatGet = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
46632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &formatGet), OHOS::GSERROR_OK);
46732a6e48fSopenharmony_ci    ASSERT_EQ(formatSet, formatGet);
46832a6e48fSopenharmony_ci}
46932a6e48fSopenharmony_ci
47032a6e48fSopenharmony_ci/*
47132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
47232a6e48fSopenharmony_ci* Type: Function
47332a6e48fSopenharmony_ci* Rank: Important(2)
47432a6e48fSopenharmony_ci* EnvConditions: N/A
47532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
47632a6e48fSopenharmony_ci*                  2. check ret
47732a6e48fSopenharmony_ci */
47832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt011, Function | MediumTest | Level1)
47932a6e48fSopenharmony_ci{
48032a6e48fSopenharmony_ci    int code = SET_SOURCE_TYPE;
48132a6e48fSopenharmony_ci    OHSurfaceSource typeSet = OHSurfaceSource::OH_SURFACE_SOURCE_GAME;
48232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), OHOS::GSERROR_OK);
48332a6e48fSopenharmony_ci
48432a6e48fSopenharmony_ci    code = GET_SOURCE_TYPE;
48532a6e48fSopenharmony_ci    OHSurfaceSource typeGet = OHSurfaceSource::OH_SURFACE_SOURCE_DEFAULT;
48632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), OHOS::GSERROR_OK);
48732a6e48fSopenharmony_ci    ASSERT_EQ(typeSet, typeGet);
48832a6e48fSopenharmony_ci}
48932a6e48fSopenharmony_ci
49032a6e48fSopenharmony_ci/*
49132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
49232a6e48fSopenharmony_ci* Type: Function
49332a6e48fSopenharmony_ci* Rank: Important(2)
49432a6e48fSopenharmony_ci* EnvConditions: N/A
49532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
49632a6e48fSopenharmony_ci*                  2. check ret
49732a6e48fSopenharmony_ci */
49832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt012, Function | MediumTest | Level1)
49932a6e48fSopenharmony_ci{
50032a6e48fSopenharmony_ci    int code = SET_APP_FRAMEWORK_TYPE;
50132a6e48fSopenharmony_ci    const char* typeSet = "test";
50232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, typeSet), OHOS::GSERROR_OK);
50332a6e48fSopenharmony_ci
50432a6e48fSopenharmony_ci    code = GET_APP_FRAMEWORK_TYPE;
50532a6e48fSopenharmony_ci    const char* typeGet;
50632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, &typeGet), OHOS::GSERROR_OK);
50732a6e48fSopenharmony_ci    ASSERT_EQ(0, strcmp(typeSet, typeGet));
50832a6e48fSopenharmony_ci}
50932a6e48fSopenharmony_ci
51032a6e48fSopenharmony_ci/*
51132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowHandleOpt
51232a6e48fSopenharmony_ci* Type: Function
51332a6e48fSopenharmony_ci* Rank: Important(2)
51432a6e48fSopenharmony_ci* EnvConditions: N/A
51532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowHandleOpt by different param
51632a6e48fSopenharmony_ci*                  2. check ret
51732a6e48fSopenharmony_ci */
51832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, HandleOpt013, Function | MediumTest | Level1)
51932a6e48fSopenharmony_ci{
52032a6e48fSopenharmony_ci    int code = SET_HDR_WHITE_POINT_BRIGHTNESS;
52132a6e48fSopenharmony_ci    float brightness = 0.8;
52232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
52332a6e48fSopenharmony_ci
52432a6e48fSopenharmony_ci    code = SET_SDR_WHITE_POINT_BRIGHTNESS;
52532a6e48fSopenharmony_ci    brightness = 0.5;
52632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
52732a6e48fSopenharmony_ci
52832a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
52932a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
53032a6e48fSopenharmony_ci
53132a6e48fSopenharmony_ci    code = SET_HDR_WHITE_POINT_BRIGHTNESS;
53232a6e48fSopenharmony_ci    brightness = 1.8;
53332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
53432a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
53532a6e48fSopenharmony_ci    brightness = -0.5;
53632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
53732a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.8) < 1e-6, true);
53832a6e48fSopenharmony_ci    brightness = 0.5;
53932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
54032a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetHdrWhitePointBrightness() - 0.5) < 1e-6, true);
54132a6e48fSopenharmony_ci
54232a6e48fSopenharmony_ci    code = SET_SDR_WHITE_POINT_BRIGHTNESS;
54332a6e48fSopenharmony_ci    brightness = 1.5;
54432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
54532a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
54632a6e48fSopenharmony_ci    brightness = -0.1;
54732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
54832a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.5) < 1e-6, true);
54932a6e48fSopenharmony_ci    brightness = 0.8;
55032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, brightness), OHOS::GSERROR_OK);
55132a6e48fSopenharmony_ci    ASSERT_EQ(fabs(cSurface->GetSdrWhitePointBrightness() - 0.8) < 1e-6, true);
55232a6e48fSopenharmony_ci}
55332a6e48fSopenharmony_ci
55432a6e48fSopenharmony_ci/*
55532a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
55632a6e48fSopenharmony_ci* Type: Function
55732a6e48fSopenharmony_ci* Rank: Important(2)
55832a6e48fSopenharmony_ci* EnvConditions: N/A
55932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by abnormal input
56032a6e48fSopenharmony_ci*                  2. check ret
56132a6e48fSopenharmony_ci */
56232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer001, Function | MediumTest | Level1)
56332a6e48fSopenharmony_ci{
56432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
56532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
56632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
56732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
56832a6e48fSopenharmony_ci}
56932a6e48fSopenharmony_ci
57032a6e48fSopenharmony_civoid SetNativeWindowConfig(NativeWindow *nativeWindow)
57132a6e48fSopenharmony_ci{
57232a6e48fSopenharmony_ci    int code = SET_USAGE;
57332a6e48fSopenharmony_ci    uint64_t usageSet = BUFFER_USAGE_CPU_READ;
57432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, usageSet), OHOS::GSERROR_OK);
57532a6e48fSopenharmony_ci
57632a6e48fSopenharmony_ci    code = SET_BUFFER_GEOMETRY;
57732a6e48fSopenharmony_ci    int32_t heightSet = 0x100;
57832a6e48fSopenharmony_ci    int32_t widthSet = 0x100;
57932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, heightSet, widthSet), OHOS::GSERROR_OK);
58032a6e48fSopenharmony_ci
58132a6e48fSopenharmony_ci    code = SET_FORMAT;
58232a6e48fSopenharmony_ci    int32_t formatSet = GRAPHIC_PIXEL_FMT_RGBA_8888;
58332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, formatSet), OHOS::GSERROR_OK);
58432a6e48fSopenharmony_ci
58532a6e48fSopenharmony_ci    code = SET_STRIDE;
58632a6e48fSopenharmony_ci    int32_t strideSet = 0x8;
58732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, strideSet), OHOS::GSERROR_OK);
58832a6e48fSopenharmony_ci
58932a6e48fSopenharmony_ci    code = SET_COLOR_GAMUT;
59032a6e48fSopenharmony_ci    int32_t colorGamutSet = static_cast<int32_t>(GraphicColorGamut::GRAPHIC_COLOR_GAMUT_DCI_P3);
59132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, colorGamutSet), OHOS::GSERROR_OK);
59232a6e48fSopenharmony_ci
59332a6e48fSopenharmony_ci    code = SET_TIMEOUT;
59432a6e48fSopenharmony_ci    int32_t timeoutSet = 10;  // 10: for test
59532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, timeoutSet), OHOS::GSERROR_OK);
59632a6e48fSopenharmony_ci}
59732a6e48fSopenharmony_ci
59832a6e48fSopenharmony_ci/*
59932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
60032a6e48fSopenharmony_ci* Type: Function
60132a6e48fSopenharmony_ci* Rank: Important(2)
60232a6e48fSopenharmony_ci* EnvConditions: N/A
60332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
60432a6e48fSopenharmony_ci*                  2. check ret
60532a6e48fSopenharmony_ci */
60632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer002, Function | MediumTest | Level1)
60732a6e48fSopenharmony_ci{
60832a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
60932a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
61032a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
61132a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
61232a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
61332a6e48fSopenharmony_ci
61432a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
61532a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
61632a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
61732a6e48fSopenharmony_ci
61832a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer = nullptr;
61932a6e48fSopenharmony_ci    int fenceFd = -1;
62032a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
62132a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
62232a6e48fSopenharmony_ci
62332a6e48fSopenharmony_ci    int code = GET_BUFFERQUEUE_SIZE;
62432a6e48fSopenharmony_ci    int32_t queueSize = 0;
62532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
62632a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
62732a6e48fSopenharmony_ci
62832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer), OHOS::GSERROR_OK);
62932a6e48fSopenharmony_ci
63032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
63132a6e48fSopenharmony_ci
63232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer), OHOS::GSERROR_OK);
63332a6e48fSopenharmony_ci
63432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer), OHOS::GSERROR_OK);
63532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
63632a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
63732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer),
63832a6e48fSopenharmony_ci        OHOS::GSERROR_BUFFER_IS_INCACHE);
63932a6e48fSopenharmony_ci
64032a6e48fSopenharmony_ci    struct Region *region = new Region();
64132a6e48fSopenharmony_ci    struct Region::Rect *rect = new Region::Rect();
64232a6e48fSopenharmony_ci    rect->x = 0x100;
64332a6e48fSopenharmony_ci    rect->y = 0x100;
64432a6e48fSopenharmony_ci    rect->w = 0x100;
64532a6e48fSopenharmony_ci    rect->h = 0x100;
64632a6e48fSopenharmony_ci    region->rects = rect;
64732a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
64832a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
64932a6e48fSopenharmony_ci
65032a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
65132a6e48fSopenharmony_ci}
65232a6e48fSopenharmony_ci
65332a6e48fSopenharmony_civoid NativeWindowAttachBuffer003Test(NativeWindow *nativeWindowTmp, NativeWindow *nativeWindowTmp1)
65432a6e48fSopenharmony_ci{
65532a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
65632a6e48fSopenharmony_ci    int fenceFd = -1;
65732a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
65832a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
65932a6e48fSopenharmony_ci
66032a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer2 = nullptr;
66132a6e48fSopenharmony_ci    fenceFd = -1;
66232a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer2, &fenceFd);
66332a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
66432a6e48fSopenharmony_ci
66532a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer3 = nullptr;
66632a6e48fSopenharmony_ci    fenceFd = -1;
66732a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer3, &fenceFd);
66832a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
66932a6e48fSopenharmony_ci
67032a6e48fSopenharmony_ci    int code = GET_BUFFERQUEUE_SIZE;
67132a6e48fSopenharmony_ci    int32_t queueSize = 0;
67232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
67332a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
67432a6e48fSopenharmony_ci
67532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
67632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer2), OHOS::GSERROR_OK);
67732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer3), OHOS::GSERROR_OK);
67832a6e48fSopenharmony_ci
67932a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer4 = nullptr;
68032a6e48fSopenharmony_ci    fenceFd = -1;
68132a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer4, &fenceFd);
68232a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
68332a6e48fSopenharmony_ci
68432a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer10 = nullptr;
68532a6e48fSopenharmony_ci    fenceFd = -1;
68632a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer10, &fenceFd);
68732a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
68832a6e48fSopenharmony_ci
68932a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer11 = nullptr;
69032a6e48fSopenharmony_ci    fenceFd = -1;
69132a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer11, &fenceFd);
69232a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
69332a6e48fSopenharmony_ci
69432a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer12 = nullptr;
69532a6e48fSopenharmony_ci    fenceFd = -1;
69632a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp1, &nativeWindowBuffer12, &fenceFd);
69732a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
69832a6e48fSopenharmony_ci
69932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp1, nativeWindowBuffer1),
70032a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_BUFFER_QUEUE_FULL);
70132a6e48fSopenharmony_ci}
70232a6e48fSopenharmony_ci
70332a6e48fSopenharmony_ci/*
70432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
70532a6e48fSopenharmony_ci* Type: Function
70632a6e48fSopenharmony_ci* Rank: Important(2)
70732a6e48fSopenharmony_ci* EnvConditions: N/A
70832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
70932a6e48fSopenharmony_ci*                  2. check ret
71032a6e48fSopenharmony_ci */
71132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer003, Function | MediumTest | Level1)
71232a6e48fSopenharmony_ci{
71332a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
71432a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
71532a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
71632a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
71732a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
71832a6e48fSopenharmony_ci
71932a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
72032a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
72132a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
72232a6e48fSopenharmony_ci
72332a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp1 = IConsumerSurface::Create();
72432a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener1 = new BufferConsumerListener();
72532a6e48fSopenharmony_ci    cSurfaceTmp1->RegisterConsumerListener(listener1);
72632a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp1 = cSurfaceTmp1->GetProducer();
72732a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp1 = Surface::CreateSurfaceAsProducer(producerTmp1);
72832a6e48fSopenharmony_ci
72932a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp1 = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp1);
73032a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp1, nullptr);
73132a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp1);
73232a6e48fSopenharmony_ci
73332a6e48fSopenharmony_ci    NativeWindowAttachBuffer003Test(nativeWindowTmp, nativeWindowTmp1);
73432a6e48fSopenharmony_ci
73532a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
73632a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp1);
73732a6e48fSopenharmony_ci}
73832a6e48fSopenharmony_ci
73932a6e48fSopenharmony_ci/*
74032a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
74132a6e48fSopenharmony_ci* Type: Function
74232a6e48fSopenharmony_ci* Rank: Important(2)
74332a6e48fSopenharmony_ci* EnvConditions: N/A
74432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
74532a6e48fSopenharmony_ci*                  2. check ret
74632a6e48fSopenharmony_ci */
74732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer004, Function | MediumTest | Level1)
74832a6e48fSopenharmony_ci{
74932a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
75032a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
75132a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
75232a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
75332a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
75432a6e48fSopenharmony_ci
75532a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
75632a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
75732a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
75832a6e48fSopenharmony_ci
75932a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer = nullptr;
76032a6e48fSopenharmony_ci    int fenceFd = -1;
76132a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
76232a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
76332a6e48fSopenharmony_ci
76432a6e48fSopenharmony_ci    struct Region *region = new Region();
76532a6e48fSopenharmony_ci    struct Region::Rect *rect = new Region::Rect();
76632a6e48fSopenharmony_ci    rect->x = 0x100;
76732a6e48fSopenharmony_ci    rect->y = 0x100;
76832a6e48fSopenharmony_ci    rect->w = 0x100;
76932a6e48fSopenharmony_ci    rect->h = 0x100;
77032a6e48fSopenharmony_ci    region->rects = rect;
77132a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindowTmp, nativeWindowBuffer, fenceFd, *region);
77232a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
77332a6e48fSopenharmony_ci
77432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer),
77532a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
77632a6e48fSopenharmony_ci
77732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindow, nativeWindowBuffer),
77832a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_BUFFER_NOT_INCACHE);
77932a6e48fSopenharmony_ci
78032a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
78132a6e48fSopenharmony_ci}
78232a6e48fSopenharmony_ci
78332a6e48fSopenharmony_ci/*
78432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
78532a6e48fSopenharmony_ci* Type: Function
78632a6e48fSopenharmony_ci* Rank: Important(2)
78732a6e48fSopenharmony_ci* EnvConditions: N/A
78832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
78932a6e48fSopenharmony_ci*                  2. check ret
79032a6e48fSopenharmony_ci */
79132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer005, Function | MediumTest | Level1)
79232a6e48fSopenharmony_ci{
79332a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
79432a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
79532a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
79632a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
79732a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
79832a6e48fSopenharmony_ci
79932a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
80032a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
80132a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
80232a6e48fSopenharmony_ci
80332a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer = nullptr;
80432a6e48fSopenharmony_ci    int fenceFd = -1;
80532a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer, &fenceFd);
80632a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
80732a6e48fSopenharmony_ci
80832a6e48fSopenharmony_ci    ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
80932a6e48fSopenharmony_ci
81032a6e48fSopenharmony_ci    ASSERT_EQ(cSurface->DetachBufferFromQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
81132a6e48fSopenharmony_ci
81232a6e48fSopenharmony_ci    ASSERT_EQ(cSurface->AttachBufferToQueue(nativeWindowBuffer->sfbuffer), GSERROR_OK);
81332a6e48fSopenharmony_ci
81432a6e48fSopenharmony_ci    sptr<SyncFence> fence = SyncFence::INVALID_FENCE;
81532a6e48fSopenharmony_ci    ASSERT_EQ(cSurface->ReleaseBuffer(nativeWindowBuffer->sfbuffer, fence), GSERROR_OK);
81632a6e48fSopenharmony_ci
81732a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
81832a6e48fSopenharmony_ci}
81932a6e48fSopenharmony_ci
82032a6e48fSopenharmony_ci/*
82132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAttachBuffer
82232a6e48fSopenharmony_ci* Type: Function
82332a6e48fSopenharmony_ci* Rank: Important(2)
82432a6e48fSopenharmony_ci* EnvConditions: N/A
82532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAttachBuffer by normal input
82632a6e48fSopenharmony_ci*                  2. check ret
82732a6e48fSopenharmony_ci */
82832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowAttachBuffer006, Function | MediumTest | Level1)
82932a6e48fSopenharmony_ci{
83032a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
83132a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
83232a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
83332a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
83432a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
83532a6e48fSopenharmony_ci
83632a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
83732a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
83832a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
83932a6e48fSopenharmony_ci
84032a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
84132a6e48fSopenharmony_ci    int fenceFd = -1;
84232a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
84332a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
84432a6e48fSopenharmony_ci
84532a6e48fSopenharmony_ci    int code = GET_BUFFERQUEUE_SIZE;
84632a6e48fSopenharmony_ci    int32_t queueSize = 0;
84732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
84832a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
84932a6e48fSopenharmony_ci    clock_t startTime, endTime;
85032a6e48fSopenharmony_ci    startTime = clock();
85132a6e48fSopenharmony_ci    for (int32_t i = 0; i < 1000; i++) {
85232a6e48fSopenharmony_ci        ASSERT_EQ(OH_NativeWindow_NativeWindowDetachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
85332a6e48fSopenharmony_ci        ASSERT_EQ(OH_NativeWindow_NativeWindowAttachBuffer(nativeWindowTmp, nativeWindowBuffer1), OHOS::GSERROR_OK);
85432a6e48fSopenharmony_ci    }
85532a6e48fSopenharmony_ci    endTime = clock();
85632a6e48fSopenharmony_ci    cout << "DetachBuffer and AttachBuffer 1000 times cost time: " << (endTime - startTime) << "ms" << endl;
85732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTmp, code, &queueSize), OHOS::GSERROR_OK);
85832a6e48fSopenharmony_ci    ASSERT_EQ(queueSize, 3);
85932a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
86032a6e48fSopenharmony_ci}
86132a6e48fSopenharmony_ci
86232a6e48fSopenharmony_ci/*
86332a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
86432a6e48fSopenharmony_ci* Type: Function
86532a6e48fSopenharmony_ci* Rank: Important(2)
86632a6e48fSopenharmony_ci* EnvConditions: N/A
86732a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer by abnormal input
86832a6e48fSopenharmony_ci*                  2. check ret
86932a6e48fSopenharmony_ci */
87032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowBuffer001, Function | MediumTest | Level2)
87132a6e48fSopenharmony_ci{
87232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(nullptr), nullptr);
87332a6e48fSopenharmony_ci}
87432a6e48fSopenharmony_ci
87532a6e48fSopenharmony_ci/*
87632a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
87732a6e48fSopenharmony_ci* Type: Function
87832a6e48fSopenharmony_ci* Rank: Important(2)
87932a6e48fSopenharmony_ci* EnvConditions: N/A
88032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer
88132a6e48fSopenharmony_ci*                  2. check ret
88232a6e48fSopenharmony_ci */
88332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowBuffer002, Function | MediumTest | Level2)
88432a6e48fSopenharmony_ci{
88532a6e48fSopenharmony_ci    nativeWindowBuffer = OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(&sBuffer);
88632a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowBuffer, nullptr);
88732a6e48fSopenharmony_ci}
88832a6e48fSopenharmony_ci
88932a6e48fSopenharmony_ci/*
89032a6e48fSopenharmony_ci* Function: OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
89132a6e48fSopenharmony_ci* Type: Function
89232a6e48fSopenharmony_ci* Rank: Important(2)
89332a6e48fSopenharmony_ci* EnvConditions: N/A
89432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer
89532a6e48fSopenharmony_ci*                  2. check ret
89632a6e48fSopenharmony_ci*/
89732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CreateNativeWindowBuffer003, Function | MediumTest | Level2)
89832a6e48fSopenharmony_ci{
89932a6e48fSopenharmony_ci    OH_NativeBuffer* nativeBuffer = sBuffer->SurfaceBufferToNativeBuffer();
90032a6e48fSopenharmony_ci    ASSERT_NE(nativeBuffer, nullptr);
90132a6e48fSopenharmony_ci    NativeWindowBuffer* nwBuffer = OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nativeBuffer);
90232a6e48fSopenharmony_ci    ASSERT_NE(nwBuffer, nullptr);
90332a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nwBuffer);
90432a6e48fSopenharmony_ci}
90532a6e48fSopenharmony_ci
90632a6e48fSopenharmony_ci/*
90732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowRequestBuffer
90832a6e48fSopenharmony_ci* Type: Function
90932a6e48fSopenharmony_ci* Rank: Important(2)
91032a6e48fSopenharmony_ci* EnvConditions: N/A
91132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
91232a6e48fSopenharmony_ci*                  2. check ret
91332a6e48fSopenharmony_ci */
91432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, RequestBuffer001, Function | MediumTest | Level2)
91532a6e48fSopenharmony_ci{
91632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nullptr, &nativeWindowBuffer, nullptr),
91732a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
91832a6e48fSopenharmony_ci}
91932a6e48fSopenharmony_ci
92032a6e48fSopenharmony_ci/*
92132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowRequestBuffer
92232a6e48fSopenharmony_ci* Type: Function
92332a6e48fSopenharmony_ci* Rank: Important(2)
92432a6e48fSopenharmony_ci* EnvConditions: N/A
92532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer by abnormal input
92632a6e48fSopenharmony_ci*                  2. check ret
92732a6e48fSopenharmony_ci */
92832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, RequestBuffer002, Function | MediumTest | Level2)
92932a6e48fSopenharmony_ci{
93032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, nullptr, nullptr),
93132a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
93232a6e48fSopenharmony_ci}
93332a6e48fSopenharmony_ci
93432a6e48fSopenharmony_ci/*
93532a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetBufferHandleFromNative
93632a6e48fSopenharmony_ci* Type: Function
93732a6e48fSopenharmony_ci* Rank: Important(2)
93832a6e48fSopenharmony_ci* EnvConditions: N/A
93932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative by abnormal input
94032a6e48fSopenharmony_ci*                  2. check ret
94132a6e48fSopenharmony_ci */
94232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, GetBufferHandle001, Function | MediumTest | Level2)
94332a6e48fSopenharmony_ci{
94432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetBufferHandleFromNative(nullptr), nullptr);
94532a6e48fSopenharmony_ci}
94632a6e48fSopenharmony_ci
94732a6e48fSopenharmony_ci/*
94832a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetBufferHandleFromNative
94932a6e48fSopenharmony_ci* Type: Function
95032a6e48fSopenharmony_ci* Rank: Important(2)
95132a6e48fSopenharmony_ci* EnvConditions: N/A
95232a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_GetBufferHandleFromNative
95332a6e48fSopenharmony_ci*                  2. check ret
95432a6e48fSopenharmony_ci */
95532a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, GetBufferHandle002, Function | MediumTest | Level2)
95632a6e48fSopenharmony_ci{
95732a6e48fSopenharmony_ci    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
95832a6e48fSopenharmony_ci    buffer->sfbuffer = sBuffer;
95932a6e48fSopenharmony_ci    ASSERT_NE(OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer), nullptr);
96032a6e48fSopenharmony_ci    delete buffer;
96132a6e48fSopenharmony_ci}
96232a6e48fSopenharmony_ci
96332a6e48fSopenharmony_ci/*
96432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowFlushBuffer
96532a6e48fSopenharmony_ci* Type: Function
96632a6e48fSopenharmony_ci* Rank: Important(2)
96732a6e48fSopenharmony_ci* EnvConditions: N/A
96832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
96932a6e48fSopenharmony_ci*                  2. check ret
97032a6e48fSopenharmony_ci */
97132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, FlushBuffer001, Function | MediumTest | Level2)
97232a6e48fSopenharmony_ci{
97332a6e48fSopenharmony_ci    int fenceFd = -1;
97432a6e48fSopenharmony_ci    struct Region *region = new Region();
97532a6e48fSopenharmony_ci    struct Region::Rect * rect = new Region::Rect();
97632a6e48fSopenharmony_ci    rect->x = 0x100;
97732a6e48fSopenharmony_ci    rect->y = 0x100;
97832a6e48fSopenharmony_ci    rect->w = 0x100;
97932a6e48fSopenharmony_ci    rect->h = 0x100;
98032a6e48fSopenharmony_ci    region->rects = rect;
98132a6e48fSopenharmony_ci
98232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nullptr, nullptr, fenceFd, *region),
98332a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
98432a6e48fSopenharmony_ci    delete region;
98532a6e48fSopenharmony_ci}
98632a6e48fSopenharmony_ci
98732a6e48fSopenharmony_ci/*
98832a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowFlushBuffer
98932a6e48fSopenharmony_ci* Type: Function
99032a6e48fSopenharmony_ci* Rank: Important(2)
99132a6e48fSopenharmony_ci* EnvConditions: N/A
99232a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer by abnormal input
99332a6e48fSopenharmony_ci*                  2. check ret
99432a6e48fSopenharmony_ci */
99532a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, FlushBuffer002, Function | MediumTest | Level2)
99632a6e48fSopenharmony_ci{
99732a6e48fSopenharmony_ci    int fenceFd = -1;
99832a6e48fSopenharmony_ci    struct Region *region = new Region();
99932a6e48fSopenharmony_ci    struct Region::Rect * rect = new Region::Rect();
100032a6e48fSopenharmony_ci    rect->x = 0x100;
100132a6e48fSopenharmony_ci    rect->y = 0x100;
100232a6e48fSopenharmony_ci    rect->w = 0x100;
100332a6e48fSopenharmony_ci    rect->h = 0x100;
100432a6e48fSopenharmony_ci    region->rects = rect;
100532a6e48fSopenharmony_ci
100632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nullptr, fenceFd, *region),
100732a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
100832a6e48fSopenharmony_ci    delete region;
100932a6e48fSopenharmony_ci}
101032a6e48fSopenharmony_ci
101132a6e48fSopenharmony_ci/*
101232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowFlushBuffer
101332a6e48fSopenharmony_ci* Type: Function
101432a6e48fSopenharmony_ci* Rank: Important(2)
101532a6e48fSopenharmony_ci* EnvConditions: N/A
101632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowFlushBuffer
101732a6e48fSopenharmony_ci*                  2. check ret
101832a6e48fSopenharmony_ci */
101932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, FlushBuffer003, Function | MediumTest | Level2)
102032a6e48fSopenharmony_ci{
102132a6e48fSopenharmony_ci    int fenceFd = -1;
102232a6e48fSopenharmony_ci    struct Region *region = new Region();
102332a6e48fSopenharmony_ci    region->rectNumber = 0;
102432a6e48fSopenharmony_ci    region->rects = nullptr;
102532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
102632a6e48fSopenharmony_ci              OHOS::GSERROR_OK);
102732a6e48fSopenharmony_ci
102832a6e48fSopenharmony_ci    region->rectNumber = 1;
102932a6e48fSopenharmony_ci    struct Region::Rect * rect = new Region::Rect();
103032a6e48fSopenharmony_ci    rect->x = 0x100;
103132a6e48fSopenharmony_ci    rect->y = 0x100;
103232a6e48fSopenharmony_ci    rect->w = 0x100;
103332a6e48fSopenharmony_ci    rect->h = 0x100;
103432a6e48fSopenharmony_ci    region->rects = rect;
103532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
103632a6e48fSopenharmony_ci              OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
103732a6e48fSopenharmony_ci    delete rect;
103832a6e48fSopenharmony_ci    delete region;
103932a6e48fSopenharmony_ci}
104032a6e48fSopenharmony_ciconstexpr int32_t MATRIX_SIZE = 16;
104132a6e48fSopenharmony_cibool CheckMatricIsSame(float matrixOld[MATRIX_SIZE], float matrixNew[MATRIX_SIZE])
104232a6e48fSopenharmony_ci{
104332a6e48fSopenharmony_ci    for (int32_t i = 0; i < MATRIX_SIZE; i++) {
104432a6e48fSopenharmony_ci        if (fabs(matrixOld[i] - matrixNew[i]) > 1e-6) {
104532a6e48fSopenharmony_ci            return false;
104632a6e48fSopenharmony_ci        }
104732a6e48fSopenharmony_ci    }
104832a6e48fSopenharmony_ci    return true;
104932a6e48fSopenharmony_ci}
105032a6e48fSopenharmony_ci
105132a6e48fSopenharmony_ci/*
105232a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetLastFlushedBuffer
105332a6e48fSopenharmony_ci* Type: Function
105432a6e48fSopenharmony_ci* Rank: Important(2)
105532a6e48fSopenharmony_ci* EnvConditions: N/A
105632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowRequestBuffer
105732a6e48fSopenharmony_ci*                  2. call OH_NativeWindow_NativeWindowFlushBuffer
105832a6e48fSopenharmony_ci*                  3. call OH_NativeWindow_GetLastFlushedBuffer
105932a6e48fSopenharmony_ci*                  4. check ret
106032a6e48fSopenharmony_ci */
106132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, GetLastFlushedBuffer001, Function | MediumTest | Level2)
106232a6e48fSopenharmony_ci{
106332a6e48fSopenharmony_ci    int code = SET_TRANSFORM;
106432a6e48fSopenharmony_ci    int32_t transform = GraphicTransformType::GRAPHIC_ROTATE_90;
106532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, transform), OHOS::GSERROR_OK);
106632a6e48fSopenharmony_ci
106732a6e48fSopenharmony_ci    code = SET_FORMAT;
106832a6e48fSopenharmony_ci    int32_t format = GRAPHIC_PIXEL_FMT_RGBA_8888;
106932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindow, code, format), OHOS::GSERROR_OK);
107032a6e48fSopenharmony_ci
107132a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer = nullptr;
107232a6e48fSopenharmony_ci    int fenceFd = -1;
107332a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
107432a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
107532a6e48fSopenharmony_ci
107632a6e48fSopenharmony_ci    struct Region *region = new Region();
107732a6e48fSopenharmony_ci    struct Region::Rect *rect = new Region::Rect();
107832a6e48fSopenharmony_ci    rect->x = 0x100;
107932a6e48fSopenharmony_ci    rect->y = 0x100;
108032a6e48fSopenharmony_ci    rect->w = 0x100;
108132a6e48fSopenharmony_ci    rect->h = 0x100;
108232a6e48fSopenharmony_ci    region->rects = rect;
108332a6e48fSopenharmony_ci    BufferHandle *bufferHanlde = OH_NativeWindow_GetBufferHandleFromNative(nativeWindowBuffer);
108432a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
108532a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
108632a6e48fSopenharmony_ci    NativeWindowBuffer *lastFlushedBuffer;
108732a6e48fSopenharmony_ci    int lastFlushedFenceFd;
108832a6e48fSopenharmony_ci    float matrix[16];
108932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, nullptr, matrix),
109032a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
109132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
109232a6e48fSopenharmony_ci        OHOS::GSERROR_OK);
109332a6e48fSopenharmony_ci    BufferHandle *lastFlushedHanlde = OH_NativeWindow_GetBufferHandleFromNative(lastFlushedBuffer);
109432a6e48fSopenharmony_ci    ASSERT_EQ(bufferHanlde->virAddr, lastFlushedHanlde->virAddr);
109532a6e48fSopenharmony_ci
109632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
109732a6e48fSopenharmony_ci        OHOS::GSERROR_OK);
109832a6e48fSopenharmony_ci    float matrix90[16] = {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
109932a6e48fSopenharmony_ci    bool bRet = CheckMatricIsSame(matrix90, matrix);
110032a6e48fSopenharmony_ci    ASSERT_EQ(bRet, true);
110132a6e48fSopenharmony_ci}
110232a6e48fSopenharmony_ci
110332a6e48fSopenharmony_ci/*
110432a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetLastFlushedBuffer
110532a6e48fSopenharmony_ci* Type: Function
110632a6e48fSopenharmony_ci* Rank: Important(2)
110732a6e48fSopenharmony_ci* EnvConditions: N/A
110832a6e48fSopenharmony_ci* CaseDescription: 1. call NativeWindowHandleOpt set BUFFER_USAGE_PROTECTED
110932a6e48fSopenharmony_ci*                  2. call OH_NativeWindow_NativeWindowRequestBuffer
111032a6e48fSopenharmony_ci*                  3. call OH_NativeWindow_NativeWindowFlushBuffer
111132a6e48fSopenharmony_ci*                  4. call OH_NativeWindow_GetLastFlushedBuffer
111232a6e48fSopenharmony_ci*                  5. check ret
111332a6e48fSopenharmony_ci */
111432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, GetLastFlushedBuffer002, Function | MediumTest | Level2)
111532a6e48fSopenharmony_ci{
111632a6e48fSopenharmony_ci    int code = SET_USAGE;
111732a6e48fSopenharmony_ci    uint64_t usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_MEM_DMA | BUFFER_USAGE_PROTECTED;
111832a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowHandleOpt(nativeWindow, code, usage), OHOS::GSERROR_OK);
111932a6e48fSopenharmony_ci
112032a6e48fSopenharmony_ci    NativeWindowBuffer* nativeWindowBuffer = nullptr;
112132a6e48fSopenharmony_ci    int fenceFd = -1;
112232a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer, &fenceFd);
112332a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
112432a6e48fSopenharmony_ci
112532a6e48fSopenharmony_ci    struct Region *region = new Region();
112632a6e48fSopenharmony_ci    struct Region::Rect *rect = new Region::Rect();
112732a6e48fSopenharmony_ci    rect->x = 0x100;
112832a6e48fSopenharmony_ci    rect->y = 0x100;
112932a6e48fSopenharmony_ci    rect->w = 0x100;
113032a6e48fSopenharmony_ci    rect->h = 0x100;
113132a6e48fSopenharmony_ci    region->rects = rect;
113232a6e48fSopenharmony_ci    ret = OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region);
113332a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
113432a6e48fSopenharmony_ci    NativeWindowBuffer* lastFlushedBuffer;
113532a6e48fSopenharmony_ci    int lastFlushedFenceFd;
113632a6e48fSopenharmony_ci    float matrix[16];
113732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, &lastFlushedBuffer, &lastFlushedFenceFd, matrix),
113832a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_NOT_SUPPORT);
113932a6e48fSopenharmony_ci}
114032a6e48fSopenharmony_ci
114132a6e48fSopenharmony_ci/*
114232a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetColorSpace
114332a6e48fSopenharmony_ci* Type: Function
114432a6e48fSopenharmony_ci* Rank: Important(2)
114532a6e48fSopenharmony_ci* EnvConditions: N/A
114632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetColorSpace
114732a6e48fSopenharmony_ci*                  2. check ret
114832a6e48fSopenharmony_ci */
114932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace001, Function | MediumTest | Level2)
115032a6e48fSopenharmony_ci{
115132a6e48fSopenharmony_ci    OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT709_LIMIT;
115232a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_GetColorSpace(nullptr, &colorSpace);
115332a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
115432a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_INTERNAL);
115532a6e48fSopenharmony_ci    }
115632a6e48fSopenharmony_ci}
115732a6e48fSopenharmony_ci
115832a6e48fSopenharmony_ci/*
115932a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetColorSpace
116032a6e48fSopenharmony_ci* Type: Function
116132a6e48fSopenharmony_ci* Rank: Important(2)
116232a6e48fSopenharmony_ci* EnvConditions: N/A
116332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetColorSpace
116432a6e48fSopenharmony_ci*                  2. check ret
116532a6e48fSopenharmony_ci */
116632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetColorSpace002, Function | MediumTest | Level2)
116732a6e48fSopenharmony_ci{
116832a6e48fSopenharmony_ci    OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT709_LIMIT;
116932a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpace);
117032a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
117132a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
117232a6e48fSopenharmony_ci    }
117332a6e48fSopenharmony_ci}
117432a6e48fSopenharmony_ci
117532a6e48fSopenharmony_ci/*
117632a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetColorSpace
117732a6e48fSopenharmony_ci* Type: Function
117832a6e48fSopenharmony_ci* Rank: Important(2)
117932a6e48fSopenharmony_ci* EnvConditions: N/A
118032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_GetColorSpace
118132a6e48fSopenharmony_ci*                  2. check ret
118232a6e48fSopenharmony_ci */
118332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace001, Function | MediumTest | Level2)
118432a6e48fSopenharmony_ci{
118532a6e48fSopenharmony_ci    OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE;
118632a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
118732a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
118832a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
118932a6e48fSopenharmony_ci    }
119032a6e48fSopenharmony_ci}
119132a6e48fSopenharmony_ci
119232a6e48fSopenharmony_ci/*
119332a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetColorSpace
119432a6e48fSopenharmony_ci* Type: Function
119532a6e48fSopenharmony_ci* Rank: Important(2)
119632a6e48fSopenharmony_ci* EnvConditions: N/A
119732a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_GetColorSpace
119832a6e48fSopenharmony_ci*                  2. check ret
119932a6e48fSopenharmony_ci */
120032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_GetColorSpace002, Function | MediumTest | Level2)
120132a6e48fSopenharmony_ci{
120232a6e48fSopenharmony_ci    OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_NONE;
120332a6e48fSopenharmony_ci    OH_NativeBuffer_ColorSpace colorSpaceSet = OH_COLORSPACE_BT709_FULL;
120432a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetColorSpace(nativeWindow, colorSpaceSet);
120532a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
120632a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
120732a6e48fSopenharmony_ci    }
120832a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetColorSpace(nativeWindow, &colorSpace);
120932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
121032a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
121132a6e48fSopenharmony_ci        ASSERT_EQ(colorSpace, colorSpaceSet);
121232a6e48fSopenharmony_ci    }
121332a6e48fSopenharmony_ci}
121432a6e48fSopenharmony_ci
121532a6e48fSopenharmony_ci/*
121632a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
121732a6e48fSopenharmony_ci* Type: Function
121832a6e48fSopenharmony_ci* Rank: Important(2)
121932a6e48fSopenharmony_ci* EnvConditions: N/A
122032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
122132a6e48fSopenharmony_ci*                  2. check ret
122232a6e48fSopenharmony_ci */
122332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue001, Function | MediumTest | Level2)
122432a6e48fSopenharmony_ci{
122532a6e48fSopenharmony_ci    int len = 60;
122632a6e48fSopenharmony_ci    uint8_t buff[len];
122732a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
122832a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(i);
122932a6e48fSopenharmony_ci    }
123032a6e48fSopenharmony_ci    int32_t buffSize;
123132a6e48fSopenharmony_ci    uint8_t *checkMetaData;
123232a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
123332a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
123432a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_OK);
123532a6e48fSopenharmony_ci    }
123632a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nullptr, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
123732a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
123832a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_OK);
123932a6e48fSopenharmony_ci    }
124032a6e48fSopenharmony_ci}
124132a6e48fSopenharmony_ci
124232a6e48fSopenharmony_ci/*
124332a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
124432a6e48fSopenharmony_ci* Type: Function
124532a6e48fSopenharmony_ci* Rank: Important(2)
124632a6e48fSopenharmony_ci* EnvConditions: N/A
124732a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
124832a6e48fSopenharmony_ci*                  2. check ret
124932a6e48fSopenharmony_ci */
125032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue002, Function | MediumTest | Level2)
125132a6e48fSopenharmony_ci{
125232a6e48fSopenharmony_ci    int len = 60;
125332a6e48fSopenharmony_ci    uint8_t buff[len];
125432a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
125532a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(i);
125632a6e48fSopenharmony_ci    }
125732a6e48fSopenharmony_ci    int32_t max_size = -1;
125832a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)max_size, buff);
125932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
126032a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_OK);
126132a6e48fSopenharmony_ci    }
126232a6e48fSopenharmony_ci}
126332a6e48fSopenharmony_ci
126432a6e48fSopenharmony_ci/*
126532a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
126632a6e48fSopenharmony_ci* Type: Function
126732a6e48fSopenharmony_ci* Rank: Important(2)
126832a6e48fSopenharmony_ci* EnvConditions: N/A
126932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
127032a6e48fSopenharmony_ci*                  2. check ret
127132a6e48fSopenharmony_ci */
127232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue003, Function | MediumTest | Level2)
127332a6e48fSopenharmony_ci{
127432a6e48fSopenharmony_ci    int len = 60;
127532a6e48fSopenharmony_ci    uint8_t buff[len];
127632a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
127732a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(i);
127832a6e48fSopenharmony_ci    }
127932a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
128032a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
128132a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
128232a6e48fSopenharmony_ci    }
128332a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
128432a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
128532a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
128632a6e48fSopenharmony_ci    }
128732a6e48fSopenharmony_ci    OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
128832a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
128932a6e48fSopenharmony_ci                                           reinterpret_cast<uint8_t *>(&type));
129032a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
129132a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
129232a6e48fSopenharmony_ci    }
129332a6e48fSopenharmony_ci}
129432a6e48fSopenharmony_ci
129532a6e48fSopenharmony_ci/*
129632a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
129732a6e48fSopenharmony_ci* Type: Function
129832a6e48fSopenharmony_ci* Rank: Important(2)
129932a6e48fSopenharmony_ci* EnvConditions: N/A
130032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
130132a6e48fSopenharmony_ci*                  2. check ret
130232a6e48fSopenharmony_ci */
130332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue004, Function | MediumTest | Level2)
130432a6e48fSopenharmony_ci{
130532a6e48fSopenharmony_ci    int len = 60;
130632a6e48fSopenharmony_ci    uint8_t buff[len];
130732a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
130832a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(i);
130932a6e48fSopenharmony_ci    }
131032a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
131132a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
131232a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
131332a6e48fSopenharmony_ci    }
131432a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
131532a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
131632a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
131732a6e48fSopenharmony_ci    }
131832a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
131932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
132032a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
132132a6e48fSopenharmony_ci    }
132232a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
132332a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
132432a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
132532a6e48fSopenharmony_ci    }
132632a6e48fSopenharmony_ci    OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
132732a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
132832a6e48fSopenharmony_ci                                           reinterpret_cast<uint8_t *>(&type));
132932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
133032a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
133132a6e48fSopenharmony_ci    }
133232a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
133332a6e48fSopenharmony_ci                                           reinterpret_cast<uint8_t *>(&type));
133432a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
133532a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
133632a6e48fSopenharmony_ci    }
133732a6e48fSopenharmony_ci}
133832a6e48fSopenharmony_ci
133932a6e48fSopenharmony_ci/*
134032a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
134132a6e48fSopenharmony_ci* Type: Function
134232a6e48fSopenharmony_ci* Rank: Important(2)
134332a6e48fSopenharmony_ci* EnvConditions: N/A
134432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
134532a6e48fSopenharmony_ci*                  2. check ret
134632a6e48fSopenharmony_ci */
134732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_SetMetadataValue005, Function | MediumTest | Level2)
134832a6e48fSopenharmony_ci{
134932a6e48fSopenharmony_ci    int len = 60;
135032a6e48fSopenharmony_ci    uint8_t buff[len];
135132a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
135232a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(i);
135332a6e48fSopenharmony_ci    }
135432a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowbuffer1 = nullptr;
135532a6e48fSopenharmony_ci    int fenceFd = -1;
135632a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowbuffer1, &fenceFd);
135732a6e48fSopenharmony_ci    if (ret != GSERROR_HDI_ERROR) {
135832a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
135932a6e48fSopenharmony_ci    }
136032a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
136132a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
136232a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
136332a6e48fSopenharmony_ci    }
136432a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
136532a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
136632a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
136732a6e48fSopenharmony_ci    }
136832a6e48fSopenharmony_ci    OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HLG;
136932a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type),
137032a6e48fSopenharmony_ci                                           reinterpret_cast<uint8_t *>(&type));
137132a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
137232a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
137332a6e48fSopenharmony_ci    }
137432a6e48fSopenharmony_ci}
137532a6e48fSopenharmony_ci
137632a6e48fSopenharmony_ci/*
137732a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetMetadataValue
137832a6e48fSopenharmony_ci* Type: Function
137932a6e48fSopenharmony_ci* Rank: Important(2)
138032a6e48fSopenharmony_ci* EnvConditions: N/A
138132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
138232a6e48fSopenharmony_ci*                  2. check ret
138332a6e48fSopenharmony_ci */
138432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue001, Function | MediumTest | Level2)
138532a6e48fSopenharmony_ci{
138632a6e48fSopenharmony_ci    int32_t buffSize;
138732a6e48fSopenharmony_ci    uint8_t *checkMetaData;
138832a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
138932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
139032a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_OK);
139132a6e48fSopenharmony_ci    }
139232a6e48fSopenharmony_ci}
139332a6e48fSopenharmony_ci
139432a6e48fSopenharmony_ci/*
139532a6e48fSopenharmony_ci* Function: OH_NativeWindow_GetMetadataValue
139632a6e48fSopenharmony_ci* Type: Function
139732a6e48fSopenharmony_ci* Rank: Important(2)
139832a6e48fSopenharmony_ci* EnvConditions: N/A
139932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_GetMetadataValue
140032a6e48fSopenharmony_ci*                  2. check ret
140132a6e48fSopenharmony_ci */
140232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue002, Function | MediumTest | Level2)
140332a6e48fSopenharmony_ci{
140432a6e48fSopenharmony_ci    uint8_t *checkMetaData;
140532a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, nullptr, &checkMetaData);
140632a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
140732a6e48fSopenharmony_ci        ASSERT_NE(ret, GSERROR_OK);
140832a6e48fSopenharmony_ci    }
140932a6e48fSopenharmony_ci}
141032a6e48fSopenharmony_ci
141132a6e48fSopenharmony_ci/*
141232a6e48fSopenharmony_ci* Function: OH_NativeWindow_SetMetadataValue
141332a6e48fSopenharmony_ci* Type: Function
141432a6e48fSopenharmony_ci* Rank: Important(2)
141532a6e48fSopenharmony_ci* EnvConditions: N/A
141632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_SetMetadataValue
141732a6e48fSopenharmony_ci*                  2. check ret
141832a6e48fSopenharmony_ci */
141932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_GetMetadataValue003, Function | MediumTest | Level2)
142032a6e48fSopenharmony_ci{
142132a6e48fSopenharmony_ci    int len = 60;
142232a6e48fSopenharmony_ci    uint8_t buff[len];
142332a6e48fSopenharmony_ci    for (int i = 0; i < 60; ++i) {
142432a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(60 - i);
142532a6e48fSopenharmony_ci    }
142632a6e48fSopenharmony_ci    int32_t buffSize;
142732a6e48fSopenharmony_ci    uint8_t *checkMetaData;
142832a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, (int32_t)len, buff);
142932a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
143032a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
143132a6e48fSopenharmony_ci    }
143232a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_STATIC_METADATA, &buffSize, &checkMetaData);
143332a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
143432a6e48fSopenharmony_ci        ASSERT_EQ(memcmp(checkMetaData, buff, 60), 0);
143532a6e48fSopenharmony_ci        delete[] checkMetaData;
143632a6e48fSopenharmony_ci        checkMetaData = nullptr;
143732a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
143832a6e48fSopenharmony_ci    }
143932a6e48fSopenharmony_ci    for (int i = 0; i < 60; i++) {
144032a6e48fSopenharmony_ci        buff[i] = static_cast<uint8_t>(70 - i);
144132a6e48fSopenharmony_ci    }
144232a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, (int32_t)len, buff);
144332a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
144432a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
144532a6e48fSopenharmony_ci    }
144632a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_DYNAMIC_METADATA, &buffSize, &checkMetaData);
144732a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
144832a6e48fSopenharmony_ci        ASSERT_EQ(memcmp(checkMetaData, buff, 60), 0);
144932a6e48fSopenharmony_ci        delete[] checkMetaData;
145032a6e48fSopenharmony_ci        checkMetaData = nullptr;
145132a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
145232a6e48fSopenharmony_ci    }
145332a6e48fSopenharmony_ci    OH_NativeBuffer_MetadataType type = OH_VIDEO_HDR_HDR10;
145432a6e48fSopenharmony_ci    int32_t typeSize = sizeof(type);
145532a6e48fSopenharmony_ci    uint8_t pa = static_cast<uint8_t>(type);
145632a6e48fSopenharmony_ci    ret = OH_NativeWindow_SetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, sizeof(type), &pa);
145732a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set colorspace
145832a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
145932a6e48fSopenharmony_ci    }
146032a6e48fSopenharmony_ci    ret = OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, &typeSize, &checkMetaData);
146132a6e48fSopenharmony_ci    if (ret != GSERROR_NOT_SUPPORT) { // some device not support set metadataValue
146232a6e48fSopenharmony_ci        ASSERT_EQ(static_cast<uint8_t>(type), checkMetaData[0]);
146332a6e48fSopenharmony_ci        delete[] checkMetaData;
146432a6e48fSopenharmony_ci        checkMetaData = nullptr;
146532a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
146632a6e48fSopenharmony_ci    }
146732a6e48fSopenharmony_ci}
146832a6e48fSopenharmony_ci/*
146932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAbortBuffer
147032a6e48fSopenharmony_ci* Type: Function
147132a6e48fSopenharmony_ci* Rank: Important(2)
147232a6e48fSopenharmony_ci* EnvConditions: N/A
147332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
147432a6e48fSopenharmony_ci*                  2. check ret
147532a6e48fSopenharmony_ci */
147632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CancelBuffer001, Function | MediumTest | Level2)
147732a6e48fSopenharmony_ci{
147832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
147932a6e48fSopenharmony_ci}
148032a6e48fSopenharmony_ci
148132a6e48fSopenharmony_ci/*
148232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAbortBuffer
148332a6e48fSopenharmony_ci* Type: Function
148432a6e48fSopenharmony_ci* Rank: Important(2)
148532a6e48fSopenharmony_ci* EnvConditions: N/A
148632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer by abnormal input
148732a6e48fSopenharmony_ci*                  2. check ret
148832a6e48fSopenharmony_ci */
148932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CancelBuffer002, Function | MediumTest | Level2)
149032a6e48fSopenharmony_ci{
149132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
149232a6e48fSopenharmony_ci}
149332a6e48fSopenharmony_ci
149432a6e48fSopenharmony_ci/*
149532a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowAbortBuffer
149632a6e48fSopenharmony_ci* Type: Function
149732a6e48fSopenharmony_ci* Rank: Important(2)
149832a6e48fSopenharmony_ci* EnvConditions: N/A
149932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowAbortBuffer
150032a6e48fSopenharmony_ci*                  2. check ret
150132a6e48fSopenharmony_ci */
150232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, CancelBuffer003, Function | MediumTest | Level2)
150332a6e48fSopenharmony_ci{
150432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer),
150532a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_BUFFER_STATE_INVALID);
150632a6e48fSopenharmony_ci
150732a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurfaceTmp = IConsumerSurface::Create();
150832a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
150932a6e48fSopenharmony_ci    cSurfaceTmp->RegisterConsumerListener(listener);
151032a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producerTmp = cSurfaceTmp->GetProducer();
151132a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurfaceTmp = Surface::CreateSurfaceAsProducer(producerTmp);
151232a6e48fSopenharmony_ci
151332a6e48fSopenharmony_ci    NativeWindow *nativeWindowTmp = OH_NativeWindow_CreateNativeWindow(&pSurfaceTmp);
151432a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowTmp, nullptr);
151532a6e48fSopenharmony_ci    SetNativeWindowConfig(nativeWindowTmp);
151632a6e48fSopenharmony_ci
151732a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
151832a6e48fSopenharmony_ci    int fenceFd = -1;
151932a6e48fSopenharmony_ci    int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindowTmp, &nativeWindowBuffer1, &fenceFd);
152032a6e48fSopenharmony_ci    ASSERT_EQ(ret, GSERROR_OK);
152132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowAbortBuffer(nativeWindow, nativeWindowBuffer1),
152232a6e48fSopenharmony_ci        OHOS::SURFACE_ERROR_BUFFER_NOT_INCACHE);
152332a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindowTmp);
152432a6e48fSopenharmony_ci}
152532a6e48fSopenharmony_ci
152632a6e48fSopenharmony_ci/*
152732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeObjectReference
152832a6e48fSopenharmony_ci* Type: Function
152932a6e48fSopenharmony_ci* Rank: Important(2)
153032a6e48fSopenharmony_ci* EnvConditions: N/A
153132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeObjectReference
153232a6e48fSopenharmony_ci*                  2. check ret
153332a6e48fSopenharmony_ci */
153432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, Reference001, Function | MediumTest | Level2)
153532a6e48fSopenharmony_ci{
153632a6e48fSopenharmony_ci    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
153732a6e48fSopenharmony_ci    buffer->sfbuffer = sBuffer;
153832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeObjectReference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
153932a6e48fSopenharmony_ci    delete buffer;
154032a6e48fSopenharmony_ci}
154132a6e48fSopenharmony_ci
154232a6e48fSopenharmony_ci/*
154332a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeObjectUnreference
154432a6e48fSopenharmony_ci* Type: Function
154532a6e48fSopenharmony_ci* Rank: Important(2)
154632a6e48fSopenharmony_ci* EnvConditions: N/A
154732a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeObjectUnreference
154832a6e48fSopenharmony_ci*                  2. check ret
154932a6e48fSopenharmony_ci */
155032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, Unreference001, Function | MediumTest | Level2)
155132a6e48fSopenharmony_ci{
155232a6e48fSopenharmony_ci    struct NativeWindowBuffer *buffer = new NativeWindowBuffer();
155332a6e48fSopenharmony_ci    buffer->sfbuffer = sBuffer;
155432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeObjectUnreference(reinterpret_cast<void *>(buffer)), OHOS::GSERROR_OK);
155532a6e48fSopenharmony_ci    delete buffer;
155632a6e48fSopenharmony_ci}
155732a6e48fSopenharmony_ci
155832a6e48fSopenharmony_ci/*
155932a6e48fSopenharmony_ci* Function: OH_NativeWindow_DestroyNativeWindow
156032a6e48fSopenharmony_ci* Type: Function
156132a6e48fSopenharmony_ci* Rank: Important(2)
156232a6e48fSopenharmony_ci* EnvConditions: N/A
156332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindow by abnormal input
156432a6e48fSopenharmony_ci*                  2. check ret
156532a6e48fSopenharmony_ci */
156632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, DestroyNativeWindow001, Function | MediumTest | Level2)
156732a6e48fSopenharmony_ci{
156832a6e48fSopenharmony_ci    OHNativeWindow* window = nullptr;
156932a6e48fSopenharmony_ci    ASSERT_EQ(window, nullptr);
157032a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(window);
157132a6e48fSopenharmony_ci}
157232a6e48fSopenharmony_ci
157332a6e48fSopenharmony_ci/*
157432a6e48fSopenharmony_ci* Function: OH_NativeWindow_DestroyNativeWindowBuffer
157532a6e48fSopenharmony_ci* Type: Function
157632a6e48fSopenharmony_ci* Rank: Important(2)
157732a6e48fSopenharmony_ci* EnvConditions: N/A
157832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer by abnormal input
157932a6e48fSopenharmony_ci*                  2. check ret
158032a6e48fSopenharmony_ci */
158132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer001, Function | MediumTest | Level2)
158232a6e48fSopenharmony_ci{
158332a6e48fSopenharmony_ci    OHNativeWindowBuffer* buffer = nullptr;
158432a6e48fSopenharmony_ci    ASSERT_EQ(buffer, nullptr);
158532a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(buffer);
158632a6e48fSopenharmony_ci}
158732a6e48fSopenharmony_ci
158832a6e48fSopenharmony_ci/*
158932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetScalingMode
159032a6e48fSopenharmony_ci* Type: Function
159132a6e48fSopenharmony_ci* Rank: Important(2)
159232a6e48fSopenharmony_ci* EnvConditions: N/A
159332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
159432a6e48fSopenharmony_ci */
159532a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetScalingMode001, Function | MediumTest | Level2)
159632a6e48fSopenharmony_ci{
159732a6e48fSopenharmony_ci    OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
159832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nullptr, -1, scalingMode), OHOS::GSERROR_INVALID_ARGUMENTS);
159932a6e48fSopenharmony_ci}
160032a6e48fSopenharmony_ci
160132a6e48fSopenharmony_ci/*
160232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetScalingMode
160332a6e48fSopenharmony_ci* Type: Function
160432a6e48fSopenharmony_ci* Rank: Important(2)
160532a6e48fSopenharmony_ci* EnvConditions: N/A
160632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
160732a6e48fSopenharmony_ci */
160832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetScalingMode002, Function | MediumTest | Level2)
160932a6e48fSopenharmony_ci{
161032a6e48fSopenharmony_ci    OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
161132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, -1, scalingMode), OHOS::GSERROR_NO_ENTRY);
161232a6e48fSopenharmony_ci}
161332a6e48fSopenharmony_ci
161432a6e48fSopenharmony_ci/*
161532a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetScalingMode
161632a6e48fSopenharmony_ci* Type: Function
161732a6e48fSopenharmony_ci* Rank: Important(2)
161832a6e48fSopenharmony_ci* EnvConditions: N/A
161932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
162032a6e48fSopenharmony_ci */
162132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetScalingMode003, Function | MediumTest | Level2)
162232a6e48fSopenharmony_ci{
162332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, firstSeqnum,
162432a6e48fSopenharmony_ci                                         static_cast<OHScalingMode>(OHScalingMode::OH_SCALING_MODE_NO_SCALE_CROP + 1)),
162532a6e48fSopenharmony_ci                                         OHOS::GSERROR_INVALID_ARGUMENTS);
162632a6e48fSopenharmony_ci}
162732a6e48fSopenharmony_ci
162832a6e48fSopenharmony_ci/*
162932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetScalingMode
163032a6e48fSopenharmony_ci* Type: Function
163132a6e48fSopenharmony_ci* Rank: Important(1)
163232a6e48fSopenharmony_ci* EnvConditions: N/A
163332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingMode with abnormal parameters and check ret
163432a6e48fSopenharmony_ci*                  2. call OH_NativeWindow_NativeWindowSetScalingMode with normal parameters and check ret
163532a6e48fSopenharmony_ci */
163632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetScalingMode004, Function | MediumTest | Level1)
163732a6e48fSopenharmony_ci{
163832a6e48fSopenharmony_ci    OHScalingMode scalingMode = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
163932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindow, firstSeqnum, scalingMode), OHOS::GSERROR_OK);
164032a6e48fSopenharmony_ci}
164132a6e48fSopenharmony_ci
164232a6e48fSopenharmony_ci/*
164332a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetScalingModeV2
164432a6e48fSopenharmony_ci* Type: Function
164532a6e48fSopenharmony_ci* Rank: Important(1)
164632a6e48fSopenharmony_ci* EnvConditions: N/A
164732a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetScalingModeV2 with abnormal parameters and check ret
164832a6e48fSopenharmony_ci*                  2. call OH_NativeWindow_NativeWindowSetScalingModeV2 with normal parameters and check ret
164932a6e48fSopenharmony_ci */
165032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetScalingMode005, Function | MediumTest | Level1)
165132a6e48fSopenharmony_ci{
165232a6e48fSopenharmony_ci    OHScalingModeV2 scalingMode = OHScalingModeV2::OH_SCALING_MODE_SCALE_TO_WINDOW_V2;
165332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingModeV2(nativeWindow, scalingMode), OHOS::GSERROR_OK);
165432a6e48fSopenharmony_ci}
165532a6e48fSopenharmony_ci
165632a6e48fSopenharmony_ci
165732a6e48fSopenharmony_ci/*
165832a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
165932a6e48fSopenharmony_ci* Type: Function
166032a6e48fSopenharmony_ci* Rank: Important(2)
166132a6e48fSopenharmony_ci* EnvConditions: N/A
166232a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
166332a6e48fSopenharmony_ci */
166432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData001, Function | MediumTest | Level2)
166532a6e48fSopenharmony_ci{
166632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nullptr, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
166732a6e48fSopenharmony_ci}
166832a6e48fSopenharmony_ci
166932a6e48fSopenharmony_ci/*
167032a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
167132a6e48fSopenharmony_ci* Type: Function
167232a6e48fSopenharmony_ci* Rank: Important(2)
167332a6e48fSopenharmony_ci* EnvConditions: N/A
167432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
167532a6e48fSopenharmony_ci */
167632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData002, Function | MediumTest | Level2)
167732a6e48fSopenharmony_ci{
167832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
167932a6e48fSopenharmony_ci}
168032a6e48fSopenharmony_ci
168132a6e48fSopenharmony_ci/*
168232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
168332a6e48fSopenharmony_ci* Type: Function
168432a6e48fSopenharmony_ci* Rank: Important(2)
168532a6e48fSopenharmony_ci* EnvConditions: N/A
168632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
168732a6e48fSopenharmony_ci*                  2. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
168832a6e48fSopenharmony_ci */
168932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData003, Function | MediumTest | Level2)
169032a6e48fSopenharmony_ci{
169132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, 0, nullptr),
169232a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
169332a6e48fSopenharmony_ci}
169432a6e48fSopenharmony_ci
169532a6e48fSopenharmony_ci/*
169632a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
169732a6e48fSopenharmony_ci* Type: Function
169832a6e48fSopenharmony_ci* Rank: Important(2)
169932a6e48fSopenharmony_ci* EnvConditions: N/A
170032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
170132a6e48fSopenharmony_ci */
170232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData004, Function | MediumTest | Level2)
170332a6e48fSopenharmony_ci{
170432a6e48fSopenharmony_ci    int32_t size = 1;
170532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, size, nullptr),
170632a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
170732a6e48fSopenharmony_ci}
170832a6e48fSopenharmony_ci
170932a6e48fSopenharmony_ci/*
171032a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
171132a6e48fSopenharmony_ci* Type: Function
171232a6e48fSopenharmony_ci* Rank: Important(2)
171332a6e48fSopenharmony_ci* EnvConditions: N/A
171432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with abnormal parameters and check ret
171532a6e48fSopenharmony_ci */
171632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData005, Function | MediumTest | Level2)
171732a6e48fSopenharmony_ci{
171832a6e48fSopenharmony_ci    int32_t size = 1;
171932a6e48fSopenharmony_ci    const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
172032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, -1, size, metaData), OHOS::GSERROR_NO_ENTRY);
172132a6e48fSopenharmony_ci}
172232a6e48fSopenharmony_ci
172332a6e48fSopenharmony_ci/*
172432a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaData
172532a6e48fSopenharmony_ci* Type: Function
172632a6e48fSopenharmony_ci* Rank: Important(1)
172732a6e48fSopenharmony_ci* EnvConditions: N/A
172832a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaData with normal parameters and check ret
172932a6e48fSopenharmony_ci */
173032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaData006, Function | MediumTest | Level1)
173132a6e48fSopenharmony_ci{
173232a6e48fSopenharmony_ci    int32_t size = 1;
173332a6e48fSopenharmony_ci    const OHHDRMetaData metaData[] = {{OH_METAKEY_RED_PRIMARY_X, 0}};
173432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaData(nativeWindow, firstSeqnum, size, metaData), OHOS::GSERROR_OK);
173532a6e48fSopenharmony_ci}
173632a6e48fSopenharmony_ci
173732a6e48fSopenharmony_ci/*
173832a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
173932a6e48fSopenharmony_ci* Type: Function
174032a6e48fSopenharmony_ci* Rank: Important(2)
174132a6e48fSopenharmony_ci* EnvConditions: N/A
174232a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
174332a6e48fSopenharmony_ci */
174432a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet001, Function | MediumTest | Level2)
174532a6e48fSopenharmony_ci{
174632a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
174732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nullptr, -1, key, 0, nullptr),
174832a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
174932a6e48fSopenharmony_ci}
175032a6e48fSopenharmony_ci
175132a6e48fSopenharmony_ci/*
175232a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
175332a6e48fSopenharmony_ci* Type: Function
175432a6e48fSopenharmony_ci* Rank: Important(2)
175532a6e48fSopenharmony_ci* EnvConditions: N/A
175632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
175732a6e48fSopenharmony_ci */
175832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet002, Function | MediumTest | Level2)
175932a6e48fSopenharmony_ci{
176032a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
176132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, 0, nullptr),
176232a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
176332a6e48fSopenharmony_ci}
176432a6e48fSopenharmony_ci
176532a6e48fSopenharmony_ci/*
176632a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
176732a6e48fSopenharmony_ci* Type: Function
176832a6e48fSopenharmony_ci* Rank: Important(2)
176932a6e48fSopenharmony_ci* EnvConditions: N/A
177032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
177132a6e48fSopenharmony_ci */
177232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet003, Function | MediumTest | Level2)
177332a6e48fSopenharmony_ci{
177432a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
177532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, 0, nullptr),
177632a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
177732a6e48fSopenharmony_ci}
177832a6e48fSopenharmony_ci
177932a6e48fSopenharmony_ci/*
178032a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
178132a6e48fSopenharmony_ci* Type: Function
178232a6e48fSopenharmony_ci* Rank: Important(2)
178332a6e48fSopenharmony_ci* EnvConditions: N/A
178432a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
178532a6e48fSopenharmony_ci */
178632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet004, Function | MediumTest | Level2)
178732a6e48fSopenharmony_ci{
178832a6e48fSopenharmony_ci    int32_t size = 1;
178932a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
179032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, size, nullptr),
179132a6e48fSopenharmony_ci              OHOS::GSERROR_INVALID_ARGUMENTS);
179232a6e48fSopenharmony_ci}
179332a6e48fSopenharmony_ci
179432a6e48fSopenharmony_ci/*
179532a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
179632a6e48fSopenharmony_ci* Type: Function
179732a6e48fSopenharmony_ci* Rank: Important(2)
179832a6e48fSopenharmony_ci* EnvConditions: N/A
179932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with abnormal parameters and check ret
180032a6e48fSopenharmony_ci */
180132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet005, Function | MediumTest | Level2)
180232a6e48fSopenharmony_ci{
180332a6e48fSopenharmony_ci    int32_t size = 1;
180432a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
180532a6e48fSopenharmony_ci    const uint8_t metaData[] = {0};
180632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, -1, key, size, metaData),
180732a6e48fSopenharmony_ci              OHOS::GSERROR_NO_ENTRY);
180832a6e48fSopenharmony_ci}
180932a6e48fSopenharmony_ci
181032a6e48fSopenharmony_ci/*
181132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetMetaDataSet
181232a6e48fSopenharmony_ci* Type: Function
181332a6e48fSopenharmony_ci* Rank: Important(1)
181432a6e48fSopenharmony_ci* EnvConditions: N/A
181532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetMetaDataSet with normal parameters and check ret
181632a6e48fSopenharmony_ci */
181732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetMetaDataSet006, Function | MediumTest | Level1)
181832a6e48fSopenharmony_ci{
181932a6e48fSopenharmony_ci    int32_t size = 1;
182032a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
182132a6e48fSopenharmony_ci    const uint8_t metaData[] = {0};
182232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetMetaDataSet(nativeWindow, firstSeqnum, key, size, metaData),
182332a6e48fSopenharmony_ci              OHOS::GSERROR_OK);
182432a6e48fSopenharmony_ci}
182532a6e48fSopenharmony_ci
182632a6e48fSopenharmony_ci/*
182732a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetTunnelHandle
182832a6e48fSopenharmony_ci* Type: Function
182932a6e48fSopenharmony_ci* Rank: Important(2)
183032a6e48fSopenharmony_ci* EnvConditions: N/A
183132a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
183232a6e48fSopenharmony_ci */
183332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetTunnelHandle001, Function | MediumTest | Level2)
183432a6e48fSopenharmony_ci{
183532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
183632a6e48fSopenharmony_ci}
183732a6e48fSopenharmony_ci
183832a6e48fSopenharmony_ci/*
183932a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetTunnelHandle
184032a6e48fSopenharmony_ci* Type: Function
184132a6e48fSopenharmony_ci* Rank: Important(2)
184232a6e48fSopenharmony_ci* EnvConditions: N/A
184332a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with abnormal parameters and check ret
184432a6e48fSopenharmony_ci */
184532a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetTunnelHandle002, Function | MediumTest | Level2)
184632a6e48fSopenharmony_ci{
184732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
184832a6e48fSopenharmony_ci}
184932a6e48fSopenharmony_ci
185032a6e48fSopenharmony_ci/*
185132a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetTunnelHandle
185232a6e48fSopenharmony_ci* Type: Function
185332a6e48fSopenharmony_ci* Rank: Important(2)
185432a6e48fSopenharmony_ci* EnvConditions: N/A
185532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
185632a6e48fSopenharmony_ci */
185732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetTunnelHandle003, Function | MediumTest | Level2)
185832a6e48fSopenharmony_ci{
185932a6e48fSopenharmony_ci    uint32_t reserveInts = 1;
186032a6e48fSopenharmony_ci    OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
186132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
186232a6e48fSopenharmony_ci    FreeOHExtDataHandle(handle);
186332a6e48fSopenharmony_ci}
186432a6e48fSopenharmony_ci
186532a6e48fSopenharmony_ci/*
186632a6e48fSopenharmony_ci* Function: OH_NativeWindow_NativeWindowSetTunnelHandle
186732a6e48fSopenharmony_ci* Type: Function
186832a6e48fSopenharmony_ci* Rank: Important(1)
186932a6e48fSopenharmony_ci* EnvConditions: N/A
187032a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_NativeWindowSetTunnelHandle with normal parameters and check ret
187132a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
187232a6e48fSopenharmony_ci */
187332a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SetTunnelHandle004, Function | MediumTest | Level1)
187432a6e48fSopenharmony_ci{
187532a6e48fSopenharmony_ci    uint32_t reserveInts = 2;
187632a6e48fSopenharmony_ci    OHExtDataHandle *handle = AllocOHExtDataHandle(reserveInts);
187732a6e48fSopenharmony_ci    nativeWindow = OH_NativeWindow_CreateNativeWindow(&pSurface);
187832a6e48fSopenharmony_ci    ASSERT_NE(nativeWindow, nullptr);
187932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_OK);
188032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetTunnelHandle(nativeWindow, handle), OHOS::GSERROR_NO_ENTRY);
188132a6e48fSopenharmony_ci    FreeOHExtDataHandle(handle);
188232a6e48fSopenharmony_ci}
188332a6e48fSopenharmony_ci
188432a6e48fSopenharmony_ci/*
188532a6e48fSopenharmony_ci* Function: NativeWindowGetTransformHint
188632a6e48fSopenharmony_ci* Type: Function
188732a6e48fSopenharmony_ci* Rank: Important(1)
188832a6e48fSopenharmony_ci* EnvConditions: N/A
188932a6e48fSopenharmony_ci* CaseDescription: 1. call NativeWindowGetTransformHint with normal parameters and check ret
189032a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
189132a6e48fSopenharmony_ci */
189232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowGetTransformHint001, Function | MediumTest | Level1)
189332a6e48fSopenharmony_ci{
189432a6e48fSopenharmony_ci    OH_NativeBuffer_TransformType transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180;
189532a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetTransformHint(nullptr, &transform), OHOS::GSERROR_INVALID_ARGUMENTS);
189632a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetTransformHint(nullptr, transform), OHOS::GSERROR_INVALID_ARGUMENTS);
189732a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetTransformHint(nativeWindow, transform), OHOS::GSERROR_OK);
189832a6e48fSopenharmony_ci    transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_NONE;
189932a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetTransformHint(nativeWindow, &transform), OHOS::GSERROR_OK);
190032a6e48fSopenharmony_ci    ASSERT_EQ(transform, OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180);
190132a6e48fSopenharmony_ci}
190232a6e48fSopenharmony_ci
190332a6e48fSopenharmony_ci/*
190432a6e48fSopenharmony_ci* Function: NativeWindowGetDefaultWidthAndHeight
190532a6e48fSopenharmony_ci* Type: Function
190632a6e48fSopenharmony_ci* Rank: Important(1)
190732a6e48fSopenharmony_ci* EnvConditions: N/A
190832a6e48fSopenharmony_ci* CaseDescription: 1. call NativeWindowGetDefaultWidthAndHeight with normal parameters and check ret
190932a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
191032a6e48fSopenharmony_ci */
191132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowGetDefaultWidthAndHeight001, Function | MediumTest | Level1)
191232a6e48fSopenharmony_ci{
191332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nullptr, nullptr, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
191432a6e48fSopenharmony_ci    cSurface->SetDefaultWidthAndHeight(300, 400);
191532a6e48fSopenharmony_ci    int32_t width;
191632a6e48fSopenharmony_ci    int32_t height;
191732a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, &height), OHOS::GSERROR_OK);
191832a6e48fSopenharmony_ci    ASSERT_EQ(width, 300);
191932a6e48fSopenharmony_ci    ASSERT_EQ(height, 400);
192032a6e48fSopenharmony_ci}
192132a6e48fSopenharmony_ci
192232a6e48fSopenharmony_ci/*
192332a6e48fSopenharmony_ci* Function: NativeWindowSetBufferHold
192432a6e48fSopenharmony_ci* Type: Function
192532a6e48fSopenharmony_ci* Rank: Important(1)
192632a6e48fSopenharmony_ci* EnvConditions: N/A
192732a6e48fSopenharmony_ci* CaseDescription: 1. call NativeWindowSetBufferHold and no ret
192832a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
192932a6e48fSopenharmony_ci */
193032a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowSetBufferHold001, Function | MediumTest | Level1)
193132a6e48fSopenharmony_ci{
193232a6e48fSopenharmony_ci    NativeWindowSetBufferHold(nullptr);
193332a6e48fSopenharmony_ci    NativeWindowSetBufferHold(nativeWindow);
193432a6e48fSopenharmony_ci    int fenceFd = -1;
193532a6e48fSopenharmony_ci    struct Region *region = new Region();
193632a6e48fSopenharmony_ci    region->rectNumber = 0;
193732a6e48fSopenharmony_ci    region->rects = nullptr;
193832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
193932a6e48fSopenharmony_ci              OHOS::GSERROR_BUFFER_STATE_INVALID);
194032a6e48fSopenharmony_ci    region->rectNumber = 1;
194132a6e48fSopenharmony_ci    struct Region::Rect * rect = new Region::Rect();
194232a6e48fSopenharmony_ci    rect->x = 0x100;
194332a6e48fSopenharmony_ci    rect->y = 0x100;
194432a6e48fSopenharmony_ci    rect->w = 0x100;
194532a6e48fSopenharmony_ci    rect->h = 0x100;
194632a6e48fSopenharmony_ci    region->rects = rect;
194732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowFlushBuffer(nativeWindow, nativeWindowBuffer, fenceFd, *region),
194832a6e48fSopenharmony_ci              OHOS::GSERROR_BUFFER_STATE_INVALID);
194932a6e48fSopenharmony_ci    cSurface->SetBufferHold(false);
195032a6e48fSopenharmony_ci    delete rect;
195132a6e48fSopenharmony_ci    delete region;
195232a6e48fSopenharmony_ci}
195332a6e48fSopenharmony_ci
195432a6e48fSopenharmony_ci/*
195532a6e48fSopenharmony_ci* Function: NativeWindow_ReadWriteWindow
195632a6e48fSopenharmony_ci* Type: Function
195732a6e48fSopenharmony_ci* Rank: Important(1)
195832a6e48fSopenharmony_ci* EnvConditions: N/A
195932a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_WriteToParcel and OH_NativeWindow_ReadFromParcel
196032a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
196132a6e48fSopenharmony_ci */
196232a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowReadWriteWindow001, Function | MediumTest | Level1)
196332a6e48fSopenharmony_ci{
196432a6e48fSopenharmony_ci    using namespace OHOS;
196532a6e48fSopenharmony_ci    sptr<OHOS::IConsumerSurface> cSurface = IConsumerSurface::Create();
196632a6e48fSopenharmony_ci    sptr<IBufferConsumerListener> listener = new BufferConsumerListener();
196732a6e48fSopenharmony_ci    cSurface->RegisterConsumerListener(listener);
196832a6e48fSopenharmony_ci    sptr<OHOS::IBufferProducer> producer = cSurface->GetProducer();
196932a6e48fSopenharmony_ci    sptr<OHOS::Surface> pSurface = Surface::CreateSurfaceAsProducer(producer);
197032a6e48fSopenharmony_ci    OHNativeWindow* nativeWindow = CreateNativeWindowFromSurface(&pSurface);
197132a6e48fSopenharmony_ci    auto uniqueId = nativeWindow->surface->GetUniqueId();
197232a6e48fSopenharmony_ci    ASSERT_NE(nativeWindow, nullptr);
197332a6e48fSopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
197432a6e48fSopenharmony_ci    OHIPCParcel *parcel2 = OH_IPCParcel_Create();
197532a6e48fSopenharmony_ci    ASSERT_NE(parcel1, nullptr);
197632a6e48fSopenharmony_ci    ASSERT_NE(parcel2, nullptr);
197732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nullptr, parcel1), SURFACE_ERROR_INVALID_PARAM);
197832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
197932a6e48fSopenharmony_ci    auto innerParcel = parcel1->msgParcel;
198032a6e48fSopenharmony_ci    parcel1->msgParcel = nullptr;
198132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel1), SURFACE_ERROR_INVALID_PARAM);
198232a6e48fSopenharmony_ci    parcel1->msgParcel = innerParcel;
198332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel1), GSERROR_OK);
198432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow, parcel2), GSERROR_OK);
198532a6e48fSopenharmony_ci    // test read
198632a6e48fSopenharmony_ci    OHNativeWindow *readWindow = nullptr;
198732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(nullptr, &readWindow), SURFACE_ERROR_INVALID_PARAM);
198832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &readWindow), GSERROR_OK);
198932a6e48fSopenharmony_ci    ASSERT_NE(readWindow, nullptr);
199032a6e48fSopenharmony_ci    // test read twice
199132a6e48fSopenharmony_ci    OHNativeWindow *tempWindow = nullptr;
199232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &tempWindow), SURFACE_ERROR_INVALID_PARAM);
199332a6e48fSopenharmony_ci    cout << "test read write window, write window is " << nativeWindow << ", read windows is " << readWindow << endl;
199432a6e48fSopenharmony_ci    auto readId = readWindow->surface->GetUniqueId();
199532a6e48fSopenharmony_ci    ASSERT_EQ(uniqueId, readId);
199632a6e48fSopenharmony_ci    OHNativeWindow *readWindow1 = nullptr;
199732a6e48fSopenharmony_ci    SurfaceUtils::GetInstance()->RemoveNativeWindow(uniqueId);
199832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel2, &readWindow1), GSERROR_OK);
199932a6e48fSopenharmony_ci    ASSERT_NE(readWindow1, nativeWindow);
200032a6e48fSopenharmony_ci    auto readId1 = readWindow1->surface->GetUniqueId();
200132a6e48fSopenharmony_ci    ASSERT_EQ(uniqueId, readId1);
200232a6e48fSopenharmony_ci    cout << "write uniqueId is " << uniqueId << ", parcel1 read id is " << readId <<
200332a6e48fSopenharmony_ci        ", parcel2 read id is " << readId1 << endl;
200432a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(readWindow1);
200532a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindow(nativeWindow);
200632a6e48fSopenharmony_ci    OH_IPCParcel_Destroy(parcel1);
200732a6e48fSopenharmony_ci    OH_IPCParcel_Destroy(parcel2);
200832a6e48fSopenharmony_ci}
200932a6e48fSopenharmony_ci
201032a6e48fSopenharmony_ci/*
201132a6e48fSopenharmony_ci* Function: NativeWindow_ReadWriteWindow
201232a6e48fSopenharmony_ci* Type: Function
201332a6e48fSopenharmony_ci* Rank: Important(1)
201432a6e48fSopenharmony_ci* EnvConditions: N/A
201532a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_WriteToParcel and OH_NativeWindow_ReadFromParcel
201632a6e48fSopenharmony_ci* @tc.require: issueI5GMZN issueI5IWHW
201732a6e48fSopenharmony_ci */
201832a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowReadWriteWindow002, Function | MediumTest | Level1)
201932a6e48fSopenharmony_ci{
202032a6e48fSopenharmony_ci    using namespace OHOS;
202132a6e48fSopenharmony_ci    // test for no surface->GetUniqueId
202232a6e48fSopenharmony_ci    OHNativeWindow* nativeWindow1 = new OHNativeWindow();
202332a6e48fSopenharmony_ci    ASSERT_NE(nativeWindow1, nullptr);
202432a6e48fSopenharmony_ci    OHIPCParcel *parcel1 = OH_IPCParcel_Create();
202532a6e48fSopenharmony_ci    ASSERT_NE(parcel1, nullptr);
202632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_WriteToParcel(nativeWindow1, parcel1), SURFACE_ERROR_INVALID_PARAM);
202732a6e48fSopenharmony_ci    OHNativeWindow *readWindow = nullptr;
202832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, nullptr), SURFACE_ERROR_INVALID_PARAM);
202932a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_ReadFromParcel(parcel1, &readWindow), SURFACE_ERROR_INVALID_PARAM);
203032a6e48fSopenharmony_ci    OH_IPCParcel_Destroy(parcel1);
203132a6e48fSopenharmony_ci    delete nativeWindow1;
203232a6e48fSopenharmony_ci}
203332a6e48fSopenharmony_ci
203432a6e48fSopenharmony_ci/*
203532a6e48fSopenharmony_ci* Function: SurfaceErrorInvalidParameter
203632a6e48fSopenharmony_ci* Type: Function
203732a6e48fSopenharmony_ci* Rank: Important(2)
203832a6e48fSopenharmony_ci* EnvConditions: N/A
203932a6e48fSopenharmony_ci* CaseDescription: 1. call functions with invalid parameters and check ret
204032a6e48fSopenharmony_ci*/
204132a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SurfaceErrorInvalidParameter001, Function | MediumTest | Level2)
204232a6e48fSopenharmony_ci{
204332a6e48fSopenharmony_ci    int fence = -1;
204432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(nullptr), nullptr);
204532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nullptr, nullptr, &fence, nullptr), SURFACE_ERROR_INVALID_PARAM);
204632a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBuffer(nativeWindow, nullptr, &fence, nullptr),
204732a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
204832a6e48fSopenharmony_ci    ASSERT_EQ(GetNativeObjectMagic(nullptr), -1);
204932a6e48fSopenharmony_ci    ASSERT_EQ(GetSurfaceId(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
205032a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetTransformHint(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
205132a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, nullptr, nullptr), SURFACE_ERROR_INVALID_PARAM);
205232a6e48fSopenharmony_ci    int32_t width;
205332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindow, &width, nullptr), SURFACE_ERROR_INVALID_PARAM);
205432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nullptr, nullptr, &fence, nullptr), SURFACE_ERROR_INVALID_PARAM);
205532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, nullptr, &fence, nullptr),
205632a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
205732a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetLastFlushedBufferV2(nativeWindow, nullptr, nullptr, nullptr),
205832a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
205932a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowDisconnect(nullptr), SURFACE_ERROR_INVALID_PARAM);
206032a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_SetColorSpace(nullptr, OH_COLORSPACE_NONE), SURFACE_ERROR_INVALID_PARAM);
206132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetColorSpace(nullptr, nullptr), SURFACE_ERROR_INVALID_PARAM);
206232a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetColorSpace(nativeWindow, nullptr), SURFACE_ERROR_INVALID_PARAM);
206332a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetMetadataValue(nullptr, OH_HDR_METADATA_TYPE, nullptr, nullptr),
206432a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
206532a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_GetMetadataValue(nativeWindow, OH_HDR_METADATA_TYPE, nullptr, nullptr),
206632a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
206732a6e48fSopenharmony_ci}
206832a6e48fSopenharmony_ci
206932a6e48fSopenharmony_ci/*
207032a6e48fSopenharmony_ci* Function: SurfaceErrorInvalidParameter
207132a6e48fSopenharmony_ci* Type: Function
207232a6e48fSopenharmony_ci* Rank: Important(2)
207332a6e48fSopenharmony_ci* EnvConditions: N/A
207432a6e48fSopenharmony_ci* CaseDescription: 1. call functions with invalid parameters and check ret
207532a6e48fSopenharmony_ci*/
207632a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, SurfaceErrorInvalidParameter002, Function | MediumTest | Level2)
207732a6e48fSopenharmony_ci{
207832a6e48fSopenharmony_ci    OHNativeWindow *nativeWindowTemp = new OHNativeWindow();
207932a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer1;
208032a6e48fSopenharmony_ci    Region region;
208132a6e48fSopenharmony_ci    int32_t height;
208232a6e48fSopenharmony_ci    int32_t width;
208332a6e48fSopenharmony_ci    int fence = -1;
208432a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, nullptr),
208532a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
208632a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowFlushBuffer(nativeWindowTemp, nativeWindowBuffer, fence, region),
208732a6e48fSopenharmony_ci        SURFACE_ERROR_INVALID_PARAM);
208832a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowHandleOpt(nativeWindowTemp, 0), OHOS::GSERROR_INVALID_ARGUMENTS);
208932a6e48fSopenharmony_ci    OHScalingMode scalingMode1 = OHScalingMode::OH_SCALING_MODE_SCALE_TO_WINDOW;
209032a6e48fSopenharmony_ci    OHScalingModeV2 scalingMode2 = OHScalingModeV2::OH_SCALING_MODE_SCALE_TO_WINDOW_V2;
209132a6e48fSopenharmony_ci    ASSERT_EQ(OH_NativeWindow_NativeWindowSetScalingMode(nativeWindowTemp, firstSeqnum, scalingMode1),
209232a6e48fSopenharmony_ci        OHOS::GSERROR_INVALID_ARGUMENTS);
209332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetScalingModeV2(nativeWindowTemp, scalingMode2), OHOS::GSERROR_INVALID_ARGUMENTS);
209432a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetScalingModeV2(nullptr, scalingMode2), OHOS::GSERROR_INVALID_ARGUMENTS);
209532a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetMetaData(nativeWindowTemp, 0, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
209632a6e48fSopenharmony_ci    OHHDRMetadataKey key = OHHDRMetadataKey::OH_METAKEY_HDR10_PLUS;
209732a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetMetaDataSet(nativeWindowTemp, 0, key, 0, nullptr), OHOS::GSERROR_INVALID_ARGUMENTS);
209832a6e48fSopenharmony_ci    OHExtDataHandle *handle = AllocOHExtDataHandle(1);
209932a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetTunnelHandle(nativeWindowTemp, handle), OHOS::GSERROR_INVALID_ARGUMENTS);
210032a6e48fSopenharmony_ci    OH_NativeBuffer_TransformType transform = OH_NativeBuffer_TransformType::NATIVEBUFFER_ROTATE_180;
210132a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetTransformHint(nativeWindowTemp, &transform), OHOS::GSERROR_INVALID_ARGUMENTS);
210232a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetTransformHint(nativeWindowTemp, transform), OHOS::GSERROR_INVALID_ARGUMENTS);
210332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowGetDefaultWidthAndHeight(nativeWindowTemp, &width, &height), OHOS::GSERROR_INVALID_ARGUMENTS);
210432a6e48fSopenharmony_ci    NativeWindowSetBufferHold(nativeWindowTemp);
210532a6e48fSopenharmony_ci}
210632a6e48fSopenharmony_ci
210732a6e48fSopenharmony_ci/*
210832a6e48fSopenharmony_ci* Function: NativeWindowSetRequestWidthAndHeight
210932a6e48fSopenharmony_ci* Type: Function
211032a6e48fSopenharmony_ci* Rank: Important(2)
211132a6e48fSopenharmony_ci* EnvConditions: N/A
211232a6e48fSopenharmony_ci* CaseDescription: 1. call NativeWindowSetRequestWidthAndHeight with invalid parameters and check ret
211332a6e48fSopenharmony_ci*                  2. call NativeWindowSetRequestWidthAndHeight with normal parameters and check ret
211432a6e48fSopenharmony_ci*                  3. call NativeWindowSetRequestWidthAndHeight with zore width and check ret
211532a6e48fSopenharmony_ci*                  3. call NativeWindowSetRequestWidthAndHeight with zore height and check ret
211632a6e48fSopenharmony_ci */
211732a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, NativeWindowSetRequestWidthAndHeight001, Function | MediumTest | Level2)
211832a6e48fSopenharmony_ci{
211932a6e48fSopenharmony_ci    int fence = -1;
212032a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nullptr, 0, 0), SURFACE_ERROR_INVALID_PARAM);
212132a6e48fSopenharmony_ci    cSurface->SetDefaultWidthAndHeight(300, 400);
212232a6e48fSopenharmony_ci    //分支1:走使用requestWidth/Height新建config分支
212332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 100, 200), OHOS::GSERROR_OK);
212432a6e48fSopenharmony_ci    NativeWindowBuffer *nativeWindowBuffer1 = nullptr;
212532a6e48fSopenharmony_ci    auto ret = OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence);
212632a6e48fSopenharmony_ci    if (ret != GSERROR_HDI_ERROR) {
212732a6e48fSopenharmony_ci        ASSERT_EQ(ret, GSERROR_OK);
212832a6e48fSopenharmony_ci        ASSERT_EQ(nativeWindowBuffer1->sfbuffer->GetWidth(), 100);
212932a6e48fSopenharmony_ci        ASSERT_EQ(nativeWindowBuffer1->sfbuffer->GetHeight(), 200);
213032a6e48fSopenharmony_ci        ASSERT_EQ(NativeWindowCancelBuffer(nativeWindow, nativeWindowBuffer1), GSERROR_OK);
213132a6e48fSopenharmony_ci    }
213232a6e48fSopenharmony_ci    //分支2:使用surface成员变量windowConfig_(未初始化)
213332a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 0, 200), OHOS::GSERROR_OK);
213432a6e48fSopenharmony_ci    ASSERT_NE(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence),
213532a6e48fSopenharmony_ci        OHOS::GSERROR_OK);
213632a6e48fSopenharmony_ci    ASSERT_EQ(NativeWindowSetRequestWidthAndHeight(nativeWindow, 100, 0), OHOS::GSERROR_OK);
213732a6e48fSopenharmony_ci    ASSERT_NE(OH_NativeWindow_NativeWindowRequestBuffer(nativeWindow, &nativeWindowBuffer1, &fence),
213832a6e48fSopenharmony_ci        OHOS::GSERROR_OK);
213932a6e48fSopenharmony_ci}
214032a6e48fSopenharmony_ci
214132a6e48fSopenharmony_ci/*
214232a6e48fSopenharmony_ci* Function: OH_NativeWindow_DestroyNativeWindowBuffer
214332a6e48fSopenharmony_ci* Type: Function
214432a6e48fSopenharmony_ci* Rank: Important(2)
214532a6e48fSopenharmony_ci* EnvConditions: N/A
214632a6e48fSopenharmony_ci* CaseDescription: 1. call OH_NativeWindow_DestroyNativeWindowBuffer again
214732a6e48fSopenharmony_ci*                  2. check ret
214832a6e48fSopenharmony_ci */
214932a6e48fSopenharmony_ciHWTEST_F(NativeWindowTest, OH_NativeWindow_DestroyNativeWindowBuffer002, Function | MediumTest | Level2)
215032a6e48fSopenharmony_ci{
215132a6e48fSopenharmony_ci    ASSERT_NE(nativeWindowBuffer, nullptr);
215232a6e48fSopenharmony_ci    OH_NativeWindow_DestroyNativeWindowBuffer(nativeWindowBuffer);
215332a6e48fSopenharmony_ci}
215432a6e48fSopenharmony_ci}
2155