File: unicode.c

package info (click to toggle)
libmatchbox 1.12%2Bgit20170224-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 748 kB
  • sloc: ansic: 8,675; makefile: 110; sh: 11
file content (67 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <check.h>
#include <stdlib.h>

#include <libmb/mb.h>

#define ISASCII(EXPECTED) \
  ck_assert (*s == EXPECTED); \
  ck_assert (mb_util_next_utf8_char (&s) == 1);

#define NEXTTEST(LEN) \
  ck_assert (mb_util_next_utf8_char (&s) == LEN);

START_TEST(next_ascii_char)
{
  char *string = "abcdef";
  unsigned char *s = (unsigned char*)string;

  ISASCII('a');
  ISASCII('b');
  ISASCII('c');
  ISASCII('d');
  ISASCII('e');
  ISASCII('f');
  ck_assert (*s == '\0');
}
END_TEST

START_TEST(next_unicode_char)
{
  /* U+10086 U+0B01 U+078F*/
  char *string = "\360\220\202\206 \340\254\201 \336\217";
  unsigned char *s = (unsigned char*)string;

  NEXTTEST(4);
  ISASCII(' ');
  NEXTTEST(3);
  ISASCII(' ');
  NEXTTEST(2);
  ck_assert (*s == NULL);
}
END_TEST


Suite *pixbuf_suite(void)
{
  Suite *s = suite_create("MbUnicode");
  TCase *tc = tcase_create("Unicode");
  suite_add_tcase (s, tc);
  tcase_add_test(tc, next_ascii_char);
  tcase_add_test(tc, next_unicode_char);
  return s;
}

int main(void)
{
  int nf;
  Suite *s = pixbuf_suite();
  SRunner *sr = srunner_create(s);
  srunner_run_all(sr, CK_NORMAL);
  nf = srunner_ntests_failed(sr);
  srunner_free(sr);
  return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}