summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichal Čihař <nijel@debian.org>2016-12-12 14:52:14 +0100
committerMichal Čihař <nijel@debian.org>2016-12-12 14:52:14 +0100
commit403eca6af192d9a1e57d7c8ea1181b3c6137bc4e (patch)
tree247e0730e4e15428cbe0113d1fcecae996eb8f79 /tests
parent4293c6165a17103edbdacb9971a8724bba275d32 (diff)
New upstream version 1.38.0
Diffstat (limited to 'tests')
-rw-r--r--tests/common.h11
-rw-r--r--tests/utf-8.c17
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/common.h b/tests/common.h
index 1b6bfca..97f0a22 100644
--- a/tests/common.h
+++ b/tests/common.h
@@ -15,6 +15,17 @@
} \
}
+#define test_string(expected, actual, length) \
+{ \
+ for (i = 0; i < length; i++) { \
+ if ((unsigned char)expected[i] != actual[i]) { \
+ fprintf(stderr, "Test \"%s\" == \"%s\" failed!\n", ""#expected, ""#actual); \
+ fprintf(stderr, "[%d] \\x%02X != \\x%02X\n", (int)i, (unsigned char)expected[i], actual[i]); \
+ exit(2); \
+ } \
+ } \
+}
+
#define gammu_test_result(error, text) \
{ \
if (error != ERR_NONE) {\
diff --git a/tests/utf-8.c b/tests/utf-8.c
index e2e3c2f..f28104b 100644
--- a/tests/utf-8.c
+++ b/tests/utf-8.c
@@ -5,10 +5,15 @@
#include "common.h"
#include <gammu.h>
#include <gammu-unicode.h>
+#include <string.h>
+
+#include "../libgammu/misc/coding/coding.h"
int main(int argc UNUSED, char **argv UNUSED)
{
unsigned char out[20];
+ gammu_char_t dest;
+ size_t i;
test_result(EncodeWithUTF8Alphabet(0x24, out) == 1);
test_result(out[0] == 0x24);
@@ -35,12 +40,24 @@ int main(int argc UNUSED, char **argv UNUSED)
test_result(out[3] == 0x8d);
test_result(EncodeUTF8(out, "\xD8\x3d\xDC\x4d\x00\x00"));
+
test_result(out[0] == 0xf0);
test_result(out[1] == 0x9f);
test_result(out[2] == 0x91);
test_result(out[3] == 0x8d);
test_result(out[4] == 0x00);
+ test_result(DecodeWithUTF8Alphabet("\xf0\x9f\x91\x8d\x00", &dest, 4) == 4);
+ test_result(dest == 0x1f44d);
+
+ DecodeUTF8(out, "\xf0\x9f\x91\x8d\x00", 4);
+
+ test_string("\xD8\x3d\xDC\x4d\x00", out, 5);
+
+ DecodeUTF8(out, "ahoj", 4);
+
+ test_string("\x00\x61\x00h\x00o\x00j\x00\x00\x00", out, 10);
+
return 0;
}