Skip to content

Commit

Permalink
Merge pull request DescentDevelopers#251 from winterheart/pstring-uni…
Browse files Browse the repository at this point in the history
…ttests

Unittests for misc
  • Loading branch information
Lgt2x committed May 1, 2024
2 parents eb4cf2f + d82d3a2 commit d132a1c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 10 additions & 0 deletions misc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 43 additions & 0 deletions misc/tests/misc_tests.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit d132a1c

Please sign in to comment.