118 lines
2.1 KiB
C++
118 lines
2.1 KiB
C++
|
#include <iostream>
|
||
|
#include <sstream>
|
||
|
#include <type_traits>
|
||
|
#include "String.h"
|
||
|
#include <gtest/gtest.h>
|
||
|
|
||
|
|
||
|
|
||
|
TEST(StringTest, defaultConstructible)
|
||
|
{
|
||
|
EXPECT_EQ(true, std::is_default_constructible<String>::value);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, copyConstructible)
|
||
|
{
|
||
|
EXPECT_EQ(true, std::is_copy_constructible<String>::value);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, copyAssignable)
|
||
|
{
|
||
|
EXPECT_EQ(true, std::is_copy_assignable<String>::value);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, moveConstructible)
|
||
|
{
|
||
|
EXPECT_EQ(true, std::is_move_constructible<String>::value);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, moveAssignable)
|
||
|
{
|
||
|
EXPECT_EQ(true, std::is_move_assignable<String>::value);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, addable)
|
||
|
{
|
||
|
String str1("cica");
|
||
|
String str2("sajt");
|
||
|
|
||
|
EXPECT_STREQ("cicasajt", (str1+str2).c_str());
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, plusequalsAddable)
|
||
|
{
|
||
|
String str1("cica");
|
||
|
String str2("sajt");
|
||
|
str1 += str2;
|
||
|
|
||
|
EXPECT_STREQ("cicasajt", str1.c_str());
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, addableChar)
|
||
|
{
|
||
|
String str("cicá");
|
||
|
|
||
|
EXPECT_STREQ("cicák", (str+'k').c_str());
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, plusequalsAddableChar)
|
||
|
{
|
||
|
String str("sajto");
|
||
|
str+='k';
|
||
|
|
||
|
EXPECT_STREQ("sajtok", str.c_str());
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, indexOperatorWorks)
|
||
|
{
|
||
|
String str("cica");
|
||
|
char i = 'i';
|
||
|
|
||
|
EXPECT_EQ(i, str[1]);
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, resourceSharingWorks)
|
||
|
{
|
||
|
String str1("sajt");
|
||
|
String str2 = String("sajt");
|
||
|
|
||
|
EXPECT_EQ(str1.c_str(), str2.c_str());
|
||
|
}
|
||
|
|
||
|
struct StreamStringTest : public ::testing::Test
|
||
|
{
|
||
|
std::stringstream _stream;
|
||
|
};
|
||
|
|
||
|
TEST_F(StreamStringTest, ostreamOperatorWorks)
|
||
|
{
|
||
|
String str("cica");
|
||
|
_stream << str;
|
||
|
|
||
|
EXPECT_STREQ("cica", _stream.str().c_str());
|
||
|
}
|
||
|
|
||
|
TEST_F(StreamStringTest, istreamOperatorWorks)
|
||
|
{
|
||
|
String str;
|
||
|
_stream << "sajt";
|
||
|
_stream >> str;
|
||
|
|
||
|
EXPECT_STREQ("sajt", str.c_str());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
int main(int argc, char **argv)
|
||
|
{
|
||
|
::testing::InitGoogleTest(&argc, argv);
|
||
|
return RUN_ALL_TESTS();
|
||
|
}
|