[kandinsky] Add unit tests for UTF-8 decoding and CodepointToIndex

This commit is contained in:
Romain Goyet
2018-10-31 10:38:25 +01:00
committed by Émilie Feral
parent bf0d947939
commit c23e5a47bc
3 changed files with 42 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ src += $(addprefix kandinsky/src/,\
ion_context.cpp \
point.cpp \
rect.cpp \
unicode/utf8decoder.cpp\
)
src += $(addprefix kandinsky/fonts/, \
@@ -22,7 +23,9 @@ src += $(addprefix kandinsky/fonts/, \
tests += $(addprefix kandinsky/test/,\
color.cpp\
font.cpp\
rect.cpp\
utf8decoder.cpp\
)
RASTERIZER_CFLAGS := -std=c99 `pkg-config freetype2 --cflags`

24
kandinsky/test/font.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include <quiz.h>
#include <kandinsky.h>
#include <assert.h>
static constexpr KDFont::CodepointIndexPair table[] = {
KDFont::CodepointIndexPair(3, 1), // Codepoint, identifier
KDFont::CodepointIndexPair(9, 4),
KDFont::CodepointIndexPair(12, 5),
KDFont::CodepointIndexPair(14, 7)
};
constexpr KDFont testFont(4, table, 10, 10, nullptr, nullptr);
const KDFont::GlyphIndex index_for_codepoint[] = {
/* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 */
0, 0, 0, 1, 2, 3, 0, 0, 0, 4, 0, 0, 5, 6, 7, 0
};
QUIZ_CASE(kandinsky_font_index_for_codepoint) {
for (int i=0; i<16; i++) {
KDFont::GlyphIndex result = testFont.indexForCodepoint(i);
quiz_assert(result == index_for_codepoint[i]);
}
}

View File

@@ -0,0 +1,15 @@
#include <quiz.h>
#include <kandinsky/unicode/utf8decoder.h>
void assert_decodes_to(const char * string, Codepoint c) {
UTF8Decoder d(string);
quiz_assert(d.nextCodepoint() == c);
quiz_assert(d.nextCodepoint() == 0);
}
QUIZ_CASE(kandinsky_utf8_decoder) {
assert_decodes_to("\x20", 0x20);
assert_decodes_to("\xC2\xA2", 0xA2);
assert_decodes_to("\xED\x9F\xBF", 0xD7FF);
assert_decodes_to("\xCC\x81", 0x301);
}