added some new, forgotten test cases and made some new ones for the new

methods of String
This commit is contained in:
Kjistóf 2016-10-23 14:14:41 +02:00
parent c42cd20dd6
commit cd7d35da9a

View File

@ -1,6 +1,7 @@
#include <iostream>
#include <sstream>
#include <type_traits>
#include <stdexcept>
#include "String.h"
#include <gtest/gtest.h>
@ -8,7 +9,7 @@
TEST(StringTest, defaultConstructible)
{
EXPECT_EQ(true, std::is_default_constructible<String>::value);
EXPECT_TRUE(std::is_default_constructible<String>::value);
}
TEST(StringTest, constcharConstructible)
@ -16,27 +17,41 @@ TEST(StringTest, constcharConstructible)
// is_constructible with multiple template params cannot be passed to macro,
// TODO: should open an issue at GTest's GitHub
auto value = std::is_constructible<String, const char*>::value;
EXPECT_EQ(true, value);
EXPECT_TRUE(value);
}
TEST(StringTest, copyConstructible)
{
EXPECT_EQ(true, std::is_copy_constructible<String>::value);
EXPECT_TRUE(std::is_copy_constructible<String>::value);
}
TEST(StringTest, copyAssignable)
{
EXPECT_EQ(true, std::is_copy_assignable<String>::value);
EXPECT_TRUE(std::is_copy_assignable<String>::value);
}
TEST(StringTest, moveConstructible)
{
EXPECT_EQ(true, std::is_move_constructible<String>::value);
EXPECT_TRUE(std::is_move_constructible<String>::value);
}
TEST(StringTest, moveAssignable)
{
EXPECT_EQ(true, std::is_move_assignable<String>::value);
EXPECT_TRUE(std::is_move_assignable<String>::value);
}
TEST(StringTest, cStrMethodWorks)
{
String str("sajtos cica");
EXPECT_STREQ("sajtos cica", str.c_str());
}
TEST(StringTest, uninitializedStringcStrThrows)
{
String str;
EXPECT_THROW(str.c_str(), std::runtime_error);
}
TEST(StringTest, addable)
@ -71,6 +86,22 @@ TEST(StringTest, plusequalsAddableChar)
EXPECT_STREQ("sajtok", str.c_str());
}
TEST(StringTest, comparable)
{
String str1("cica");
String str2("cica");
EXPECT_EQ(str1, str2);
}
TEST(StringTest, uninitializedStringCompareThrows)
{
String str1;
String str2;
EXPECT_THROW(str1 == str2, std::runtime_error);
}
TEST(StringTest, indexOperatorWorks)
{
String str("cica");
@ -79,6 +110,29 @@ TEST(StringTest, indexOperatorWorks)
EXPECT_EQ(i, str[1]);
}
TEST(StringTest, indexoperatorBoundCheckWorks)
{
String str("sajt");
EXPECT_THROW(str[4], std::out_of_range);
}
TEST(StringTest, uninitializedStringIndexingThrows)
{
String str;
EXPECT_THROW(str[0], std::runtime_error);
}
TEST(StringTest, copyOnWriteWorks)
{
String str1("cica");
String str2 = str1;
str2[0] = ' ';
EXPECT_STRNE(str1.c_str(), str2.c_str());
}
TEST(StringTest, resourceSharingWorks)
{
String str1("sajt");