mirror of
https://github.com/kevinbentley/Descent3.git
synced 2026-04-08 05:00:04 -04:00
Merge pull request #251 from winterheart/pstring-unittests
Unittests for misc
This commit is contained in:
@@ -10,3 +10,7 @@ set(CPPS
|
||||
add_library(misc STATIC ${HEADERS} ${CPPS})
|
||||
|
||||
target_link_libraries(misc spdlog::spdlog_header_only ddebug)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
10
misc/tests/CMakeLists.txt
Normal file
10
misc/tests/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
add_executable(
|
||||
misc_tests
|
||||
misc_tests.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
misc_tests
|
||||
GTest::gtest_main
|
||||
misc
|
||||
)
|
||||
gtest_discover_tests(misc_tests)
|
||||
43
misc/tests/misc_tests.cpp
Normal file
43
misc/tests/misc_tests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Descent 3
|
||||
* Copyright (C) 2024 Descent Developers
|
||||
*
|
||||
* 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 3 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 <utility>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "pstring.h"
|
||||
|
||||
TEST(D3, CleanupStr) {
|
||||
std::vector<std::pair<const char*, const char*>> test_data = {
|
||||
{"String with tails \t \n ", "String with tails"},
|
||||
{" \t \n String with heads", "String with heads"},
|
||||
{" \t \n String with heads and tails \t \n ", "String with heads and tails"},
|
||||
{"A normal string", "A normal string"},
|
||||
{"", ""},
|
||||
{" ", ""},
|
||||
{" \n One \n \n Two \n \n ", "One \n \n Two"},
|
||||
{"A very large string which excess size of result", "A very large string which exces"},
|
||||
|
||||
};
|
||||
char result[32];
|
||||
|
||||
for (auto i : test_data) {
|
||||
CleanupStr(result, i.first, 32);
|
||||
ASSERT_STREQ(result, i.second);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user