LCOV - code coverage report
Current view: top level - tests - tst_idna2.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 17 35 48.6 %
Date: 2015-03-02 11:46:03 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* tst_idna2.c --- Self tests for idna_to_ascii_8z().
       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 <idna.h>
      31             : 
      32             : #include "utils.h"
      33             : 
      34             : struct idna
      35             : {
      36             :   const char *in;
      37             :   const char *out;
      38             : };
      39             : 
      40             : static const struct idna idna[] = {
      41             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xc3\xad\x64\x6e", "example.xn--dn-mja"
      42             :    /* 1-1-1 Has an IDN in just the TLD */
      43             :    },
      44             :   {"\xc3\xab\x78\x2e\xc3\xad\x64\x6e", "xn--x-ega.xn--dn-mja"
      45             :    /* 1-1-2 Has an IDN in the TLD and SLD */
      46             :    },
      47             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xc3\xa5\xc3\xbe\xc3\xa7",
      48             :    "example.xn--5cae2e"
      49             :    /* 1-2-1 Latin-1 TLD */
      50             :    },
      51             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xc4\x83\x62\xc4\x89",
      52             :    "example.xn--b-rhat"
      53             :    /* 1-2-2 Latin Extended A TLD */
      54             :    },
      55             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xc8\xa7\xc6\x80\xc6\x88",
      56             :    "example.xn--lhaq98b"
      57             :    /* 1-2-3 Latin Extended B TLD */
      58             :    },
      59             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\xb8\x81\xe1\xb8\x83\xe1\xb8\x89",
      60             :    "example.xn--2fges"
      61             :    /* 1-2-4 Latin Extended Additional TLD */
      62             :    },
      63             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe4\xb8\xbf\xe4\xba\xba\xe5\xb0\xb8",
      64             :    "example.xn--xiqplj17a"
      65             :    /* 1-3-1 Han TLD */
      66             :    },
      67             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe3\x81\x8b\xe3\x81\x8c\xe3\x81\x8d",
      68             :    "example.xn--u8jcd"
      69             :    /* 1-3-2 Hiragana TLD */
      70             :    },
      71             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe3\x82\xab\xe3\x82\xac\xe3\x82\xad",
      72             :    "example.xn--lckcd"
      73             :    /* 1-3-3 Katakana TLD */
      74             :    },
      75             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\x84\x80\xe1\x85\xa1\xe1\x86\xa8",
      76             :    "example.xn--p39a"
      77             :    /* 1-3-4 Hangul Jamo TLD */
      78             :    /* Don't resolve as example.xn--ypd8qrh */
      79             :    },
      80             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xea\xb1\xa9\xeb\x93\x86\xec\x80\xba",
      81             :    "example.xn--o69aq2nl0j"
      82             :    /* 1-3-5 Hangul TLD */
      83             :    },
      84             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xea\x80\x8a\xea\x80\xa0\xea\x8a\xb8",
      85             :    "example.xn--6l7arby7j"
      86             :    /* 1-3-6 Yi TLD */
      87             :    },
      88             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xce\xb1\xce\xb2\xce\xb3",
      89             :    "example.xn--mxacd"
      90             :    /* 1-3-7 Greek TLD */
      91             :    },
      92             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\xbc\x82\xe1\xbc\xa6\xe1\xbd\x95",
      93             :    "example.xn--fng7dpg"
      94             :    /* 1-3-8 Greek Extended TLD */
      95             :    },
      96             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xd0\xb0\xd0\xb1\xd0\xb2",
      97             :    "example.xn--80acd"
      98             :    /* 1-3-9 Cyrillic TLD */
      99             :    },
     100             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xd5\xa1\xd5\xa2\xd5\xa3",
     101             :    "example.xn--y9acd"
     102             :    /* 1-3-10 Armeian TLD */
     103             :    },
     104             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\x83\x90\xe1\x83\x91\xe1\x83\x92",
     105             :    "example.xn--lodcd"
     106             :    /* 1-3-11 Georgian TLD */
     107             :    },
     108             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe2\x88\xa1\xe2\x86\xba\xe2\x8a\x82",
     109             :    "example.xn--b7gxomk"
     110             :    /* 1-4-1 Symbols TLD */
     111             :    },
     112             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xa4\x95\xe0\xa4\x96\xe0\xa4\x97",
     113             :    "example.xn--11bcd"
     114             :    /* 1-5-1 Devanagari TLD */
     115             :    },
     116             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xa6\x95\xe0\xa6\x96\xe0\xa6\x97",
     117             :    "example.xn--p5bcd"
     118             :    /* 1-5-2 Bengali TLD */
     119             :    },
     120             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xa8\x95\xe0\xa8\x96\xe0\xa8\x97",
     121             :    "example.xn--d9bcd"
     122             :    /* 1-5-3 Gurmukhi TLD */
     123             :    },
     124             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xaa\x95\xe0\xaa\x96\xe0\xaa\x97",
     125             :    "example.xn--0dccd"
     126             :    /* 1-5-4 Gujarati TLD */
     127             :    },
     128             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xac\x95\xe0\xac\x96\xe0\xac\x97",
     129             :    "example.xn--ohccd"
     130             :    /* 1-5-5 Oriya TLD */
     131             :    },
     132             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xae\x95\xe0\xae\x99\xe0\xae\x9a",
     133             :    "example.xn--clcid"
     134             :    /* 1-5-6 Tamil TLD */
     135             :    },
     136             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xb0\x95\xe0\xb0\x96\xe0\xb0\x97",
     137             :    "example.xn--zoccd"
     138             :    /* 1-5-7 Telugu TLD */
     139             :    },
     140             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xb2\x95\xe0\xb2\x96\xe0\xb2\x97",
     141             :    "example.xn--nsccd"
     142             :    /* 1-5-8 Kannada TLD */
     143             :    },
     144             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xb4\x95\xe0\xb4\x96\xe0\xb4\x97",
     145             :    "example.xn--bwccd"
     146             :    /* 1-5-9 Malayalam TLD */
     147             :    },
     148             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xb6\x9a\xe0\xb6\x9b\xe0\xb6\x9c",
     149             :    "example.xn--3zccd"
     150             :    /* 1-5-10 Sinhala TLD */
     151             :    },
     152             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xb8\x81\xe0\xb8\x82\xe0\xb8\x83",
     153             :    "example.xn--12ccd"
     154             :    /* 1-5-11 Thai TLD */
     155             :    },
     156             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xba\x81\xe0\xba\x82\xe0\xba\x84",
     157             :    "example.xn--p6ccg"
     158             :    /* 1-5-12 Lao TLD */
     159             :    },
     160             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe0\xbd\x80\xe0\xbd\x81\xe0\xbd\x82",
     161             :    "example.xn--5cdcd"
     162             :    /* 1-5-13 Tibetan TLD */
     163             :    },
     164             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\x80\x80\xe1\x80\x81\xe1\x80\x82",
     165             :    "example.xn--nidcd"
     166             :    /* 1-5-14 Myanmar TLD */
     167             :    },
     168             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\x9e\x80\xe1\x9e\x81\xe1\x9e\x82",
     169             :    "example.xn--i2ecd"
     170             :    /* 1-5-15 Khmer TLD */
     171             :    },
     172             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xe1\xa0\xa0\xe1\xa0\xa1\xe1\xa0\xa2",
     173             :    "example.xn--26ecd"
     174             :    /* 1-5-16 Mongolian TLD */
     175             :    },
     176             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xd8\xa7\xd8\xa8\xd8\xa9",
     177             :    "example.xn--mgbcd"
     178             :    /* 1-6-1 Arabic TLD */
     179             :    },
     180             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xd7\x90\xd7\x91\xd7\x92",
     181             :    "example.xn--4dbcd"
     182             :    /* 1-6-2 Hebrew TLD */
     183             :    },
     184             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xdc\x90\xdc\x91\xdc\x92",
     185             :    "example.xn--9mbcd"
     186             :    /* 1-6-3 Syriac TLD */
     187             :    },
     188             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\x61\x62\x63\xe3\x82\xab\xe3\x82\xac\xe3\x82\xad",
     189             :    "example.xn--abc-mj4bfg"
     190             :    /* 1-7-1 ASCII and non-Latin TLD */
     191             :    },
     192             :   {"\x65\x78\x61\x6d\x70\x6c\x65\x2e\xc3\xa5\xc3\xbe\xc3\xa7\xe3\x82\xab\xe3\x82\xac\xe3\x82\xad",
     193             :    "example.xn--5cae2e328wfag"
     194             :    /* 1-7-2 Latin (non-ASCII) and non-Latin TLD */
     195             :    },
     196             :   {"\xc3\xad\x21\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     197             :    /* 2-3-1-1 Includes ! before Nameprep */
     198             :    /* Don't resolve as xn--!dn-qma.example */
     199             :    },
     200             :   {"\xc3\xad\x24\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     201             :    /* 2-3-1-2 Includes $ before Nameprep */
     202             :    /* Don't resolve as xn--$dn-qma.example */
     203             :    },
     204             :   {"\xc3\xad\x2b\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     205             :    /* 2-3-1-3 Includes + before Nameprep */
     206             :    /* Don't resolve as xn--+dn-qma.example */
     207             :    },
     208             :   {"\x2d\xc3\xad\x31\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     209             :    /* 2-3-2-1 Leading hyphen before Nameprep */
     210             :    /* Don't resolve as xn---1dn-vpa.example */
     211             :    },
     212             :   {"\xc3\xad\x31\x64\x6e\x2d\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     213             :    /* 2-3-2-2 Trailing hyphen before Nameprep */
     214             :    /* Don't resolve as xn--1dn--upa.example */
     215             :    },
     216             :   {"\xc3\xad\xef\xbc\x8b\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     217             :    /* 2-3-3-1 Gets a + after Nameprep */
     218             :    /* Don't resolve as xn--dn-mja0331x.example */
     219             :    },
     220             :   {"\xc3\xad\xe2\x81\xbc\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     221             :    /* 2-3-3-2 Gets a = after Nameprep */
     222             :    /* Don't resolve as xn--dn-mja0343a.example */
     223             :    },
     224             :   {"\xef\xb9\xa3\xc3\xad\x32\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     225             :    /* 2-3-4-1 Leading hyphen after Nameprep */
     226             :    /* Don't resolve as xn--2dn-qma32863a.example */
     227             :    /* Don't resolve as xn---2dn-vpa.example */
     228             :    },
     229             :   {"\xc3\xad\x32\x64\x6e\xef\xbc\x8d\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     230             :    /* 2-3-4-2 Trailing hyphen after Nameprep */
     231             :    /* Don't resolve as xn--2dn-qma79363a.example */
     232             :    /* Don't resolve as xn--2dn--upa.example */
     233             :    },
     234             :   {"\xc2\xb9\x31\x2e\x65\x78\x61\x6d\x70\x6c\x65", "11.example"
     235             :    /* 2-4-1 All-ASCII check, Latin */
     236             :    },
     237             :   {"\xe2\x85\xa5\x76\x69\x2e\x65\x78\x61\x6d\x70\x6c\x65", "vivi.example"
     238             :    /* 2-4-2 All-ASCII check, symbol */
     239             :    },
     240             :   {"\xc3\x9f\x73\x73\x2e\x65\x78\x61\x6d\x70\x6c\x65", "ssss.example"
     241             :    /* 2-4-3 All-ASCII check, sharp S */
     242             :    },
     243             :   {"\x78\x6e\x2d\x2d\xc3\xaf\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     244             :    /* 2-5-1 ACE prefix before Nameprep, body */
     245             :    /* Don't resolve as xn--xn--dn-sja.example */
     246             :    /* Don't resolve as xn--dn-sja.example */
     247             :    },
     248             :   {"\xe2\x85\xb9\x6e\x2d\x2d\xc3\xa4\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     249             :    ""
     250             :    /* 2-5-2 ACE prefix before Nameprep, prefix */
     251             :    /* Don't resolve as xn--xn--dn-uia.example */
     252             :    /* Don't resolve as xn--dn-uia.example */
     253             :    },
     254             :   {"", ""
     255             :    /* 2-8-1 Zero-length label after Nameprep */
     256             :    /* Don't resolve as xn--kba.example */
     257             :    /* Don't resolve as xn--.example */
     258             :    },
     259             :   {"\x33\x30\x30\x32\x2d\x74\x65\x73\x74\xe3\x80\x82\xc3\xad\x64\x6e",
     260             :    "3002-test.xn--dn-mja"
     261             :    /* 2-9-1 U+3002 acts as a label separator */
     262             :    /* Don't resolve as xn--3002-testdn-wcb2087m.example */
     263             :    },
     264             :   {"\x66\x66\x30\x65\x2d\x74\x65\x73\x74\xef\xbc\x8e\xc3\xad\x64\x6e",
     265             :    "ff0e-test.xn--dn-mja"
     266             :    /* 2-9-2 U+FF0E acts as a label separator */
     267             :    /* Don't resolve as xn--ff0e-testdn-wcb45865f.example */
     268             :    },
     269             :   {"\x66\x66\x36\x31\x2d\x74\x65\x73\x74\xef\xbd\xa1\xc3\xad\x64\x6e",
     270             :    "ff61-test.xn--dn-mja"
     271             :    /* 2-9-3 U+FF61 acts as a label separator */
     272             :    /* Don't resolve as xn--ff61-testdn-wcb33975f.example */
     273             :    },
     274             :   {"\x30\x30\x61\x64\x6f\x75\x74\xc2\xad\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     275             :    "xn--00adoutdn-m5a.example"
     276             :    /* 4-1-1-1 00adout<00AD><00ED>dn.example -> 00adout<00ED>dn.example */
     277             :    /* Don't resolve as xn--00adoutdn-cna81e.example */
     278             :    },
     279             :   {"\x32\x30\x30\x64\x6f\x75\x74\xe2\x80\x8d\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     280             :    "xn--200doutdn-m5a.example"
     281             :    /* 4-1-1-2 200dout<200D><00ED>dn.example -> 200dout<00ED>dn.example */
     282             :    /* Don't resolve as xn--200doutdn-m5a1678f.example */
     283             :    },
     284             :   {"\x73\x69\x6d\x70\x6c\x65\x63\x61\x70\x44\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     285             :    "xn--simplecapddn-1fb.example"
     286             :    /* 4-1-2-1 simplecap<0044><00ED>dn.example -> simplecap<0064><00ED>dn.example */
     287             :    },
     288             :   {"\x6c\x61\x74\x69\x6e\x74\x6f\x67\x72\x65\x65\x6b\xc2\xb5\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     289             :    "xn--latintogreekdn-cmb716i.example"
     290             :    /* 4-1-2-2 latintogreek<00B5><00ED>dn.example -> latintogreek<03BC><00ED>dn.example */
     291             :    /* Don't resolve as xn--latintogreekdn-cxa01g.example */
     292             :    },
     293             :   {"\x6c\x61\x74\x69\x6e\x65\x78\x74\xc3\x87\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     294             :    "xn--latinextdn-v6a6e.example"
     295             :    /* 4-1-2-3 latinext<00C7><00ED>dn.example -> latinext<00E7><00ED>dn.example */
     296             :    /* Don't resolve as xn--latinextdn-twa07b.example */
     297             :    },
     298             :   {"\x73\x68\x61\x72\x70\x73\xc3\x9f\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     299             :    "xn--sharpsssdn-r8a.example"
     300             :    /* 4-1-2-4 sharps<00DF><00ED>dn.example -> sharpsss<00ED>dn.example */
     301             :    /* Don't resolve as xn--sharpsdn-vya4l.example */
     302             :    },
     303             :   {"\x74\x75\x72\x6b\x69\x73\x68\x69\xc4\xb0\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     304             :    "xn--turkishiidn-wcb701e.example"
     305             :    /* 4-1-2-5 turkishi<0130><00ED>dn.example -> turkishi<0069><0307><00ED>dn.example */
     306             :    /* Don't resolve as xn--turkishidn-r8a71f.example */
     307             :    },
     308             :   {"\x65\x78\x70\x74\x77\x6f\xc5\x89\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     309             :    "xn--exptwondn-m5a502c.example"
     310             :    /* 4-1-2-6 exptwo<0149><00ED>dn.example -> exptwo<02BC><006E><00ED>dn.example */
     311             :    /* Don't resolve as xn--exptwodn-h2a33g.example */
     312             :    },
     313             :   {"\x61\x64\x64\x66\x6f\x6c\x64\xcf\x92\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     314             :    "xn--addfolddn-m5a121f.example"
     315             :    /* 4-1-2-7 addfold<03D2><00ED>dn.example -> addfold<03C5><00ED>dn.example */
     316             :    /* Don't resolve as xn--addfolddn-m5a462f.example */
     317             :    },
     318             :   {"\x65\x78\x70\x74\x68\x72\x65\x65\xe1\xbd\x92\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     319             :    "xn--expthreedn-r8a5844g.example"
     320             :    /* 4-1-2-8 expthree<1F52><00ED>dn.example -> expthree<03C5><0313><0300><00ED>dn.example */
     321             :    },
     322             :   {"\x6e\x6f\x6e\x62\x6d\x70\xf0\x90\x90\x80\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     323             :    "xn--nonbmpdn-h2a34747d.example"
     324             :    /* 4-1-2-9 nonbmp<10400><00ED>dn.example -> nonbmp<10428><00ED>dn.example */
     325             :    /* Don't resolve as xn--nonbmpdn-h2a37046d.example */
     326             :    },
     327             :   {"\x6e\x6f\x6e\x62\x6d\x70\x74\x6f\x61\x73\x63\x69\x69\xf0\x9d\x90\x80\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     328             :    "xn--nonbmptoasciiadn-msb.example"
     329             :    /* 4-1-2-10 nonbmptoascii<1D400><00ED>dn.example -> nonbmptoasciia<00ED>dn.example */
     330             :    /* Don't resolve as xn--nonbmptoasciidn-hpb54112i.example */
     331             :    },
     332             :   {"\x72\x65\x67\x63\x6f\x6d\x62\x65\xcc\x81\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     333             :    "xn--regcombdn-h4a8b.example"
     334             :    /* 4-2-1-1 regcomb<0065><0301><00ED>dn.example -> regcomb<00E9><00ED>dn.example */
     335             :    /* Don't resolve as xn--regcombedn-r8a794d.example */
     336             :    },
     337             :   {"\x63\x6f\x6d\x62\x61\x6e\x64\x63\x61\x73\x65\x45\xcc\x81\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     338             :    "xn--combandcasedn-lhb4d.example"
     339             :    /* 4-2-1-2 combandcase<0045><0301><00ED>dn.example -> combandcase<00E9><00ED>dn.example */
     340             :    /* Don't resolve as xn--combandcaseedn-cmb526f.example */
     341             :    },
     342             :   {"\x61\x64\x6a\x63\x6f\x6d\x62\xc2\xba\xcc\x81\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     343             :    "xn--adjcombdn-m5a9d.example"
     344             :    /* 4-2-1-3 adjcomb<00BA><0301><00ED>dn.example -> adjcomb<00F3><00ED>dn.example */
     345             :    /* Don't resolve as xn--adjcombdn-1qa57cp3r.example */
     346             :    },
     347             :   {"\x65\x78\x74\x63\x6f\x6d\x62\x6f\x63\xcc\x81\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     348             :    "xn--extcombodn-r8a52a.example"
     349             :    /* 4-2-1-4 extcombo<0063><0301><00ED>dn.example -> extcombo<0107><00ED>dn.example */
     350             :    /* Don't resolve as xn--extcombocdn-wcb920e.example */
     351             :    },
     352             :   {"\x64\x6f\x75\x62\x6c\x65\x64\x69\x61\x63\x31\x75\xcc\x88\xcc\x81\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     353             :    "xn--doublediac1dn-6ib836a.example"
     354             :    /* 4-2-1-5 doublediac1<0075><0308><0301><00ED>dn.example -> doublediac2<01D8><00ED>dn.example */
     355             :    /* Don't resolve as xn--doublediac1udn-cmb526fnd.example */
     356             :    },
     357             :   {"\x64\x6f\x75\x62\x6c\x65\x64\x69\x61\x63\x32\x75\xcc\x81\xcc\x88\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     358             :    "xn--doublediac2dn-6ib8qs73a.example"
     359             :    /* 4-2-1-6 doublediac2<0075><0301><0308><00ED>dn.example -> doublediac2<01D8><00ED>dn.example */
     360             :    /* Don't resolve as xn--doublediac2udn-cmb526fod.example */
     361             :    },
     362             :   {"\x6e\x65\x77\x6e\x6f\x72\x6d\xf0\xaf\xa1\xb4\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     363             :    "xn--newnormdn-m5a7856x.example"
     364             :    /* 4-2-2-1 newnorm<2F874><00ED>dn.example -> newnorm<5F33><00ED>dn.example should not become <5F53> */
     365             :    /* Don't resolve as xn--newnormdn-m5a9396x.example */
     366             :    /* Don't resolve as xn--newnormdn-m5a9968x.example */
     367             :    },
     368             :   {"\xe2\x80\x80\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     369             :    /* 4-3-1 Spacing */
     370             :    /* Don't resolve as xn--dn-mja3392a.example */
     371             :    },
     372             :   {"\xdb\x9d\xc3\xad\x64\x6e\x2d\x32\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     373             :    /* 4-3-2 Control */
     374             :    /* Don't resolve as xn--dn-2-upa332g.example */
     375             :    },
     376             :   {"\xee\x80\x85\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     377             :    /* 4-3-3 Private use */
     378             :    /* Don't resolve as xn--dn-mja1659t.example */
     379             :    },
     380             :   {"\xf3\xb0\x80\x85\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     381             :    /* 4-3-4 Private use, non-BMP */
     382             :    /* Don't resolve as xn--dn-mja7922x.example */
     383             :    },
     384             :   {"\xef\xb7\x9d\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     385             :    /* 4-3-5 Non-character */
     386             :    /* Don't resolve as xn--dn-mja1210x.example */
     387             :    },
     388             :   {"\xf0\x9f\xbf\xbe\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     389             :    /* 4-3-6 Non-character, non-BMP */
     390             :    /* Don't resolve as xn--dn-mja7922x.example */
     391             :    },
     392             :   {"\xef\xbf\xbd\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     393             :    /* 4-3-7 Surrogate points */
     394             :    /* Don't resolve as xn--dn-mja7922x.example */
     395             :    },
     396             :   {"\xef\xbf\xba\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     397             :    /* 4-3-8 Inappropriate for plain */
     398             :    /* Don't resolve as xn--dn-mja5822x.example */
     399             :    },
     400             :   {"\xe2\xbf\xb5\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     401             :    /* 4-3-9 Inappropriate for canonical */
     402             :    /* Don't resolve as xn--dn-mja3729b.example */
     403             :    },
     404             :   {"\xe2\x81\xaa\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     405             :    /* 4-3-10 Change display simple */
     406             :    /* Don't resolve as xn--dn-mja7533a.example */
     407             :    },
     408             :   {"\xe2\x80\x8f\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     409             :    /* 4-3-11 Change display RTL */
     410             :    /* Don't resolve as xn--dn-mja3992a.example */
     411             :    },
     412             :   {"\xf3\xa0\x80\x81\xf3\xa0\x81\x85\xf3\xa0\x81\x8e\x68\x69\x69\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     413             :    ""
     414             :    /* 4-3-12 Language tags */
     415             :    /* Don't resolve as xn--hiidn-km43aaa.example */
     416             :    },
     417             :   {"\xd8\xa8\x6f\xd8\xb8\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     418             :    /* 4-4-1 Arabic RandALCat-LCat-RandALCat */
     419             :    /* Don't resolve as xn--o-0mc3c.example */
     420             :    },
     421             :   {"\xd8\xa8\xd8\xb8\x6f\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     422             :    /* 4-4-2 Arabic RandALCat-RandALCat-other */
     423             :    /* Don't resolve as xn--o-0mc2c.example */
     424             :    },
     425             :   {"\x6f\xd8\xa8\xd8\xb8\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     426             :    /* 4-4-3 Arabic other-RandALCat-RandALCat */
     427             :    /* Don't resolve as xn--o-1mc2c.example */
     428             :    },
     429             :   {"\xd7\x91\x6f\xd7\xa1\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     430             :    /* 4-4-4 Hebrew RandALCat-LCat-RandALCat */
     431             :    /* Don't resolve as xn--o-1hc3c.example */
     432             :    },
     433             :   {"\xd7\x91\xd7\xa1\x6f\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     434             :    /* 4-4-5 Hebrew RandALCat-RandALCat-other */
     435             :    /* Don't resolve as xn--o-1hc2c.example */
     436             :    },
     437             :   {"\x6f\xd7\x91\xd7\xa1\x2e\x65\x78\x61\x6d\x70\x6c\x65", ""
     438             :    /* 4-4-6 Hebrew other-RandALCat-RandALCat */
     439             :    /* Don't resolve as xn--o-2hc2c.example */
     440             :    },
     441             :   {"\xc8\xb7\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     442             :    "xn--dn-mja33k.example"
     443             :    /* 5-1-1 Unassigned in BMP; zone editors should reject */
     444             :    },
     445             :   {"\xf0\x90\x88\x85\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     446             :    "xn--dn-mja7734x.example"
     447             :    /* 5-1-2 Unassinged outside BMP; zone editors should reject */
     448             :    /* Don't resolve as xn--dn-mja7922x.example */
     449             :    },
     450             :   {"\xc8\xb4\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     451             :    "xn--dn-mja12k.example"
     452             :    /* 5-2-1 Newly assigned in BMP; zone editors should reject */
     453             :    },
     454             :   {"\xf0\x90\x80\x85\xc3\xad\x64\x6e\x2e\x65\x78\x61\x6d\x70\x6c\x65",
     455             :    "xn--dn-mja9232x.example"
     456             :    /* 5-2-2 Newly assigned outside of BMP; zone editors should reject */
     457             :    /* Don't resolve as xn--dn-mja7922x.example */
     458             :    }
     459             : };
     460             : 
     461             : void
     462           1 : doit (void)
     463             : {
     464             :   size_t i;
     465             :   char *out;
     466             :   int rc;
     467             : 
     468          99 :   for (i = 0; i < sizeof (idna) / sizeof (idna[0]); i++)
     469             :     {
     470          98 :       if (debug)
     471           0 :         printf ("IDNA2 entry %ld\n", i);
     472             : 
     473          98 :       if (debug)
     474             :         {
     475             :           uint32_t *p;
     476             :           size_t len;
     477           0 :           printf ("in: %s\n", idna[i].in);
     478           0 :           hexprint (idna[i].in, strlen (idna[i].in));
     479           0 :           escapeprint (idna[i].in, strlen (idna[i].in));
     480           0 :           p = stringprep_utf8_to_ucs4 (idna[i].in, -1, &len);
     481           0 :           ucs4print (p, len);
     482           0 :           free (p);
     483             :         }
     484             : 
     485          98 :       rc = idna_to_ascii_8z (idna[i].in, &out,
     486             :                              IDNA_ALLOW_UNASSIGNED |
     487             :                              IDNA_USE_STD3_ASCII_RULES);
     488          98 :       if (rc != IDNA_SUCCESS && strlen (idna[i].out) > 0)
     489             :         {
     490           0 :           fail ("IDNA2 entry %ld failed: %d\n", i, rc);
     491           0 :           continue;
     492             :         }
     493             : 
     494          98 :       if (debug && rc == IDNA_SUCCESS)
     495             :         {
     496           0 :           printf ("computed out: %s\n", out);
     497           0 :           printf ("expected out: %s\n", idna[i].out);
     498             :         }
     499          98 :       else if (debug)
     500           0 :         printf ("returned %d\n", rc);
     501             : 
     502          98 :       if (rc == IDNA_SUCCESS)
     503             :         {
     504         138 :           if (strlen (idna[i].out) != strlen (out) ||
     505          69 :               strcasecmp (idna[i].out, out) != 0)
     506             :             {
     507           0 :               fail ("IDNA2 entry %ld failed\n", i);
     508           0 :               if (debug)
     509           0 :                 printf ("ERROR\n");
     510             :             }
     511          69 :           else if (debug)
     512           0 :             printf ("OK\n");
     513             : 
     514          69 :           free (out);
     515          69 :           out = NULL;
     516             :         }
     517          29 :       else if (rc != IDNA_SUCCESS && strlen (idna[i].out) == 0 && debug)
     518           0 :         printf ("OK (fail)\n");
     519          29 :       else if (debug)
     520           0 :         printf ("OK\n");
     521             :     }
     522           1 : }

Generated by: LCOV version 1.11