ui_box_progress_unit_test.cpp 5.3 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
/*
 * 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_box_progress.h"

#include <climits>
#include <gtest/gtest.h>

using namespace testing::ext;
namespace OHOS {
namespace {
    const int16_t MAX = 500;
    const int16_t MIN = 100;
    const int16_t WIDTH = 100;
    const int16_t HEIGHT = 100;
}

class UIBoxProgressTest : public testing::Test {
public:
    UIBoxProgressTest() : boxProgress_(nullptr) {}
    virtual ~UIBoxProgressTest() {}
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
    UIBoxProgress* boxProgress_;
};

void UIBoxProgressTest::SetUpTestCase()
{
}

void UIBoxProgressTest::TearDownTestCase()
{
}

void UIBoxProgressTest::SetUp()
{
    if (boxProgress_ == nullptr) {
        boxProgress_ = new UIBoxProgress();
    }
}

void UIBoxProgressTest::TearDown()
{
    if (boxProgress_ != nullptr) {
        delete boxProgress_;
        boxProgress_ = nullptr;
    }
}

/**
 * @tc.name: UIBoxProgressGetViewType_001
 * @tc.desc: Verify GetViewType function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
70
HWTEST_F(UIBoxProgressTest, UIBoxProgressGetViewType_001, TestSize.Level1)
M
mamingshuai 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    EXPECT_EQ(boxProgress_->GetViewType(), UI_BOX_PROGRESS);
}

/**
 * @tc.name: UIBoxProgressSetDirection_001
 * @tc.desc: Verify SetDirection function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetDirection_001, TestSize.Level0)
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    UIBoxProgress::Direction direction = UIBoxProgress::Direction::DIR_BOTTOM_TO_TOP;
    boxProgress_->SetDirection(direction);
    EXPECT_EQ(boxProgress_->GetDirection(), direction);
    direction = UIBoxProgress::Direction::DIR_LEFT_TO_RIGHT;
    boxProgress_->SetDirection(direction);
    EXPECT_EQ(boxProgress_->GetDirection(), direction);
    direction = UIBoxProgress::Direction::DIR_RIGHT_TO_LEFT;
    boxProgress_->SetDirection(direction);
    EXPECT_EQ(boxProgress_->GetDirection(), direction);
    direction = UIBoxProgress::Direction::DIR_TOP_TO_BOTTOM;
    boxProgress_->SetDirection(direction);
    EXPECT_EQ(boxProgress_->GetDirection(), direction);
}

/**
 * @tc.name: UIBoxProgressSetValidWidth_001
 * @tc.desc: Verify SetValidWidth function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
111
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValidWidth_001, TestSize.Level1)
M
mamingshuai 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    const int16_t valueWidth = 10;
    boxProgress_->Resize(WIDTH, HEIGHT);
    EXPECT_EQ(boxProgress_->GetValidWidth(), WIDTH);
    boxProgress_->SetValidWidth(valueWidth);
    EXPECT_EQ(boxProgress_->GetValidWidth(), valueWidth);
}

/**
 * @tc.name: UIBoxProgressSetValidHeight_001
 * @tc.desc: Verify SetValidHeight function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
130
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValidHeight_001, TestSize.Level1)
M
mamingshuai 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    const int16_t valueHeight = 10;
    boxProgress_->Resize(WIDTH, HEIGHT);
    EXPECT_EQ(boxProgress_->GetValidHeight(), HEIGHT);
    boxProgress_->SetValidHeight(valueHeight);
    EXPECT_EQ(boxProgress_->GetValidHeight(), valueHeight);
}

/**
 * @tc.name: UIBoxProgressSetValue_001
 * @tc.desc: Verify SetValue function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
149
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetValue_001, TestSize.Level1)
M
mamingshuai 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }
    boxProgress_->SetRange(MAX, MIN);

    int16_t value = MIN - 1;
    boxProgress_->SetValue(value);
    EXPECT_EQ(boxProgress_->GetValue(), MIN);

    value = MAX + 1;
    boxProgress_->SetValue(value);
    EXPECT_EQ(boxProgress_->GetValue(), MAX);
}

/**
 * @tc.name: UIBoxProgressSetWidth_001
 * @tc.desc: Verify SetWidth function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
172
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetWidth_001, TestSize.Level1)
M
mamingshuai 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }

    boxProgress_->SetWidth(WIDTH);
    EXPECT_EQ(boxProgress_->GetWidth(), WIDTH);
    EXPECT_EQ(boxProgress_->GetValidWidth(), WIDTH);
}

/**
 * @tc.name: UIBoxProgressSetHeight_001
 * @tc.desc: Verify SetHeight function, equal.
 * @tc.type: FUNC
 * @tc.require: AR000DSMQG
 */
邓志豪 已提交
190
HWTEST_F(UIBoxProgressTest, UIBoxProgressSetHeight_001, TestSize.Level1)
M
mamingshuai 已提交
191 192 193 194 195 196 197 198 199 200 201
{
    if (boxProgress_ == nullptr) {
        EXPECT_NE(0, 0);
        return;
    }

    boxProgress_->SetHeight(HEIGHT);
    EXPECT_EQ(boxProgress_->GetHeight(), HEIGHT);
    EXPECT_EQ(boxProgress_->GetValidHeight(), HEIGHT);
}
} // namespace OHOS