diff --git a/test.cpp b/test.cpp index ab1020d..424d749 100644 --- a/test.cpp +++ b/test.cpp @@ -12,20 +12,23 @@ /// Testing helper classes /// /////////////////////////////////////////////////////////////// using str3 = std::tuple; -class addStringTest : public ::testing::TestWithParam +class AddStringTest : public ::testing::TestWithParam {}; using strcharstr = std::tuple; -class addCharStringTest : public ::testing::TestWithParam +class AddCharStringTest : public ::testing::TestWithParam {}; -struct StreamStringTest : public ::testing::Test +class ComparableStringTest : public ::testing::TestWithParam {}; + +class ResourceSharingStringTest : public ::testing::TestWithParam {}; + +class StreamStringTest : public ::testing::TestWithParam { +public: std::stringstream _stream; }; -class SingleParamStringTest : public ::testing::TestWithParam {}; - /////////////////////////////////////////////////////////////// /// Testing data /// /////////////////////////////////////////////////////////////// @@ -53,6 +56,7 @@ static const std::vector testvalues3 = /////////////////////////////////////////////////////////////// /// Tests /// /////////////////////////////////////////////////////////////// +// Basic tests TEST(StringTest, defaultConstructible) { EXPECT_TRUE(std::is_default_constructible::value); @@ -100,7 +104,9 @@ TEST(StringTest, uninitializedStringcStrThrows) EXPECT_THROW(str.c_str(), std::runtime_error); } -TEST_P(addStringTest, addable) + +// add operator tests +TEST_P(AddStringTest, addable) { String str1(std::get<0>(GetParam()).c_str()); String str2(std::get<1>(GetParam()).c_str()); @@ -108,7 +114,7 @@ TEST_P(addStringTest, addable) EXPECT_STREQ(std::get<2>(GetParam()).c_str(), (str1+str2).c_str()); } -TEST_P(addStringTest, plusEqualsable) +TEST_P(AddStringTest, plusEqualsable) { String str1(std::get<0>(GetParam()).c_str()); String str2(std::get<1>(GetParam()).c_str()); @@ -116,32 +122,34 @@ TEST_P(addStringTest, plusEqualsable) EXPECT_STREQ(std::get<2>(GetParam()).c_str(), str1.c_str()); } -INSTANTIATE_TEST_CASE_P(testGroup1, addStringTest, ::testing::ValuesIn(testvalues1)); +INSTANTIATE_TEST_CASE_P(tests, AddStringTest, ::testing::ValuesIn(testvalues1)); -TEST_P(addCharStringTest, addCharable) +TEST_P(AddCharStringTest, addCharable) { String str(std::get<0>(GetParam()).c_str()); EXPECT_STREQ(std::get<2>(GetParam()).c_str(), (str+std::get<1>(GetParam())).c_str()); } -TEST_P(addCharStringTest, plusEqualsCharable) +TEST_P(AddCharStringTest, plusEqualsCharable) { String str(std::get<0>(GetParam()).c_str()); str+=std::get<1>(GetParam()); EXPECT_STREQ(std::get<2>(GetParam()).c_str(), str.c_str()); } -INSTANTIATE_TEST_CASE_P(testGroup1, addCharStringTest, ::testing::ValuesIn(testvalues2)); +INSTANTIATE_TEST_CASE_P(tests, AddCharStringTest, ::testing::ValuesIn(testvalues2)); -TEST_P(SingleParamStringTest, comparable) + +// Comparison tests +TEST_P(ComparableStringTest, comparable) { String str1(GetParam().c_str()); String str2(GetParam().c_str()); EXPECT_EQ(str1, str2); } -INSTANTIATE_TEST_CASE_P(testGroup1, SingleParamStringTest, ::testing::ValuesIn(testvalues3)); +INSTANTIATE_TEST_CASE_P(tests, ComparableStringTest, ::testing::ValuesIn(testvalues3)); TEST(StringTest, uninitializedStringCompareThrows) { @@ -151,6 +159,8 @@ TEST(StringTest, uninitializedStringCompareThrows) EXPECT_THROW(str1 == str2, std::runtime_error); } + +// Index operator tests TEST(StringTest, indexOperatorWorks) { String str("cica"); @@ -173,6 +183,8 @@ TEST(StringTest, uninitializedStringIndexingThrows) EXPECT_THROW(str[0], std::runtime_error); } + +// COW & resource sharing tests TEST(StringTest, copyOnWriteWorks) { String str1("cica"); @@ -182,30 +194,34 @@ TEST(StringTest, copyOnWriteWorks) EXPECT_STRNE(str1.c_str(), str2.c_str()); } -TEST(StringTest, resourceSharingWorks) +TEST_P(ResourceSharingStringTest, resourceSharingWorks) { - String str1("sajt"); - String str2 = String("sajt"); + String str1(GetParam().c_str()); + String str2 = String(GetParam().c_str()); EXPECT_EQ(str1.c_str(), str2.c_str()); } +INSTANTIATE_TEST_CASE_P(tests, ResourceSharingStringTest, ::testing::ValuesIn(testvalues3)); -TEST_F(StreamStringTest, ostreamOperatorWorks) + +// Stream tests +TEST_P(StreamStringTest, ostreamOperatorWorks) { - String str("cica"); + String str(GetParam().c_str()); _stream << str; - EXPECT_STREQ("cica", _stream.str().c_str()); + EXPECT_STREQ(GetParam().c_str(), _stream.str().c_str()); } -TEST_F(StreamStringTest, istreamOperatorWorks) +TEST_P(StreamStringTest, istreamOperatorWorks) { String str; - _stream << "sajt"; + _stream << GetParam().c_str(); _stream >> str; - EXPECT_STREQ("sajt", str.c_str()); + EXPECT_STREQ(GetParam().c_str(), str.c_str()); } +INSTANTIATE_TEST_CASE_P(tests, StreamStringTest, ::testing::ValuesIn(testvalues3));