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 18 #include "drawing_point.h" 19 #include <random> 20 21 using namespace testing; 22 using namespace testing::ext; 23 24 namespace OHOS { 25 namespace Rosen { 26 namespace Drawing { 27 class DrawingNativePointTest : public testing::Test { 28 protected: 29 // 在每个测试用例执行前调用 SetUp()30 void SetUp() override 31 { 32 // 设置代码 33 std::cout << "DrawingNativePointTest Setup code called before each test case." << std::endl; 34 OH_Drawing_ErrorCodeReset(); 35 std::cout << "DrawingNativePointTest errorCodeReset before each test case." << std::endl; 36 } TearDown()37 void TearDown() override 38 { 39 std::cout << "DrawingNativePointTest Setup code called after each test case." << std::endl; 40 OH_Drawing_ErrorCodeReset(); 41 std::cout << "DrawingNativePointTest errorCodeReset after each test case." << std::endl; 42 } 43 }; 44 45 /* 46 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0100 47 * @tc.name: testPointCreateNormal 48 * @tc.desc: test for testPointCreateNormal. 49 * @tc.size : SmallTest 50 * @tc.type : Function 51 * @tc.level : Level 0 52 */ 53 HWTEST_F(DrawingNativePointTest, testPointCreateNormal, Function | SmallTest | Level0) { 54 // 1. Pass integer values for X and Y coordinates to OH_Drawing_PointCreate interface 55 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 56 // add assert 57 EXPECT_NE(point, nullptr); 58 // 2. Pass floating-point values for X and Y coordinates to OH_Drawing_PointCreate interface 59 OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100.5f, 60.0f); 60 // add assert 61 EXPECT_NE(point2, nullptr); 62 // 3. Free memory 63 OH_Drawing_PointDestroy(point); 64 OH_Drawing_PointDestroy(point2); 65 } 66 67 /* 68 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0101 69 * @tc.name: testPointCreateNull 70 * @tc.desc: test for testPointCreateNull. 71 * @tc.size : SmallTest 72 * @tc.type : Function 73 * @tc.level : Level 3 74 */ 75 HWTEST_F(DrawingNativePointTest, testPointCreateNull, Function | SmallTest | Level3) { 76 // 1. The first parameter of OH_Drawing_PointCreate is empty 77 OH_Drawing_Point *point = OH_Drawing_PointCreate(0, 60); 78 // add assert 79 EXPECT_NE(point, nullptr); 80 // 2. The second parameter of OH_Drawing_PointCreate is empty 81 OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, 0); 82 // add assert 83 EXPECT_NE(point2, nullptr); 84 // 3. Free memory 85 OH_Drawing_PointDestroy(point); 86 OH_Drawing_PointDestroy(point2); 87 } 88 89 /* 90 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0102 91 * @tc.name: testPointCreateAbnormal 92 * @tc.desc: test for testPointCreateAbnormal. 93 * @tc.size : SmallTest 94 * @tc.type : Function 95 * @tc.level : Level 3 96 */ 97 HWTEST_F(DrawingNativePointTest, testPointCreateAbnormal, Function | SmallTest | Level3) { 98 // 1. The first parameter of OH_Drawing_PointCreate is negative 99 OH_Drawing_Point *point = OH_Drawing_PointCreate(-100, 60); 100 // add assert 101 EXPECT_NE(point, nullptr); 102 // 2. The second parameter of OH_Drawing_PointCreate is negative 103 OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, -60); 104 // add assert 105 EXPECT_NE(point2, nullptr); 106 // 3. Free memory 107 OH_Drawing_PointDestroy(point); 108 OH_Drawing_PointDestroy(point2); 109 } 110 111 /* 112 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0103 113 * @tc.name: testPointCreateMaximum 114 * @tc.desc: test for testPointCreateMaximum. 115 * @tc.size : SmallTest 116 * @tc.type : Function 117 * @tc.level : Level 3 118 */ 119 HWTEST_F(DrawingNativePointTest, testPointCreateMaximum, Function | SmallTest | Level3) { 120 // 1. The first parameter of OH_Drawing_PointCreate is FLT_MAX 121 OH_Drawing_Point *point = OH_Drawing_PointCreate(FLT_MAX, 60); 122 // add assert 123 EXPECT_NE(point, nullptr); 124 // 2. The second parameter of OH_Drawing_PointCreate is FLT_MAX 125 OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, FLT_MAX); 126 // add assert 127 EXPECT_NE(point2, nullptr); 128 // 3. Free memory 129 OH_Drawing_PointDestroy(point); 130 OH_Drawing_PointDestroy(point2); 131 } 132 133 /* 134 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0104 135 * @tc.name: testPointCreateMultipleCalls 136 * @tc.desc: test for testPointCreateMultipleCalls. 137 * @tc.size : SmallTest 138 * @tc.type : Function 139 * @tc.level : Level 3 140 */ 141 HWTEST_F(DrawingNativePointTest, testPointCreateMultipleCalls, Function | SmallTest | Level3) { 142 // 1. Call OH_Drawing_PointCreate 10 times with random values for X and Y coordinates 143 std::random_device rd; 144 std::mt19937 gen(rd()); 145 std::uniform_real_distribution<float> dis(0, 100); 146 for (int i = 0; i < 10; i++) { 147 OH_Drawing_Point *point = OH_Drawing_PointCreate(dis(gen), dis(gen)); 148 // add assert 149 EXPECT_NE(point, nullptr); 150 OH_Drawing_PointDestroy(point); 151 } 152 } 153 154 /* 155 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0200 156 * @tc.name: testPointDestroyNormal 157 * @tc.desc: test for testPointDestroyNormal. 158 * @tc.size : SmallTest 159 * @tc.type : Function 160 * @tc.level : Level 0 161 */ 162 HWTEST_F(DrawingNativePointTest, testPointDestroyNormal, Function | SmallTest | Level0) { 163 // 1. Call OH_Drawing_PointCreate 164 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 165 // add assert 166 EXPECT_NE(point, nullptr); 167 // 2. Call OH_Drawing_PointDestroy 168 OH_Drawing_PointDestroy(point); 169 } 170 171 /* 172 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0201 173 * @tc.name: testPointDestroyNull 174 * @tc.desc: test for testPointDestroyNull. 175 * @tc.size : SmallTest 176 * @tc.type : Function 177 * @tc.level : Level 3 178 */ 179 HWTEST_F(DrawingNativePointTest, testPointDestroyNull, Function | SmallTest | Level3) { 180 // 1. The parameter of OH_Drawing_PointDestroy is nullptr 181 OH_Drawing_PointDestroy(nullptr); 182 // add assert 183 EXPECT_TRUE(true); 184 } 185 186 /* 187 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0300 188 * @tc.name: testPointGetXNormal 189 * @tc.desc: test for testPointGetXNormal. 190 * @tc.size : SmallTest 191 * @tc.type : Function 192 * @tc.level : Level 0 193 */ 194 HWTEST_F(DrawingNativePointTest, testPointGetXNormal, Function | SmallTest | Level0) { 195 //1. Pass integer values to OH_Drawing_PointGetX interface 196 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 197 // add assert 198 EXPECT_NE(point, nullptr); 199 float x; 200 OH_Drawing_PointGetX(point, &x); 201 //2. Pass floating-point values to OH_Drawing_PointGetX interface 202 OH_Drawing_Point *point1 = OH_Drawing_PointCreate(100.0f, 60.0f); 203 // add assert 204 EXPECT_NE(point1, nullptr); 205 OH_Drawing_PointGetX(point1, &x); 206 //3. free memory 207 OH_Drawing_PointDestroy(point); 208 OH_Drawing_PointDestroy(point1); 209 } 210 211 /* 212 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0301 213 * @tc.name: testPointGetXNull 214 * @tc.desc: test for testPointGetXNull. 215 * @tc.size : SmallTest 216 * @tc.type : Function 217 * @tc.level : Level 3 218 */ 219 HWTEST_F(DrawingNativePointTest, testPointGetXNull, Function | SmallTest | Level3) { 220 //1. OH_Drawing_PointGetX with the first parameter as null 221 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 222 // add assert 223 EXPECT_NE(point, nullptr); 224 float x; 225 EXPECT_EQ(OH_Drawing_PointGetX(nullptr, &x), OH_DRAWING_ERROR_INVALID_PARAMETER); 226 //2. OH_Drawing_PointGetX with the second parameter as null 227 EXPECT_EQ(OH_Drawing_PointGetX(point, nullptr), OH_DRAWING_ERROR_INVALID_PARAMETER); 228 //3. free memory 229 OH_Drawing_PointDestroy(point); 230 } 231 232 /* 233 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0302 234 * @tc.name: testPointGetXMultipleCalls 235 * @tc.desc: test for testPointGetXMultipleCalls. 236 * @tc.size : SmallTest 237 * @tc.type : Function 238 * @tc.level : Level 3 239 */ 240 HWTEST_F(DrawingNativePointTest, testPointGetXMultipleCalls, Function | SmallTest | Level3) { 241 //1. Call OH_Drawing_PointGetX 10 times with random values 242 std::random_device rd; 243 std::mt19937 gen(rd()); 244 std::uniform_real_distribution<float> dis(0, 100); 245 float x; 246 OH_Drawing_Point *point = nullptr; 247 for (int i = 0; i < 10; i++) { 248 point = OH_Drawing_PointCreate(dis(gen), dis(gen)); 249 // add assert 250 EXPECT_NE(point, nullptr); 251 OH_Drawing_PointGetX(point, &x); 252 } 253 //2. free memory 254 OH_Drawing_PointDestroy(point); 255 } 256 257 /* 258 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0400 259 * @tc.name: testPointGetYNormal 260 * @tc.desc: test for testPointGetYNormal. 261 * @tc.size : SmallTest 262 * @tc.type : Function 263 * @tc.level : Level 0 264 */ 265 HWTEST_F(DrawingNativePointTest, testPointGetYNormal, Function | SmallTest | Level0) { 266 //1. Pass integer values to OH_Drawing_PointGetY interface 267 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 268 // add assert 269 EXPECT_NE(point, nullptr); 270 float y; 271 OH_Drawing_PointGetX(nullptr, &y); 272 //2. Pass floating-point values to OH_Drawing_PointGetX interface 273 OH_Drawing_Point *point1 = OH_Drawing_PointCreate(100.0f, 60.0f); 274 // add assert 275 EXPECT_NE(point1, nullptr); 276 OH_Drawing_PointGetX(point1, &y); 277 //3. free memory 278 OH_Drawing_PointDestroy(point); 279 OH_Drawing_PointDestroy(point1); 280 } 281 282 /* 283 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0401 284 * @tc.name: testPointGetYNull 285 * @tc.desc: test for testPointGetYNull. 286 * @tc.size : SmallTest 287 * @tc.type : Function 288 * @tc.level : Level 3 289 */ 290 HWTEST_F(DrawingNativePointTest, testPointGetYNull, Function | SmallTest | Level3) { 291 //1. OH_Drawing_PointGetY with the first parameter as null 292 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 293 // add assert 294 EXPECT_NE(point, nullptr); 295 float y; 296 EXPECT_EQ(OH_Drawing_PointGetY(nullptr, &y), OH_DRAWING_ERROR_INVALID_PARAMETER); 297 //2. OH_Drawing_PointGetY with the second parameter as null 298 EXPECT_EQ(OH_Drawing_PointGetY(point, nullptr), OH_DRAWING_ERROR_INVALID_PARAMETER); 299 //3. free memory 300 OH_Drawing_PointDestroy(point); 301 } 302 303 /* 304 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0402 305 * @tc.name: testPointGetYMultipleCalls 306 * @tc.desc: test for testPointGetYMultipleCalls. 307 * @tc.size : SmallTest 308 * @tc.type : Function 309 * @tc.level : Level 3 310 */ 311 HWTEST_F(DrawingNativePointTest, testPointGetYMultipleCalls, Function | SmallTest | Level3) { 312 //1. Call OH_Drawing_PointGetX 10 times with random values 313 std::random_device rd; 314 std::mt19937 gen(rd()); 315 std::uniform_real_distribution<float> dis(0, 100); 316 float y; 317 OH_Drawing_Point *point = nullptr; 318 for (int i = 0; i < 10; i++) { 319 OH_Drawing_Point *point = OH_Drawing_PointCreate(dis(gen), dis(gen)); 320 // add assert 321 EXPECT_NE(point, nullptr); 322 OH_Drawing_PointGetX(point, &y); 323 } 324 //2. free memory 325 OH_Drawing_PointDestroy(point); 326 } 327 328 /* 329 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0400 330 * @tc.name: testPointSetNormal 331 * @tc.desc: test for testPointSetNormal. 332 * @tc.size : SmallTest 333 * @tc.type : Function 334 * @tc.level : Level 0 335 */ 336 HWTEST_F(DrawingNativePointTest, testPointSetNormal, Function | SmallTest | Level0) { 337 //1. Pass integar point values to OH_Drawing_PointSet interface 338 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 339 // add assert 340 EXPECT_NE(point, nullptr); 341 // add assert 342 EXPECT_EQ(OH_Drawing_PointSet(point, 10, 10), OH_DRAWING_SUCCESS); 343 //2. Pass floating-point values to OH_Drawing_PointSet interface 344 // add assert 345 EXPECT_EQ(OH_Drawing_PointSet(point, 20.f, 20.f), OH_DRAWING_SUCCESS); 346 //3. free memory 347 OH_Drawing_PointDestroy(point); 348 } 349 350 /* 351 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0401 352 * @tc.name: testPointSetNull 353 * @tc.desc: test for testPointSetNull. 354 * @tc.size : SmallTest 355 * @tc.type : Function 356 * @tc.level : Level 3 357 */ 358 HWTEST_F(DrawingNativePointTest, testPointSetNull, Function | SmallTest | Level3) { 359 //1. OH_Drawing_PointSet with the first parameter as null 360 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 361 // add assert 362 EXPECT_NE(point, nullptr); 363 EXPECT_EQ(OH_Drawing_PointSet(nullptr, 10, 10), OH_DRAWING_ERROR_INVALID_PARAMETER); 364 //2. OH_Drawing_PointSet with the second parameter as 0 365 EXPECT_EQ(OH_Drawing_PointSet(point, 0, 10), OH_DRAWING_SUCCESS); 366 //3. OH_Drawing_PointSet with the third parameter as 0 367 EXPECT_EQ(OH_Drawing_PointSet(point, 10, 0), OH_DRAWING_SUCCESS); 368 //4. free memory 369 OH_Drawing_PointDestroy(point); 370 } 371 372 /* 373 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0402 374 * @tc.name: testPointSetMultipleCalls 375 * @tc.desc: test for testPointSetMultipleCalls. 376 * @tc.size : SmallTest 377 * @tc.type : Function 378 * @tc.level : Level 3 379 */ 380 HWTEST_F(DrawingNativePointTest, testPointSetMultipleCalls, Function | SmallTest | Level3) { 381 //1. Call OH_Drawing_PointSet 10 times with random values 382 OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60); 383 // add assert 384 EXPECT_NE(point, nullptr); 385 std::random_device rd; 386 std::mt19937 gen(rd()); 387 std::uniform_real_distribution<float> dis(0, 100); 388 for (int i = 0; i < 10; i++) { 389 // add assert 390 EXPECT_EQ(OH_Drawing_PointSet(point, dis(gen), dis(gen)), OH_DRAWING_SUCCESS); 391 } 392 //2. free memory 393 OH_Drawing_PointDestroy(point); 394 } 395 396 } // namespace Drawing 397 } // namespace Rosen 398 } // namespace OHOS