* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "include/DrawingNativePathTest.h"
#include "include/OhosCommonTest.h"
#define DRAWING_NUMBER_1 1
#define DRAWING_NUMBER_2 2
#define DRAWING_NUMBER_4 4
#define DRAWING_NUMBER_5 5
#define DRAWING_NUMBER_10 10
#define DRAWING_NUMBER_30 30
#define DRAWING_NUMBER_50 50
#define DRAWING_NUMBER_100 100
namespace OHOS {
namespace Rosen {
namespace Drawing {
void DrawingNativePathPart2TestSetUp()
{
std::cout << "DrawingNativePathPart2Test Setup code called before each test case." << std::endl;
OH_Drawing_ErrorCodeReset();
std::cout << "DrawingNativePathPart2Test errorCodeReset before each test case." << std::endl;
}
void DrawingNativePathPart2TestTearDown()
{
std::cout << "DrawingNativePathPart2Test Setup code called after each test case." << std::endl;
OH_Drawing_ErrorCodeReset();
std::cout << "DrawingNativePathPart2Test errorCodeReset after each test case." << std::endl;
}
int TestPathAddArcNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddArc(path, rect, 0.0f, 0.0f);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddArcNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathAddArc(nullptr, rect, 0.0f, 0.0f);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddArc(path, nullptr, 0.0f, 0.0f);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathAddArc(path, rect, 0.0f, 0.0f);
OH_Drawing_PathAddArc(path, rect, 0.0f, 0.0f);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddArcAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddArc(path, rect, DRAWING_NUMBER_30, 30.0f);
OH_Drawing_PathAddArc(path, rect, 30.0f, DRAWING_NUMBER_30);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddArcMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddArc(path, rect, FLT_MAX + DRAWING_NUMBER_1, 0.0f);
OH_Drawing_PathAddArc(path, rect, 0.0f, FLT_MAX + DRAWING_NUMBER_1);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddPath(path, src, nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_5, DRAWING_NUMBER_4, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0,
DRAWING_NUMBER_1);
OH_Drawing_PathAddPath(nullptr, src, matrix);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPath(path, nullptr, matrix);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathAddPath(path, src, nullptr);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithMatrixAndModeNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
for (int i = 0; i < DRAWING_NUMBER_2; i++) {
OH_Drawing_ErrorCodeReset();
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_5, DRAWING_NUMBER_4, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0,
DRAWING_NUMBER_1);
OH_Drawing_PathAddPathWithMatrixAndMode(path, src, matrix, modes[i]);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_MatrixDestroy(matrix);
}
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithMatrixAndModeNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_5, DRAWING_NUMBER_4, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0,
DRAWING_NUMBER_1);
OH_Drawing_PathAddPathWithMatrixAndMode(nullptr, src, matrix, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPathWithMatrixAndMode(path, nullptr, matrix, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathAddPathWithMatrixAndMode(path, src, nullptr, PATH_ADD_MODE_APPEND);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithModeNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
for (int i = 0; i < DRAWING_NUMBER_2; i++) {
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPathWithMode(path, src, modes[i]);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
}
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithModeNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathAddPathWithMode(nullptr, src, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPathWithMode(path, nullptr, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithOffsetAndModeNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddMode modes[] = {PATH_ADD_MODE_APPEND, PATH_ADD_MODE_EXTEND};
for (int i = 0; i < DRAWING_NUMBER_2; i++) {
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, 10.0f, modes[i]);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
}
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithOffsetAndModeNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathAddPathWithOffsetAndMode(nullptr, src, 10.0f, 10.0f, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPathWithOffsetAndMode(path, nullptr, 10.0f, 10.0f, PATH_ADD_MODE_APPEND);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 0.0f, 10.0f, PATH_ADD_MODE_APPEND);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, 0.0f, PATH_ADD_MODE_APPEND);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithOffsetAndModeAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, DRAWING_NUMBER_10, 10.0f, PATH_ADD_MODE_APPEND);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, DRAWING_NUMBER_10, PATH_ADD_MODE_APPEND);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(src);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPathWithOffsetAndModeMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, FLT_MAX + DRAWING_NUMBER_1, 10.0f, PATH_ADD_MODE_APPEND);
OH_Drawing_PathAddPathWithOffsetAndMode(path, src, 10.0f, FLT_MAX + DRAWING_NUMBER_1, PATH_ADD_MODE_APPEND);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddOvalNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathDirection directions[] = {PATH_DIRECTION_CW, PATH_DIRECTION_CCW};
for (int i = 0; i < DRAWING_NUMBER_2; i++) {
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddOval(path, rect, directions[i]);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
}
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddOvalNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathAddOval(nullptr, rect, PATH_DIRECTION_CW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddOval(path, nullptr, PATH_DIRECTION_CW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPolygonNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_Point2D point1 = {0, 0};
OH_Drawing_Point2D point2 = {DRAWING_NUMBER_100, 0};
OH_Drawing_Point2D point3 = {DRAWING_NUMBER_100, DRAWING_NUMBER_100};
OH_Drawing_Point2D point4 = {0, DRAWING_NUMBER_100};
OH_Drawing_Point2D points[DRAWING_NUMBER_4] = {point1, point2, point3, point4};
OH_Drawing_PathAddPolygon(path, points, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPolygonNormal2()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_Point2D point1 = {0, 0};
OH_Drawing_Point2D point2 = {DRAWING_NUMBER_100, 0};
OH_Drawing_Point2D point3 = {DRAWING_NUMBER_100, DRAWING_NUMBER_100};
OH_Drawing_Point2D point4 = {0, DRAWING_NUMBER_100};
OH_Drawing_Point2D points[DRAWING_NUMBER_4] = {point1, point2, point3, point4};
OH_Drawing_PathAddPolygon(path, points, DRAWING_NUMBER_4, false);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPolygonNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Point2D point1 = {0, 0};
OH_Drawing_Point2D point2 = {DRAWING_NUMBER_100, 0};
OH_Drawing_Point2D point3 = {DRAWING_NUMBER_100, DRAWING_NUMBER_100};
OH_Drawing_Point2D point4 = {0, DRAWING_NUMBER_100};
OH_Drawing_Point2D points[DRAWING_NUMBER_4] = {point1, point2, point3, point4};
OH_Drawing_PathAddPolygon(nullptr, points, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPolygon(path, nullptr, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathAddPolygon(path, points, 0, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPolygonAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_Point2D point1 = {0, 0};
OH_Drawing_Point2D point2 = {DRAWING_NUMBER_100, 0};
OH_Drawing_Point2D point3 = {DRAWING_NUMBER_100, DRAWING_NUMBER_100};
OH_Drawing_Point2D point4 = {0, DRAWING_NUMBER_100};
OH_Drawing_Point2D points[DRAWING_NUMBER_4] = {point1, point2, point3, point4};
OH_Drawing_PathAddPolygon(path, points, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathAddPolygon(path, points, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathAddPolygon(path, points, 4.0f, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddPolygonMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_Point2D point1 = {FLT_MAX + DRAWING_NUMBER_1, 0};
OH_Drawing_Point2D point2 = {FLT_MAX + DRAWING_NUMBER_1, 0};
OH_Drawing_Point2D point3 = {FLT_MAX + DRAWING_NUMBER_1, DRAWING_NUMBER_100};
OH_Drawing_Point2D point4 = {FLT_MAX + DRAWING_NUMBER_1, DRAWING_NUMBER_100};
OH_Drawing_Point2D points[DRAWING_NUMBER_4] = {point1, point2, point3, point4};
OH_Drawing_PathAddPolygon(path, points, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_Point2D point5 = {0, FLT_MAX + DRAWING_NUMBER_1};
OH_Drawing_Point2D point6 = {DRAWING_NUMBER_100, FLT_MAX + DRAWING_NUMBER_1};
OH_Drawing_Point2D point7 = {DRAWING_NUMBER_100, FLT_MAX + DRAWING_NUMBER_1};
OH_Drawing_Point2D point8 = {0, FLT_MAX + DRAWING_NUMBER_1};
OH_Drawing_Point2D points2[DRAWING_NUMBER_4] = {point5, point6, point7, point8};
OH_Drawing_PathAddPolygon(path, points2, DRAWING_NUMBER_4, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddCircleNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, DRAWING_NUMBER_50, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, DRAWING_NUMBER_50, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddCircleNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathAddCircle(nullptr, DRAWING_NUMBER_50, DRAWING_NUMBER_50, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathAddCircle(path, 0.00f, DRAWING_NUMBER_50, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, 0.00f, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, DRAWING_NUMBER_50, 0.00f,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddCircleAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, 50.0f, 10.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathAddCircle(path, 50.0f, DRAWING_NUMBER_50, 10.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathAddCircle(path, 50.0f, 50.0f, DRAWING_NUMBER_10, OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathAddCircleMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathAddCircle(path, FLT_MAX + DRAWING_NUMBER_1, DRAWING_NUMBER_50, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, FLT_MAX + DRAWING_NUMBER_1, DRAWING_NUMBER_10,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
OH_Drawing_PathAddCircle(path, DRAWING_NUMBER_50, DRAWING_NUMBER_50, FLT_MAX + DRAWING_NUMBER_1,
OH_Drawing_PathDirection::PATH_DIRECTION_CCW);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathBuildFromSvgStringNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
const char *svgString = "M 0 0 L 100 100";
bool svgResult = OH_Drawing_PathBuildFromSvgString(path, svgString);
EXPECT_EQ(svgResult, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathBuildFromSvgStringNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
bool svgResult = OH_Drawing_PathBuildFromSvgString(nullptr, "M 0 0 L 100 100");
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
EXPECT_EQ(svgResult, false);
OH_Drawing_ErrorCodeReset();
svgResult = OH_Drawing_PathBuildFromSvgString(path, nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
EXPECT_EQ(svgResult, false);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathContainsNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathLineTo(path, 0, 0);
OH_Drawing_PathClose(path);
EXPECT_EQ(OH_Drawing_PathContains(path, DRAWING_NUMBER_50, DRAWING_NUMBER_50), true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathContainsNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
bool ret = OH_Drawing_PathContains(nullptr, DRAWING_NUMBER_50, DRAWING_NUMBER_50);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
EXPECT_EQ(ret, false);
ret = OH_Drawing_PathContains(path, 0.0f, DRAWING_NUMBER_50);
EXPECT_EQ(ret, false);
ret = OH_Drawing_PathContains(path, DRAWING_NUMBER_50, 0.0f);
EXPECT_EQ(ret, false);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathContainsAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathLineTo(path, 0, 0);
OH_Drawing_PathClose(path);
bool ret = OH_Drawing_PathContains(path, DRAWING_NUMBER_50, 50.0f);
EXPECT_EQ(ret, true);
ret = OH_Drawing_PathContains(path, 50.0f, DRAWING_NUMBER_50);
EXPECT_EQ(ret, true);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathContainsMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, 0, DRAWING_NUMBER_100);
OH_Drawing_PathClose(path);
bool ret = OH_Drawing_PathContains(path, FLT_MAX + DRAWING_NUMBER_1, DRAWING_NUMBER_50);
EXPECT_EQ(ret, false);
ret = OH_Drawing_PathContains(path, DRAWING_NUMBER_50, FLT_MAX + DRAWING_NUMBER_1);
EXPECT_EQ(ret, false);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathTransformNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_1, 0, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0, DRAWING_NUMBER_1);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathTransform(path, matrix);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathTransformNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_1, 0, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0, DRAWING_NUMBER_1);
OH_Drawing_PathTransform(nullptr, matrix);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathTransform(path, nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathTransformWithPerspectiveClipNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_MatrixSetMatrix(matrix, DRAWING_NUMBER_1, 0, 0, 0, -DRAWING_NUMBER_1, 0, 0, 0, DRAWING_NUMBER_1);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, dst, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(src);
OH_Drawing_PathDestroy(dst);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathTransformWithPerspectiveClipNormal2()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathMoveTo(src, 0, 0);
OH_Drawing_PathLineTo(src, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, dst, false);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(src);
OH_Drawing_PathDestroy(dst);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathTransformWithPerspectiveClipNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *src = OH_Drawing_PathCreate();
EXPECT_NE(src, nullptr);
OH_Drawing_Matrix *matrix = OH_Drawing_MatrixCreate();
EXPECT_NE(matrix, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathTransformWithPerspectiveClip(nullptr, matrix, dst, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathTransformWithPerspectiveClip(src, nullptr, dst, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathTransformWithPerspectiveClip(src, matrix, nullptr, true);
OH_Drawing_PathDestroy(src);
OH_Drawing_PathDestroy(dst);
OH_Drawing_MatrixDestroy(matrix);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathSetFillTypeNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathLineTo(path, 0, 0);
OH_Drawing_PathClose(path);
OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_WINDING);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_EVEN_ODD);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_INVERSE_WINDING);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathSetFillType(path, OH_Drawing_PathFillType::PATH_FILL_TYPE_INVERSE_EVEN_ODD);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathSetFillTypeNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathSetFillType(nullptr, OH_Drawing_PathFillType::PATH_FILL_TYPE_WINDING);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathSetFillType(path, static_cast<OH_Drawing_PathFillType>(-DRAWING_NUMBER_1));
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathSetFillTypeMultipleCalls()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathLineTo(path, 0, 0);
OH_Drawing_PathClose(path);
for (int i = 0; i < DRAWING_NUMBER_10; i++) {
OH_Drawing_PathSetFillType(path, static_cast<OH_Drawing_PathFillType>(i));
}
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathGetLengthNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
float length = OH_Drawing_PathGetLength(path, true);
EXPECT_NE(length, 0.0f);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathGetLengthNormal2()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
float length = OH_Drawing_PathGetLength(path, false);
EXPECT_NE(length, 0.0f);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathGetLengthNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathGetLength(nullptr, true);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathGetBoundsNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathGetBounds(path, rect);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathGetBoundsNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_NE(rect, nullptr);
OH_Drawing_PathGetBounds(nullptr, rect);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_ErrorCodeReset();
OH_Drawing_PathGetBounds(path, nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
OH_Drawing_RectDestroy(rect);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathCloseNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, 0);
OH_Drawing_PathClose(path);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathCloseNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathClose(nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathOffsetNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathOffset(path, dst, DRAWING_NUMBER_10, DRAWING_NUMBER_10);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(dst);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathOffsetNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathOffset(nullptr, dst, DRAWING_NUMBER_10, DRAWING_NUMBER_10);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathOffset(path, nullptr, DRAWING_NUMBER_10, DRAWING_NUMBER_10);
OH_Drawing_PathOffset(path, dst, 0.00f, DRAWING_NUMBER_10);
OH_Drawing_PathOffset(path, dst, DRAWING_NUMBER_10, 0.00f);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(dst);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathOffsetAbnormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathOffset(path, dst, DRAWING_NUMBER_10, 10.0f);
OH_Drawing_PathOffset(path, dst, 10.0f, DRAWING_NUMBER_10);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(dst);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathOffsetMaximal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_Path *dst = OH_Drawing_PathCreate();
EXPECT_NE(dst, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathOffset(path, dst, FLT_MAX + DRAWING_NUMBER_1, 10.0f);
OH_Drawing_PathOffset(path, dst, 10.0f, FLT_MAX + DRAWING_NUMBER_1);
OH_Drawing_PathDestroy(path);
OH_Drawing_PathDestroy(dst);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathResetNormal()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathReset(path);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_SUCCESS);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathResetNull()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathReset(nullptr);
EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
int TestPathResetMultipleCalls()
{
DrawingNativePathPart2TestSetUp();
OH_Drawing_Path *path = OH_Drawing_PathCreate();
EXPECT_NE(path, nullptr);
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathReset(path);
for (int i = 0; i < DRAWING_NUMBER_10; i++) {
OH_Drawing_PathMoveTo(path, 0, 0);
OH_Drawing_PathLineTo(path, DRAWING_NUMBER_100, DRAWING_NUMBER_100);
OH_Drawing_PathReset(path);
}
OH_Drawing_PathDestroy(path);
DrawingNativePathPart2TestTearDown();
return OH_DRAWING_SUCCESS;
}
}
}
}