LCOV - code coverage report
Current view: top level - tests - tst_nfkc.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 12 35 34.3 %
Date: 2015-07-08 23:12:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* tst_nfkc.c --- Self tests for stringprep_utf8_nfkc_normalize().
       2             :  * Copyright (C) 2002-2015 Simon Josefsson
       3             :  *
       4             :  * This file is part of GNU Libidn.
       5             :  *
       6             :  * This program is free software: you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  *
      19             :  */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : # include "config.h"
      23             : #endif
      24             : 
      25             : #include <stdio.h>
      26             : #include <stdlib.h>
      27             : #include <stdarg.h>
      28             : #include <string.h>
      29             : 
      30             : #include <stringprep.h>
      31             : 
      32             : #include "utils.h"
      33             : 
      34             : struct nfkc
      35             : {
      36             :   const char *in;
      37             :   const char *out;
      38             : };
      39             : 
      40             : static struct nfkc nfkc[] = {
      41             :   {"\xC2\xB5", "\xCE\xBC"},
      42             :   {"\xC2\xAA", "\x61"},
      43             :   /* From <http://www.unicode.org/review/pr-29.html>. Note that we
      44             :    * compute the output according to Unicode 3.2 without the proposed
      45             :    * update.
      46             :    *
      47             :    *   1.
      48             :    *
      49             :    *   U+1100 (ᄀ) HANGUL CHOSEONG KIYEOK +
      50             :    *   U+0300 (◌̀) COMBINING GRAVE ACCENT +
      51             :    *   U+1161 (ᅡ) HANGUL JUNGSEONG A
      52             :    *
      53             :    *   According to the old language, the NFC form of this would be B:
      54             :    *
      55             :    *   2.
      56             :    *
      57             :    *   U+AC00 (가) HANGUL SYLLABLE GA +
      58             :    *   U+0300 (◌̀) COMBINING GRAVE ACCENT
      59             :    */
      60             :   {"\xE1\x84\x80\xCC\x80\xE1\x85\xA1", "\xEA\xB0\x80\xCC\x80"},
      61             :   /* Second test case from page.  Again, we do not implement the
      62             :    * updated proposal.  <U+0B47; U+0300; U+0B3E> -> U+0B4B U+0300
      63             :    */
      64             :   {"\xE0\xAD\x87\xCC\x80\xE0\xAC\xBE", "\xE0\xAD\x8b\xCC\x80"}
      65             : };
      66             : 
      67             : void
      68           1 : doit (void)
      69             : {
      70             :   char *out;
      71             :   size_t i;
      72             : 
      73           5 :   for (i = 0; i < sizeof (nfkc) / sizeof (nfkc[0]); i++)
      74             :     {
      75           4 :       if (debug)
      76           0 :         printf ("NFKC entry %ld\n", i);
      77             : 
      78           4 :       out = stringprep_utf8_nfkc_normalize (nfkc[i].in,
      79           4 :                                             (ssize_t) strlen (nfkc[i].in));
      80           4 :       if (out == NULL)
      81             :         {
      82           0 :           fail ("NFKC entry %ld failed fatally\n", i);
      83           0 :           continue;
      84             :         }
      85             : 
      86           4 :       if (debug)
      87             :         {
      88             :           uint32_t *t;
      89             :           size_t len;
      90             : 
      91           0 :           printf ("in:\n");
      92           0 :           escapeprint (nfkc[i].in, strlen (nfkc[i].in));
      93           0 :           hexprint (nfkc[i].in, strlen (nfkc[i].in));
      94           0 :           binprint (nfkc[i].in, strlen (nfkc[i].in));
      95             : 
      96             : 
      97           0 :           printf ("out:\n");
      98           0 :           escapeprint (out, strlen (out));
      99           0 :           hexprint (out, strlen (out));
     100           0 :           binprint (out, strlen (out));
     101           0 :           t = stringprep_utf8_to_ucs4 (out, -1, &len);
     102           0 :           if (t)
     103             :             {
     104           0 :               ucs4print (t, len);
     105           0 :               free (t);
     106             :             }
     107             : 
     108           0 :           printf ("expected out:\n");
     109           0 :           escapeprint (nfkc[i].out, strlen (nfkc[i].out));
     110           0 :           hexprint (nfkc[i].out, strlen (nfkc[i].out));
     111           0 :           binprint (nfkc[i].out, strlen (nfkc[i].out));
     112             :         }
     113             : 
     114           8 :       if (strlen (nfkc[i].out) != strlen (out) ||
     115           4 :           memcmp (nfkc[i].out, out, strlen (out)) != 0)
     116             :         {
     117           0 :           fail ("NFKC entry %ld failed\n", i);
     118           0 :           if (debug)
     119           0 :             printf ("ERROR\n");
     120             :         }
     121           4 :       else if (debug)
     122           0 :         printf ("OK\n");
     123             : 
     124           4 :       free (out);
     125             :     }
     126           1 : }

Generated by: LCOV version 1.11