rewritten some of the parametric test cases to use std::string

This commit is contained in:
Kjistóf 2016-10-24 21:08:01 +02:00
parent a9307e5657
commit 3149e1a653

View File

@ -3,6 +3,7 @@
#include <type_traits>
#include <stdexcept>
#include <tuple>
#include <string>
#include "String.h"
#include <gtest/gtest.h>
@ -10,11 +11,11 @@
///////////////////////////////////////////////////////////////
/// Testing helper classes ///
///////////////////////////////////////////////////////////////
using str3 = std::tuple<const char*, const char*, const char*>;
using str3 = std::tuple<std::string, std::string, std::string>;
class addStringTest : public ::testing::TestWithParam<str3>
{};
using strcharstr = std::tuple<const char*, char, const char*>;
using strcharstr = std::tuple<std::string, char, std::string>;
class addCharStringTest : public ::testing::TestWithParam<strcharstr>
{};
@ -23,7 +24,7 @@ struct StreamStringTest : public ::testing::Test
std::stringstream _stream;
};
class SingleParamStringTest : public ::testing::TestWithParam<std::tuple<const char*>> {};
class SingleParamStringTest : public ::testing::TestWithParam<std::string> {};
///////////////////////////////////////////////////////////////
/// Testing data ///
@ -46,14 +47,8 @@ static const std::vector<strcharstr> testvalues2 =
std::make_tuple("te", 'j', "tej")
};
static const std::vector<std::tuple<const char*>> 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<std::string> 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);
}