LCOV - code coverage report
Current view: top level - tests - tld_test_full_uri.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 49.0 % 51 25
Test Date: 2025-07-17 21:03:15 Functions: 100.0 % 3 3
Legend: Lines: hit not hit

            Line data    Source code
       1              : /* TLD library -- test the TLD interface
       2              :  * Copyright (c) 2011-2023  Made to Order Software Corp.  All Rights Reserved
       3              :  *
       4              :  * Permission is hereby granted, free of charge, to any person obtaining a
       5              :  * copy of this software and associated documentation files (the
       6              :  * "Software"), to deal in the Software without restriction, including
       7              :  * without limitation the rights to use, copy, modify, merge, publish,
       8              :  * distribute, sublicense, and/or sell copies of the Software, and to
       9              :  * permit persons to whom the Software is furnished to do so, subject to
      10              :  * the following conditions:
      11              :  *
      12              :  * The above copyright notice and this permission notice shall be included
      13              :  * in all copies or substantial portions of the Software.
      14              :  *
      15              :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      16              :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      17              :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      18              :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      19              :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      20              :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      21              :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      22              :  */
      23              : 
      24              : /** \file
      25              :  * \brief Test a full URI with tld_check_uri() function.
      26              :  *
      27              :  * This file implements various tests to verify that the
      28              :  * tld_check_uri() function works as expected.
      29              :  */
      30              : 
      31              : // libtld
      32              : //
      33              : #include    <libtld/tld.h>
      34              : #include    <libtld/tld_data.h>
      35              : #include    <libtld/tld_file.h>
      36              : 
      37              : 
      38              : // C
      39              : //
      40              : #include    <string.h>
      41              : #include    <stdlib.h>
      42              : #include    <stdio.h>
      43              : #include    <limits.h>
      44              : 
      45              : 
      46              : 
      47              : 
      48              : int err_count = 0;
      49              : int verbose = 0;
      50              : 
      51              : 
      52              : 
      53              : char *              g_filename1 = "../../BUILD/Debug/contrib/libtld/libtld/tlds.tld";
      54              : char *              g_filename2 = "../libtld/tlds.tld";
      55              : struct tld_file *   g_tld_file = NULL;
      56              : 
      57              : 
      58              : /* we get access to the table with all the TLDs so we can go through them all
      59              :  * the library does not give direct access by default... (although maybe we
      60              :  * could give users access to the data)
      61              :  */
      62            1 : void load_tlds()
      63              : {
      64              :     enum tld_file_error err;
      65              : 
      66            1 :     err = tld_file_load(g_filename1, &g_tld_file);
      67            1 :     if(err == TLD_FILE_ERROR_NONE)
      68              :     {
      69            1 :         return;
      70              :     }
      71              : 
      72            0 :     err = tld_file_load(g_filename2, &g_tld_file);
      73            0 :     if(err == TLD_FILE_ERROR_NONE)
      74              :     {
      75            0 :         return;
      76              :     }
      77              : 
      78            0 :     fprintf(stderr, "fatal error: could not read TLD files \"%s\" or \"%s\".\n",
      79              :                         g_filename1, g_filename2);
      80            0 :     exit(1);
      81              : }
      82              : 
      83              : 
      84              : 
      85              : 
      86              : 
      87              : /// \brief Structure used to define many tests to run against the tld_check_uri() function
      88              : struct test_info
      89              : {
      90              :     /// The URI to be tested
      91              :     const char *        f_uri;
      92              :     /// The valid protocols for that test
      93              :     const char *        f_protocols;
      94              :     /// Flags used to call the tld_check_uri() function
      95              :     int                 f_flags;
      96              :     /// The expected result
      97              :     enum tld_result     f_result;
      98              :     /// The expected info values
      99              :     struct tld_info     f_info;
     100              : };
     101              : 
     102              : /* WARNING: the first and last protocols need to be tested for full
     103              :  *          validity of the library; if you add more, add them in the
     104              :  *          middle or update the list of entries below to include the
     105              :  *          new start/end protocols.
     106              :  */
     107              : #define PROTOCOLS "ftp,sftp,http,https,gopher"
     108              : 
     109              : const struct test_info test_info_entries[] =
     110              : {
     111              :     /* NULL entries */
     112              :     {
     113              :       NULL,
     114              :       PROTOCOLS,
     115              :       0,
     116              :       TLD_RESULT_NULL,
     117              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     118              :     },
     119              :     {
     120              :       "",
     121              :       PROTOCOLS,
     122              :       0,
     123              :       TLD_RESULT_NULL,
     124              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     125              :     },
     126              :     /* invalid entries */
     127              :     {
     128              :       "bad://www.m2osw.th/bad-protocol",
     129              :       PROTOCOLS,
     130              :       0,
     131              :       TLD_RESULT_BAD_URI,
     132              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     133              :     },
     134              :     {
     135              :       "b!d://www.m2osw.cg/bad-protocol/character",
     136              :       PROTOCOLS,
     137              :       0,
     138              :       TLD_RESULT_BAD_URI,
     139              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     140              :     },
     141              :     {
     142              :       "https:/www.m2osw.sx.cn/missing/slash",
     143              :       PROTOCOLS,
     144              :       0,
     145              :       TLD_RESULT_BAD_URI,
     146              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     147              :     },
     148              :     {
     149              :       "http:q/www.m2osw.lezajsk.pl/q/instead/of/slash",
     150              :       PROTOCOLS,
     151              :       0,
     152              :       TLD_RESULT_BAD_URI,
     153              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     154              :     },
     155              :     {
     156              :       "https::/www.m2osw.museum.mv/two/colons",
     157              :       PROTOCOLS,
     158              :       0,
     159              :       TLD_RESULT_BAD_URI,
     160              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     161              :     },
     162              :     {
     163              :       "http:///www.m2osw.rec.co/3/slashes",
     164              :       PROTOCOLS,
     165              :       0,
     166              :       TLD_RESULT_BAD_URI,
     167              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     168              :     },
     169              :     {
     170              :       "https://@www.m2osw.co.zm/bad?user=info",
     171              :       PROTOCOLS,
     172              :       0,
     173              :       TLD_RESULT_BAD_URI,
     174              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     175              :     },
     176              :     {
     177              :       "https://@www.m2osw.mil.py@/bad?user=info",
     178              :       PROTOCOLS,
     179              :       0,
     180              :       TLD_RESULT_BAD_URI,
     181              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     182              :     },
     183              :     {
     184              :       "https://:password1@www.m2osw.net.tn/bad?user=info",
     185              :       PROTOCOLS,
     186              :       0,
     187              :       TLD_RESULT_BAD_URI,
     188              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     189              :     },
     190              :     {
     191              :       "https://alexis:@www.m2osw.int.rw/bad?user=info",
     192              :       PROTOCOLS,
     193              :       0,
     194              :       TLD_RESULT_BAD_URI,
     195              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     196              :     },
     197              :     {
     198              :       "https://:@www.m2osw.l.lc/bad?user=info",
     199              :       PROTOCOLS,
     200              :       0,
     201              :       TLD_RESULT_BAD_URI,
     202              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     203              :     },
     204              :     {
     205              :       "https://www.m2osw.mil.sh:/bad?port=empty",
     206              :       PROTOCOLS,
     207              :       0,
     208              :       TLD_RESULT_BAD_URI,
     209              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     210              :     },
     211              :     {
     212              :       "https://www.m2osw.krasnoyarsk.ru:abc/bad?port=invalid&p=number",
     213              :       PROTOCOLS,
     214              :       0,
     215              :       TLD_RESULT_BAD_URI,
     216              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     217              :     },
     218              :     {
     219              :       "sftp://www.m2osw.cat.tt:-33/bad?port=unexpected number",
     220              :       PROTOCOLS,
     221              :       0,
     222              :       TLD_RESULT_BAD_URI,
     223              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     224              :     },
     225              :     {
     226              :       "https://www.m2osw.cat.tt/bad/variable/name?=value",
     227              :       PROTOCOLS,
     228              :       0,
     229              :       TLD_RESULT_BAD_URI,
     230              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     231              :     },
     232              :     {
     233              :       "http://www.m2osw.edu.pt/bar%xx/percent",
     234              :       PROTOCOLS,
     235              :       0,
     236              :       TLD_RESULT_BAD_URI,
     237              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     238              :     },
     239              :     {
     240              :       "http://www.m2osw.tjeldsund.no/con\trol/character",
     241              :       PROTOCOLS,
     242              :       0,
     243              :       TLD_RESULT_BAD_URI,
     244              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     245              :     },
     246              :     {
     247              :       "http://www.m2osw.edu.pt/con%09rol/character", /* %09 = \t */
     248              :       PROTOCOLS,
     249              :       0,
     250              :       TLD_RESULT_BAD_URI,
     251              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     252              :     },
     253              :     {
     254              :       "http://www.m2osw.other.nf/space character",
     255              :       PROTOCOLS,
     256              :       VALID_URI_NO_SPACES,
     257              :       TLD_RESULT_BAD_URI,
     258              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     259              :     },
     260              :     {
     261              :       "http://www.m2osw.co.mp/space+character",
     262              :       PROTOCOLS,
     263              :       VALID_URI_NO_SPACES,
     264              :       TLD_RESULT_BAD_URI,
     265              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     266              :     },
     267              :     {
     268              :       "http://www.m2osw.bv.nl/space%20character",
     269              :       PROTOCOLS,
     270              :       VALID_URI_NO_SPACES,
     271              :       TLD_RESULT_BAD_URI,
     272              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     273              :     },
     274              :     {
     275              :       "http://www.m2osw.gov.pk/bad/variable/name?good=value&=at&the=beginning",
     276              :       PROTOCOLS,
     277              :       0,
     278              :       TLD_RESULT_BAD_URI,
     279              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     280              :     },
     281              :     {
     282              :       "http://www.m2osw.rakpetroleum.om/bad/variable/name?good=value&at=the&=beginning",
     283              :       PROTOCOLS,
     284              :       0,
     285              :       TLD_RESULT_BAD_URI,
     286              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     287              :     },
     288              :     {
     289              :       "http://www.m2osw.orange.om/missing/question/mark&good=values&here=perfect",
     290              :       PROTOCOLS,
     291              :       0,
     292              :       TLD_RESULT_BAD_URI,
     293              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     294              :     },
     295              :     {
     296              :       "http://www.m2osw.orange.om/invalid%9ftoo/large",
     297              :       PROTOCOLS,
     298              :       VALID_URI_ASCII_ONLY,
     299              :       TLD_RESULT_BAD_URI,
     300              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     301              :     },
     302              :     {
     303              :       "http://www.m2osw.orange.om/invalid%9ztoo/large",
     304              :       PROTOCOLS,
     305              :       0,
     306              :       TLD_RESULT_BAD_URI,
     307              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     308              :     },
     309              :     {
     310              :       "http://www.m2osw.orange.om/invalid%z9too/large",
     311              :       PROTOCOLS,
     312              :       0,
     313              :       TLD_RESULT_BAD_URI,
     314              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     315              :     },
     316              :     {
     317              :       "http://www.m2osw.backspace.\010.no/forbid/control-characters",
     318              :       PROTOCOLS,
     319              :       0,
     320              :       TLD_RESULT_BAD_URI,
     321              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     322              :     },
     323              :     {
     324              :       "http://www.m2osw.backspace.no/forbid/control-characters/\010/in/path/too",
     325              :       PROTOCOLS,
     326              :       0,
     327              :       TLD_RESULT_BAD_URI,
     328              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     329              :     },
     330              :     {
     331              :       "http://www.m2osw.and\xF8y.no/forbid/special-characters",
     332              :       PROTOCOLS,
     333              :       VALID_URI_ASCII_ONLY,
     334              :       TLD_RESULT_BAD_URI,
     335              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     336              :     },
     337              :     {
     338              :       "http://www.m2osw.and%F8y.no/forbid/special-characters",
     339              :       PROTOCOLS,
     340              :       VALID_URI_ASCII_ONLY,
     341              :       TLD_RESULT_BAD_URI,
     342              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     343              :     },
     344              :     {
     345              :       "http://www.m2osw.and .no/forbid/spaces",
     346              :       PROTOCOLS,
     347              :       VALID_URI_ASCII_ONLY,
     348              :       TLD_RESULT_BAD_URI,
     349              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     350              :     },
     351              :     {
     352              :       "http://www.m2osw.and+.no/forbid/spaces",
     353              :       PROTOCOLS,
     354              :       VALID_URI_ASCII_ONLY,
     355              :       TLD_RESULT_BAD_URI,
     356              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     357              :     },
     358              :     {
     359              :       "http://www.m2osw.and%20.no/forbid/spaces",
     360              :       PROTOCOLS,
     361              :       VALID_URI_ASCII_ONLY,
     362              :       TLD_RESULT_BAD_URI,
     363              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     364              :     },
     365              :     {
     366              :       "http://www.m2osw.%1F.no/escape/forbidden",
     367              :       PROTOCOLS,
     368              :       VALID_URI_ASCII_ONLY,
     369              :       TLD_RESULT_BAD_URI,
     370              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     371              :     },
     372              :     {
     373              :       "http://www.m2osw.no/large/characters\xF0/forbidden",
     374              :       PROTOCOLS,
     375              :       VALID_URI_ASCII_ONLY,
     376              :       TLD_RESULT_BAD_URI,
     377              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     378              :     },
     379              :     {
     380              :       "http://a--really--long--domain-name--is-actually--forbidden.this--is--done-by--checking--the--length--which--is--limited--to--two--hundred--and--fifty--six--characters.note--that--the--buffer--must--include--a--null--terminator--which--means--you--really--are--limited--to--255--characters.www.m2osw.no/large/characters\xF0/forbidden",
     381              :       PROTOCOLS,
     382              :       0,
     383              :       TLD_RESULT_BAD_URI,
     384              :       { TLD_CATEGORY_UNDEFINED, TLD_STATUS_UNDEFINED, "", NULL, -1, 0 }
     385              :     },
     386              :     /* valid entries */
     387              :     {
     388              :       "https://www.m2osw.co.uk/simple",
     389              :       PROTOCOLS,
     390              :       0,
     391              :       TLD_RESULT_SUCCESS,
     392              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "United Kingdom", ".co.uk/", 17, 0 }
     393              :     },
     394              :     {
     395              :       "ftp://www.m2osw.ltd%2Euk/encoded/period", /* still encoded */
     396              :       PROTOCOLS,
     397              :       0,
     398              :       TLD_RESULT_SUCCESS,
     399              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "United Kingdom", ".ltd%2Euk/", 15, 0 }
     400              :     },
     401              :     {
     402              :       "http://www.m2osw.orange.edu.om/valid%9fcharacter",
     403              :       PROTOCOLS,
     404              :       0,
     405              :       TLD_RESULT_SUCCESS,
     406              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "Oman", ".edu.om", 23, 0 }
     407              :     },
     408              :     {
     409              :       "http://www.m2osw.orange.edu.om/valid\x9f/character",
     410              :       PROTOCOLS,
     411              :       0,
     412              :       TLD_RESULT_SUCCESS,
     413              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "Oman", ".edu.om", 23, 0 }
     414              :     },
     415              :     {
     416              :       "ftp://www.m2osw.ltd%2euk/encoded/period", /* still encoded */
     417              :       PROTOCOLS,
     418              :       0,
     419              :       TLD_RESULT_SUCCESS,
     420              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "United Kingdom", ".ltd%2euk/", 15, 0 }
     421              :     },
     422              :     {
     423              :       "http://m2osw.org.nr/encoded/period?#&=55", /* looks like an empty variable name */
     424              :       PROTOCOLS,
     425              :       0,
     426              :       TLD_RESULT_SUCCESS,
     427              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "Nauru", ".org.nr/", 12, 0 }
     428              :     },
     429              :     {
     430              :       "http://snap.m2osw.blogspot.com:888/longer/address",
     431              :       PROTOCOLS,
     432              :       0,
     433              :       TLD_RESULT_SUCCESS,
     434              :       { TLD_CATEGORY_ENTREPRENEURIAL, TLD_STATUS_VALID, "", ".blogspot.com:", 17, 0 }
     435              :     },
     436              :     {
     437              :       "HTTP://alexis:password1@www.m2osw.com:888/correct/uri?with=variable",
     438              :       PROTOCOLS,
     439              :       0,
     440              :       TLD_RESULT_SUCCESS,
     441              :       { TLD_CATEGORY_INTERNATIONAL, TLD_STATUS_VALID, "", ".com:", 33, 0 }
     442              :     },
     443              :     {
     444              :       "ftp://ftp.m2osw.me/freeware/download/snap/snap-1.0.tar.gz",
     445              :       PROTOCOLS,
     446              :       0,
     447              :       TLD_RESULT_SUCCESS,
     448              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "Montenegro", ".me/", 15, 0 }
     449              :     },
     450              :     {
     451              :       "gopher://news.m2osw.ca.us:71/protocols",
     452              :       PROTOCOLS,
     453              :       0,
     454              :       TLD_RESULT_SUCCESS,
     455              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "United States", ".ca.us:", 19, 0 }
     456              :     },
     457              :     {
     458              :       "random://news.m2osw.edu.mm/asterisk/protocols",
     459              :       "*",
     460              :       0,
     461              :       TLD_RESULT_SUCCESS,
     462              :       { TLD_CATEGORY_COUNTRY, TLD_STATUS_VALID, "Republic of the Union of Myanmar", ".edu.mm/", 19, 0 }
     463              :     },
     464              : };
     465              : #define    test_info_entries_length (sizeof(test_info_entries) / sizeof(test_info_entries[0]))
     466              : 
     467              : 
     468            1 : void test_uri()
     469              : {
     470            1 :     struct tld_info info;
     471              :     enum tld_result result;
     472              :     size_t i;
     473              : 
     474           51 :     for(i = 0; i < test_info_entries_length; ++i)
     475              :     {
     476              :         //fprintf(stderr, "testing [%s]\n", test_info_entries[i].f_uri);
     477           50 :         result = tld_check_uri(test_info_entries[i].f_uri, &info, test_info_entries[i].f_protocols, test_info_entries[i].f_flags);
     478           50 :         if(result != test_info_entries[i].f_result)
     479              :         {
     480            0 :             fprintf(stderr, "error:%s: URI failed with the wrong result: %d, expected %d\n", test_info_entries[i].f_uri, result, test_info_entries[i].f_result);
     481            0 :             ++err_count;
     482              :         }
     483              : 
     484           50 :         if(test_info_entries[i].f_info.f_tld == NULL)
     485              :         {
     486           39 :             if(info.f_tld != NULL)
     487              :             {
     488            0 :                 fprintf(stderr, "error:%s: TLD was expected to be NULL, got \"%s\" instead.\n", test_info_entries[i].f_uri, info.f_tld);
     489            0 :                 ++err_count;
     490              :             }
     491              :         }
     492              :         else
     493              :         {
     494           11 :             if(info.f_tld == NULL)
     495              :             {
     496            0 :                 fprintf(stderr, "error:%s: TLD was not expected to be NULL but \"%s\" instead.\n", test_info_entries[i].f_uri, test_info_entries[i].f_info.f_tld);
     497            0 :                 ++err_count;
     498              :             }
     499           11 :             else if(strncmp(test_info_entries[i].f_info.f_tld, info.f_tld, strlen(test_info_entries[i].f_info.f_tld)) != 0)
     500              :             {
     501            0 :                 fprintf(stderr, "error:%s: TLD was not properly extracted: \"%s\".\n", test_info_entries[i].f_uri, info.f_tld);
     502            0 :                 ++err_count;
     503              :             }
     504              :         }
     505              : 
     506           50 :         if(info.f_category != test_info_entries[i].f_info.f_category)
     507              :         {
     508            0 :             fprintf(stderr, "error:%s: category was not properly extracted, got %d, expected %d.\n",
     509            0 :                     test_info_entries[i].f_uri, info.f_category, test_info_entries[i].f_info.f_category);
     510            0 :             ++err_count;
     511              :         }
     512              : 
     513           50 :         if(info.f_status != test_info_entries[i].f_info.f_status)
     514              :         {
     515            0 :             fprintf(stderr, "error:%s: status was not properly extracted.\n", test_info_entries[i].f_uri);
     516            0 :             ++err_count;
     517              :         }
     518              : 
     519           50 :         if(strcmp(info.f_country, test_info_entries[i].f_info.f_country) != 0)
     520              :         {
     521            0 :             fprintf(stderr, "error:%s: country was not properly extracted.\n", test_info_entries[i].f_uri);
     522            0 :             ++err_count;
     523              :         }
     524              : 
     525           50 :         if(info.f_offset != test_info_entries[i].f_info.f_offset)
     526              :         {
     527            0 :             fprintf(stderr, "error:%s: TLD offset is not the expected value (%d).\n", test_info_entries[i].f_uri, info.f_offset);
     528            0 :             ++err_count;
     529              :         }
     530              :     }
     531            1 : }
     532              : 
     533              : 
     534              : 
     535              : 
     536              : 
     537              : 
     538              : 
     539              : 
     540              : 
     541            1 : int main(int argc, char *argv[])
     542              : {
     543            1 :     fprintf(stderr, "testing tld full URI version %s: tld_valid_uri() function\n", tld_version());
     544              : 
     545            1 :     if(argc > 1)
     546              :     {
     547            0 :         if(strcmp(argv[1], "-v") == 0)
     548              :         {
     549            0 :             verbose = 1;
     550              :         }
     551              :     }
     552              : 
     553              :     /* call all the tests, one by one
     554              :      * failures are "recorded" in the err_count global variable
     555              :      * and the process stops with an error message and exit(1)
     556              :      * if err_count is not zero.
     557              :      */
     558            1 :     load_tlds();
     559            1 :     test_uri();
     560              : 
     561            1 :     if(err_count)
     562              :     {
     563            0 :         fprintf(stderr, "%d error%s occured.\n",
     564            0 :                     err_count, err_count != 1 ? "s" : "");
     565              :     }
     566            1 :     exit(err_count ? 1 : 0);
     567              : }
     568              : 
     569              : /* vim: ts=4 sw=4 et
     570              :  */
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions