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 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class NativeDrawingMemoryStreamTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36 };
37
SetUpTestCase()38 void NativeDrawingMemoryStreamTest::SetUpTestCase() {}
TearDownTestCase()39 void NativeDrawingMemoryStreamTest::TearDownTestCase() {}
SetUp()40 void NativeDrawingMemoryStreamTest::SetUp() {}
TearDown()41 void NativeDrawingMemoryStreamTest::TearDown() {}
42
43 /**
44 * @tc.name: NativeDrawingCastToMemoryStreamTest001
45 * @tc.desc: test for OH_Drawing_MemoryStreamCreate.
46 * @tc.type: FUNC
47 * @tc.require: AR20240104201189
48 */
49 HWTEST_F(NativeDrawingMemoryStreamTest, NativeDrawingMemoryStreamCreateTest001, TestSize.Level1)
50 {
51 char data[10] = { 0 };
52 OH_Drawing_MemoryStream* stream = OH_Drawing_MemoryStreamCreate(data, 10, false);
53 ASSERT_TRUE(stream != nullptr);
54 OH_Drawing_MemoryStreamCreate(nullptr, 0, false);
55 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
56 OH_Drawing_MemoryStreamCreate(stream, 0, false);
57 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
58 }
59
60 /**
61 * @tc.name: NativeDrawingMemoryStreamDestroyTest001
62 * @tc.desc: test for OH_Drawing_MemoryStreamCreate.
63 * @tc.type: FUNC
64 * @tc.require: AR20240104201189
65 */
66 HWTEST_F(NativeDrawingMemoryStreamTest, NativeDrawingMemoryStreamDestroyTest001, TestSize.Level1)
67 {
68 char data[10] = { 0 };
69 OH_Drawing_MemoryStream* stream = OH_Drawing_MemoryStreamCreate(data, 10, false);
70 ASSERT_TRUE(stream != nullptr);
71 OH_Drawing_MemoryStreamDestroy(stream);
72 }
73
74 } // namespace Drawing
75 } // namespace Rosen
76 } // namespace OHOS
77