mirror of
https://github.com/nemtrif/utfcpp.git
synced 2025-04-04 13:05:06 +00:00
Restructure tests.
This commit is contained in:
parent
e3e57c811a
commit
53398ca702
7 changed files with 47 additions and 34 deletions
|
@ -1,17 +1,9 @@
|
|||
add_executable(negative ${PROJECT_SOURCE_DIR}/tests/negative.cpp)
|
||||
add_executable(cpp11 ${PROJECT_SOURCE_DIR}/tests/test_cpp11.cpp)
|
||||
add_executable(cpp17 ${PROJECT_SOURCE_DIR}/tests/test_cpp17.cpp)
|
||||
add_executable(apitests
|
||||
${PROJECT_SOURCE_DIR}/tests/test_checked_api.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/test_unchecked_api.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/test_checked_iterator.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/test_unchecked_iterator.cpp
|
||||
)
|
||||
add_executable(apitests ${PROJECT_SOURCE_DIR}/tests/apitests.cpp)
|
||||
|
||||
add_executable(noexceptionstests
|
||||
${PROJECT_SOURCE_DIR}/tests/test_unchecked_api.cpp
|
||||
${PROJECT_SOURCE_DIR}/tests/test_unchecked_iterator.cpp
|
||||
)
|
||||
add_executable(noexceptionstests ${PROJECT_SOURCE_DIR}/tests/noexceptionstests.cpp)
|
||||
|
||||
target_link_libraries(negative PRIVATE utf8::cpp)
|
||||
target_link_libraries(cpp11 PRIVATE utf8::cpp)
|
||||
|
|
6
tests/apitests.cpp
Normal file
6
tests/apitests.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "../extern/ftest/ftest.h"
|
||||
|
||||
#include "test_checked_api.h"
|
||||
#include "test_checked_iterator.h"
|
||||
#include "test_unchecked_api.h"
|
||||
#include "test_unchecked_iterator.h"
|
4
tests/noexceptionstests.cpp
Normal file
4
tests/noexceptionstests.cpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include "../extern/ftest/ftest.h"
|
||||
|
||||
#include "test_unchecked_api.h"
|
||||
#include "test_unchecked_iterator.h"
|
|
@ -1,5 +1,6 @@
|
|||
#define F_TEST_NO_MAIN
|
||||
#include "../extern/ftest/ftest.h"
|
||||
#ifndef UTF8_FOR_CPP_TEST_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
#define UTF8_FOR_CPP_TEST_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
#include <string>
|
||||
|
@ -42,8 +43,8 @@ TEST(CheckedAPITests, test_append)
|
|||
// Ensure no warnings with plain char
|
||||
char c[2] = {0,0};
|
||||
append('a', c);
|
||||
EXPECT_EQ (u[0], 'a');
|
||||
EXPECT_EQ (u[1], 0);
|
||||
EXPECT_EQ (c[0], 'a');
|
||||
EXPECT_EQ (c[1], 0);
|
||||
}
|
||||
|
||||
TEST(CheckedAPITests, test_next)
|
||||
|
@ -193,3 +194,5 @@ TEST(CheckedAPITests, test_starts_with_bom)
|
|||
bool no_bbom = starts_with_bom(threechars, threechars + sizeof(threechars));
|
||||
EXPECT_FALSE (no_bbom);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,5 +1,6 @@
|
|||
#define F_TEST_NO_MAIN
|
||||
#include "../extern/ftest/ftest.h"
|
||||
#ifndef UTF8_FOR_CPP_TEST_CHECKED_ITERATOR_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
#define UTF8_FOR_CPP_TEST_CHECKED_ITERATOR_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
using namespace utf8;
|
||||
|
@ -30,3 +31,5 @@ TEST(CheckedIteratrTests, test_decrement)
|
|||
EXPECT_EQ (--it, utf8::iterator<const char*>(threechars, threechars, threechars + 9));
|
||||
EXPECT_EQ (*it, 0x10346);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,36 +1,38 @@
|
|||
#include "../extern/ftest/ftest.h"
|
||||
#ifndef UTF8_FOR_CPP_TEST_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
#define UTF8_FOR_CPP_TEST_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
|
||||
#include "utf8/unchecked.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace utf8::unchecked;
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(UnCheckedAPITests, test_append)
|
||||
{
|
||||
unsigned char u[5] = {0,0,0,0,0};
|
||||
append(0x0448, u);
|
||||
utf8::unchecked::append(0x0448, u);
|
||||
EXPECT_EQ (u[0], 0xd1);
|
||||
EXPECT_EQ (u[1], 0x88);
|
||||
EXPECT_EQ (u[2], 0);
|
||||
EXPECT_EQ (u[3], 0);
|
||||
EXPECT_EQ (u[4], 0);
|
||||
|
||||
append(0x65e5, u);
|
||||
utf8::unchecked::append(0x65e5, u);
|
||||
EXPECT_EQ (u[0], 0xe6);
|
||||
EXPECT_EQ (u[1], 0x97);
|
||||
EXPECT_EQ (u[2], 0xa5);
|
||||
EXPECT_EQ (u[3], 0);
|
||||
EXPECT_EQ (u[4], 0);
|
||||
|
||||
append(0x3044, u);
|
||||
utf8::unchecked::append(0x3044, u);
|
||||
EXPECT_EQ (u[0], 0xe3);
|
||||
EXPECT_EQ (u[1], 0x81);
|
||||
EXPECT_EQ (u[2], 0x84);
|
||||
EXPECT_EQ (u[3], 0);
|
||||
EXPECT_EQ (u[4], 0);
|
||||
|
||||
append(0x10346, u);
|
||||
utf8::unchecked::append(0x10346, u);
|
||||
EXPECT_EQ (u[0], 0xf0);
|
||||
EXPECT_EQ (u[1], 0x90);
|
||||
EXPECT_EQ (u[2], 0x8d);
|
||||
|
@ -65,7 +67,7 @@ TEST(UnCheckedAPITests, test_next)
|
|||
TEST(UnCheckedAPITests, test_peek_next)
|
||||
{
|
||||
const char* const cw = "\xe6\x97\xa5\xd1\x88";
|
||||
unsigned int cp = peek_next(cw);
|
||||
unsigned int cp = utf8::unchecked::peek_next(cw);
|
||||
EXPECT_EQ (cp, 0x65e5);
|
||||
}
|
||||
|
||||
|
@ -73,19 +75,19 @@ TEST(UnCheckedAPITests, test_prior)
|
|||
{
|
||||
const char* twochars = "\xe6\x97\xa5\xd1\x88";
|
||||
const char* w = twochars + 3;
|
||||
unsigned int cp = prior (w);
|
||||
unsigned int cp = utf8::unchecked::prior (w);
|
||||
EXPECT_EQ (cp, 0x65e5);
|
||||
EXPECT_EQ (w, twochars);
|
||||
|
||||
const char* threechars = "\xf0\x90\x8d\x86\xe6\x97\xa5\xd1\x88";
|
||||
w = threechars + 9;
|
||||
cp = prior(w);
|
||||
cp = utf8::unchecked::prior(w);
|
||||
EXPECT_EQ (cp, 0x0448);
|
||||
EXPECT_EQ (w, threechars + 7);
|
||||
cp = prior(w);
|
||||
cp = utf8::unchecked::prior(w);
|
||||
EXPECT_EQ (cp, 0x65e5);
|
||||
EXPECT_EQ (w, threechars + 4);
|
||||
cp = prior(w);
|
||||
cp = utf8::unchecked::prior(w);
|
||||
EXPECT_EQ (cp, 0x10346);
|
||||
EXPECT_EQ (w, threechars);
|
||||
}
|
||||
|
@ -117,7 +119,7 @@ TEST(UnCheckedAPITests, test_utf32to8)
|
|||
{
|
||||
unsigned int utf32string[] = {0x448, 0x65E5, 0x10346, 0};
|
||||
string utf8result;
|
||||
utf32to8(utf32string, utf32string + 3, back_inserter(utf8result));
|
||||
utf8::unchecked::utf32to8(utf32string, utf32string + 3, back_inserter(utf8result));
|
||||
EXPECT_EQ (utf8result.size(), 9);
|
||||
}
|
||||
|
||||
|
@ -125,7 +127,7 @@ TEST(UnCheckedAPITests, test_utf8to32)
|
|||
{
|
||||
const char* twochars = "\xe6\x97\xa5\xd1\x88";
|
||||
vector<unsigned int> utf32result;
|
||||
utf8to32(twochars, twochars + 5, back_inserter(utf32result));
|
||||
utf8::unchecked::utf8to32(twochars, twochars + 5, back_inserter(utf32result));
|
||||
EXPECT_EQ (utf32result.size(), 2);
|
||||
}
|
||||
|
||||
|
@ -133,7 +135,7 @@ TEST(UnCheckedAPITests, test_utf16to8)
|
|||
{
|
||||
unsigned short utf16string[] = {0x41, 0x0448, 0x65e5, 0xd834, 0xdd1e};
|
||||
string utf8result;
|
||||
utf16to8(utf16string, utf16string + 5, back_inserter(utf8result));
|
||||
utf8::unchecked::utf16to8(utf16string, utf16string + 5, back_inserter(utf8result));
|
||||
EXPECT_EQ (utf8result.size(), 10);
|
||||
}
|
||||
|
||||
|
@ -141,7 +143,7 @@ TEST(UnCheckedAPITests, test_utf8to16)
|
|||
{
|
||||
char utf8_with_surrogates[] = "\xe6\x97\xa5\xd1\x88\xf0\x9d\x84\x9e";
|
||||
vector <unsigned short> utf16result;
|
||||
utf8to16(utf8_with_surrogates, utf8_with_surrogates + 9, back_inserter(utf16result));
|
||||
utf8::unchecked::utf8to16(utf8_with_surrogates, utf8_with_surrogates + 9, back_inserter(utf16result));
|
||||
EXPECT_EQ (utf16result.size(), 4);
|
||||
EXPECT_EQ (utf16result[2], 0xd834);
|
||||
EXPECT_EQ (utf16result[3], 0xdd1e);
|
||||
|
@ -151,7 +153,7 @@ TEST(UnCheckedAPITests, test_replace_invalid)
|
|||
{
|
||||
char invalid_sequence[] = "a\x80\xe0\xa0\xc0\xaf\xed\xa0\x80z";
|
||||
vector<char> replace_invalid_result;
|
||||
replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), std::back_inserter(replace_invalid_result), '?');
|
||||
utf8::unchecked::replace_invalid (invalid_sequence, invalid_sequence + sizeof(invalid_sequence), std::back_inserter(replace_invalid_result), '?');
|
||||
bool bvalid = utf8::is_valid(replace_invalid_result.begin(), replace_invalid_result.end());
|
||||
EXPECT_TRUE (bvalid);
|
||||
const char fixed_invalid_sequence[] = "a????z";
|
||||
|
@ -159,3 +161,4 @@ TEST(UnCheckedAPITests, test_replace_invalid)
|
|||
EXPECT_TRUE (std::equal(replace_invalid_result.begin(), replace_invalid_result.begin() + sizeof(fixed_invalid_sequence), fixed_invalid_sequence));
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#define F_TEST_NO_MAIN
|
||||
#include "../extern/ftest/ftest.h"
|
||||
#ifndef UTF8_FOR_CPP_TEST_UNCHECKED_ITERATOR_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
#define UTF8_FOR_CPP_TEST_UNCHECKED_ITERATOR_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
|
||||
|
||||
#include "utf8/unchecked.h"
|
||||
|
||||
|
@ -32,3 +32,5 @@ TEST(UnCheckedIteratrTests, test_decrement)
|
|||
EXPECT_EQ (*it, 0x10346);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue