GoogleTest系列:TEST_P的基本用法

一、代码部分

#include <gtest/gtest.h>

class Bis 
{
public:
    bool Even(int n) 
    {
        if (n % 2 == 0) 
        {
            return true;
        }
        else 
        {
            return false;
        }
    };
 
    bool Suc(bool bSuc) 
    {
        return bSuc;
    }
};

class CombineTest : 
    public ::testing::TestWithParam< ::testing::tuple<bool, int> > {
protected:
	bool checkData() {
		bool suc = ::testing::get<0>(GetParam());
        int n = ::testing::get<1>(GetParam());
		return bis.Suc(suc) && bis.Even(n);
	}
private:
	Bis bis;
};

TEST_P(CombineTest, Test) {
	EXPECT_TRUE(checkData());
}
 
INSTANTIATE_TEST_CASE_P(TestBisValuesCombine, CombineTest, ::testing::Combine(::testing::Bool(), ::testing::Values(0, 1, 2, 3, 4)));

二、结果部分

Running main() from external/googletest/googletest/src/gtest_main.cc
[==========] Running 10 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 10 tests from TestBisValuesCombine/CombineTest
[ RUN      ] TestBisValuesCombine/CombineTest.Test/0
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/0, where GetParam() = (false, 0) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/1
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/1, where GetParam() = (false, 1) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/2
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/2, where GetParam() = (false, 2) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/3
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/3, where GetParam() = (false, 3) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/4
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/4, where GetParam() = (false, 4) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/5
[       OK ] TestBisValuesCombine/CombineTest.Test/5 (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/6
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/6, where GetParam() = (true, 1) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/7
[       OK ] TestBisValuesCombine/CombineTest.Test/7 (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/8
vendor/mediatek/tests/vendor/HIDL_FORMATTER/interface/1.0/HIDL_FORMATTERV1_0AIT.cpp:38: Failure
Value of: checkData()
  Actual: false
Expected: true
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/8, where GetParam() = (true, 3) (0 ms)
[ RUN      ] TestBisValuesCombine/CombineTest.Test/9
[       OK ] TestBisValuesCombine/CombineTest.Test/9 (0 ms)
[----------] 10 tests from TestBisValuesCombine/CombineTest (3 ms total)

[----------] Global test environment tear-down
[==========] 10 tests from 1 test suite ran. (4 ms total)
[  PASSED  ] 3 tests.
[  FAILED  ] 7 tests, listed below:
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/0, where GetParam() = (false, 0)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/1, where GetParam() = (false, 1)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/2, where GetParam() = (false, 2)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/3, where GetParam() = (false, 3)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/4, where GetParam() = (false, 4)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/6, where GetParam() = (true, 1)
[  FAILED  ] TestBisValuesCombine/CombineTest.Test/8, where GetParam() = (true, 3)

 7 FAILED TESTS
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值