1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <fstream>
17 #include <gtest/gtest.h>
18
19 #include "drawing_error_code.h"
20 #include "drawing_memory_stream.h"
21
22 #include "utils/memory_stream.h"
23
24 #ifdef RS_ENABLE_VK
25 #include "platform/ohos/backend/rs_vulkan_context.h"
26 #endif
27
28 using namespace testing;
29 using namespace testing::ext;
30
31 namespace OHOS {
32 namespace Rosen {
33 namespace Drawing {
34 class NativeDrawingMemoryStreamTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40 };
41
SetUpTestCase()42 void NativeDrawingMemoryStreamTest::SetUpTestCase()
43 {
44 #ifdef RS_ENABLE_VK
45 RsVulkanContext::SetRecyclable(false);
46 #endif
47 }
TearDownTestCase()48 void NativeDrawingMemoryStreamTest::TearDownTestCase() {}
SetUp()49 void NativeDrawingMemoryStreamTest::SetUp() {}
TearDown()50 void NativeDrawingMemoryStreamTest::TearDown() {}
51
52 /**
53 * @tc.name: NativeDrawingCastToMemoryStreamTest001
54 * @tc.desc: test for OH_Drawing_MemoryStreamCreate.
55 * @tc.type: FUNC
56 * @tc.require: AR20240104201189
57 */
58 HWTEST_F(NativeDrawingMemoryStreamTest, NativeDrawingMemoryStreamCreateTest001, TestSize.Level1)
59 {
60 char data[10] = { 0 };
61 OH_Drawing_MemoryStream* stream = OH_Drawing_MemoryStreamCreate(data, 10, false);
62 ASSERT_TRUE(stream != nullptr);
63 OH_Drawing_MemoryStreamCreate(nullptr, 0, false);
64 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
65 OH_Drawing_MemoryStreamCreate(stream, 0, false);
66 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
67 }
68
69 /**
70 * @tc.name: NativeDrawingMemoryStreamDestroyTest001
71 * @tc.desc: test for OH_Drawing_MemoryStreamCreate.
72 * @tc.type: FUNC
73 * @tc.require: AR20240104201189
74 */
75 HWTEST_F(NativeDrawingMemoryStreamTest, NativeDrawingMemoryStreamDestroyTest001, TestSize.Level1)
76 {
77 char data[10] = { 0 };
78 OH_Drawing_MemoryStream* stream = OH_Drawing_MemoryStreamCreate(data, 10, false);
79 ASSERT_TRUE(stream != nullptr);
80 OH_Drawing_MemoryStreamDestroy(stream);
81 }
82
83 } // namespace Drawing
84 } // namespace Rosen
85 } // namespace OHOS
86