chiark / gitweb /
Fix service file to match installed elogind binary location
[elogind.git] / src / test / test-utf8.c
index 3399f2ba9c1ee9d4c024b9a9a610c68b78f3096d..1ce5a5a24d0b18fd1ad366c36cd3cb7f023c06c4 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
@@ -19,6 +17,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "alloc-util.h"
+#include "string-util.h"
 #include "utf8.h"
 #include "util.h"
 
@@ -93,6 +93,18 @@ static void test_utf8_escaping_printable(void) {
         assert_se(utf8_is_valid(p6));
 }
 
+static void test_utf16_to_utf8(void) {
+        char *a = NULL;
+        const uint16_t utf16[] = { htole16('a'), htole16(0xd800), htole16('b'), htole16(0xdc00), htole16('c'), htole16(0xd801), htole16(0xdc37) };
+        const char utf8[] = { 'a', 'b', 'c', 0xf0, 0x90, 0x90, 0xb7, 0 };
+
+        a = utf16_to_utf8(utf16, 14);
+        assert_se(a);
+        assert_se(streq(a, utf8));
+
+        free(a);
+}
+
 int main(int argc, char *argv[]) {
         test_utf8_is_valid();
         test_utf8_is_printable();
@@ -100,6 +112,7 @@ int main(int argc, char *argv[]) {
         test_utf8_encoded_valid_unichar();
         test_utf8_escaping();
         test_utf8_escaping_printable();
+        test_utf16_to_utf8();
 
         return 0;
 }