LCOV - GNU Libidn - tests/tst_idna3.c

LCOV - code coverage report
Current view: top level - tests - tst_idna3.c (source / functions) Hit Total Coverage
Test: GNU Libidn Lines: 11 17 64.7 %
Date: 2020年07月22日 17:53:13 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

 Line data Source code
 1  : /* tst_idna3.c --- Self tests for upper-case XN-- regression.
 2  : * Copyright (C) 2011-2020 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  : #include <idn-free.h>
 32  : 
 33  : #include "utils.h"
 34  : 
 35  : struct idna
 36  : {
 37  : const char *in;
 38  : const char *out;
 39  : };
 40  : 
 41  : static const struct idna idna[] = {
 42  : /* Test vectors from http://bugs.debian.org/610617 */
 43  : {"XN----7SBAABF4DLDYSIEHP4NTB.XN--P1AI",
 44  : "\xd1\x81\xd0\xb0\xd0\xbc\xd0\xb0\xd1\x80\xd1\x81\xd0\xba\xd0\xb0\xd1"
 45  : "\x8f\x2d\xd0\xbe\xd0\xb1\xd0\xbb\xd0\xb0\xd1\x81\xd1\x82\xd1\x8c\x2e"
 46  : "\xd1\x80\xd1\x84"},
 47  : {"xn----7SBAABF4DLDYSIEHP4NTB.XN--P1AI",
 48  : "\xd1\x81\xd0\xb0\xd0\xbc\xd0\xb0\xd1\x80\xd1\x81\xd0\xba\xd0\xb0\xd1"
 49  : "\x8f\x2d\xd0\xbe\xd0\xb1\xd0\xbb\xd0\xb0\xd1\x81\xd1\x82\xd1\x8c\x2e"
 50  : "\xd1\x80\xd1\x84"},
 51  : {"xn----7SBAABF4DLDYSIEHP4NTB.xn--P1AI",
 52  : "\xd1\x81\xd0\xb0\xd0\xbc\xd0\xb0\xd1\x80\xd1\x81\xd0\xba\xd0\xb0\xd1"
 53  : "\x8f\x2d\xd0\xbe\xd0\xb1\xd0\xbb\xd0\xb0\xd1\x81\xd1\x82\xd1\x8c\x2e"
 54  : "\xd1\x80\xd1\x84"}
 55  : };
 56  : 
 57  : void
 58  1 : doit (void)
 59  : {
 60  : int rc;
 61  1 : char *out = NULL;
 62  : unsigned i;
 63  : 
 64  4 : for (i = 0; i < sizeof (idna) / sizeof (idna[0]); i++)
 65  : {
 66  3 : rc = idna_to_unicode_8z8z (idna[i].in, &out, 0);
 67  3 : if (rc != IDNA_SUCCESS)
 68  0 : fail ("IDNA3[%u] failed %d\n", i, rc);
 69  : 
 70  3 : if (debug && rc == IDNA_SUCCESS)
 71  : {
 72  0 : printf ("input: %s\n", idna[i].in);
 73  0 : printf ("computed out: %s\n", out);
 74  0 : printf ("expected out: %s\n", idna[i].out);
 75  : }
 76  : 
 77  3 : if (strcmp (out, idna[i].out) != 0)
 78  0 : fail ("IDNA3[%u] failed\n", i);
 79  3 : else if (debug)
 80  0 : printf ("IDNA3[%u] success\n", i);
 81  : 
 82  3 : if (out)
 83  3 : idn_free (out);
 84  : }
 85  1 : }

Generated by: LCOV version 1.13

AltStyle によって変換されたページ (->オリジナル) /