diff --git a/kandinsky/Makefile b/kandinsky/Makefile index 9705de6fe..af4804052 100644 --- a/kandinsky/Makefile +++ b/kandinsky/Makefile @@ -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` diff --git a/kandinsky/test/font.cpp b/kandinsky/test/font.cpp new file mode 100644 index 000000000..96a2acfed --- /dev/null +++ b/kandinsky/test/font.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +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]); + } +} diff --git a/kandinsky/test/utf8decoder.cpp b/kandinsky/test/utf8decoder.cpp new file mode 100644 index 000000000..3e858f526 --- /dev/null +++ b/kandinsky/test/utf8decoder.cpp @@ -0,0 +1,15 @@ +#include +#include + +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); +}