This source file includes following definitions.
- test_u8_grapheme_next
 
- main
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 #include <config.h>
  20 
  21 
  22 #include <unigbrk.h>
  23 
  24 #include <stdio.h>
  25 #include <stdlib.h>
  26 
  27 #include "macros.h"
  28 
  29 static void
  30 test_u8_grapheme_next (const char *input, size_t n, size_t len)
     
  31 {
  32   const uint8_t *s = (const uint8_t *) input;
  33   const uint8_t *next = u8_grapheme_next (s, s + n);
  34   if (next != s + len)
  35     {
  36       size_t i;
  37 
  38       if (next == NULL)
  39         fputs ("u8_grapheme_next returned NULL", stderr);
  40       else
  41         fprintf (stderr, "u8_grapheme_next skipped %zu bytes", next - s);
  42       fprintf (stderr, ", expected %zu:\n", len);
  43       for (i = 0; i < n; i++)
  44         fprintf (stderr, " %02x", s[i]);
  45       putc ('\n', stderr);
  46       abort ();
  47     }
  48 }
  49 
  50 int
  51 main (void)
     
  52 {
  53   static const uint8_t s[] = "abc";
  54 
  55   
  56   ASSERT (u8_grapheme_next (NULL, NULL) == NULL);
  57   ASSERT (u8_grapheme_next (s, s) == NULL);
  58 
  59   
  60   test_u8_grapheme_next ("a", 1, 1);
  61   test_u8_grapheme_next ("ab", 2, 1);
  62   test_u8_grapheme_next ("abc", 3, 1);
  63 
  64   
  65 #define HIRAGANA_A "\343\201\202" 
  66   test_u8_grapheme_next (HIRAGANA_A, 3, 3);
  67   test_u8_grapheme_next (HIRAGANA_A"x", 4, 3);
  68   test_u8_grapheme_next (HIRAGANA_A HIRAGANA_A, 6, 3);
  69 
  70   
  71 #define GRAVE "\314\200"        
  72 #define ACUTE "\314\201"        
  73   test_u8_grapheme_next ("e"ACUTE, 3, 3);
  74   test_u8_grapheme_next ("e"ACUTE GRAVE, 5, 5);
  75   test_u8_grapheme_next ("e"ACUTE"x", 4, 3);
  76   test_u8_grapheme_next ("e"ACUTE "e"ACUTE, 6, 3);
  77 
  78   return 0;
  79 }