ui_picker_unit_test.cpp 4.4 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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_picker.h"
#include <climits>
#include <gtest/gtest.h>
Z
zhangguyuan 已提交
19
#include "gfx_utils/style.h"
M
mamingshuai 已提交
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

using namespace testing::ext;
namespace OHOS {
class UIPickerTest : public testing::Test {
public:
    static void SetUpTestCase(void);
    static void TearDownTestCase(void);
    static UIPicker* picker_;
};

UIPicker* UIPickerTest::picker_ = nullptr;

void UIPickerTest::SetUpTestCase(void)
{
    if (picker_ == nullptr) {
        picker_ = new UIPicker();
    }
}

void UIPickerTest::TearDownTestCase(void)
{
    if (picker_ != nullptr) {
        delete picker_;
        picker_ = nullptr;
    }
}

/**
 * @tc.name: UIPickerGetViewType_001
 * @tc.desc: Verify GetViewType function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
邓志豪 已提交
53
HWTEST_F(UIPickerTest, UIPickerGetViewType_001, TestSize.Level1)
M
mamingshuai 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    EXPECT_EQ(picker_->GetViewType(), UI_PICKER);
}

/**
 * @tc.name: UIPickerGetHighlightFontId_001
 * @tc.desc: Verify GetHighlightFontId function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
邓志豪 已提交
68
HWTEST_F(UIPickerTest, UIPickerGetHighlightFontId_001, TestSize.Level1)
M
mamingshuai 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    uint8_t highlightFontId = StyleDefault::GetPickerHighlightStyle().font_;
    EXPECT_EQ(picker_->GetHighlightFontId(), highlightFontId);
}

/**
 * @tc.name: UIPickerSetFontId_001
 * @tc.desc: Verify SetFontId function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
邓志豪 已提交
84
HWTEST_F(UIPickerTest, UIPickerSetFontId_001, TestSize.Level1)
M
mamingshuai 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    const uint8_t backgroundFontId = 16;
    const uint8_t highlightFontId = 18;

    picker_->SetFontId(backgroundFontId, highlightFontId);
    EXPECT_EQ(picker_->GetBackgroundFontId(), backgroundFontId);
    EXPECT_EQ(picker_->GetHighlightFontId(), highlightFontId);
}

/**
 * @tc.name: UIPickerSetTextColor_001
 * @tc.desc: Verify SetTextColor function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
邓志豪 已提交
104
HWTEST_F(UIPickerTest, UIPickerSetTextColor_001, TestSize.Level1)
M
mamingshuai 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    ColorType backgroundColor;
    ColorType highlightColor;
    backgroundColor.alpha = OPA_OPAQUE;
    highlightColor.alpha = OPA_OPAQUE;

    picker_->SetTextColor(backgroundColor, highlightColor);
    EXPECT_EQ(picker_->GetBackgroundTextColor().alpha, backgroundColor.alpha);
    EXPECT_EQ(picker_->GetHighlightTextColor().alpha, highlightColor.alpha);
}

/**
 * @tc.name: UIPickerSetWidth_001
 * @tc.desc: Verify SetWidth function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
邓志豪 已提交
126
HWTEST_F(UIPickerTest, UIPickerSetWidth_001, TestSize.Level1)
M
mamingshuai 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 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
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    const int16_t width = 10;
    const int16_t height = 20;

    picker_->SetWidth(width);
    picker_->SetHeight(height);
    EXPECT_EQ(picker_->GetWidth(), width);
    EXPECT_EQ(picker_->GetHeight(), height);
}


/**
 * @tc.name: UIPickerSetSelected_001
 * @tc.desc: Verify SetSelected function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000EEMQ6
 */
HWTEST_F(UIPickerTest, UIPickerSetSelected_001, TestSize.Level0)
{
    if (picker_ == nullptr) {
        EXPECT_EQ(1, 0);
        return;
    }
    const uint16_t index = 30;
    const int16_t itemHeight = 10;
    const int16_t width = 100;
    const int16_t height = 100;
    const int16_t startValue= 0;
    const int16_t endValue = 100;
    picker_->SetPosition(0, 0, width, height);
    picker_->SetItemHeight(itemHeight);
    picker_->SetValues(startValue, endValue);
    const char* value[1];

    value[0] = "abc";
    picker_->SetValues(value, 1);
    picker_->SetValues(startValue, endValue);
    picker_->SetSelected(index);
    EXPECT_EQ(picker_->GetSelected(), index);
}
}