aboutsummaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-08-29 22:03:22 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-04 13:03:29 +0100
commit2aaebc193c231878133b70e466bd564645db5e4e (patch)
tree989052254d5698d4d545f7979fff69363b5b403e /tests/common
parent24d12b93e5cab844209c5a6709ebd4f27f8263cc (diff)
UnitTests: Cleanup + StringConvert/ChatCommand tests (PR #25353)
(cherry picked from commit 8ce3635d39dbdd101ddf180a66c483162df99c04)
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/EventMap.cpp (renamed from tests/common/test-EventMap.cpp)2
-rw-r--r--tests/common/StringConvert.cpp131
-rw-r--r--tests/common/Timer.cpp (renamed from tests/common/test-Timer.cpp)2
-rw-r--r--tests/common/test-main.cpp20
4 files changed, 133 insertions, 22 deletions
diff --git a/tests/common/test-EventMap.cpp b/tests/common/EventMap.cpp
index 31b27af5daa..1f3ff927fef 100644
--- a/tests/common/test-EventMap.cpp
+++ b/tests/common/EventMap.cpp
@@ -16,7 +16,7 @@
*/
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
-#include "catch2/catch.hpp"
+#include "tc_catch2.h"
#include "EventMap.h"
diff --git a/tests/common/StringConvert.cpp b/tests/common/StringConvert.cpp
new file mode 100644
index 00000000000..d25e28f3d19
--- /dev/null
+++ b/tests/common/StringConvert.cpp
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "tc_catch2.h"
+
+#include "StringConvert.h"
+
+TEST_CASE("String to uint32", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<uint32>("42") == 42);
+ REQUIRE(Trinity::StringTo<uint32>("42", 10) == 42);
+ REQUIRE(Trinity::StringTo<uint32>(" 42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("tail42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("42tail") == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<uint32>("ff", 16) == 0xff);
+ REQUIRE(Trinity::StringTo<uint32>("0xff") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("0xff", 0) == 0xff);
+
+ REQUIRE(Trinity::StringTo<uint32>("101010", 2) == 0b101010);
+ REQUIRE(Trinity::StringTo<uint32>("0b101010") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("0b101010", 0) == 0b101010);
+
+ REQUIRE(Trinity::StringTo<uint32>("5000000000") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("100000000", 16) == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("0x100000000", 0) == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint32>("0xffffffff", 0) == 0xffffffff);
+}
+
+TEST_CASE("String to uint64", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<uint64>("42") == 42);
+ REQUIRE(Trinity::StringTo<uint64>("42", 10) == 42);
+ REQUIRE(Trinity::StringTo<uint64>(" 42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("tail42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("42tail") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("-1", 0) == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<uint64>("ff", 16) == 0xff);
+ REQUIRE(Trinity::StringTo<uint64>("0xff") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("0xff", 0) == 0xff);
+
+ REQUIRE(Trinity::StringTo<uint64>("101010", 2) == 0b101010);
+ REQUIRE(Trinity::StringTo<uint64>("0b101010") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("0b101010", 0) == 0b101010);
+
+ REQUIRE(Trinity::StringTo<uint64>("5000000000") == 5000000000ULL);
+ REQUIRE(Trinity::StringTo<uint64>("100000000", 16) == 0x100000000ULL);
+
+ REQUIRE(Trinity::StringTo<uint64>("20000000000000000000") == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("10000000000000000", 16) == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("0x10000000000000000", 0) == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint64>("0xFFFFFFFFFFFFFFFF", 0) == 0xffffffffffffffffULL);
+}
+
+TEST_CASE("String to int32", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<int32>("-42") == -42);
+ REQUIRE(Trinity::StringTo<int32>("42") == 42);
+ REQUIRE(Trinity::StringTo<int32>("+42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int32>("--42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int32>("~42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int32>("42-") == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<int32>("-ffff", 16) == -0xffff);
+ REQUIRE(Trinity::StringTo<int32>("ffffffff", 16) == std::nullopt);
+ REQUIRE(Trinity::StringTo<int32>("7fffffff", 16) == 0x7fffffff);
+}
+
+TEST_CASE("String to int64", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<int64>("-42") == -42);
+ REQUIRE(Trinity::StringTo<int64>("42") == 42);
+ REQUIRE(Trinity::StringTo<int64>("+42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int64>("--42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int64>("~42") == std::nullopt);
+ REQUIRE(Trinity::StringTo<int64>("42-") == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<int64>("-ffff", 16) == -0xffff);
+ REQUIRE(Trinity::StringTo<int64>("ffffffff", 16) == 0xffffffff);
+ REQUIRE(Trinity::StringTo<int64>("7fffffff", 16) == 0x7fffffff);
+
+ REQUIRE(Trinity::StringTo<int64>("ffffffffffffffff", 16) == std::nullopt);
+ REQUIRE(Trinity::StringTo<int64>("7fffffffffffffff", 16) == 0x7fffffffffffffffLL);
+
+ REQUIRE(Trinity::StringTo<int64>("-8500000000000000", 16) == std::nullopt);
+}
+
+TEST_CASE("String to smaller integer types", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<uint8>("0xff", 0) == 0xff);
+ REQUIRE(Trinity::StringTo<uint8>("0x1ff", 0) == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<int8>("0xff", 0) == std::nullopt);
+ REQUIRE(Trinity::StringTo<int8>("0x7f", 0) == 0x7f);
+ REQUIRE(Trinity::StringTo<int8>("-7f", 16) == -0x7f);
+
+ REQUIRE(Trinity::StringTo<uint16>("0x1ff", 0) == 0x1ff);
+ REQUIRE(Trinity::StringTo<uint16>("0x1ffff", 0) == std::nullopt);
+ REQUIRE(Trinity::StringTo<uint16>("-1", 0) == std::nullopt);
+
+ REQUIRE(Trinity::StringTo<int16>("0x1ff", 0) == 0x1ff);
+ REQUIRE(Trinity::StringTo<int16>("0xffff", 0) == std::nullopt);
+ REQUIRE(Trinity::StringTo<int16>("0x7fff", 0) == 0x7fff);
+ REQUIRE(Trinity::StringTo<int16>("-1", 0) == -1);
+}
+
+TEST_CASE("Test.String to boolean", "[StringConvert]")
+{
+ REQUIRE(Trinity::StringTo<bool>("true") == true);
+ REQUIRE(Trinity::StringTo<bool>("false") == false);
+ REQUIRE(Trinity::StringTo<bool>("ture") == std::nullopt);
+ REQUIRE(Trinity::StringTo<bool>("true", 10) == std::nullopt);
+ REQUIRE(Trinity::StringTo<bool>("1") == true);
+ REQUIRE(Trinity::StringTo<bool>("1", 10) == true);
+ REQUIRE(Trinity::StringTo<bool>("0", 10) == false);
+}
diff --git a/tests/common/test-Timer.cpp b/tests/common/Timer.cpp
index 76d02d51aa0..9117b1338a1 100644
--- a/tests/common/test-Timer.cpp
+++ b/tests/common/Timer.cpp
@@ -16,7 +16,7 @@
*/
#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
-#include "catch2/catch.hpp"
+#include "tc_catch2.h"
#include "Timer.h"
diff --git a/tests/common/test-main.cpp b/tests/common/test-main.cpp
deleted file mode 100644
index 8ed9dd5863b..00000000000
--- a/tests/common/test-main.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#define CATCH_CONFIG_MAIN
-#include "catch2/catch.hpp"