1 /* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gtest/gtest.h" 17 #include "drawing_bitmap.h" 18 #include "drawing_brush.h" 19 #include "drawing_canvas.h" 20 #include "drawing_color.h" 21 #include "drawing_color_filter.h" 22 #include "drawing_filter.h" 23 #include "drawing_font.h" 24 #include "drawing_image.h" 25 #include "drawing_mask_filter.h" 26 #include "drawing_matrix.h" 27 #include "drawing_memory_stream.h" 28 #include "drawing_path.h" 29 #include "drawing_pen.h" 30 #include "drawing_point.h" 31 #include "drawing_rect.h" 32 #include "drawing_region.h" 33 #include "drawing_round_rect.h" 34 #include "drawing_sampling_options.h" 35 #include "drawing_shader_effect.h" 36 #include "drawing_text_blob.h" 37 #include "drawing_typeface.h" 38 #include "drawing_record_cmd.h" 39 #include <random> 40 41 using namespace testing; 42 using namespace testing::ext; 43 44 namespace OHOS { 45 namespace Rosen { 46 namespace Drawing { 47 class DrawingRecordCmdUtilsBeginRecordingTest : public testing::Test { 48 protected: 49 // 在每个测试用例执行前调用 SetUp()50 void SetUp() override 51 { 52 // 设置代码 53 std::cout << "DrawingRecordCmdUtilsBeginRecordingTest Setup code called before each test case." << std::endl; 54 OH_Drawing_ErrorCodeReset(); 55 std::cout << "DrawingRecordCmdUtilsBeginRecordingTest errorCodeReset before each test case." << std::endl; 56 } TearDown()57 void TearDown() override 58 { 59 std::cout << "DrawingRecordCmdUtilsBeginRecordingTest Setup code called after each test case." << std::endl; 60 OH_Drawing_ErrorCodeReset(); 61 std::cout << "DrawingRecordCmdUtilsBeginRecordingTest errorCodeReset after each test case." << std::endl; 62 } 63 }; 64 65 /* 66 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECORDER_0102 67 * @tc.name: testRecordCmdUtilsBeginRecordingAbnormal 68 * @tc.desc: test for testRecordCmdUtilsBeginRecordingAbnormal. 69 * @tc.size : SmallTest 70 * @tc.type : Function 71 * @tc.level : Level 3 72 */ 73 HWTEST_F(DrawingRecordCmdUtilsBeginRecordingTest, testRecordCmdUtilsBeginRecordingAbnormal, Function | SmallTest | Level3) { 74 // 1. The first and fourth parameters of the OH-Drawing-RecordCmdUtelsBeginRecording interface are not empty 75 //with width and height being 0 and -1 76 OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); 77 // add assert 78 EXPECT_NE(canvas, nullptr); 79 OH_Drawing_Canvas** canvass = &canvas; 80 OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 81 OH_Drawing_RecordCmdUtils* recordcmd1 = OH_Drawing_RecordCmdUtilsCreate (); 82 drawingErrorCode = OH_Drawing_RecordCmdUtilsBeginRecording (nullptr, 0, -1, canvass); 83 EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 84 // 2. free memory 85 OH_Drawing_RecordCmdUtilsDestroy (recordcmd1); 86 OH_Drawing_CanvasDestroy (canvas); 87 } 88 89 /* 90 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECORDER_0103 91 * @tc.name: testRecordCmdUtilsBeginRecordingCalls 92 * @tc.desc: test for testRecordCmdUtilsBeginRecordingCalls. 93 * @tc.size : SmallTest 94 * @tc.type : Function 95 * @tc.level : Level 2 96 */ 97 HWTEST_F(DrawingRecordCmdUtilsBeginRecordingTest, testRecordCmdUtilsBeginRecordingCalls, Function | SmallTest | Level2) { 98 // 1. Call OH-Drawing-RecordCmdUtelsBeginRecording 10 times 99 OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); 100 // add assert 101 EXPECT_NE(canvas, nullptr); 102 OH_Drawing_Canvas** canvass = &canvas; 103 OH_Drawing_RecordCmdUtils* recordcmd1 = OH_Drawing_RecordCmdUtilsCreate (); 104 OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 105 for (int i = 0; i < 10; i++) 106 { 107 drawingErrorCode = OH_Drawing_RecordCmdUtilsBeginRecording (nullptr, 1, 1, canvass); 108 EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 109 } 110 // 2. free memory 111 OH_Drawing_RecordCmdUtilsDestroy (recordcmd1); 112 OH_Drawing_CanvasDestroy (canvas); 113 } 114 115 } // namespace Drawing 116 } // namespace Rosen 117 } // namespace OHOS 118