ui_label_button_unit_test.cpp 5.2 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
/*
 * Copyright (c) 2020-2021 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 "components/ui_label_button.h"

#include <climits>
#include <gtest/gtest.h>
#include "font/ui_font.h"

using namespace testing::ext;
namespace OHOS {
class UILabelButtonTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    static UILabelButton* labelBtn_;
};

UILabelButton* UILabelButtonTest::labelBtn_ = nullptr;

void UILabelButtonTest::SetUpTestCase()
{
    if (labelBtn_ == nullptr) {
        labelBtn_ = new UILabelButton();
    }
}

void UILabelButtonTest::TearDownTestCase()
{
    if (labelBtn_ != nullptr) {
        delete labelBtn_;
        labelBtn_ = nullptr;
    }
}

/**
 * @tc.name: UILabelButtonGetViewType_001
 * @tc.desc: Verify GetViewType function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonGetViewType_001, TestSize.Level1)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    EXPECT_EQ(labelBtn_->GetViewType(), UI_LABEL_BUTTON);
}

/**
 * @tc.name: UILabelButtonSetText_001
 * @tc.desc: Verify SetText function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonSetText_001, TestSize.Level1)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    const char* text = "abc";

    labelBtn_->SetText(text);
    if (labelBtn_->GetText() == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    EXPECT_EQ(strcmp(labelBtn_->GetText(), text), 0);
}
/**
 * @tc.name: UILabelButtonSetLablePosition_001
L
lancer 已提交
86
 * @tc.desc: Verify SetLabelPosition function.
M
mamingshuai 已提交
87 88 89
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
邓志豪 已提交
90
HWTEST_F(UILabelButtonTest, UILabelButtonSetLablePosition_001, TestSize.Level1)
M
mamingshuai 已提交
91 92 93 94 95 96 97 98
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    const int16_t posX = 10;
    const int16_t posY = 20;

L
lancer 已提交
99
    labelBtn_->SetLabelPosition(posX, posY);
M
mamingshuai 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    EXPECT_EQ(labelBtn_->GetLabelPosition().x, posX);
    EXPECT_EQ(labelBtn_->GetLabelPosition().y, posY);
}

/**
 * @tc.name: UILabelButtonSetAlign_001
 * @tc.desc: Verify SetAlign function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonSetAlign_001, TestSize.Level0)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    labelBtn_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT);
    EXPECT_EQ(labelBtn_->GetAlign(), UITextLanguageAlignment::TEXT_ALIGNMENT_RIGHT);
}

/**
 * @tc.name: UILabelButtonSetDirect_001
 * @tc.desc: Verify SetDirect function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonSetDirect_001, TestSize.Level0)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    labelBtn_->SetDirect(UITextLanguageDirect::TEXT_DIRECT_RTL);
    EXPECT_EQ(labelBtn_->GetDirect(), UITextLanguageDirect::TEXT_DIRECT_RTL);
}

/**
 * @tc.name: UILabelButtonSetLabelStyle_001
 * @tc.desc: Verify SetLabelStyle function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
邓志豪 已提交
142
HWTEST_F(UILabelButtonTest, UILabelButtonSetLabelStyle_001, TestSize.Level1)
M
mamingshuai 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    Style style;
    style.borderWidth_ = 1;

    labelBtn_->SetLabelStyle(style);
    EXPECT_EQ(labelBtn_->GetLabelStyle().borderWidth_, style.borderWidth_);
}

/**
 * @tc.name: UILabelButtonSetLabelStyle_002
 * @tc.desc: Verify SetLabelStyle function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonSetLabelStyle_002, TestSize.Level1)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    labelBtn_->SetLabelStyle(STYLE_BORDER_OPA, OPA_TRANSPARENT);
    EXPECT_EQ(labelBtn_->GetLabelStyle(STYLE_BORDER_OPA), OPA_TRANSPARENT);
}

/**
 * @tc.name: UILabelButtonSetTextColor_001
 * @tc.desc: Verify SetTextColor function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
邓志豪 已提交
177
HWTEST_F(UILabelButtonTest, UILabelButtonSetTextColor_001, TestSize.Level1)
M
mamingshuai 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    labelBtn_->SetTextColor(Color::Gray());
    EXPECT_EQ(labelBtn_->GetLabelStyle().textColor_.full, Color::Gray().full);
}

/**
 * @tc.name: UILabelButtonSetFont_001
 * @tc.desc: Verify SetFontId function.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ5
 */
HWTEST_F(UILabelButtonTest, UILabelButtonSetFontId_001, TestSize.Level0)
{
    if (labelBtn_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    const uint8_t fontId = 16;
    labelBtn_->SetFontId(fontId);
    if (!UIFont::GetInstance()->IsVectorFont()) {
        EXPECT_EQ(labelBtn_->GetFontId(), fontId);
    } else {
        EXPECT_EQ(labelBtn_->GetFontId(), 0);
    }
}
} // namespace OHOS