Skip to content
Snippets Groups Projects
Commit f100fed0 authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

Add tests for stringutility.hh

parent f529d23f
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ set(TESTS
shared_ptrtest_config
singletontest
streamtest
stringutilitytest
testfloatcmp
tuplestest
tupleutilitytest
......@@ -144,6 +145,9 @@ add_executable("sllisttest" EXCLUDE_FROM_ALL sllisttest.cc)
add_executable("streamtest" streamtest.cc)
target_link_libraries("streamtest" "dunecommon")
add_executable("stringutilitytest" stringutilitytest.cc)
target_link_libraries("stringutilitytest" "dunecommon")
add_executable("testdebugallocator" testdebugallocator.cc)
target_link_libraries(testdebugallocator dunecommon)
add_executable("testdebugallocator_fail1" testdebugallocator.cc)
......
......@@ -32,6 +32,7 @@ TESTPROGS = \
shared_ptrtest_config \
singletontest \
streamtest \
stringutilitytest \
testdebugallocator \
testdebugallocator_fail1 \
testdebugallocator_fail2 \
......@@ -176,6 +177,8 @@ sourcescheck_NOSOURCES = timing.cc
streamtest_SOURCES = streamtest.cc
stringutilitytest_SOURCES = stringutilitytest.cc
testdebugallocator_SOURCES = testdebugallocator.cc
testdebugallocator_CPPFLAGS = $(AM_CPPFLAGS)
......
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string>
#include <dune/common/stringutility.hh>
namespace {
const std::string hello_world("hello world");
} /* namespace */
bool test_hasPrefix()
{
bool pass = true;
using Dune::hasPrefix;
pass &= hasPrefix(hello_world, "hello");
pass &= !hasPrefix(hello_world, "world");
return pass;
}
bool test_hasSuffix()
{
bool pass = true;
using Dune::hasSuffix;
pass &= hasSuffix(hello_world, "world");
pass &= !hasSuffix(hello_world, "hello");
return pass;
}
bool test_formatString()
{
bool pass = true;
const int one = 1;
const static std::string format("hello %i");
const static std::string expected("hello 1");
using Dune::formatString;
const std::string s = formatString(format, one);
pass &= (s == expected);
return pass;
}
int main()
{
bool pass = true;
pass &= test_hasPrefix();
pass &= test_hasSuffix();
pass &= test_formatString();
return pass ? 0 : 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment