add test: cstring

This commit is contained in:
bolero-MURAKAMI 2013-01-13 01:49:11 +09:00
parent b51b14efa9
commit d1379ff155
14 changed files with 478 additions and 0 deletions

View file

@ -0,0 +1,48 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP
#define SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP
# define TESTSPR_CPP_INCLUDE
#endif
#include "./memcmp.cpp"
#include "./strcmp.cpp"
#include "./strcoll.cpp"
#include "./strncmp.cpp"
#include "./memchr.cpp"
#include "./strchr.cpp"
#include "./strcspn.cpp"
#include "./strpbrk.cpp"
#include "./strrchr.cpp"
#include "./strspn.cpp"
#include "./strstr.cpp"
#include "./strlen.cpp"
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP
# undef TESTSPR_CPP_INCLUDE
#endif
namespace testspr {
static void cstring_test() {
testspr::cstring_memcmp_test();
testspr::cstring_strcmp_test();
testspr::cstring_strcoll_test();
testspr::cstring_strncmp_test();
testspr::cstring_memchr_test();
testspr::cstring_strchr_test();
testspr::cstring_strcspn_test();
testspr::cstring_strpbrk_test();
testspr::cstring_strrchr_test();
testspr::cstring_strspn_test();
testspr::cstring_strstr_test();
testspr::cstring_strlen_test();
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP

View file

@ -0,0 +1,28 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP
#define SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP
#include <sprout/cstring/memchr.hpp>
#include <sprout/iterator.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_memchr_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR unsigned char buf[] = "abcdef\0ghij";
SPROUT_STATIC_CONSTEXPR unsigned char b = 'h';
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::memchr(buf, b, 12);
TESTSPR_BOTH_ASSERT(sprout::distance(buf, reinterpret_cast<unsigned char const*>(found)) == 8);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_memchr_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP
#define SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP
#include <sprout/cstring/memcmp.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_memcmp_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR unsigned char buf[] = "\0abc\0de";
SPROUT_STATIC_CONSTEXPR unsigned char buf2[] = "\0abc\0de";
SPROUT_STATIC_CONSTEXPR unsigned char buf3[] = "\0abcdef";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::memcmp(buf, buf2, 7);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::memcmp(buf, buf3, 7);
TESTSPR_BOTH_ASSERT(result < 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_memcmp_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP

View file

@ -0,0 +1,28 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP
#include <sprout/cstring/strchr.hpp>
#include <sprout/iterator.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strchr_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmnabcdefghijklmn";
SPROUT_STATIC_CONSTEXPR char c = 'd';
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strchr(str, c);
TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 3);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strchr_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP

View file

@ -0,0 +1,42 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP
#include <sprout/cstring/strcmp.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strcmp_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str1[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str2[] = "ABD";
SPROUT_STATIC_CONSTEXPR char str3[] = "B";
SPROUT_STATIC_CONSTEXPR char str4[] = "AAAA";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str1);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str2);
TESTSPR_BOTH_ASSERT(result < 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str3);
TESTSPR_BOTH_ASSERT(result < 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str4);
TESTSPR_BOTH_ASSERT(result > 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strcmp_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP

View file

@ -0,0 +1,42 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP
#include <sprout/cstring/strcoll.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strcoll_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str1[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str2[] = "ABD";
SPROUT_STATIC_CONSTEXPR char str3[] = "B";
SPROUT_STATIC_CONSTEXPR char str4[] = "AAAA";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str1);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str2);
TESTSPR_BOTH_ASSERT(result < 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str3);
TESTSPR_BOTH_ASSERT(result < 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str4);
TESTSPR_BOTH_ASSERT(result > 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strcoll_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP
#include <sprout/cstring/strcspn.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strcspn_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij";
SPROUT_STATIC_CONSTEXPR char str1[] = "hj";
SPROUT_STATIC_CONSTEXPR char str2[] = "ghj";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcspn(str, str1);
TESTSPR_BOTH_ASSERT(result == 14);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strcspn(str, str2);
TESTSPR_BOTH_ASSERT(result == 6);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strcspn_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP

View file

@ -0,0 +1,31 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP
#include <sprout/cstring/strlen.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strlen_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str1[] = "today";
SPROUT_STATIC_CONSTEXPR char str2[] = "hello world";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strlen(str1);
TESTSPR_BOTH_ASSERT(result == 5);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strlen(str2);
TESTSPR_BOTH_ASSERT(result == 11);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strlen_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP

View file

@ -0,0 +1,57 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP
#include <sprout/cstring/strncmp.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strncmp_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str1[] = "ABD";
SPROUT_STATIC_CONSTEXPR char str2[] = "ABC";
SPROUT_STATIC_CONSTEXPR char str3[] = "AAA";
SPROUT_STATIC_CONSTEXPR char str4[] = "ABCD";
SPROUT_STATIC_CONSTEXPR char str5[] = "AB";
SPROUT_STATIC_CONSTEXPR char str6[] = "B";
SPROUT_STATIC_CONSTEXPR char str7[] = "A";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str1, 2);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str2, 2);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str3, 2);
TESTSPR_BOTH_ASSERT(result > 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str4, 2);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str5, 2);
TESTSPR_BOTH_ASSERT(result == 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str6, 2);
TESTSPR_BOTH_ASSERT(result < 0);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str7, 2);
TESTSPR_BOTH_ASSERT(result > 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strncmp_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP

View file

@ -0,0 +1,33 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP
#include <sprout/cstring/strpbrk.hpp>
#include <sprout/iterator.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strpbrk_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij";
SPROUT_STATIC_CONSTEXPR char str1[] = "ghsp";
SPROUT_STATIC_CONSTEXPR char str2[] = "sp";
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strpbrk(str, str1);
TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 6);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strpbrk(str, str2);
TESTSPR_BOTH_ASSERT(!found);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strpbrk_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP

View file

@ -0,0 +1,28 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP
#include <sprout/cstring/strrchr.hpp>
#include <sprout/iterator.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strrchr_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmnabcdefghijklmn";
SPROUT_STATIC_CONSTEXPR char c = 'd';
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strrchr(str, c);
TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 17);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strrchr_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP

View file

@ -0,0 +1,32 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP
#include <sprout/cstring/strspn.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strspn_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij";
SPROUT_STATIC_CONSTEXPR char str1[] = "abcfg";
SPROUT_STATIC_CONSTEXPR char str2[] = "gfedcba";
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strspn(str, str1);
TESTSPR_BOTH_ASSERT(result == 3);
}
{
SPROUT_STATIC_CONSTEXPR auto result = sprout::strspn(str, str2);
TESTSPR_BOTH_ASSERT(result == 14);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strspn_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP

View file

@ -0,0 +1,43 @@
#ifndef SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP
#define SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP
#include <sprout/cstring/strstr.hpp>
#include <sprout/iterator.hpp>
#include <testspr/tools.hpp>
namespace testspr {
static void cstring_strstr_test() {
using namespace sprout;
{
SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmn";
SPROUT_STATIC_CONSTEXPR char str1[] = "defgh";
SPROUT_STATIC_CONSTEXPR char str2[] = "xyz";
SPROUT_STATIC_CONSTEXPR char str3[] = "abcdefghijklmnopqr";
SPROUT_STATIC_CONSTEXPR char str4[] = "";
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str1);
TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 3);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str2);
TESTSPR_BOTH_ASSERT(!found);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str3);
TESTSPR_BOTH_ASSERT(!found);
}
{
SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str4);
TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 0);
}
}
}
} // namespace testspr
#ifndef TESTSPR_CPP_INCLUDE
# define TESTSPR_TEST_FUNCTION testspr::cstring_strstr_test
# include <testspr/include_main.hpp>
#endif
#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP

View file

@ -14,6 +14,7 @@
#include "../libs/variant/test/variant.cpp"
#include "../libs/algorithm/test/algorithm.cpp"
#include "../libs/random/test/random.cpp"
#include "../libs/cstring/test/cstring.cpp"
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_TESTSPR_SPROUT_HPP
# undef TESTSPR_CPP_INCLUDE
@ -29,6 +30,7 @@ namespace testspr {
testspr::variant_test();
testspr::algorithm_test();
testspr::random_test();
testspr::cstring_test();
}
} // namespace testspr