From 3149e1a653f407e391edc638afd060753264696e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 24 Oct 2016 21:08:01 +0200 Subject: [PATCH] rewritten some of the parametric test cases to use std::string --- test.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/test.cpp b/test.cpp index 46bfad8..ab1020d 100644 --- a/test.cpp +++ b/test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "String.h" #include @@ -10,11 +11,11 @@ /////////////////////////////////////////////////////////////// /// Testing helper classes /// /////////////////////////////////////////////////////////////// -using str3 = std::tuple; +using str3 = std::tuple; class addStringTest : public ::testing::TestWithParam {}; -using strcharstr = std::tuple; +using strcharstr = std::tuple; class addCharStringTest : public ::testing::TestWithParam {}; @@ -23,7 +24,7 @@ struct StreamStringTest : public ::testing::Test std::stringstream _stream; }; -class SingleParamStringTest : public ::testing::TestWithParam> {}; +class SingleParamStringTest : public ::testing::TestWithParam {}; /////////////////////////////////////////////////////////////// /// Testing data /// @@ -46,14 +47,8 @@ static const std::vector testvalues2 = std::make_tuple("te", 'j', "tej") }; -static const std::vector> testvalues3 = - { - std::make_tuple("cica"), - std::make_tuple("sajt"), - std::make_tuple("sör"), - std::make_tuple("C++11"), - std::make_tuple("suchInitializerList") - }; +static const std::vector testvalues3 = + { "cica", "sajt", "sör", "C++11", "suchInitializerList" }; /////////////////////////////////////////////////////////////// /// Tests /// @@ -107,42 +102,42 @@ TEST(StringTest, uninitializedStringcStrThrows) TEST_P(addStringTest, addable) { - String str1(std::get<0>(GetParam())); - String str2(std::get<1>(GetParam())); + String str1(std::get<0>(GetParam()).c_str()); + String str2(std::get<1>(GetParam()).c_str()); - EXPECT_STREQ(std::get<2>(GetParam()), (str1+str2).c_str()); + EXPECT_STREQ(std::get<2>(GetParam()).c_str(), (str1+str2).c_str()); } TEST_P(addStringTest, plusEqualsable) { - String str1(std::get<0>(GetParam())); - String str2(std::get<1>(GetParam())); + String str1(std::get<0>(GetParam()).c_str()); + String str2(std::get<1>(GetParam()).c_str()); str1 += str2; - EXPECT_STREQ(std::get<2>(GetParam()), str1.c_str()); + EXPECT_STREQ(std::get<2>(GetParam()).c_str(), str1.c_str()); } INSTANTIATE_TEST_CASE_P(testGroup1, addStringTest, ::testing::ValuesIn(testvalues1)); TEST_P(addCharStringTest, addCharable) { - String str(std::get<0>(GetParam())); + String str(std::get<0>(GetParam()).c_str()); - EXPECT_STREQ(std::get<2>(GetParam()), (str+std::get<1>(GetParam())).c_str()); + EXPECT_STREQ(std::get<2>(GetParam()).c_str(), (str+std::get<1>(GetParam())).c_str()); } TEST_P(addCharStringTest, plusEqualsCharable) { - String str(std::get<0>(GetParam())); + String str(std::get<0>(GetParam()).c_str()); str+=std::get<1>(GetParam()); - EXPECT_STREQ(std::get<2>(GetParam()), str.c_str()); + EXPECT_STREQ(std::get<2>(GetParam()).c_str(), str.c_str()); } INSTANTIATE_TEST_CASE_P(testGroup1, addCharStringTest, ::testing::ValuesIn(testvalues2)); TEST_P(SingleParamStringTest, comparable) { - String str1(std::get<0>(GetParam())); - String str2(std::get<0>(GetParam())); + String str1(GetParam().c_str()); + String str2(GetParam().c_str()); EXPECT_EQ(str1, str2); }