root/maint/gnulib/tests/unistr/test-u8-strmblen.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Test of u8_strmblen() function.
   2    Copyright (C) 2010-2021 Free Software Foundation, Inc.
   3 
   4    This program is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU General Public License as published by
   6    the Free Software Foundation; either version 3 of the License, or
   7    (at your option) any later version.
   8 
   9    This program is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU General Public License for more details.
  13 
  14    You should have received a copy of the GNU General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
  18 
  19 #include <config.h>
  20 
  21 #include "unistr.h"
  22 
  23 #include "macros.h"
  24 
  25 int
  26 main ()
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28   int ret;
  29 
  30   /* Test NUL unit input.  */
  31   {
  32     static const uint8_t input[] = "";
  33     ret = u8_strmblen (input);
  34     ASSERT (ret == 0);
  35   }
  36 
  37   /* Test ISO 646 unit input.  */
  38   {
  39     ucs4_t c;
  40     uint8_t buf[2];
  41 
  42     for (c = 1; c < 0x80; c++)
  43       {
  44         buf[0] = c;
  45         buf[1] = 0;
  46         ret = u8_strmblen (buf);
  47         ASSERT (ret == 1);
  48       }
  49   }
  50 
  51   /* Test 2-byte character input.  */
  52   {
  53     static const uint8_t input[] = { 0xC3, 0x97, 0 };
  54     ret = u8_strmblen (input);
  55     ASSERT (ret == 2);
  56   }
  57 
  58   /* Test 3-byte character input.  */
  59   {
  60     static const uint8_t input[] = { 0xE2, 0x82, 0xAC, 0 };
  61     ret = u8_strmblen (input);
  62     ASSERT (ret == 3);
  63   }
  64 
  65   /* Test 4-byte character input.  */
  66   {
  67     static const uint8_t input[] = { 0xF4, 0x8F, 0xBF, 0xBD, 0 };
  68     ret = u8_strmblen (input);
  69     ASSERT (ret == 4);
  70   }
  71 
  72   /* Test incomplete/invalid 1-byte input.  */
  73   {
  74     static const uint8_t input[] = { 0xC1, 0 };
  75     ret = u8_strmblen (input);
  76     ASSERT (ret == -1);
  77   }
  78   {
  79     static const uint8_t input[] = { 0xC3, 0 };
  80     ret = u8_strmblen (input);
  81     ASSERT (ret == -1);
  82   }
  83   {
  84     static const uint8_t input[] = { 0xE2, 0 };
  85     ret = u8_strmblen (input);
  86     ASSERT (ret == -1);
  87   }
  88   {
  89     static const uint8_t input[] = { 0xF4, 0 };
  90     ret = u8_strmblen (input);
  91     ASSERT (ret == -1);
  92   }
  93   {
  94     static const uint8_t input[] = { 0xFE, 0 };
  95     ret = u8_strmblen (input);
  96     ASSERT (ret == -1);
  97   }
  98 
  99   /* Test incomplete/invalid 2-byte input.  */
 100   {
 101     static const uint8_t input[] = { 0xE0, 0x9F, 0 };
 102     ret = u8_strmblen (input);
 103     ASSERT (ret == -1);
 104   }
 105   {
 106     static const uint8_t input[] = { 0xE2, 0x82, 0 };
 107     ret = u8_strmblen (input);
 108     ASSERT (ret == -1);
 109   }
 110   {
 111     static const uint8_t input[] = { 0xE2, 0xD0, 0 };
 112     ret = u8_strmblen (input);
 113     ASSERT (ret == -1);
 114   }
 115   {
 116     static const uint8_t input[] = { 0xF0, 0x8F, 0 };
 117     ret = u8_strmblen (input);
 118     ASSERT (ret == -1);
 119   }
 120   {
 121     static const uint8_t input[] = { 0xF3, 0x8F, 0 };
 122     ret = u8_strmblen (input);
 123     ASSERT (ret == -1);
 124   }
 125   {
 126     static const uint8_t input[] = { 0xF3, 0xD0, 0 };
 127     ret = u8_strmblen (input);
 128     ASSERT (ret == -1);
 129   }
 130 
 131   /* Test incomplete/invalid 3-byte input.  */
 132   {
 133     static const uint8_t input[] = { 0xF3, 0x8F, 0xBF, 0 };
 134     ret = u8_strmblen (input);
 135     ASSERT (ret == -1);
 136   }
 137   {
 138     static const uint8_t input[] = { 0xF3, 0xD0, 0xBF, 0 };
 139     ret = u8_strmblen (input);
 140     ASSERT (ret == -1);
 141   }
 142   {
 143     static const uint8_t input[] = { 0xF3, 0x8F, 0xD0, 0 };
 144     ret = u8_strmblen (input);
 145     ASSERT (ret == -1);
 146   }
 147 
 148   return 0;
 149 }

/* [previous][next][first][last][top][bottom][index][help] */