Updates tests to work with the latest TinyTest.
Adds StringTraits::Literal variants that work with strings. Names the workspace CPPUtils to match the import name in TinyTest. This resolves the dependency issue.
This commit is contained in:
3
BUILD
3
BUILD
@@ -7,6 +7,8 @@
|
|||||||
# #
|
# #
|
||||||
# Licensed under the MIT license. See below for details. #
|
# Licensed under the MIT license. See below for details. #
|
||||||
# #
|
# #
|
||||||
|
########################################################################################################################
|
||||||
|
# #
|
||||||
# MIT License #
|
# MIT License #
|
||||||
# #
|
# #
|
||||||
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
||||||
@@ -36,6 +38,7 @@ cc_library(
|
|||||||
srcs = ["ansi_escapes.cpp"],
|
srcs = ["ansi_escapes.cpp"],
|
||||||
hdrs = ["ansi_escapes.h"],
|
hdrs = ["ansi_escapes.h"],
|
||||||
includes = ["ansi_escapes.h"],
|
includes = ["ansi_escapes.h"],
|
||||||
|
deps = [":pretty_print"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
|
|||||||
11
WORKSPACE
11
WORKSPACE
@@ -8,6 +8,8 @@
|
|||||||
# #
|
# #
|
||||||
# Licensed under the MIT license. See below for details. #
|
# Licensed under the MIT license. See below for details. #
|
||||||
# #
|
# #
|
||||||
|
########################################################################################################################
|
||||||
|
# #
|
||||||
# MIT License #
|
# MIT License #
|
||||||
# #
|
# #
|
||||||
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
# Copyright (c) 2023 Tom Hicks <headhunter3@gmail.com> #
|
||||||
@@ -26,6 +28,8 @@
|
|||||||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
|
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #
|
||||||
# #
|
# #
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
workspace(name = "CPPUtils")
|
||||||
|
|
||||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
# Hedron's Compile Commands Extractor for Bazel
|
# Hedron's Compile Commands Extractor for Bazel
|
||||||
@@ -45,7 +49,8 @@ hedron_compile_commands_setup()
|
|||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "tinytest",
|
name = "tinytest",
|
||||||
sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b",
|
# sha256 = "71f366e680606e18268e6b9673a65c44c9e672f7356a61ffbcd3502c6a8eea0b",
|
||||||
strip_prefix = "TinyTest-460c9492d927689b9db7f28d8742705dc0bbee62",
|
sha256 = "49a229ff3b2470e72743f2cc239cb2bc381f2976047a34b6832115097be7d887",
|
||||||
urls = ["https://github.com/headhunter45/TinyTest/archive/460c9492d927689b9db7f28d8742705dc0bbee62.zip"],
|
strip_prefix = "TinyTest-011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab",
|
||||||
|
urls = ["https://github.com/headhunter45/TinyTest/archive/011953cd2ccecdc5fe0b8fe83b8d0dde10fa81ab.zip"],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -43,45 +43,45 @@ using std::ostream;
|
|||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::string_view;
|
using std::string_view;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
} // End namespace
|
} // End namespace
|
||||||
|
|
||||||
string filter(const string& text) {
|
string filter(const string &text) {
|
||||||
std::regex pattern("\033");
|
std::regex pattern("\033");
|
||||||
return std::regex_replace(text, pattern, "\\033");
|
return std::regex_replace(text, pattern, "\\033");
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetRedComponent() {
|
TestResults test_GetRedComponent() {
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::GetRedComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetRedComponent(uint32_t)",
|
||||||
CPPUtils::GetRedComponent,
|
CPPUtils::GetRedComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)),
|
MakeTest("should get the red component 0x34 from 0x12345678", 0x34U, make_tuple(0x12345678U)),
|
||||||
make_test("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)),
|
MakeTest("should get the red component 0x56 from 0x34567890", 0x56U, make_tuple(0x34567890U)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetGreenComponent() {
|
TestResults test_GetGreenComponent() {
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::GetGreenComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetGreenComponent(uint32_t)",
|
||||||
CPPUtils::GetGreenComponent,
|
CPPUtils::GetGreenComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)),
|
MakeTest("should get the green component 0x56 from 0x12345678", 0x56U, make_tuple(0x12345678U)),
|
||||||
make_test("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)),
|
MakeTest("should get the green component 0x78 from 0x34567890", 0x78U, make_tuple(0x34567890U)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_GetBlueComponent() {
|
TestResults test_GetBlueComponent() {
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::GetBlueComponent(uint32_t)",
|
MakeTestSuite("CPPUtils::GetBlueComponent(uint32_t)",
|
||||||
CPPUtils::GetBlueComponent,
|
CPPUtils::GetBlueComponent,
|
||||||
{
|
{
|
||||||
make_test("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)),
|
MakeTest("should get the blue component 0x78 from 0x12345678", 0x78, make_tuple(0x12345678)),
|
||||||
make_test("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)),
|
MakeTest("should get the blue component 0x90 from 0x34567890", 0x90, make_tuple(0x34567890)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_EscapeWithBasicString() {
|
TestResults test_EscapeWithBasicString() {
|
||||||
@@ -90,13 +90,13 @@ TestResults test_EscapeWithBasicString() {
|
|||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(string)",
|
"CPPUtils::Escape(string)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,29 +106,29 @@ TestResults test_EscapeWithBasicStringView() {
|
|||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(string_view)",
|
"CPPUtils::Escape(string_view)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_EscapeWithConstCharStar() {
|
TestResults test_EscapeWithConstCharStar() {
|
||||||
auto function_to_test = [](const char* text) {
|
auto function_to_test = [](const char *text) {
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
CPPUtils::Escape(os, text);
|
CPPUtils::Escape(os, text);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::Escape(const char*)",
|
"CPPUtils::Escape(const char*)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
MakeTest("should escape \"asdf\" to \"\\033[asdfm\"", (string) "\033[asdfm", make_tuple("asdf")),
|
||||||
make_test("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
MakeTest("should escape \"fdsa\" to \"\\033[fdsam\"", (string) "\033[fdsam", make_tuple("fdsa")),
|
||||||
make_test("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
MakeTest("should escape \"1;2;3\" to \"\\033[1;2;3m\"", (string) "\033[1;2;3m", make_tuple("1;2;3")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,14 +138,14 @@ TestResults test_ForegroundColor8Bit() {
|
|||||||
CPPUtils::ForegroundColor8Bit(os, color);
|
CPPUtils::ForegroundColor8Bit(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
MakeTestSuite("CPPUtils::ForegroundColor8Bit(uint8_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)),
|
MakeTest("should write \"\\033[38;5;7m\"", (string) "\033[38;5;7m", make_tuple(0x07U)),
|
||||||
make_test("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)),
|
MakeTest("should write \"\\033[38;5;1m\"", (string) "\033[38;5;1m", make_tuple(0x01U)),
|
||||||
make_test("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)),
|
MakeTest("should write \"\\033[38;5;11m\"", (string) "\033[38;5;11m", make_tuple(0x0BU)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_BackgroundColor8Bit() {
|
TestResults test_BackgroundColor8Bit() {
|
||||||
@@ -154,14 +154,14 @@ TestResults test_BackgroundColor8Bit() {
|
|||||||
CPPUtils::BackgroundColor8Bit(os, color);
|
CPPUtils::BackgroundColor8Bit(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
MakeTestSuite("CPPUtils::BackgroundColor8Bit(uint8_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)),
|
MakeTest("should write \"\\033[48;5;7m\"", (string) "\033[48;5;7m", make_tuple(0x07U)),
|
||||||
make_test("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)),
|
MakeTest("should write \"\\033[48;5;1m\"", (string) "\033[48;5;1m", make_tuple(0x01U)),
|
||||||
make_test("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)),
|
MakeTest("should write \"\\033[48;5;11m\"", (string) "\033[48;5;11m", make_tuple(0x0BU)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_ForegroundTrueColorWithUInt32() {
|
TestResults test_ForegroundTrueColorWithUInt32() {
|
||||||
@@ -170,11 +170,11 @@ TestResults test_ForegroundTrueColorWithUInt32() {
|
|||||||
CPPUtils::ForegroundTrueColor(os, color);
|
CPPUtils::ForegroundTrueColor(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ForegroundTrueColor(uint32_t)",
|
"CPPUtils::ForegroundTrueColor(uint32_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)),
|
MakeTest("should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x00154588)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,11 +184,11 @@ TestResults test_BackgroundTrueColorWithUInt32() {
|
|||||||
CPPUtils::BackgroundTrueColor(os, color);
|
CPPUtils::BackgroundTrueColor(os, color);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::BackgroundTrueColor(uint32_t)",
|
"CPPUtils::BackgroundTrueColor(uint32_t)",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)),
|
MakeTest("should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x00154588)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,13 +198,13 @@ TestResults test_ForegroundTrueColorWith3UInt8() {
|
|||||||
CPPUtils::ForegroundTrueColor(os, red, green, blue);
|
CPPUtils::ForegroundTrueColor(os, red, green, blue);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite("CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||||
"CPPUtils::ForegroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
function_to_test,
|
||||||
function_to_test,
|
{
|
||||||
{
|
MakeTest("should write \"\\033[38;2;21;69;136m\"",
|
||||||
make_test(
|
(string) "\033[38;2;21;69;136m",
|
||||||
"should write \"\\033[38;2;21;69;136m\"", (string) "\033[38;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
make_tuple(0x15, 0x45, 0x88)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_BackgroundTrueColorWith3UInt8() {
|
TestResults test_BackgroundTrueColorWith3UInt8() {
|
||||||
@@ -213,13 +213,13 @@ TestResults test_BackgroundTrueColorWith3UInt8() {
|
|||||||
CPPUtils::BackgroundTrueColor(os, red, green, blue);
|
CPPUtils::BackgroundTrueColor(os, red, green, blue);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite("CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
||||||
"CPPUtils::BackgroundTrueColor(uint8_t, uint8_t, uint8_t)",
|
function_to_test,
|
||||||
function_to_test,
|
{
|
||||||
{
|
MakeTest("should write \"\\033[48;2;21;69;136m\"",
|
||||||
make_test(
|
(string) "\033[48;2;21;69;136m",
|
||||||
"should write \"\\033[48;2;21;69;136m\"", (string) "\033[48;2;21;69;136m", make_tuple(0x15, 0x45, 0x88)),
|
make_tuple(0x15, 0x45, 0x88)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_Reset() {
|
TestResults test_Reset() {
|
||||||
@@ -228,14 +228,14 @@ TestResults test_Reset() {
|
|||||||
CPPUtils::Reset(os);
|
CPPUtils::Reset(os);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("CPPUtils::Reset",
|
return ExecuteSuite(MakeTestSuite("CPPUtils::Reset",
|
||||||
function_to_test,
|
function_to_test,
|
||||||
{
|
{
|
||||||
make_test("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
MakeTest("should write \"\\033[m\"", (string) "\033[m", make_tuple()),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
|
|
||||||
results += test_GetRedComponent();
|
results += test_GetRedComponent();
|
||||||
@@ -252,5 +252,5 @@ int main(int argc, char* argv[]) {
|
|||||||
results += test_BackgroundTrueColorWith3UInt8();
|
results += test_BackgroundTrueColorWith3UInt8();
|
||||||
results += test_Reset();
|
results += test_Reset();
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,16 +45,16 @@ using std::make_tuple;
|
|||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
string no_errors = "no errors";
|
string no_errors = "no errors";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TestResults test_ConsoleLogger_LogMessage() {
|
TestResults test_ConsoleLogger_LogMessage() {
|
||||||
auto log_message = [](const Logger::MessageType& type, const string& message) -> string {
|
auto log_message = [](const Logger::MessageType &type, const string &message) -> string {
|
||||||
ostringstream errors;
|
ostringstream errors;
|
||||||
ostringstream output;
|
ostringstream output;
|
||||||
auto destination = make_shared<ConsoleLogger>();
|
auto destination = make_shared<ConsoleLogger>();
|
||||||
@@ -62,33 +62,33 @@ TestResults test_ConsoleLogger_LogMessage() {
|
|||||||
destination->LogMessage(type, message);
|
destination->LogMessage(type, message);
|
||||||
return output.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite("CPPUtils::ConsoleLogger::LogMessage(cosnt std::string&)",
|
return ExecuteSuite(MakeTestSuite("CPPUtils::ConsoleLogger::LogMessage(cosnt std::string&)",
|
||||||
log_message,
|
log_message,
|
||||||
{make_test("should print \"[Debug] this is a message\"",
|
{MakeTest("should print \"[Debug] this is a message\"",
|
||||||
(string) "[Debug] this is a message\n",
|
(string) "[Debug] this is a message\n",
|
||||||
make_tuple(Logger::MessageType::Debug, "this is a message")),
|
make_tuple(Logger::MessageType::Debug, "this is a message")),
|
||||||
make_test("should print \"[Error] this is an error\"",
|
MakeTest("should print \"[Error] this is an error\"",
|
||||||
(string) "[Error] this is an error\n",
|
(string) "[Error] this is an error\n",
|
||||||
make_tuple(Logger::MessageType::Error, "this is an error")),
|
make_tuple(Logger::MessageType::Error, "this is an error")),
|
||||||
make_test("should print \"[Wtf] what a terrible failure\"",
|
MakeTest("should print \"[Wtf] what a terrible failure\"",
|
||||||
(string) "[Wtf] what a terrible failure\n",
|
(string) "[Wtf] what a terrible failure\n",
|
||||||
make_tuple(Logger::MessageType::Wtf, "what a terrible failure")),
|
make_tuple(Logger::MessageType::Wtf, "what a terrible failure")),
|
||||||
make_test("should print \"[Info] this is some information\"",
|
MakeTest("should print \"[Info] this is some information\"",
|
||||||
(string) "[Info] this is some information\n",
|
(string) "[Info] this is some information\n",
|
||||||
make_tuple(Logger::MessageType::Info, "this is some information")),
|
make_tuple(Logger::MessageType::Info, "this is some information")),
|
||||||
make_test("should print \"[Warning] this is a warning\"",
|
MakeTest("should print \"[Warning] this is a warning\"",
|
||||||
(string) "[Warning] this is a warning\n",
|
(string) "[Warning] this is a warning\n",
|
||||||
make_tuple(Logger::MessageType::Warning, "this is a warning")),
|
make_tuple(Logger::MessageType::Warning, "this is a warning")),
|
||||||
make_test("should print \"[Verbose] this is verbose\"",
|
MakeTest("should print \"[Verbose] this is verbose\"",
|
||||||
(string) "[Verbose] this is verbose\n",
|
(string) "[Verbose] this is verbose\n",
|
||||||
make_tuple(Logger::MessageType::Verbose, "this is verbose")),
|
make_tuple(Logger::MessageType::Verbose, "this is verbose")),
|
||||||
make_test("should print \"[Unclassified] unclassified message\"",
|
MakeTest("should print \"[Unclassified] unclassified message\"",
|
||||||
(string) "[Unclassified] unclassified message\n",
|
(string) "[Unclassified] unclassified message\n",
|
||||||
make_tuple((Logger::MessageType)1000, "unclassified message"))}));
|
make_tuple((Logger::MessageType)1000, "unclassified message"))}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_ConsoleLogger_LogErrorWithMessage() {
|
TestResults test_ConsoleLogger_LogErrorWithMessage() {
|
||||||
auto log_error = [](const Logger::MessageType& type, const std::exception& ex) -> string {
|
auto log_error = [](const Logger::MessageType &type, const std::exception &ex) -> string {
|
||||||
ostringstream errors;
|
ostringstream errors;
|
||||||
ostringstream output;
|
ostringstream output;
|
||||||
auto destination = make_shared<ConsoleLogger>();
|
auto destination = make_shared<ConsoleLogger>();
|
||||||
@@ -96,34 +96,34 @@ TestResults test_ConsoleLogger_LogErrorWithMessage() {
|
|||||||
destination->LogError(type, ex);
|
destination->LogError(type, ex);
|
||||||
return output.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::ConsoleLogger::LogError(const std::exception&)",
|
MakeTestSuite("CPPUtils::ConsoleLogger::LogError(const std::exception&)",
|
||||||
log_error,
|
log_error,
|
||||||
{make_test("should print \"[Debug] caught exception: this is an exception\"",
|
{MakeTest("should print \"[Debug] caught exception: this is an exception\"",
|
||||||
(string) "[Debug] caught exception: this is an exception\n",
|
(string) "[Debug] caught exception: this is an exception\n",
|
||||||
make_tuple(Logger::MessageType::Debug, std::runtime_error("this is an exception"))),
|
make_tuple(Logger::MessageType::Debug, std::runtime_error("this is an exception"))),
|
||||||
make_test("should print \"[Error] caught exception: this is an error\"",
|
MakeTest("should print \"[Error] caught exception: this is an error\"",
|
||||||
(string) "[Error] caught exception: this is an error\n",
|
(string) "[Error] caught exception: this is an error\n",
|
||||||
make_tuple(Logger::MessageType::Error, std::runtime_error("this is an error"))),
|
make_tuple(Logger::MessageType::Error, std::runtime_error("this is an error"))),
|
||||||
make_test("should print \"[Wtf] caught exception: what a terrible failure\"",
|
MakeTest("should print \"[Wtf] caught exception: what a terrible failure\"",
|
||||||
(string) "[Wtf] caught exception: what a terrible failure\n",
|
(string) "[Wtf] caught exception: what a terrible failure\n",
|
||||||
make_tuple(Logger::MessageType::Wtf, std::runtime_error("what a terrible failure"))),
|
make_tuple(Logger::MessageType::Wtf, std::runtime_error("what a terrible failure"))),
|
||||||
make_test("should print \"[Info] caught exception: this is some information\"",
|
MakeTest("should print \"[Info] caught exception: this is some information\"",
|
||||||
(string) "[Info] caught exception: this is some information\n",
|
(string) "[Info] caught exception: this is some information\n",
|
||||||
make_tuple(Logger::MessageType::Info, std::runtime_error("this is some information"))),
|
make_tuple(Logger::MessageType::Info, std::runtime_error("this is some information"))),
|
||||||
make_test("should print \"[Warning] caught exception: this is a warning\"",
|
MakeTest("should print \"[Warning] caught exception: this is a warning\"",
|
||||||
(string) "[Warning] caught exception: this is a warning\n",
|
(string) "[Warning] caught exception: this is a warning\n",
|
||||||
make_tuple(Logger::MessageType::Warning, std::runtime_error("this is a warning"))),
|
make_tuple(Logger::MessageType::Warning, std::runtime_error("this is a warning"))),
|
||||||
make_test("should print \"[Verbose] caught exception: this is verbose\"",
|
MakeTest("should print \"[Verbose] caught exception: this is verbose\"",
|
||||||
(string) "[Verbose] caught exception: this is verbose\n",
|
(string) "[Verbose] caught exception: this is verbose\n",
|
||||||
make_tuple(Logger::MessageType::Verbose, std::runtime_error("this is verbose"))),
|
make_tuple(Logger::MessageType::Verbose, std::runtime_error("this is verbose"))),
|
||||||
make_test("should print \"[Unclassified] caught exception: unclassified message\"",
|
MakeTest("should print \"[Unclassified] caught exception: unclassified message\"",
|
||||||
(string) "[Unclassified] caught exception: unclassified message\n",
|
(string) "[Unclassified] caught exception: unclassified message\n",
|
||||||
make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))}));
|
make_tuple((Logger::MessageType)1000, std::runtime_error("unclassified message")))}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_ConsoleLogger_LogErrorWithoutMessage() {
|
TestResults test_ConsoleLogger_LogErrorWithoutMessage() {
|
||||||
auto log_error = [](const Logger::MessageType& type, const std::string& message, const std::exception& ex) -> string {
|
auto log_error = [](const Logger::MessageType &type, const std::string &message, const std::exception &ex) -> string {
|
||||||
ostringstream errors;
|
ostringstream errors;
|
||||||
ostringstream output;
|
ostringstream output;
|
||||||
auto destination = make_shared<ConsoleLogger>();
|
auto destination = make_shared<ConsoleLogger>();
|
||||||
@@ -131,45 +131,45 @@ TestResults test_ConsoleLogger_LogErrorWithoutMessage() {
|
|||||||
destination->LogError(type, message, ex);
|
destination->LogError(type, message, ex);
|
||||||
return output.str();
|
return output.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ConsoleLogger::LogError(const std::string&, const std::exception&)",
|
"CPPUtils::ConsoleLogger::LogError(const std::string&, const std::exception&)",
|
||||||
log_error,
|
log_error,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print \"[Debug] this is a message with caught exception this is an exception\"",
|
"should print \"[Debug] this is a message with caught exception this is an exception\"",
|
||||||
(string) "[Debug] this is a message with caught exception this is an exception\n",
|
(string) "[Debug] this is a message with caught exception this is an exception\n",
|
||||||
make_tuple(Logger::MessageType::Debug, "this is a message", std::runtime_error("this is an exception"))),
|
make_tuple(Logger::MessageType::Debug, "this is a message", std::runtime_error("this is an exception"))),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print \"[Error] this is an error with caught exception this is an exception\"",
|
"should print \"[Error] this is an error with caught exception this is an exception\"",
|
||||||
(string) "[Error] this is an error with caught exception this is an exception\n",
|
(string) "[Error] this is an error with caught exception this is an exception\n",
|
||||||
make_tuple(Logger::MessageType::Error, "this is an error", std::runtime_error("this is an exception"))),
|
make_tuple(Logger::MessageType::Error, "this is an error", std::runtime_error("this is an exception"))),
|
||||||
make_test(
|
MakeTest("should print \"[Wtf] what a terrible failure with caught exception this is an exception\"",
|
||||||
"should print \"[Wtf] what a terrible failure with caught exception this is an exception\"",
|
(string) "[Wtf] what a terrible failure with caught exception this is an exception\n",
|
||||||
(string) "[Wtf] what a terrible failure with caught exception this is an exception\n",
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
make_tuple(
|
"what a terrible failure",
|
||||||
Logger::MessageType::Wtf, "what a terrible failure", std::runtime_error("this is an exception"))),
|
std::runtime_error("this is an exception"))),
|
||||||
make_test(
|
MakeTest("should print \"[Info] this is some information with caught exception this is an exception\"",
|
||||||
"should print \"[Info] this is some information with caught exception this is an exception\"",
|
(string) "[Info] this is some information with caught exception this is an exception\n",
|
||||||
(string) "[Info] this is some information with caught exception this is an exception\n",
|
make_tuple(Logger::MessageType::Info,
|
||||||
make_tuple(
|
"this is some information",
|
||||||
Logger::MessageType::Info, "this is some information", std::runtime_error("this is an exception"))),
|
std::runtime_error("this is an exception"))),
|
||||||
make_test("should print \"[Warning] this is a warning with caught exception this is an exception\"",
|
MakeTest("should print \"[Warning] this is a warning with caught exception this is an exception\"",
|
||||||
(string) "[Warning] this is a warning with caught exception this is an exception\n",
|
(string) "[Warning] this is a warning with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(
|
||||||
Logger::MessageType::Warning, "this is a warning", std::runtime_error("this is an exception"))),
|
Logger::MessageType::Warning, "this is a warning", std::runtime_error("this is an exception"))),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print \"[Verbose] this is verbose with caught exception this is an exception\"",
|
"should print \"[Verbose] this is verbose with caught exception this is an exception\"",
|
||||||
(string) "[Verbose] this is verbose with caught exception this is an exception\n",
|
(string) "[Verbose] this is verbose with caught exception this is an exception\n",
|
||||||
make_tuple(Logger::MessageType::Verbose, "this is verbose", std::runtime_error("this is an exception"))),
|
make_tuple(Logger::MessageType::Verbose, "this is verbose", std::runtime_error("this is an exception"))),
|
||||||
make_test("should print \"[Unclassified] unclassified message with caught exception this is an exception\"",
|
MakeTest("should print \"[Unclassified] unclassified message with caught exception this is an exception\"",
|
||||||
(string) "[Unclassified] unclassified message with caught exception this is an exception\n",
|
(string) "[Unclassified] unclassified message with caught exception this is an exception\n",
|
||||||
make_tuple(
|
make_tuple(
|
||||||
(Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))),
|
(Logger::MessageType)1000, "unclassified message", std::runtime_error("this is an exception"))),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_ConsoleLogger_SetOutputStream() {
|
TestResults test_ConsoleLogger_SetOutputStream() {
|
||||||
auto set_get_output_stream = [](std::ostream& os, bool only_get) -> bool {
|
auto set_get_output_stream = [](std::ostream &os, bool only_get) -> bool {
|
||||||
auto destination = make_shared<ConsoleLogger>();
|
auto destination = make_shared<ConsoleLogger>();
|
||||||
if (!only_get) {
|
if (!only_get) {
|
||||||
destination->SetOutputStream(os);
|
destination->SetOutputStream(os);
|
||||||
@@ -177,17 +177,17 @@ TestResults test_ConsoleLogger_SetOutputStream() {
|
|||||||
return &destination->GetOutputStream() == &os;
|
return &destination->GetOutputStream() == &os;
|
||||||
};
|
};
|
||||||
std::ostringstream os1;
|
std::ostringstream os1;
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::ConsoleLogger::Set/GetOutputStream(std::ostream&)",
|
"CPPUtils::ConsoleLogger::Set/GetOutputStream(std::ostream&)",
|
||||||
set_get_output_stream,
|
set_get_output_stream,
|
||||||
{
|
{
|
||||||
make_test("should get cout by default", true, make_tuple(std::ref(std::cout), true)),
|
MakeTest("should get cout by default", true, make_tuple(std::ref(std::cout), true)),
|
||||||
make_test("should set and get the same output stream", true, make_tuple(std::ref(std::cout), false)),
|
MakeTest("should set and get the same output stream", true, make_tuple(std::ref(std::cout), false)),
|
||||||
make_test("should set and get the same output stream", true, make_tuple(std::ref((std::ostream&)os1), false)),
|
MakeTest("should set and get the same output stream", true, make_tuple(std::ref((std::ostream &)os1), false)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
|
|
||||||
results += test_ConsoleLogger_LogMessage();
|
results += test_ConsoleLogger_LogMessage();
|
||||||
@@ -197,5 +197,5 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
PrintResults(cout, results);
|
PrintResults(cout, results);
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
825
logger_test.cpp
825
logger_test.cpp
File diff suppressed because it is too large
Load Diff
@@ -56,21 +56,50 @@ template <typename TChar> struct StringTraits;
|
|||||||
|
|
||||||
/// @brief This SFINAE struct is use to select a narrow string.
|
/// @brief This SFINAE struct is use to select a narrow string.
|
||||||
template <> struct StringTraits<char> {
|
template <> struct StringTraits<char> {
|
||||||
|
/// @brief Gets the narrow string.
|
||||||
|
/// @param narrow The narrow string. This is always returned by this specialization.
|
||||||
|
/// @param wide The wide string. This is ignored for this specialization.
|
||||||
|
/// @return The narrow string.
|
||||||
static constexpr const char *Literal(const char *narrow, const wchar_t *wide) { return narrow; }
|
static constexpr const char *Literal(const char *narrow, const wchar_t *wide) { return narrow; }
|
||||||
|
|
||||||
|
/// @brief Gets the narrow string.
|
||||||
|
/// @param narrow The narrow string. This is always returned by this specialization.
|
||||||
|
/// @param wide The wide string. This is ignored for this specialization.
|
||||||
|
/// @return The narrow string.
|
||||||
|
static const std::string Literal(const std::string &narrow, const std::wstring &wide) { return narrow; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief This SFINAE struct is used to select a wide string.
|
/// @brief This SFINAE struct is used to select a wide string.
|
||||||
template <> struct StringTraits<wchar_t> {
|
template <> struct StringTraits<wchar_t> {
|
||||||
|
/// @brief Gets the wide string.
|
||||||
|
/// @param narrow The narrow string. This ignored for this specialization.
|
||||||
|
/// @param wide The wide string. This is is always returned by this specialization.
|
||||||
|
/// @return The wide string.
|
||||||
static constexpr const wchar_t *Literal(const char *narrow, const wchar_t *wide) { return wide; }
|
static constexpr const wchar_t *Literal(const char *narrow, const wchar_t *wide) { return wide; }
|
||||||
|
|
||||||
|
/// @brief Gets the wide string.
|
||||||
|
/// @param narrow The narrow string. This ignored for this specialization.
|
||||||
|
/// @param wide The wide string. This is is always returned by this specialization.
|
||||||
|
/// @return The wide string.
|
||||||
|
static const std::wstring Literal(const std::string &narrow, const std::wstring &wide) { return wide; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief This SFINAE struct is used to help select container like types.
|
/// @brief This SFINAE struct is used to help select container like types.
|
||||||
/// @tparam T The potential container type.
|
/// @tparam T The potential container type.
|
||||||
template <typename T> struct is_container {
|
template <typename T> struct is_container {
|
||||||
|
/// @brief Returns true because the type has begin and end methods.
|
||||||
|
/// @tparam U The type to check.
|
||||||
|
/// @param <anonymous> A pointer that is not used.
|
||||||
|
/// @return True because the type is a container.
|
||||||
template <typename U> static constexpr bool test(decltype(std::begin(std::declval<U>())) *) { return true; }
|
template <typename U> static constexpr bool test(decltype(std::begin(std::declval<U>())) *) { return true; }
|
||||||
|
|
||||||
|
/// @brief Returns false because the type is not a container.
|
||||||
|
/// @tparam U The type to check.
|
||||||
|
/// @param <anonymous> A pointer that is not used.
|
||||||
|
/// @return False because the type is not a container.
|
||||||
template <typename U> static constexpr bool test(...) { return false; }
|
template <typename U> static constexpr bool test(...) { return false; }
|
||||||
|
|
||||||
|
/// @brief Tests whether type T is a container.
|
||||||
static constexpr bool value = test<T>(nullptr);
|
static constexpr bool value = test<T>(nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ using std::make_tuple;
|
|||||||
using std::ostringstream;
|
using std::ostringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::string_view;
|
using std::string_view;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
using namespace CPPUtils;
|
using namespace CPPUtils;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
@@ -55,55 +55,55 @@ using std::wstring;
|
|||||||
TestResults test_EscapeForPrintingWithAConstCharPointer() {
|
TestResults test_EscapeForPrintingWithAConstCharPointer() {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); };
|
auto escape_const_char_pointer = [](const char *value) -> string { return EscapeForPrinting(value); };
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(
|
||||||
"CPPUtils::EscapeForPrinting(const char*)",
|
MakeTestSuite("CPPUtils::EscapeForPrinting(const char*)",
|
||||||
escape_const_char_pointer,
|
escape_const_char_pointer,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple("")),
|
MakeTest("should escape an empty string", (string) "", make_tuple("")),
|
||||||
make_test("should esacpe a string with no special characters",
|
MakeTest("should esacpe a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple("This is a normal string.")),
|
make_tuple("This is a normal string.")),
|
||||||
make_test("should escape the escape character by itself", (string) "\\033", make_tuple("\033")),
|
MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple("\033")),
|
||||||
make_test("should escape the escape character within a string",
|
MakeTest("should escape the escape character within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple("This string has an \033 in it.")),
|
make_tuple("This string has an \033 in it.")),
|
||||||
}));
|
}));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_EscapeForPrintingWithAString() {
|
TestResults test_EscapeForPrintingWithAString() {
|
||||||
TestResults results;
|
TestResults results;
|
||||||
auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); };
|
auto escape_string = [](const string &value) -> string { return EscapeForPrinting(value); };
|
||||||
results += execute_suite(make_test_suite(
|
results += ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::EscapeForPrinting(const std::string&)",
|
"CPPUtils::EscapeForPrinting(const std::string&)",
|
||||||
escape_string,
|
escape_string,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple((string) "")),
|
MakeTest("should escape an empty string", (string) "", make_tuple((string) "")),
|
||||||
make_test("should escape a string with no special characters",
|
MakeTest("should escape a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple((string) "This is a normal string.")),
|
make_tuple((string) "This is a normal string.")),
|
||||||
make_test("should escape the escape character by itself", (string) "\\033", make_tuple((string) "\033")),
|
MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple((string) "\033")),
|
||||||
make_test("should escape the escape character within a string",
|
MakeTest("should escape the escape character within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple((string) "This string has an \033 in it.")),
|
make_tuple((string) "This string has an \033 in it.")),
|
||||||
}));
|
}));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_EscapeForPrintingWithAStringView() {
|
TestResults test_EscapeForPrintingWithAStringView() {
|
||||||
auto escape_string_view = [](const string_view &value) -> string { return EscapeForPrinting(value); };
|
auto escape_string_view = [](const string_view &value) -> string { return EscapeForPrinting(value); };
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::EscapeForPrinting(const std::string_view&)",
|
"CPPUtils::EscapeForPrinting(const std::string_view&)",
|
||||||
escape_string_view,
|
escape_string_view,
|
||||||
{
|
{
|
||||||
make_test("should escape an empty string", (string) "", make_tuple((string_view) "")),
|
MakeTest("should escape an empty string", (string) "", make_tuple((string_view) "")),
|
||||||
make_test("should escape a string with no special characters",
|
MakeTest("should escape a string with no special characters",
|
||||||
(string) "This is a normal string.",
|
(string) "This is a normal string.",
|
||||||
make_tuple((string_view) "This is a normal string.")),
|
make_tuple((string_view) "This is a normal string.")),
|
||||||
make_test("should escape the escape character by itself", (string) "\\033", make_tuple((string_view) "\033")),
|
MakeTest("should escape the escape character by itself", (string) "\\033", make_tuple((string_view) "\033")),
|
||||||
make_test("should escape the escape character within a string",
|
MakeTest("should escape the escape character within a string",
|
||||||
(string) "This string has an \\033 in it.",
|
(string) "This string has an \\033 in it.",
|
||||||
make_tuple((string_view) "This string has an \033 in it.")),
|
make_tuple((string_view) "This string has an \033 in it.")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,13 +113,13 @@ TestResults test_PrettyPrintWithAConstCharPointer() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const char*)",
|
MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const char*)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple("")),
|
MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple("")),
|
||||||
make_test("should print \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")),
|
MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple("hello world")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_PrettyPrintWithAString() {
|
TestResults test_PrettyPrintWithAString() {
|
||||||
@@ -128,12 +128,12 @@ TestResults test_PrettyPrintWithAString() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::string&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::string&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string) "")),
|
MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple((string) "")),
|
||||||
make_test("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string) "hello world")),
|
MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string) "hello world")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,13 +143,12 @@ TestResults test_PrettyPrintWithAStringView() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::string_view&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::string_view&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")),
|
MakeTest("should print \"\" for an empty string", (string) "\"\"", make_tuple((string_view) "")),
|
||||||
make_test(
|
MakeTest("should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")),
|
||||||
"should print \"hello world\"", (string) "\"hello world\"", make_tuple((string_view) "hello world")),
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,13 +168,13 @@ TestResults test_PrettyPrintWithATuple() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, std::tuple)",
|
"CPPUtils::PrettyPrint(std::ostream&, std::tuple)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print a tuple of mixed types", (string) "[ 1, \"hello\", 9 ]", make_tuple(1)),
|
MakeTest("should print a tuple of mixed types", (string) "[ 1, \"hello\", 9 ]", make_tuple(1)),
|
||||||
make_test("should print an empty tuple", (string) "[]", make_tuple(2)),
|
MakeTest("should print an empty tuple", (string) "[]", make_tuple(2)),
|
||||||
make_test("should print a tuple of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)),
|
MakeTest("should print a tuple of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,18 +202,18 @@ TestResults test_PrettyPrintWithAnInitializerList() {
|
|||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, std::initializer_list)",
|
"CPPUtils::PrettyPrint(std::ostream&, std::initializer_list)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print an initializer_list of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(1)),
|
"should print an initializer_list of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(1)),
|
||||||
make_test("should print an empty initializer_list", (string) "[]", make_tuple(2)),
|
MakeTest("should print an empty initializer_list", (string) "[]", make_tuple(2)),
|
||||||
make_test("should print an initializer_list of integers", (string) "[ 1, 2, 3 ]", make_tuple(3)),
|
MakeTest("should print an initializer_list of integers", (string) "[ 1, 2, 3 ]", make_tuple(3)),
|
||||||
make_test("should print an initializer_list of strings with four elements",
|
MakeTest("should print an initializer_list of strings with four elements",
|
||||||
(string) "[ \"one\", \"two\", \"three\", \"four\" ]",
|
(string) "[ \"one\", \"two\", \"three\", \"four\" ]",
|
||||||
make_tuple(4)),
|
make_tuple(4)),
|
||||||
make_test("should print an initializer_list of doubles", (string) "[ 1.1, 2.2, 3.3 ]", make_tuple(5)),
|
MakeTest("should print an initializer_list of doubles", (string) "[ 1.1, 2.2, 3.3 ]", make_tuple(5)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,14 +251,14 @@ TestResults test_PrettyPrintWithDifferentContainerTypes() {
|
|||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
|
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, TContainer)",
|
"CPPUtils::PrettyPrint(std::ostream&, TContainer)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print a vector of integers", (string) "[ 1, 2, 3 ]", make_tuple(1)),
|
MakeTest("should print a vector of integers", (string) "[ 1, 2, 3 ]", make_tuple(1)),
|
||||||
make_test("should print a queue of integers", (string) "[ 1, 2, 3 ]", make_tuple(2)),
|
MakeTest("should print a queue of integers", (string) "[ 1, 2, 3 ]", make_tuple(2)),
|
||||||
make_test("should print a vector of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)),
|
MakeTest("should print a vector of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(3)),
|
||||||
make_test("should print a queue of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(4)),
|
MakeTest("should print a queue of strings", (string) "[ \"one\", \"two\", \"three\" ]", make_tuple(4)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,11 +270,11 @@ TestResults test_PrettyPrintWithSimpleTypes() {
|
|||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
||||||
pretty_print_int,
|
pretty_print_int,
|
||||||
{
|
{
|
||||||
make_test("should print 42 for an int", (string) "42", make_tuple(42)),
|
MakeTest("should print 42 for an int", (string) "42", make_tuple(42)),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
auto pretty_print_float = [](float value) -> string {
|
auto pretty_print_float = [](float value) -> string {
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
@@ -283,24 +282,24 @@ TestResults test_PrettyPrintWithSimpleTypes() {
|
|||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
results +=
|
results +=
|
||||||
execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
||||||
pretty_print_float,
|
pretty_print_float,
|
||||||
{
|
{
|
||||||
make_test("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)),
|
MakeTest("should print 3.14 for a float", (string) "3.14", make_tuple(3.14f)),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
auto pretty_print_string = [](const string &value) -> string {
|
auto pretty_print_string = [](const string &value) -> string {
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
PrettyPrint(os, value);
|
PrettyPrint(os, value);
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
results += execute_suite(make_test_suite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
results += ExecuteSuite(MakeTestSuite("CPPUtils::PrettyPrint(std::ostream&, const TItem&)",
|
||||||
pretty_print_string,
|
pretty_print_string,
|
||||||
{
|
{
|
||||||
make_test("should print \"hello world\" for a string",
|
MakeTest("should print \"hello world\" for a string",
|
||||||
(string) "\"hello world\"",
|
(string) "\"hello world\"",
|
||||||
make_tuple((string) "hello world")),
|
make_tuple((string) "hello world")),
|
||||||
}));
|
}));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,15 +319,15 @@ TestResults test_PrettyPrintWithAPair() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrint(std::ostream&, const std::pair<T1, T2>&)",
|
"CPPUtils::PrettyPrint(std::ostream&, const std::pair<T1, T2>&)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print (1, 2) for a pair of ints", (string) "(1, 2)", make_tuple(1)),
|
MakeTest("should print (1, 2) for a pair of ints", (string) "(1, 2)", make_tuple(1)),
|
||||||
make_test("should print (3.14, 42) for a pair of float and int", (string) "(3.14, 42)", make_tuple(2)),
|
MakeTest("should print (3.14, 42) for a pair of float and int", (string) "(3.14, 42)", make_tuple(2)),
|
||||||
make_test("should print (\"hello\", \"world\") for a pair of strings",
|
MakeTest("should print (\"hello\", \"world\") for a pair of strings",
|
||||||
(string) "(\"hello\", \"world\")",
|
(string) "(\"hello\", \"world\")",
|
||||||
make_tuple(3)),
|
make_tuple(3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,18 +347,18 @@ TestResults test_PrettyPrintWithSeparatorWithAConstCharPointer() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(
|
return ExecuteSuite(
|
||||||
make_test_suite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
MakeTestSuite("CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print 1, 2, 3 for a list of ints", (string) "1, 2, 3", make_tuple(", ", 1)),
|
MakeTest("should print 1, 2, 3 for a list of ints", (string) "1, 2, 3", make_tuple(", ", 1)),
|
||||||
make_test("should print 3.14; 42; \"hello world\" for a list of float, int and string",
|
MakeTest("should print 3.14; 42; \"hello world\" for a list of float, int and string",
|
||||||
(string) "3.14; 42; \"hello world\"",
|
(string) "3.14; 42; \"hello world\"",
|
||||||
make_tuple("; ", 2)),
|
make_tuple("; ", 2)),
|
||||||
make_test("should print \"hello\" \"world\" for a list of strings",
|
MakeTest("should print \"hello\" \"world\" for a list of strings",
|
||||||
(string) "\"hello\" \"world\"",
|
(string) "\"hello\" \"world\"",
|
||||||
make_tuple(" ", 3)),
|
make_tuple(" ", 3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestResults test_PrettyPrintWithSeparatorWithAString() {
|
TestResults test_PrettyPrintWithSeparatorWithAString() {
|
||||||
@@ -378,17 +377,17 @@ TestResults test_PrettyPrintWithSeparatorWithAString() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test("should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string) " | ", 1)),
|
MakeTest("should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string) " | ", 1)),
|
||||||
make_test("should print 3.14 / 42 / \"hello world\" for a list of float, int and string",
|
MakeTest("should print 3.14 / 42 / \"hello world\" for a list of float, int and string",
|
||||||
(string) "3.14 / 42 / \"hello world\"",
|
(string) "3.14 / 42 / \"hello world\"",
|
||||||
make_tuple((string) " / ", 2)),
|
make_tuple((string) " / ", 2)),
|
||||||
make_test("should print \"hello\" - \"world\" for a list of strings",
|
MakeTest("should print \"hello\" - \"world\" for a list of strings",
|
||||||
(string) "\"hello\" - \"world\"",
|
(string) "\"hello\" - \"world\"",
|
||||||
make_tuple((string) " - ", 3)),
|
make_tuple((string) " - ", 3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,18 +407,18 @@ TestResults test_PrettyPrintWithSeparatorWithAStringView() {
|
|||||||
}
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
"CPPUtils::PrettyPrintWithSeparator(std::ostream&, const TChar*, Args&&...)",
|
||||||
pretty_print,
|
pretty_print,
|
||||||
{
|
{
|
||||||
make_test(
|
MakeTest(
|
||||||
"should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string_view) " | ", 1)),
|
"should print 1 | 2 | 3 for a list of ints", (string) "1 | 2 | 3", make_tuple((string_view) " | ", 1)),
|
||||||
make_test("should print 3.14 / 42 / \"hello world\" for a list of float, int and string",
|
MakeTest("should print 3.14 / 42 / \"hello world\" for a list of float, int and string",
|
||||||
(string) "3.14 / 42 / \"hello world\"",
|
(string) "3.14 / 42 / \"hello world\"",
|
||||||
make_tuple((string_view) " / ", 2)),
|
make_tuple((string_view) " / ", 2)),
|
||||||
make_test("should print \"hello\" - \"world\" for a list of strings",
|
MakeTest("should print \"hello\" - \"world\" for a list of strings",
|
||||||
(string) "\"hello\" - \"world\"",
|
(string) "\"hello\" - \"world\"",
|
||||||
make_tuple((string_view) " - ", 3)),
|
make_tuple((string_view) " - ", 3)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,5 +443,5 @@ int main(int argc, char *argv[]) {
|
|||||||
results += test_PrettyPrintWithSeparatorWithAString();
|
results += test_PrettyPrintWithSeparatorWithAString();
|
||||||
results += test_PrettyPrintWithSeparatorWithAStringView();
|
results += test_PrettyPrintWithSeparatorWithAStringView();
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ using std::shared_ptr;
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::tuple;
|
using std::tuple;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using TinyTest::execute_suite;
|
using TinyTest::ExecuteSuite;
|
||||||
using TinyTest::make_test;
|
using TinyTest::MakeTest;
|
||||||
using TinyTest::make_test_suite;
|
using TinyTest::MakeTestSuite;
|
||||||
using TinyTest::TestResults;
|
using TinyTest::TestResults;
|
||||||
string no_errors = "no errors";
|
string no_errors = "no errors";
|
||||||
typedef tuple<string, string, UINT> MessageBoxEvent;
|
typedef tuple<string, string, UINT> MessageBoxEvent;
|
||||||
@@ -302,57 +302,57 @@ TestResults test_WindowsLogger_LogMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)",
|
"CPPUtils::WindowsLogger::LogMessage(cosnt std::string&)",
|
||||||
log_message,
|
log_message,
|
||||||
{
|
{
|
||||||
make_test("should log \"this is a message\" with title \"Debug\"",
|
MakeTest("should log \"this is a message\" with title \"Debug\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
"this is a message",
|
"this is a message",
|
||||||
"this is a message",
|
"this is a message",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test(
|
MakeTest(
|
||||||
"should log \"this is an error\" with title \"ERROR\"",
|
"should log \"this is an error\" with title \"ERROR\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(
|
make_tuple(
|
||||||
Logger::MessageType::Error, "this is an error", "this is an error", "ERROR", MB_OK | MB_ICONHAND)),
|
Logger::MessageType::Error, "this is an error", "this is an error", "ERROR", MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"what a terrible failure\" with title \"How did you let this happen?\"",
|
MakeTest("should log \"what a terrible failure\" with title \"How did you let this happen?\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"this is some information\" with title \"Information\"",
|
MakeTest("should log \"this is some information\" with title \"Information\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
"this is some information",
|
"this is some information",
|
||||||
"this is some information",
|
"this is some information",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"this is a warning\" with title \"Warning\"",
|
MakeTest("should log \"this is a warning\" with title \"Warning\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
"this is a warning",
|
"this is a warning",
|
||||||
"this is a warning",
|
"this is a warning",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test("should log \"this is verbose\" with title \"Verbose\"",
|
MakeTest("should log \"this is verbose\" with title \"Verbose\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"unclassified message\" with title \"Unclassified\"",
|
MakeTest("should log \"unclassified message\" with title \"Unclassified\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
"unclassified message",
|
"unclassified message",
|
||||||
"unclassified message",
|
"unclassified message",
|
||||||
"Unclassified",
|
"Unclassified",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,59 +374,59 @@ TestResults test_WindowsLogger_LogErrorWithMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogError(const std::exception&)",
|
"CPPUtils::WindowsLogger::LogError(const std::exception&)",
|
||||||
log_error,
|
log_error,
|
||||||
{
|
{
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"Debug\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test("should log \"Exception: this is an error\" with title \"ERROR\"",
|
MakeTest("should log \"Exception: this is an error\" with title \"ERROR\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
std::runtime_error("this is an error"),
|
std::runtime_error("this is an error"),
|
||||||
"Exception: this is an error",
|
"Exception: this is an error",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
MB_OK | MB_ICONHAND)),
|
MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"",
|
MakeTest("should log \"Exception: what a terrible failure\" with title \"How did you let this happen?\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
std::runtime_error("what a terrible failure"),
|
std::runtime_error("what a terrible failure"),
|
||||||
"Exception: what a terrible failure",
|
"Exception: what a terrible failure",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"Exception: this is some information\" with title \"Information\"",
|
MakeTest("should log \"Exception: this is some information\" with title \"Information\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
std::runtime_error("this is some information"),
|
std::runtime_error("this is some information"),
|
||||||
"Exception: this is some information",
|
"Exception: this is some information",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"Exception: this is a warning\" with title \"Warning\"",
|
MakeTest("should log \"Exception: this is a warning\" with title \"Warning\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
std::runtime_error("this is a warning"),
|
std::runtime_error("this is a warning"),
|
||||||
"Exception: this is a warning",
|
"Exception: this is a warning",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test("should log \"Exception: this is verbose\" with title \"Verbose\"",
|
MakeTest("should log \"Exception: this is verbose\" with title \"Verbose\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
std::runtime_error("this is verbose"),
|
std::runtime_error("this is verbose"),
|
||||||
"Exception: this is verbose",
|
"Exception: this is verbose",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"Exception: unclassified message\" with title \"Unclassified\"",
|
MakeTest("should log \"Exception: unclassified message\" with title \"Unclassified\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
std::runtime_error("unclassified message"),
|
std::runtime_error("unclassified message"),
|
||||||
"Exception: unclassified message",
|
"Exception: unclassified message",
|
||||||
"Unclassified",
|
"Unclassified",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,67 +449,67 @@ TestResults test_WindowsLogger_LogErrorWithoutMessage() {
|
|||||||
}
|
}
|
||||||
return GetErrors(errors);
|
return GetErrors(errors);
|
||||||
};
|
};
|
||||||
return execute_suite(make_test_suite(
|
return ExecuteSuite(MakeTestSuite(
|
||||||
"CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)",
|
"CPPUtils::WindowsLogger::LogError(const std::string&, const std::exception&)",
|
||||||
log_error,
|
log_error,
|
||||||
{
|
{
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"Debug\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"Debug\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Debug,
|
make_tuple(Logger::MessageType::Debug,
|
||||||
"this is a message",
|
"this is a message",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Debug",
|
"Debug",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"ERROR\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"ERROR\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Error,
|
make_tuple(Logger::MessageType::Error,
|
||||||
"this is an error",
|
"this is an error",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"ERROR",
|
"ERROR",
|
||||||
MB_OK | MB_ICONHAND)),
|
MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"How did you let this happen?\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Wtf,
|
make_tuple(Logger::MessageType::Wtf,
|
||||||
"what a terrible failure",
|
"what a terrible failure",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"How did you let this happen?",
|
"How did you let this happen?",
|
||||||
MB_OK | MB_ICONHAND)),
|
MB_OK | MB_ICONHAND)),
|
||||||
make_test("should log \"Exception this is an exception\" with title \"Information\"",
|
MakeTest("should log \"Exception this is an exception\" with title \"Information\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Info,
|
make_tuple(Logger::MessageType::Info,
|
||||||
"this is some information",
|
"this is some information",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Information",
|
"Information",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"Exception: this is a warning with caught exception this is an exception\" with title "
|
MakeTest("should log \"Exception: this is a warning with caught exception this is an exception\" with title "
|
||||||
"\"Warning\"",
|
"\"Warning\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Warning,
|
make_tuple(Logger::MessageType::Warning,
|
||||||
"this is a warning",
|
"this is a warning",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Warning",
|
"Warning",
|
||||||
MB_OK | MB_ICONEXCLAMATION)),
|
MB_OK | MB_ICONEXCLAMATION)),
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"Verbose\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"Verbose\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple(Logger::MessageType::Verbose,
|
make_tuple(Logger::MessageType::Verbose,
|
||||||
"this is verbose",
|
"this is verbose",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Verbose",
|
"Verbose",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
make_test("should log \"Exception: this is an exception\" with title \"Unclassified\"",
|
MakeTest("should log \"Exception: this is an exception\" with title \"Unclassified\"",
|
||||||
no_errors,
|
no_errors,
|
||||||
make_tuple((Logger::MessageType)1000,
|
make_tuple((Logger::MessageType)1000,
|
||||||
"unclassified message",
|
"unclassified message",
|
||||||
std::runtime_error("this is an exception"),
|
std::runtime_error("this is an exception"),
|
||||||
"Exception: this is an exception",
|
"Exception: this is an exception",
|
||||||
"Unclassified",
|
"Unclassified",
|
||||||
MB_OK | MB_ICONASTERISK)),
|
MB_OK | MB_ICONASTERISK)),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -522,6 +522,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
PrintResults(cout, results);
|
PrintResults(cout, results);
|
||||||
|
|
||||||
return results.failed() + results.errors();
|
return results.Failed() + results.Errors();
|
||||||
}
|
}
|
||||||
#endif // End defined(_WIN32)
|
#endif // End defined(_WIN32)
|
||||||
|
|||||||
Reference in New Issue
Block a user