1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "gtest/gtest.h" 17f6603c60Sopenharmony_ci#include <climits> 18f6603c60Sopenharmony_ci#include "demo.h" 19f6603c60Sopenharmony_ciusing namespace std; 20f6603c60Sopenharmony_ciusing namespace testing::ext; 21f6603c60Sopenharmony_ci 22f6603c60Sopenharmony_ciclass Demo : public testing::Test { 23f6603c60Sopenharmony_ciprotected: 24f6603c60Sopenharmony_ci // SetUpTestCase:测试套预置动作,在第一个TestCase之前执行 25f6603c60Sopenharmony_ci static void SetUpTestCase(void) {} 26f6603c60Sopenharmony_ci // TearDownTestCase:测试套清理动作,在最后一个TestCase之后执行 27f6603c60Sopenharmony_ci static void TearDownTestCase(void) {} 28f6603c60Sopenharmony_ci // 用例的预置动作 29f6603c60Sopenharmony_ci virtual void SetUp() {} 30f6603c60Sopenharmony_ci // 用例的清理动作 31f6603c60Sopenharmony_ci virtual void TearDown() {} 32f6603c60Sopenharmony_ci}; 33f6603c60Sopenharmony_ci 34f6603c60Sopenharmony_ci 35f6603c60Sopenharmony_ci// Return the sum of n. If n is negative, return 0. 36f6603c60Sopenharmony_cistatic int Sum(int n) 37f6603c60Sopenharmony_ci{ 38f6603c60Sopenharmony_ci if (n <= 0) { 39f6603c60Sopenharmony_ci return 0; 40f6603c60Sopenharmony_ci } 41f6603c60Sopenharmony_ci int sum = 0; 42f6603c60Sopenharmony_ci for (int i = 1; i <= n; i++) { 43f6603c60Sopenharmony_ci sum += i; 44f6603c60Sopenharmony_ci } 45f6603c60Sopenharmony_ci return sum; 46f6603c60Sopenharmony_ci} 47f6603c60Sopenharmony_ci 48f6603c60Sopenharmony_ci/** 49f6603c60Sopenharmony_ci * @tc.number : TEST_CASE_100 50f6603c60Sopenharmony_ci * @tc.name : Demo test 51f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 52f6603c60Sopenharmony_ci */ 53f6603c60Sopenharmony_ciHWTEST_F(Demo, Negative, Function | MediumTest | Level0) { 54f6603c60Sopenharmony_ci EXPECT_EQ(NUM0, Sum(NG_NUM5)); 55f6603c60Sopenharmony_ci EXPECT_EQ(NUM0, Sum(NG_NUM1)); 56f6603c60Sopenharmony_ci} 57f6603c60Sopenharmony_ci 58f6603c60Sopenharmony_ci/** 59f6603c60Sopenharmony_ci * @tc.number : TEST_CASE_200 60f6603c60Sopenharmony_ci * @tc.name : Demo test 61f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 62f6603c60Sopenharmony_ci */ 63f6603c60Sopenharmony_ciHWTEST_F(Demo, Zero, Function | MediumTest | Level0) { 64f6603c60Sopenharmony_ci EXPECT_EQ(NUM0, Sum(NUM0)); 65f6603c60Sopenharmony_ci} 66f6603c60Sopenharmony_ci 67f6603c60Sopenharmony_ci/** 68f6603c60Sopenharmony_ci * @tc.number : TEST_CASE_300 69f6603c60Sopenharmony_ci * @tc.name : Demo test 70f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 71f6603c60Sopenharmony_ci */ 72f6603c60Sopenharmony_ciHWTEST_F(Demo, Positive, Function | MediumTest | Level0) { 73f6603c60Sopenharmony_ci EXPECT_EQ(NUM1, Sum(NUM1)); 74f6603c60Sopenharmony_ci EXPECT_EQ(NUM45, Sum(NUM10)); 75f6603c60Sopenharmony_ci EXPECT_EQ(NUM4950, Sum(NUM100)); 76f6603c60Sopenharmony_ci} 77