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