• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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, Hardware
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 "drawing_point.h"
17 #include "gtest/gtest.h"
18 #include "utils/scalar.h"
19 
20 #ifdef RS_ENABLE_VK
21 #include "platform/ohos/backend/rs_vulkan_context.h"
22 #endif
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class NativeDrawingPointTest : 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 NativeDrawingPointTest::SetUpTestCase()
39 {
40 #ifdef RS_ENABLE_VK
41     RsVulkanContext::SetRecyclable(false);
42 #endif
43 }
TearDownTestCase()44 void NativeDrawingPointTest::TearDownTestCase() {}
SetUp()45 void NativeDrawingPointTest::SetUp() {}
TearDown()46 void NativeDrawingPointTest::TearDown() {}
47 
48 /*
49  * @tc.name: NativeDrawingPointTest_PointGetAndSet001
50  * @tc.desc: test for set and get the x-axis and y-axis coordinates of the point.
51  * @tc.type: FUNC
52  * @tc.require: AR000GTO5R
53  */
54 HWTEST_F(NativeDrawingPointTest, NativeDrawingPointTest_PointGetAndSet001, TestSize.Level1)
55 {
56     OH_Drawing_Point* centerPt = OH_Drawing_PointCreate(0, 0);
57     EXPECT_EQ(OH_Drawing_PointSet(nullptr, 150, 250), OH_DRAWING_ERROR_INVALID_PARAMETER);
58     EXPECT_EQ(OH_Drawing_PointSet(centerPt, 150, 250), OH_DRAWING_SUCCESS); // 150: point's x, 250: point's y
59     float x, y;
60     EXPECT_EQ(OH_Drawing_PointGetX(centerPt, &x), OH_DRAWING_SUCCESS);
61     EXPECT_EQ(OH_Drawing_PointGetX(nullptr, &x), OH_DRAWING_ERROR_INVALID_PARAMETER);
62     EXPECT_EQ(OH_Drawing_PointGetX(centerPt, nullptr), OH_DRAWING_ERROR_INVALID_PARAMETER);
63     EXPECT_EQ(OH_Drawing_PointGetY(centerPt, &y), OH_DRAWING_SUCCESS);
64     EXPECT_EQ(OH_Drawing_PointGetY(nullptr, &y), OH_DRAWING_ERROR_INVALID_PARAMETER);
65     EXPECT_EQ(OH_Drawing_PointGetY(centerPt, nullptr), OH_DRAWING_ERROR_INVALID_PARAMETER);
66 
67     EXPECT_TRUE(IsScalarAlmostEqual(x, 150));
68     EXPECT_TRUE(IsScalarAlmostEqual(y, 250));
69     OH_Drawing_PointDestroy(centerPt);
70     OH_Drawing_PointDestroy(nullptr);
71 }
72 } // namespace Drawing
73 } // namespace Rosen
74 } // namespace OHOS