* Copyright (c) 2024 Huawei Device 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 <gtest/gtest.h>
#include "modifier_test_base.h"
#include "modifiers_test_utils.h"
#include "core/interfaces/native/utility/reverse_converter.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Ace::NG {
namespace {
const auto ATTRIBUTE_WIDTH_NAME = "width";
const auto ATTRIBUTE_WIDTH_DEFAULT_VALUE = "0.00vp";
const auto ATTRIBUTE_HEIGHT_NAME = "height";
const auto ATTRIBUTE_HEIGHT_DEFAULT_VALUE = "0.00vp";
typedef std::pair<Opt_Length, std::string> DimensionTestStep;
static const std::vector<DimensionTestStep> VALID_VALUE_TEST_PLAN = {
{ Converter::ArkValue<Opt_Length>(1.), "1.00vp" },
{ Converter::ArkValue<Opt_Length>(0.), "0.00vp" },
{ Converter::ArkValue<Opt_Length>(2.45), "2.45vp" },
{ Converter::ArkValue<Opt_Length>("5px"), "5.00px" },
{ Converter::ArkValue<Opt_Length>("22.35px"), "22.35px" },
{ Converter::ArkValue<Opt_Length>("7vp"), "7.00vp" },
{ Converter::ArkValue<Opt_Length>("1.65vp"), "1.65vp" },
{ Converter::ArkValue<Opt_Length>("65fp"), "65.00fp" },
{ Converter::ArkValue<Opt_Length>("4.3fp"), "4.30fp" },
{ Converter::ArkValue<Opt_Length>("11lpx"), "11.00lpx" },
{ Converter::ArkValue<Opt_Length>("0.5lpx"), "0.50lpx" },
{ Converter::ArkValue<Opt_Length>("3"), "3.00vp" },
{ Converter::ArkValue<Opt_Length>("10.65"), "10.65vp" },
{ Converter::ArkValue<Opt_Length>("23%"), "23.00%" },
};
static const std::vector<DimensionTestStep> INVALID_VALUE_TEST_PLAN = {
{ Converter::ArkValue<Opt_Length>(-1.), "0.00vp" },
{ Converter::ArkValue<Opt_Length>(-3.56), "0.00vp" },
{ Converter::ArkValue<Opt_Length>("invalid value"), "0.00vp" },
{ Converter::ArkValue<Opt_Length>("-8px"), "0.00px" },
{ Converter::ArkValue<Opt_Length>("-15.6px"), "0.00px" },
{ Converter::ArkValue<Opt_Length>("-21vp"), "0.00vp" },
{ Converter::ArkValue<Opt_Length>("-8.6vp"), "0.00vp" },
{ Converter::ArkValue<Opt_Length>("-32fp"), "0.00fp" },
{ Converter::ArkValue<Opt_Length>("-9.99fp"), "0.00fp" },
{ Converter::ArkValue<Opt_Length>("-22lpx"), "0.00lpx" },
{ Converter::ArkValue<Opt_Length>("-1.23lpx"), "0.00lpx" },
{ Converter::ArkValue<Opt_Length>("-6"), "0.00vp" },
{ Converter::ArkValue<Opt_Length>("-16.2"), "0.00vp" },
};
}
class EllipseModifierTest : public ModifierTestBase<GENERATED_ArkUIEllipseModifier,
&GENERATED_ArkUINodeModifiers::getEllipseModifier, GENERATED_ARKUI_ELLIPSE> {
};
* @tc.name: setEllipseOptionsTestDefaultValues
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EllipseModifierTest, setEllipseOptionsTestDefaultValues, TestSize.Level1)
{
std::optional<std::string> strResult;
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_WIDTH_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_WIDTH_DEFAULT_VALUE));
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_HEIGHT_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_HEIGHT_DEFAULT_VALUE));
}
* @tc.name: setEllipseOptionsTestValidWidthValues
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EllipseModifierTest, setEllipseOptionsTestValidWidthValues, TestSize.Level1)
{
std::optional<std::string> strResult;
Opt_EllipseOptions optionsOpt;
Ark_EllipseOptions options;
options.height = Converter::ArkValue<Opt_Length>(Ark_Empty());
for (const auto &[width, expected]: VALID_VALUE_TEST_PLAN) {
options.width = width;
optionsOpt = Converter::ArkValue<Opt_EllipseOptions>(options);
modifier_->setEllipseOptions(node_, &optionsOpt);
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_WIDTH_NAME);
EXPECT_THAT(strResult, Eq(expected));
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_HEIGHT_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_HEIGHT_DEFAULT_VALUE));
}
}
* @tc.name: setEllipseOptionsTestValidHeightValues
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EllipseModifierTest, setEllipseOptionsTestValidHeightValues, TestSize.Level1)
{
std::optional<std::string> strResult;
Opt_EllipseOptions optionsOpt;
Ark_EllipseOptions options;
options.width = Converter::ArkValue<Opt_Length>(Ark_Empty());
for (const auto &[height, expected]: VALID_VALUE_TEST_PLAN) {
options.height = height;
optionsOpt = Converter::ArkValue<Opt_EllipseOptions>(options);
modifier_->setEllipseOptions(node_, &optionsOpt);
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_HEIGHT_NAME);
EXPECT_THAT(strResult, Eq(expected));
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_WIDTH_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_WIDTH_DEFAULT_VALUE));
}
}
* @tc.name: setEllipseOptionsTestInvalidWidthValues
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EllipseModifierTest, setEllipseOptionsTestInvalidWidthValues, TestSize.Level1)
{
std::optional<std::string> strResult;
Opt_EllipseOptions optionsOpt;
Ark_EllipseOptions options;
options.height = Converter::ArkValue<Opt_Length>(Ark_Empty());
for (const auto &[width, expected]: INVALID_VALUE_TEST_PLAN) {
options.width = width;
optionsOpt = Converter::ArkValue<Opt_EllipseOptions>(options);
modifier_->setEllipseOptions(node_, &optionsOpt);
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_WIDTH_NAME);
EXPECT_THAT(strResult, Eq(expected));
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_HEIGHT_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_HEIGHT_DEFAULT_VALUE));
}
}
* @tc.name: setEllipseOptionsTestInvalidHeightValues
* @tc.desc:
* @tc.type: FUNC
*/
HWTEST_F(EllipseModifierTest, setEllipseOptionsTestInvalidHeightValues, TestSize.Level1)
{
std::optional<std::string> strResult;
Opt_EllipseOptions optionsOpt;
Ark_EllipseOptions options;
options.width = Converter::ArkValue<Opt_Length>(Ark_Empty());
for (const auto &[height, expected]: INVALID_VALUE_TEST_PLAN) {
options.height = height;
optionsOpt = Converter::ArkValue<Opt_EllipseOptions>(options);
modifier_->setEllipseOptions(node_, &optionsOpt);
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_HEIGHT_NAME);
EXPECT_THAT(strResult, Eq(expected));
strResult = GetAttrValue<std::string>(node_, ATTRIBUTE_WIDTH_NAME);
EXPECT_THAT(strResult, Eq(ATTRIBUTE_WIDTH_DEFAULT_VALUE));
}
}
}