mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[kandinsky] Add unit tests for UTF-8 decoding and CodepointToIndex
This commit is contained in:
committed by
Émilie Feral
parent
6fac2120fe
commit
865e7cb39e
@@ -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
24
kandinsky/test/font.cpp
Normal 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]);
|
||||
}
|
||||
}
|
||||
15
kandinsky/test/utf8decoder.cpp
Normal file
15
kandinsky/test/utf8decoder.cpp
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user