wpkg test coverage results

Coverage test results of the Windows Packager by Made to Order Software Corporation.

LCOV - code coverage report
Current view: top level - tests/unittests - unittest_uri_filename.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 194 197 98.5 %
Date: 2013-06-17 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*    unittest_uri_filename.cpp
       2             :  *    Copyright (C) 2013  Made to Order Software Corporation
       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 2 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 along
      15             :  *    with this program; if not, write to the Free Software Foundation, Inc.,
      16             :  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  *
      18             :  *    Authors
      19             :  *    Alexis Wilke   alexis@m2osw.com
      20             :  */
      21             : 
      22             : #include "unittest_uri_filename.h"
      23             : #include "libdebpackages/wpkg_filename.h"
      24             : #include "libdebpackages/wpkg_util.h"
      25             : 
      26             : #include <cppunit/config/SourcePrefix.h>
      27             : #include <string.h>
      28             : #include <time.h>
      29             : 
      30             : 
      31           1 : CPPUNIT_TEST_SUITE_REGISTRATION( URIFilenameUnitTests );
      32             : 
      33           4 : void URIFilenameUnitTests::setUp()
      34             : {
      35             :     // we can only have one of those for ALL the tests...
      36           4 :     putenv(const_cast<char *>("WPKG_SUBST=f=/opt/wpkg|/m2osw/packages:h=usr/local/bin/wpkg"));
      37           4 : }
      38             : 
      39          15 : void URIFilenameUnitTests::check(const wpkg_filename::uri_filename& fn, const expected_result& er)
      40             : {
      41          15 :     std::string msg("URIFilenameUnitTests::check(): \"");
      42          15 :     msg += er.f_original_filename;
      43          15 :     msg += "\"";
      44             : 
      45          15 :     msg += " [";
      46          15 :     msg += std::string(er.f_full_path) + "] [";
      47          15 :     msg += fn.full_path() + "] [";
      48          15 :     msg += fn.get_decode() ? "true" : "false";
      49          15 :     msg += "]";
      50             : 
      51          15 :     if(er.f_fixed_original_filename)
      52             :     {
      53           1 :         CPPUNIT_ASSERT_MESSAGE(msg, fn.original_filename() == er.f_fixed_original_filename);
      54             :     }
      55             :     else
      56             :     {
      57          14 :         CPPUNIT_ASSERT_MESSAGE(msg, fn.original_filename() == er.f_original_filename);
      58             :     }
      59          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.path_type() == er.f_path_type);
      60          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.path_protocol() == er.f_path_protocol);
      61             : 
      62          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.path_only( /*true*/ ) == er.f_path_only);
      63          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.path_only(true) == er.f_path_only);
      64          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.path_only(false) == er.f_path_only_no_drive);
      65          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.full_path() == er.f_full_path);
      66             : 
      67          15 :     size_t i(0);
      68          84 :     for(; i < sizeof(er.f_segments) / sizeof(er.f_segments[0]); ++i)
      69             :     {
      70          84 :         if(er.f_segments[i] == NULL)
      71             :         {
      72          15 :             break;
      73             :         }
      74          69 :         std::string smsg = msg + " \"" + fn.segment(static_cast<int>(i)) + "\" [" + er.f_segments[i] + "]";
      75          69 :         CPPUNIT_ASSERT_MESSAGE(smsg, fn.segment(static_cast<int>(i)) == er.f_segments[i]);
      76             : 
      77          69 :         if(er.f_is_direct)
      78             :         {
      79          65 :             CPPUNIT_ASSERT_MESSAGE(smsg, wpkg_util::is_valid_windows_filename(fn.segment(static_cast<int>(i))));
      80             :         }
      81          69 :     }
      82          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.segment_size() == static_cast<int>(i));
      83             : 
      84          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.dirname( /*true*/ ) == er.f_dirname);
      85          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.dirname(true) == er.f_dirname);
      86          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.dirname(false) == er.f_dirname_no_drive);
      87          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.basename( /*false*/ ) == er.f_basename);
      88          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.basename(false) == er.f_basename);
      89          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.basename(true) == er.f_basename_last_only);
      90          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.extension() == er.f_extension);
      91          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.previous_extension() == er.f_previous_extension);
      92          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.msdos_drive() == er.f_msdos_drive);
      93          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_username() == er.f_username);
      94          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_password() == er.f_password);
      95          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_domain() == er.f_domain);
      96          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_port() == er.f_port);
      97          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_share() == er.f_share);
      98          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_decode() == er.f_decode);
      99          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.get_anchor() == er.f_anchor);
     100             : 
     101             :     // test the map knowing the exact variable names
     102          15 :     i = 0;
     103          18 :     for(; i < sizeof(er.f_query_variables) / sizeof(er.f_query_variables[0]) / 2; ++i)
     104             :     {
     105          18 :         if(er.f_query_variables[i * 2] == NULL)
     106             :         {
     107          15 :             break;
     108             :         }
     109           3 :         std::string smsg = msg + " \"" + fn.query_variable(er.f_query_variables[i * 2]) + "\" [" + er.f_query_variables[i * 2 + 1] + "]";
     110           3 :         CPPUNIT_ASSERT_MESSAGE(smsg, fn.query_variable(er.f_query_variables[i * 2]) == er.f_query_variables[i * 2 + 1]);
     111           3 :     }
     112             : 
     113          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.query_variable("no-a-variable") == "");
     114             : 
     115             :     // now test the map itself
     116          15 :     wpkg_filename::uri_filename::query_variables_t vars(fn.all_query_variables());
     117          15 :     i = 0;
     118          18 :     for(wpkg_filename::uri_filename::query_variables_t::const_iterator v(vars.begin()); i < sizeof(er.f_query_variables) / sizeof(er.f_query_variables[0]) / 2; ++i, ++v)
     119             :     {
     120          18 :         if(er.f_query_variables[i * 2] == NULL)
     121             :         {
     122          15 :             break;
     123             :         }
     124           3 :         std::string smsg = msg + " \"" + fn.query_variable(er.f_query_variables[i * 2]) + "\" [" + er.f_query_variables[i * 2 + 1] + "]";
     125           3 :         CPPUNIT_ASSERT_MESSAGE(smsg, v != vars.end());
     126           3 :         CPPUNIT_ASSERT_MESSAGE(smsg, v->first == er.f_query_variables[i * 2]);
     127           3 :         CPPUNIT_ASSERT_MESSAGE(smsg, v->second == er.f_query_variables[i * 2 + 1]);
     128           3 :     }
     129             :     // check that the size of the vars is not larger than the f_query_variables
     130          15 :     CPPUNIT_ASSERT_MESSAGE(msg, vars.size() == i);
     131             : 
     132             :     // check a glob() call on each file, that allows us to make sure the glob()
     133             :     // function works as expected
     134             :     {
     135          15 :         std::string smsg = msg + " glob: \"" + er.f_glob + "\"";
     136          15 :         CPPUNIT_ASSERT_MESSAGE(smsg, fn.glob(er.f_glob));
     137             :     }
     138             : 
     139          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.empty() == er.f_empty);
     140          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.is_deb() == er.f_is_deb);
     141          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.is_valid() == er.f_is_valid);
     142          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.is_direct() == er.f_is_direct);
     143          15 :     CPPUNIT_ASSERT_MESSAGE(msg, fn.is_absolute() == er.f_is_absolute);
     144          15 : }
     145             : 
     146             : URIFilenameUnitTests::expected_result empty =
     147             : {
     148             :     /* f_original_filename;         */ "",
     149             :     /* f_fixed_original_filename;   */ NULL,
     150             :     /* f_path_type;                 */ wpkg_filename::uri_filename::uri_type_undefined,
     151             :     /* f_path_protocol;             */ "",
     152             :     /* f_path_only;                 */ "",
     153             :     /* f_path_only_no_drive;        */ "",
     154             :     /* f_full_path;                 */ "",
     155             :     /* f_segments[32];              */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     156             :     /* f_dirname;                   */ "",
     157             :     /* f_dirname_no_drive;          */ "",
     158             :     /* f_basename;                  */ "",
     159             :     /* f_basename_last_only;        */ "",
     160             :     /* f_extension;                 */ "",
     161             :     /* f_previous_extension;        */ "",
     162             :     /* f_msdos_drive;               */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     163             :     /* f_username;                  */ "",
     164             :     /* f_password;                  */ "",
     165             :     /* f_domain;                    */ "",
     166             :     /* f_port;                      */ "",
     167             :     /* f_share;                     */ "",
     168             :     /* f_decode;                    */ false,
     169             :     /* f_anchor;                    */ "",
     170             :     /* f_query_variables[32];       */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     171             :     /* f_glob;                      */ "*",
     172             :     /* f_empty;                     */ true,
     173             :     /* f_is_deb;                    */ false,
     174             :     /* f_is_valid;                  */ false,
     175             :     /* f_is_direct;                 */ false,
     176             :     /* f_is_absolute;               */ false
     177           1 : };
     178             : 
     179           1 : void URIFilenameUnitTests::path()
     180             : {
     181             :     {
     182           1 :         wpkg_filename::uri_filename filename;
     183           1 :         check(filename, empty);
     184             :     }
     185             : 
     186             :     {
     187             :         expected_result result =
     188             :         {
     189             :             /* f_original_filename;   */ "/simple/path/.with./.double.extensions.tar.gz",
     190             :             /* f_fixed_original_fi... */ NULL,
     191             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     192             :             /* f_path_protocol;       */ "file",
     193             :             /* f_path_only;           */ "/simple/path/.with./.double.extensions.tar.gz",
     194             :             /* f_path_only_no_drive;  */ "/simple/path/.with./.double.extensions.tar.gz",
     195             :             /* f_full_path;           */ "/simple/path/.with./.double.extensions.tar.gz",
     196             :             /* f_segments[32];        */ { "simple", "path", ".with.", ".double.extensions.tar.gz", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     197             :             /* f_dirname;             */ "/simple/path/.with.",
     198             :             /* f_dirname_no_drive;    */ "/simple/path/.with.",
     199             :             /* f_basename;            */ ".double.extensions",
     200             :             /* f_basename_last_only;  */ ".double.extensions.tar",
     201             :             /* f_extension;           */ "gz",
     202             :             /* f_previous_extension;  */ "tar",
     203             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     204             :             /* f_username;            */ "",
     205             :             /* f_password;            */ "",
     206             :             /* f_domain;              */ "",
     207             :             /* f_port;                */ "",
     208             :             /* f_share;               */ "",
     209             :             /* f_decode;              */ false,
     210             :             /* f_anchor;              */ "",
     211             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     212             :             /* f_glob;                */ "/simple/path/.[a-z]ith./.double.extensions.t?r.*",
     213             :             /* f_empty;               */ false,
     214             :             /* f_is_deb;              */ false,
     215             :             /* f_is_valid;            */ true,
     216             :             /* f_is_direct;           */ true,
     217             :             /* f_is_absolute;         */ true
     218           1 :         };
     219             : 
     220           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     221           1 :         check(filename, result);
     222             :     }
     223             : 
     224             :     {
     225             :         expected_result result =
     226             :         {
     227             :             /* f_original_filename;   */ "simple/relative/path/with/one-extension.tar",
     228             :             /* f_fixed_original_fi... */ NULL,
     229             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     230             :             /* f_path_protocol;       */ "file",
     231             :             /* f_path_only;           */ "simple/relative/path/with/one-extension.tar",
     232             :             /* f_path_only_no_drive;  */ "simple/relative/path/with/one-extension.tar",
     233             :             /* f_full_path;           */ "simple/relative/path/with/one-extension.tar",
     234             :             /* f_segments[32];        */ { "simple", "relative", "path", "with", "one-extension.tar", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     235             :             /* f_dirname;             */ "simple/relative/path/with",
     236             :             /* f_dirname_no_drive;    */ "simple/relative/path/with",
     237             :             /* f_basename;            */ "one-extension",
     238             :             /* f_basename_last_only;  */ "one-extension",
     239             :             /* f_extension;           */ "tar",
     240             :             /* f_previous_extension;  */ "tar",
     241             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     242             :             /* f_username;            */ "",
     243             :             /* f_password;            */ "",
     244             :             /* f_domain;              */ "",
     245             :             /* f_port;                */ "",
     246             :             /* f_share;               */ "",
     247             :             /* f_decode;              */ false,
     248             :             /* f_anchor;              */ "",
     249             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     250             :             /* f_glob;                */ "simple/*/path/with/one-extension.tar",
     251             :             /* f_empty;               */ false,
     252             :             /* f_is_deb;              */ false,
     253             :             /* f_is_valid;            */ true,
     254             :             /* f_is_direct;           */ true,
     255             :             /* f_is_absolute;         */ false
     256           1 :         };
     257             : 
     258           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     259           1 :         check(filename, result);
     260             :     }
     261             : 
     262             :     {
     263             :         expected_result result =
     264             :         {
     265             :             /* f_original_filename;   */ "~/simple/relative/path/with/one-extension.tar",
     266             :             /* f_fixed_original_fi... */ "/home/wpkg/simple/relative/path/with/one-extension.tar",
     267             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     268             :             /* f_path_protocol;       */ "file",
     269             :             /* f_path_only;           */ "/home/wpkg/simple/relative/path/with/one-extension.tar",
     270             :             /* f_path_only_no_drive;  */ "/home/wpkg/simple/relative/path/with/one-extension.tar",
     271             :             /* f_full_path;           */ "/home/wpkg/simple/relative/path/with/one-extension.tar",
     272             :             /* f_segments[32];        */ { "home", "wpkg", "simple", "relative", "path", "with", "one-extension.tar", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
     273             :             /* f_dirname;             */ "/home/wpkg/simple/relative/path/with",
     274             :             /* f_dirname_no_drive;    */ "/home/wpkg/simple/relative/path/with",
     275             :             /* f_basename;            */ "one-extension",
     276             :             /* f_basename_last_only;  */ "one-extension",
     277             :             /* f_extension;           */ "tar",
     278             :             /* f_previous_extension;  */ "tar",
     279             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     280             :             /* f_username;            */ "",
     281             :             /* f_password;            */ "",
     282             :             /* f_domain;              */ "",
     283             :             /* f_port;                */ "",
     284             :             /* f_share;               */ "",
     285             :             /* f_decode;              */ false,
     286             :             /* f_anchor;              */ "",
     287             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     288             :             /* f_glob;                */ "/home/wpkg/simple/relative/[p][a][t][h]/with/one-*?.tar",
     289             :             /* f_empty;               */ false,
     290             :             /* f_is_deb;              */ false,
     291             :             /* f_is_valid;            */ true,
     292             :             /* f_is_direct;           */ true,
     293             :             /* f_is_absolute;         */ true
     294           1 :         };
     295             : 
     296           1 :         putenv(const_cast<char *>("HOME=/home/wpkg"));
     297           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     298           1 :         check(filename, result);
     299             :     }
     300             : 
     301             :     {
     302             :         expected_result result =
     303             :         {
     304             :             /* f_original_filename;   */ "~name/simple/relative/path/with/one-extension.tar",
     305             :             /* f_fixed_original_fi... */ NULL,
     306             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     307             :             /* f_path_protocol;       */ "file",
     308             :             /* f_path_only;           */ "simple/relative/path/with/one-extension.tar",
     309             :             /* f_path_only_no_drive;  */ "simple/relative/path/with/one-extension.tar",
     310             :             /* f_full_path;           */ "simple/relative/path/with/one-extension.tar",
     311             :             /* f_segments[32];        */ { "simple", "relative", "path", "with", "one-extension.tar", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     312             :             /* f_dirname;             */ "simple/relative/path/with",
     313             :             /* f_dirname_no_drive;    */ "simple/relative/path/with",
     314             :             /* f_basename;            */ "one-extension",
     315             :             /* f_basename_last_only;  */ "one-extension",
     316             :             /* f_extension;           */ "tar",
     317             :             /* f_previous_extension;  */ "tar",
     318             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     319             :             /* f_username;            */ "",
     320             :             /* f_password;            */ "",
     321             :             /* f_domain;              */ "",
     322             :             /* f_port;                */ "",
     323             :             /* f_share;               */ "",
     324             :             /* f_decode;              */ false,
     325             :             /* f_anchor;              */ "",
     326             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     327             :             /* f_glob;                */ "~name/simple/relative/p?t?/wi?h?one-extension.tar",
     328             :             /* f_empty;               */ false,
     329             :             /* f_is_deb;              */ false,
     330             :             /* f_is_valid;            */ true,
     331             :             /* f_is_direct;           */ true,
     332             :             /* f_is_absolute;         */ false
     333           1 :         };
     334             : 
     335             :         try
     336             :         {
     337           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     338           1 :             CPPUNIT_ASSERT(!"~name/... did not generate an exception");
     339             :         }
     340           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     341             :         {
     342             :         }
     343             :     }
     344             : 
     345             :     {
     346             :         expected_result result =
     347             :         {
     348             :             /* f_original_filename;   */ "~/simple/relative/path/with/one-extension.tar",
     349             :             /* f_fixed_original_fi... */ NULL,
     350             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     351             :             /* f_path_protocol;       */ "file",
     352             :             /* f_path_only;           */ "simple/relative/path/with/one-extension.tar",
     353             :             /* f_path_only_no_drive;  */ "simple/relative/path/with/one-extension.tar",
     354             :             /* f_full_path;           */ "simple/relative/path/with/one-extension.tar",
     355             :             /* f_segments[32];        */ { "simple", "relative", "path", "with", "one-extension.tar", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     356             :             /* f_dirname;             */ "simple/relative/path/with",
     357             :             /* f_dirname_no_drive;    */ "simple/relative/path/with",
     358             :             /* f_basename;            */ "one-extension",
     359             :             /* f_basename_last_only;  */ "one-extension",
     360             :             /* f_extension;           */ "tar",
     361             :             /* f_previous_extension;  */ "tar",
     362             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     363             :             /* f_username;            */ "",
     364             :             /* f_password;            */ "",
     365             :             /* f_domain;              */ "",
     366             :             /* f_port;                */ "",
     367             :             /* f_share;               */ "",
     368             :             /* f_decode;              */ false,
     369             :             /* f_anchor;              */ "",
     370             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     371             :             /* f_glob;                */ "simple/rel*ative/path/with/one-extension.tar",
     372             :             /* f_empty;               */ false,
     373             :             /* f_is_deb;              */ false,
     374             :             /* f_is_valid;            */ true,
     375             :             /* f_is_direct;           */ true,
     376             :             /* f_is_absolute;         */ false
     377           1 :         };
     378             : 
     379             :         try
     380             :         {
     381           1 :             putenv(const_cast<char *>("HOME=~/test"));
     382           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     383           1 :             CPPUNIT_ASSERT(!"HOME=~/test did not generate an exception");
     384             :         }
     385           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     386             :         {
     387             :         }
     388             :     }
     389             : 
     390             :     {
     391             :         expected_result result =
     392             :         {
     393             :             /* f_original_filename;   */ "~/simple/relative/path/with/one-extension.tar",
     394             :             /* f_fixed_original_fi... */ NULL,
     395             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     396             :             /* f_path_protocol;       */ "file",
     397             :             /* f_path_only;           */ "simple/relative/path/with/one-extension.tar",
     398             :             /* f_path_only_no_drive;  */ "simple/relative/path/with/one-extension.tar",
     399             :             /* f_full_path;           */ "simple/relative/path/with/one-extension.tar",
     400             :             /* f_segments[32];        */ { "simple", "relative", "path", "with", "one-extension.tar", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     401             :             /* f_dirname;             */ "simple/relative/path/with",
     402             :             /* f_dirname_no_drive;    */ "simple/relative/path/with",
     403             :             /* f_basename;            */ "one-extension",
     404             :             /* f_basename_last_only;  */ "one-extension",
     405             :             /* f_extension;           */ "tar",
     406             :             /* f_previous_extension;  */ "tar",
     407             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     408             :             /* f_username;            */ "",
     409             :             /* f_password;            */ "",
     410             :             /* f_domain;              */ "",
     411             :             /* f_port;                */ "",
     412             :             /* f_share;               */ "",
     413             :             /* f_decode;              */ false,
     414             :             /* f_anchor;              */ "",
     415             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     416             :             /* f_glob;                */ "simple/re?*?ve/path/with/one-extension.tar",
     417             :             /* f_empty;               */ false,
     418             :             /* f_is_deb;              */ false,
     419             :             /* f_is_valid;            */ true,
     420             :             /* f_is_direct;           */ true,
     421             :             /* f_is_absolute;         */ false
     422           1 :         };
     423             : 
     424             :         try
     425             :         {
     426           1 :             putenv(const_cast<char *>("HOME=not/absolute"));
     427           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     428           1 :             CPPUNIT_ASSERT(!"HOME=not/absolute did not generate an exception");
     429             :         }
     430           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     431             :         {
     432             :         }
     433             :     }
     434             : 
     435             :     {
     436             :         expected_result result =
     437             :         {
     438             :             /* f_original_filename;   */ "File:///simple/full/path/with/one-extension.tar#test",
     439             :             /* f_fixed_original_fi... */ NULL,
     440             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     441             :             /* f_path_protocol;       */ "file",
     442             :             /* f_path_only;           */ "/simple/full/path/with/one-extension.tar#test",
     443             :             /* f_path_only_no_drive;  */ "/simple/full/path/with/one-extension.tar#test",
     444             :             /* f_full_path;           */ "/simple/full/path/with/one-extension.tar#test",
     445             :             /* f_segments[32];        */ { "simple", "full", "path", "with", "one-extension.tar#test", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     446             :             /* f_dirname;             */ "/simple/full/path/with",
     447             :             /* f_dirname_no_drive;    */ "/simple/full/path/with",
     448             :             /* f_basename;            */ "one-extension",
     449             :             /* f_basename_last_only;  */ "one-extension",
     450             :             /* f_extension;           */ "tar#test",
     451             :             /* f_previous_extension;  */ "tar#test",
     452             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     453             :             /* f_username;            */ "",
     454             :             /* f_password;            */ "",
     455             :             /* f_domain;              */ "",
     456             :             /* f_port;                */ "",
     457             :             /* f_share;               */ "",
     458             :             /* f_decode;              */ false,
     459             :             /* f_anchor;              */ "",
     460             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     461             :             /* f_glob;                */ "/simple/full/*.tar#test",
     462             :             /* f_empty;               */ false,
     463             :             /* f_is_deb;              */ false,
     464             :             /* f_is_valid;            */ true,
     465             :             /* f_is_direct;           */ true,
     466             :             /* f_is_absolute;         */ true
     467           1 :         };
     468             : 
     469           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     470           1 :         check(filename, result);
     471             :     }
     472             : 
     473             :     {
     474             :         expected_result result =
     475             :         {
     476             :             /* f_original_filename;   */ "File:///k:/simple/full/path/with/one-extension.tar#test",
     477             :             /* f_fixed_original_fi... */ NULL,
     478             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     479             :             /* f_path_protocol;       */ "file",
     480             :             /* f_path_only;           */ "K:/simple/full/path/with/one-extension.tar#test",
     481             :             /* f_path_only_no_drive;  */ "/simple/full/path/with/one-extension.tar#test",
     482             :             /* f_full_path;           */ "K:/simple/full/path/with/one-extension.tar#test",
     483             :             /* f_segments[32];        */ { "simple", "full", "path", "with", "one-extension.tar#test", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     484             :             /* f_dirname;             */ "K:/simple/full/path/with",
     485             :             /* f_dirname_no_drive;    */ "/simple/full/path/with",
     486             :             /* f_basename;            */ "one-extension",
     487             :             /* f_basename_last_only;  */ "one-extension",
     488             :             /* f_extension;           */ "tar#test",
     489             :             /* f_previous_extension;  */ "tar#test",
     490             :             /* f_msdos_drive;         */ 'K',
     491             :             /* f_username;            */ "",
     492             :             /* f_password;            */ "",
     493             :             /* f_domain;              */ "",
     494             :             /* f_port;                */ "",
     495             :             /* f_share;               */ "",
     496             :             /* f_decode;              */ false,
     497             :             /* f_anchor;              */ "",
     498             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     499             :             /* f_glob;                */ "/simple/full/*.tar#test",
     500             :             /* f_empty;               */ false,
     501             :             /* f_is_deb;              */ false,
     502             :             /* f_is_valid;            */ true,
     503             :             /* f_is_direct;           */ true,
     504             :             /* f_is_absolute;         */ true
     505           1 :         };
     506             : 
     507           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     508           1 :         check(filename, result);
     509             :     }
     510             : 
     511             :     {
     512             :         expected_result result =
     513             :         {
     514             :             /* f_original_filename;   */ "File:///c|/simple/full/path/with/one-extension.tar#test",
     515             :             /* f_fixed_original_fi... */ NULL,
     516             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     517             :             /* f_path_protocol;       */ "file",
     518             :             /* f_path_only;           */ "C:/simple/full/path/with/one-extension.tar#test",
     519             :             /* f_path_only_no_drive;  */ "/simple/full/path/with/one-extension.tar#test",
     520             :             /* f_full_path;           */ "C:/simple/full/path/with/one-extension.tar#test",
     521             :             /* f_segments[32];        */ { "simple", "full", "path", "with", "one-extension.tar#test", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     522             :             /* f_dirname;             */ "C:/simple/full/path/with",
     523             :             /* f_dirname_no_drive;    */ "/simple/full/path/with",
     524             :             /* f_basename;            */ "one-extension",
     525             :             /* f_basename_last_only;  */ "one-extension",
     526             :             /* f_extension;           */ "tar#test",
     527             :             /* f_previous_extension;  */ "tar#test",
     528             :             /* f_msdos_drive;         */ 'C',
     529             :             /* f_username;            */ "",
     530             :             /* f_password;            */ "",
     531             :             /* f_domain;              */ "",
     532             :             /* f_port;                */ "",
     533             :             /* f_share;               */ "",
     534             :             /* f_decode;              */ false,
     535             :             /* f_anchor;              */ "",
     536             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     537             :             /* f_glob;                */ "/simple/full/*.tar#test",
     538             :             /* f_empty;               */ false,
     539             :             /* f_is_deb;              */ false,
     540             :             /* f_is_valid;            */ true,
     541             :             /* f_is_direct;           */ true,
     542             :             /* f_is_absolute;         */ true
     543           1 :         };
     544             : 
     545           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     546           1 :         check(filename, result);
     547             :     }
     548             : 
     549             :     {
     550             :         expected_result result =
     551             :         {
     552             :             /* f_original_filename;   */ "HTTP://alexis:secret@www.m2osw.com:888/some/path//to/filename.tar.zip?#here",
     553             :             /* f_fixed_original_fi... */ NULL,
     554             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     555             :             /* f_path_protocol;       */ "http",
     556             :             /* f_path_only;           */ "/some/path/to/filename.tar.zip",
     557             :             /* f_path_only_no_drive;  */ "/some/path/to/filename.tar.zip",
     558             :             /* f_full_path;           */ "http://alexis:secret@www.m2osw.com:888/some/path/to/filename.tar.zip#here",
     559             :             /* f_segments[32];        */ { "some", "path", "to", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     560             :             /* f_dirname;             */ "/some/path/to",
     561             :             /* f_dirname_no_drive;    */ "/some/path/to",
     562             :             /* f_basename;            */ "filename.tar",
     563             :             /* f_basename_last_only;  */ "filename.tar",
     564             :             /* f_extension;           */ "zip",
     565             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     566             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     567             :             /* f_username;            */ "alexis",
     568             :             /* f_password;            */ "secret",
     569             :             /* f_domain;              */ "www.m2osw.com",
     570             :             /* f_port;                */ "888",
     571             :             /* f_share;               */ "",
     572             :             /* f_decode;              */ true,
     573             :             /* f_anchor;              */ "here",
     574             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     575             :             /* f_glob;                */ "/some/path/to/*",
     576             :             /* f_empty;               */ false,
     577             :             /* f_is_deb;              */ false,
     578             :             /* f_is_valid;            */ true,
     579             :             /* f_is_direct;           */ false,
     580             :             /* f_is_absolute;         */ true
     581           1 :         };
     582             : 
     583           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     584           1 :         check(filename, result);
     585             :     }
     586             : 
     587             :     {
     588             :         expected_result result =
     589             :         {
     590             :             /* f_original_filename;   */ "smb://alexis:secret@simple:123/share/full/path/filename.tar.zip?var=555#test",
     591             :             /* f_fixed_original_fi... */ NULL,
     592             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     593             :             /* f_path_protocol;       */ "smb",
     594             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     595             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     596             :             /* f_full_path;           */ "smb://alexis:secret@simple:123/share/full/path/filename.tar.zip?var=555#test",
     597             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     598             :             /* f_dirname;             */ "/full/path",
     599             :             /* f_dirname_no_drive;    */ "/full/path",
     600             :             /* f_basename;            */ "filename.tar",
     601             :             /* f_basename_last_only;  */ "filename.tar",
     602             :             /* f_extension;           */ "zip",
     603             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     604             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     605             :             /* f_username;            */ "alexis",
     606             :             /* f_password;            */ "secret",
     607             :             /* f_domain;              */ "simple",
     608             :             /* f_port;                */ "123",
     609             :             /* f_share;               */ "share",
     610             :             /* f_decode;              */ true,
     611             :             /* f_anchor;              */ "test",
     612             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     613             :             /* f_glob;                */ "/full/path/filename.tar.zip",
     614             :             /* f_empty;               */ false,
     615             :             /* f_is_deb;              */ false,
     616             :             /* f_is_valid;            */ true,
     617             :             /* f_is_direct;           */ true,
     618             :             /* f_is_absolute;         */ true
     619           1 :         };
     620             : 
     621           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     622           1 :         check(filename, result);
     623             :     }
     624             : 
     625             :     {
     626             :         expected_result result =
     627             :         {
     628             :             /* f_original_filename;   */ "netbios://alexis:secret@simple:123/share/full/path/filename.tar.zip?var=555&home=/#test",
     629             :             /* f_fixed_original_fi... */ NULL,
     630             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     631             :             /* f_path_protocol;       */ "smb",
     632             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     633             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     634             :             /* f_full_path;           */ "smb://alexis:secret@simple:123/share/full/path/filename.tar.zip?home=/&var=555#test",
     635             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     636             :             /* f_dirname;             */ "/full/path",
     637             :             /* f_dirname_no_drive;    */ "/full/path",
     638             :             /* f_basename;            */ "filename.tar",
     639             :             /* f_basename_last_only;  */ "filename.tar",
     640             :             /* f_extension;           */ "zip",
     641             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     642             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     643             :             /* f_username;            */ "alexis",
     644             :             /* f_password;            */ "secret",
     645             :             /* f_domain;              */ "simple",
     646             :             /* f_port;                */ "123",
     647             :             /* f_share;               */ "share",
     648             :             /* f_decode;              */ true,
     649             :             /* f_anchor;              */ "test",
     650             :             /* f_query_variables[32]; */ { "home", "/", "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     651             :             /* f_glob;                */ "/f?ll/p?th/f?lename.tar.zip",
     652             :             /* f_empty;               */ false,
     653             :             /* f_is_deb;              */ false,
     654             :             /* f_is_valid;            */ true,
     655             :             /* f_is_direct;           */ true,
     656             :             /* f_is_absolute;         */ true
     657           1 :         };
     658             : 
     659           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     660           1 :         check(filename, result);
     661             :     }
     662             : 
     663             :     {
     664             :         expected_result result =
     665             :         {
     666             :             /* f_original_filename;   */ "nbs://alexis@simple:123/share/full/path/filename.tar.zip?var=555#test",
     667             :             /* f_fixed_original_fi... */ NULL,
     668             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     669             :             /* f_path_protocol;       */ "smbs",
     670             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     671             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     672             :             /* f_full_path;           */ "smbs://alexis@simple:123/share/full/path/filename.tar.zip?var=555#test",
     673             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     674             :             /* f_dirname;             */ "/full/path",
     675             :             /* f_dirname_no_drive;    */ "/full/path",
     676             :             /* f_basename;            */ "filename.tar",
     677             :             /* f_basename_last_only;  */ "filename.tar",
     678             :             /* f_extension;           */ "zip",
     679             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     680             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     681             :             /* f_username;            */ "alexis",
     682             :             /* f_password;            */ "secret",
     683             :             /* f_domain;              */ "simple",
     684             :             /* f_port;                */ "123",
     685             :             /* f_share;               */ "share",
     686             :             /* f_decode;              */ true,
     687             :             /* f_anchor;              */ "test",
     688             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     689             :             /* f_glob;                */ "*/filename.tar.zip*",
     690             :             /* f_empty;               */ false,
     691             :             /* f_is_deb;              */ false,
     692             :             /* f_is_valid;            */ true,
     693             :             /* f_is_direct;           */ true,
     694             :             /* f_is_absolute;         */ true
     695           1 :         };
     696             : 
     697             :         try
     698             :         {
     699           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     700           1 :             CPPUNIT_ASSERT(!"netbios with the username or password missing");
     701             :         }
     702           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     703             :         {
     704             :         }
     705             :     }
     706             : 
     707             :     {
     708             :         expected_result result =
     709             :         {
     710             :             /* f_original_filename;   */ "nbs://:password@simple:123/share/full/path\\filename.tar.zip?var=555#test",
     711             :             /* f_fixed_original_fi... */ NULL,
     712             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     713             :             /* f_path_protocol;       */ "smbs",
     714             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     715             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     716             :             /* f_full_path;           */ "smbs://alexis@simple:123/share/full/path/filename.tar.zip?var=555#test",
     717             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     718             :             /* f_dirname;             */ "/full/path",
     719             :             /* f_dirname_no_drive;    */ "/full/path",
     720             :             /* f_basename;            */ "filename.tar",
     721             :             /* f_basename_last_only;  */ "filename.tar",
     722             :             /* f_extension;           */ "zip",
     723             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     724             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     725             :             /* f_username;            */ "alexis",
     726             :             /* f_password;            */ "secret",
     727             :             /* f_domain;              */ "simple",
     728             :             /* f_port;                */ "123",
     729             :             /* f_share;               */ "share",
     730             :             /* f_decode;              */ true,
     731             :             /* f_anchor;              */ "test",
     732             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     733             :             /* f_glob;                */ "*/share/full/path\\filename.tar.zip",
     734             :             /* f_empty;               */ false,
     735             :             /* f_is_deb;              */ false,
     736             :             /* f_is_valid;            */ true,
     737             :             /* f_is_direct;           */ true,
     738             :             /* f_is_absolute;         */ true
     739           1 :         };
     740             : 
     741             :         try
     742             :         {
     743           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     744           1 :             CPPUNIT_ASSERT(!"netbios with the username or password missing");
     745             :         }
     746           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     747             :         {
     748             :         }
     749             :     }
     750             : 
     751             :     {
     752             :         expected_result result =
     753             :         {
     754             :             /* f_original_filename;   */ "nbs://simple/share/full/path/filename.tar.zip?v r=555#test",
     755             :             /* f_fixed_original_fi... */ NULL,
     756             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     757             :             /* f_path_protocol;       */ "smbs",
     758             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     759             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     760             :             /* f_full_path;           */ "smbs://alexis@simple:123/share/full/path/filename.tar.zip?var=555#test",
     761             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     762             :             /* f_dirname;             */ "/full/path",
     763             :             /* f_dirname_no_drive;    */ "/full/path",
     764             :             /* f_basename;            */ "filename.tar",
     765             :             /* f_basename_last_only;  */ "filename.tar",
     766             :             /* f_extension;           */ "zip",
     767             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     768             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     769             :             /* f_username;            */ "alexis",
     770             :             /* f_password;            */ "secret",
     771             :             /* f_domain;              */ "simple",
     772             :             /* f_port;                */ "123",
     773             :             /* f_share;               */ "share",
     774             :             /* f_decode;              */ true,
     775             :             /* f_anchor;              */ "test",
     776             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     777             :             /* f_glob;                */ "*path*",
     778             :             /* f_empty;               */ false,
     779             :             /* f_is_deb;              */ false,
     780             :             /* f_is_valid;            */ true,
     781             :             /* f_is_direct;           */ true,
     782             :             /* f_is_absolute;         */ true
     783           1 :         };
     784             : 
     785             :         try
     786             :         {
     787           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     788           1 :             CPPUNIT_ASSERT(!"space in variable name");
     789             :         }
     790           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     791             :         {
     792             :         }
     793             :     }
     794             : 
     795             :     {
     796             :         expected_result result =
     797             :         {
     798             :             /* f_original_filename;   */ "nbs://alexis:@simple:123/share/full/path/filename.tar.zip?var=555#test",
     799             :             /* f_fixed_original_fi... */ NULL,
     800             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     801             :             /* f_path_protocol;       */ "smbs",
     802             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     803             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     804             :             /* f_full_path;           */ "smbs://alexis@simple:123/share/full/path/filename.tar.zip?var=555#test",
     805             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     806             :             /* f_dirname;             */ "/full/path",
     807             :             /* f_dirname_no_drive;    */ "/full/path",
     808             :             /* f_basename;            */ "filename.tar",
     809             :             /* f_basename_last_only;  */ "filename.tar",
     810             :             /* f_extension;           */ "zip",
     811             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     812             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     813             :             /* f_username;            */ "alexis",
     814             :             /* f_password;            */ "secret",
     815             :             /* f_domain;              */ "simple",
     816             :             /* f_port;                */ "123",
     817             :             /* f_share;               */ "share",
     818             :             /* f_decode;              */ true,
     819             :             /* f_anchor;              */ "test",
     820             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     821             :             /* f_glob;                */ "nbs://\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?\?/share/full/path/filename.tar.zip?var=555#test",
     822             :             /* f_empty;               */ false,
     823             :             /* f_is_deb;              */ false,
     824             :             /* f_is_valid;            */ true,
     825             :             /* f_is_direct;           */ true,
     826             :             /* f_is_absolute;         */ true
     827           1 :         };
     828             : 
     829             :         try
     830             :         {
     831           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     832           1 :             CPPUNIT_ASSERT(!"netbios with the username or password missing");
     833             :         }
     834           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     835             :         {
     836             :         }
     837             :     }
     838             : 
     839             :     {
     840             :         expected_result result =
     841             :         {
     842             :             /* f_original_filename;   */ "nbs://simple/",
     843             :             /* f_fixed_original_fi... */ NULL,
     844             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     845             :             /* f_path_protocol;       */ "smbs",
     846             :             /* f_path_only;           */ "/full/path/filename.tar.zip",
     847             :             /* f_path_only_no_drive;  */ "/full/path/filename.tar.zip",
     848             :             /* f_full_path;           */ "smbs://alexis:secret@simple:123/share/full/path/filename.tar.zip?var=555#test",
     849             :             /* f_segments[32];        */ { "full", "path", "filename.tar.zip", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     850             :             /* f_dirname;             */ "/full/path",
     851             :             /* f_dirname_no_drive;    */ "/full/path",
     852             :             /* f_basename;            */ "filename.tar",
     853             :             /* f_basename_last_only;  */ "filename.tar",
     854             :             /* f_extension;           */ "zip",
     855             :             /* f_previous_extension;  */ "zip", // zip is not expected to be used with .tar!
     856             :             /* f_msdos_drive;         */ wpkg_filename::uri_filename::uri_no_msdos_drive,
     857             :             /* f_username;            */ "alexis",
     858             :             /* f_password;            */ "secret",
     859             :             /* f_domain;              */ "simple",
     860             :             /* f_port;                */ "123",
     861             :             /* f_share;               */ "share",
     862             :             /* f_decode;              */ true,
     863             :             /* f_anchor;              */ "test",
     864             :             /* f_query_variables[32]; */ { "var", "555", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     865             :             /* f_glob;                */ "[A-Za-z]bs://simple/",
     866             :             /* f_empty;               */ false,
     867             :             /* f_is_deb;              */ false,
     868             :             /* f_is_valid;            */ true,
     869             :             /* f_is_direct;           */ true,
     870             :             /* f_is_absolute;         */ true
     871           1 :         };
     872             : 
     873             :         try
     874             :         {
     875           1 :             wpkg_filename::uri_filename filename(result.f_original_filename);
     876           1 :             CPPUNIT_ASSERT(!"netbios path without shared name");
     877             :         }
     878           1 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
     879             :         {
     880             :         }
     881             :     }
     882             : 
     883             :     {
     884             :         expected_result result =
     885             :         {
     886             :             /* f_original_filename;   */ "c:\\simple\\full\\path\\with\\bzip2-extension.tar.bz2",
     887             :             /* f_fixed_original_fi... */ NULL,
     888             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     889             :             /* f_path_protocol;       */ "file",
     890             :             /* f_path_only;           */ "C:/simple/full/path/with/bzip2-extension.tar.bz2",
     891             :             /* f_path_only_no_drive;  */ "/simple/full/path/with/bzip2-extension.tar.bz2",
     892             :             /* f_full_path;           */ "C:/simple/full/path/with/bzip2-extension.tar.bz2",
     893             :             /* f_segments[32];        */ { "simple", "full", "path", "with", "bzip2-extension.tar.bz2", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     894             :             /* f_dirname;             */ "C:/simple/full/path/with",
     895             :             /* f_dirname_no_drive;    */ "/simple/full/path/with",
     896             :             /* f_basename;            */ "bzip2-extension",
     897             :             /* f_basename_last_only;  */ "bzip2-extension.tar",
     898             :             /* f_extension;           */ "bz2",
     899             :             /* f_previous_extension;  */ "tar",
     900             :             /* f_msdos_drive;         */ 'C',
     901             :             /* f_username;            */ "",
     902             :             /* f_password;            */ "",
     903             :             /* f_domain;              */ "",
     904             :             /* f_port;                */ "",
     905             :             /* f_share;               */ "",
     906             :             /* f_decode;              */ false,
     907             :             /* f_anchor;              */ "",
     908             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     909             :             /* f_glob;                */ "/*.bz2",
     910             :             /* f_empty;               */ false,
     911             :             /* f_is_deb;              */ false,
     912             :             /* f_is_valid;            */ true,
     913             :             /* f_is_direct;           */ true,
     914             :             /* f_is_absolute;         */ true
     915           1 :         };
     916             : 
     917           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     918           1 :         check(filename, result);
     919             :     }
     920             : 
     921             :     {
     922             :         expected_result result =
     923             :         {
     924             :             /* f_original_filename;   */ "J:\\windows\\\\path\\and///Unix/too.tar.bz2",
     925             :             /* f_fixed_original_fi... */ NULL,
     926             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     927             :             /* f_path_protocol;       */ "file",
     928             :             /* f_path_only;           */ "J:/windows/path/and/Unix/too.tar.bz2",
     929             :             /* f_path_only_no_drive;  */ "/windows/path/and/Unix/too.tar.bz2",
     930             :             /* f_full_path;           */ "J:/windows/path/and/Unix/too.tar.bz2",
     931             :             /* f_segments[32];        */ { "windows", "path", "and", "Unix", "too.tar.bz2", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     932             :             /* f_dirname;             */ "J:/windows/path/and/Unix",
     933             :             /* f_dirname_no_drive;    */ "/windows/path/and/Unix",
     934             :             /* f_basename;            */ "too",
     935             :             /* f_basename_last_only;  */ "too.tar",
     936             :             /* f_extension;           */ "bz2",
     937             :             /* f_previous_extension;  */ "tar",
     938             :             /* f_msdos_drive;         */ 'J',
     939             :             /* f_username;            */ "",
     940             :             /* f_password;            */ "",
     941             :             /* f_domain;              */ "",
     942             :             /* f_port;                */ "",
     943             :             /* f_share;               */ "",
     944             :             /* f_decode;              */ false,
     945             :             /* f_anchor;              */ "",
     946             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     947             :             /* f_glob;                */ "\\windows\\*\\and/Unix/too.tar.bz2",
     948             :             /* f_empty;               */ false,
     949             :             /* f_is_deb;              */ false,
     950             :             /* f_is_valid;            */ true,
     951             :             /* f_is_direct;           */ true,
     952             :             /* f_is_absolute;         */ true
     953           1 :         };
     954             : 
     955           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     956           1 :         check(filename, result);
     957             :     }
     958             : 
     959             :     {
     960             :         expected_result result =
     961             :         {
     962             :             /* f_original_filename;   */ "k:non-absolute\\windows\\\\path\\and///UNIX/too.tar.bz2",
     963             :             /* f_fixed_original_fi... */ NULL,
     964             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
     965             :             /* f_path_protocol;       */ "file",
     966             :             /* f_path_only;           */ "K:non-absolute/windows/path/and/UNIX/too.tar.bz2",
     967             :             /* f_path_only_no_drive;  */ "non-absolute/windows/path/and/UNIX/too.tar.bz2",
     968             :             /* f_full_path;           */ "K:non-absolute/windows/path/and/UNIX/too.tar.bz2",
     969             :             /* f_segments[32];        */ { "non-absolute", "windows", "path", "and", "UNIX", "too.tar.bz2", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     970             :             /* f_dirname;             */ "K:non-absolute/windows/path/and/UNIX",
     971             :             /* f_dirname_no_drive;    */ "non-absolute/windows/path/and/UNIX",
     972             :             /* f_basename;            */ "too",
     973             :             /* f_basename_last_only;  */ "too.tar",
     974             :             /* f_extension;           */ "bz2",
     975             :             /* f_previous_extension;  */ "tar",
     976             :             /* f_msdos_drive;         */ 'K',
     977             :             /* f_username;            */ "",
     978             :             /* f_password;            */ "",
     979             :             /* f_domain;              */ "",
     980             :             /* f_port;                */ "",
     981             :             /* f_share;               */ "",
     982             :             /* f_decode;              */ false,
     983             :             /* f_anchor;              */ "",
     984             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     985             :             /* f_glob;                */ "non-*\\windows/path\\and/*\\too.tar.bz2",
     986             :             /* f_empty;               */ false,
     987             :             /* f_is_deb;              */ false,
     988             :             /* f_is_valid;            */ true,
     989             :             /* f_is_direct;           */ true,
     990             :             /* f_is_absolute;         */ false
     991           1 :         };
     992             : 
     993           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
     994           1 :         check(filename, result);
     995             :     }
     996             : 
     997             :     {
     998             :         expected_result result =
     999             :         {
    1000             :             /* f_original_filename;   */ "z:non-absolute\\wind:ows\\\\path\\and///UNIX/*.tar.bz2",
    1001             :             /* f_fixed_original_fi... */ NULL,
    1002             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
    1003             :             /* f_path_protocol;       */ "file",
    1004             :             /* f_path_only;           */ "Z:non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1005             :             /* f_path_only_no_drive;  */ "non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1006             :             /* f_full_path;           */ "Z:non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1007             :             /* f_segments[32];        */ { "non-absolute", "wind:ows", "path", "and", "UNIX", "*.tar.bz2", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    1008             :             /* f_dirname;             */ "Z:non-absolute/wind:ows/path/and/UNIX",
    1009             :             /* f_dirname_no_drive;    */ "non-absolute/wind:ows/path/and/UNIX",
    1010             :             /* f_basename;            */ "*",
    1011             :             /* f_basename_last_only;  */ "*.tar",
    1012             :             /* f_extension;           */ "bz2",
    1013             :             /* f_previous_extension;  */ "tar",
    1014             :             /* f_msdos_drive;         */ 'Z',
    1015             :             /* f_username;            */ "",
    1016             :             /* f_password;            */ "",
    1017             :             /* f_domain;              */ "",
    1018             :             /* f_port;                */ "",
    1019             :             /* f_share;               */ "",
    1020             :             /* f_decode;              */ false,
    1021             :             /* f_anchor;              */ "",
    1022             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    1023             :             /* f_glob;                */ "non?absolute\\wind?ows\\path[ -z]and/U?IX/*.tar.bz2",
    1024             :             /* f_empty;               */ false,
    1025             :             /* f_is_deb;              */ false,
    1026             :             /* f_is_valid;            */ true,
    1027             :             /* f_is_direct;           */ true,
    1028             :             /* f_is_absolute;         */ false
    1029           1 :         };
    1030             : 
    1031           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
    1032           1 :         check(filename, result);
    1033             :     }
    1034             : 
    1035             :     {
    1036             :         expected_result result =
    1037             :         {
    1038             :             /* f_original_filename;   */ "f:non-absolute\\wind:ows\\\\path\\and///UNIX/*.tar.bz2",
    1039             :             /* f_fixed_original_fi... */ NULL,
    1040             :             /* f_path_type;           */ wpkg_filename::uri_filename::uri_type_direct,
    1041             :             /* f_path_protocol;       */ "file",
    1042             :             /* f_path_only;           */ "/opt/wpkg/m2osw/packages/non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1043             :             /* f_path_only_no_drive;  */ "non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1044             :             /* f_full_path;           */ "/opt/wpkg/m2osw/packages/non-absolute/wind:ows/path/and/UNIX/*.tar.bz2",
    1045             :             /* f_segments[32];        */ { "non-absolute", "wind:ows", "path", "and", "UNIX", "*.tar.bz2", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    1046             :             /* f_dirname;             */ "/opt/wpkg/m2osw/packages/non-absolute/wind:ows/path/and/UNIX",
    1047             :             /* f_dirname_no_drive;    */ "non-absolute/wind:ows/path/and/UNIX",
    1048             :             /* f_basename;            */ "*",
    1049             :             /* f_basename_last_only;  */ "*.tar",
    1050             :             /* f_extension;           */ "bz2",
    1051             :             /* f_previous_extension;  */ "tar",
    1052             :             /* f_msdos_drive;         */ 'F',
    1053             :             /* f_username;            */ "",
    1054             :             /* f_password;            */ "",
    1055             :             /* f_domain;              */ "",
    1056             :             /* f_port;                */ "",
    1057             :             /* f_share;               */ "",
    1058             :             /* f_decode;              */ false,
    1059             :             /* f_anchor;              */ "",
    1060             :             /* f_query_variables[32]; */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    1061             :             /* f_glob;                */ "non?absolute\\wind?ows\\path[ -z]and/U?IX/*.tar.bz2",
    1062             :             /* f_empty;               */ false,
    1063             :             /* f_is_deb;              */ false,
    1064             :             /* f_is_valid;            */ true,
    1065             :             /* f_is_direct;           */ true,
    1066             :             /* f_is_absolute;         */ false
    1067           1 :         };
    1068             : 
    1069           1 :         wpkg_filename::uri_filename filename(result.f_original_filename);
    1070           1 :         check(filename, result);
    1071             :     }
    1072             : 
    1073           1 : }
    1074             : 
    1075             : 
    1076             : namespace
    1077             : {
    1078             :     const char *bad_filenames[] =
    1079             :     {
    1080             :         "/invalid/COM1/filename",
    1081             :         "/invalid/com2/filename",
    1082             :         "/invalid/Com3/filename",
    1083             :         "/invalid/cOm4/filename",
    1084             :         "/invalid/cOM5/filename",
    1085             :         "/invalid/COm6/filename",
    1086             :         "/invalid/CoM7/filename",
    1087             :         "/invalid/coM8/filename",
    1088             :         "/invalid/COM9/filename",
    1089             :         "/invalid/LPT1/filename",
    1090             :         "/invalid/lpt2/filename",
    1091             :         "/invalid/Lpt3/filename",
    1092             :         "/invalid/lPt4/filename",
    1093             :         "/invalid/lPT5/filename",
    1094             :         "/invalid/LPt6/filename",
    1095             :         "/invalid/LpT7/filename",
    1096             :         "/invalid/lpT8/filename",
    1097             :         "/invalid/LPT9/filename",
    1098             :         "/Aux/filename",
    1099             :         "cOn",
    1100             :         "/bad/NUL",
    1101             :         "bad/NUL",
    1102             :         "NUL/test",
    1103             :         "/prn/"
    1104             :     };
    1105             : 
    1106             :     // Note: The : * and ? characters are accepted as versions need :
    1107             :     //       on unices and patterns use * and ? here and there
    1108             :     const char *bad_characters[] =
    1109             :     {
    1110             :         "/really/invalid/file\"name",
    1111             :         "/really/invalid/file<name",
    1112             :         "/really/invalid/file>name",
    1113             :         "/really/invalid/file|name",
    1114             : 
    1115             :         "/in-valid/file\"name",
    1116             :         "/in-valid/file<name",
    1117             :         "/in-valid/file>name",
    1118             :         "/in-valid/file|name",
    1119             : 
    1120             :         "/invalid_/file\"name/here",
    1121             :         "/invalid_/file<name/here/too",
    1122             :         "/invalid_/file>name/",
    1123             :         "/invalid_/file|name/here",
    1124             : 
    1125             :         "file\"name",
    1126             :         "file<name",
    1127             :         "file>name",
    1128             :         "file|name",
    1129             : 
    1130             :         " filename",
    1131             :         "filename ",
    1132             :         " filename ",
    1133             : 
    1134             :         "/file\"name",
    1135             :         "/file<name",
    1136             :         "/file>name",
    1137             :         "/file|name",
    1138             : 
    1139             :         "file\"name/file*name",
    1140             :         "file<name/plus",
    1141             :         "file>name/minus",
    1142             :         "file|name/more/path"
    1143             :     };
    1144             : }
    1145             : 
    1146           1 : void URIFilenameUnitTests::invalid_ms_paths()
    1147             : {
    1148          25 :     for(size_t i(0); i < sizeof(bad_filenames) / sizeof(bad_filenames[0]); ++i)
    1149             :     {
    1150             :         try
    1151             :         {
    1152          24 :             wpkg_filename::uri_filename filename(bad_filenames[i]);
    1153          24 :             CPPUNIT_ASSERT_MESSAGE(bad_filenames[i], !"invalid MS-Windows filename accepted");
    1154             :         }
    1155          24 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
    1156             :         {
    1157             :         }
    1158             :     }
    1159             : 
    1160          28 :     for(size_t i(0); i < sizeof(bad_characters) / sizeof(bad_characters[0]); ++i)
    1161             :     {
    1162             :         try
    1163             :         {
    1164          27 :             wpkg_filename::uri_filename filename(bad_characters[i]);
    1165          27 :             CPPUNIT_ASSERT_MESSAGE(bad_characters[i], !"invalid MS-Windows character accepted");
    1166             :         }
    1167          27 :         catch(const wpkg_filename::wpkg_filename_exception_parameter&)
    1168             :         {
    1169             :         }
    1170             :     }
    1171           1 : }
    1172             : 
    1173             : 
    1174             : 
    1175             : namespace
    1176             : {
    1177             :     const char *bad_uri[][2] =
    1178             :     {
    1179             :         { "http://www.m2osw.com/bad/var?=555", "a URI query string variable name cannot be empty in" },
    1180             :         { "http://www.m2osw.com/bad/var?this one=555", "a URI query string variable name cannot include a space in" },
    1181             :         { "~username/not-legal", "tilde + username is not supported; '~/' was expected at the start of your filename" },
    1182             :         { "smb://domain.only.is.not.enough", "smb paths require at least the share name not found in" },
    1183             :         { "smb://domain.only.is.not.enough/", "smb paths require at least the share name not found in" },
    1184             :         { "http://alexis:@www.m2osw.com/", "when specifying a username and password, both must be valid (not empty)" },
    1185             :         { "http://:topsecret@www.m2osw.com/", "when specifying a username and password, both must be valid (not empty)" }
    1186             :     };
    1187             : }
    1188             : 
    1189             : 
    1190           1 : void URIFilenameUnitTests::invalid_uri()
    1191             : {
    1192           1 :     const char *home = getenv("HOME");
    1193           1 :     putenv(const_cast<char *>("HOME=/home/wpkg"));
    1194           8 :     for(size_t i(0); i < sizeof(bad_uri) / sizeof(bad_uri[0]); ++i)
    1195             :     {
    1196             :         try
    1197             :         {
    1198           7 :             wpkg_filename::uri_filename filename(bad_uri[i][0]);
    1199           0 :             CPPUNIT_ASSERT_MESSAGE(bad_uri[i][0], !"invalid URI filename accepted");
    1200             :         }
    1201          14 :         catch(const wpkg_filename::wpkg_filename_exception_parameter& e)
    1202             :         {
    1203           7 :             CPPUNIT_ASSERT_MESSAGE(std::string("got \"") + e.what() + "\", expected \"" + bad_uri[i][1] + "\"", std::string(e.what()).substr(0, strlen(bad_uri[i][1])) == bad_uri[i][1]);
    1204             :         }
    1205             :     }
    1206           1 :     putenv(const_cast<char *>("HOME=~/bad/home"));
    1207             :     try
    1208             :     {
    1209           1 :         wpkg_filename::uri_filename filename("~/fail/because/of/home");
    1210           0 :         CPPUNIT_ASSERT_MESSAGE("~/fail/because/of/home", !"invalid URI filename accepted");
    1211             :     }
    1212           2 :     catch(const wpkg_filename::wpkg_filename_exception_parameter& e)
    1213             :     {
    1214           1 :         CPPUNIT_ASSERT_MESSAGE(std::string("got \"") + e.what() + "\", expected \"$HOME path cannot itself start with a tilde (~).\"", std::string(e.what()) == "$HOME path cannot itself start with a tilde (~).");
    1215             :     }
    1216           1 :     putenv(const_cast<char *>("HOME=bad/home"));
    1217             :     try
    1218             :     {
    1219           1 :         wpkg_filename::uri_filename filename("~/fail/because/of/home");
    1220           0 :         CPPUNIT_ASSERT_MESSAGE("~/fail/because/of/home", !"invalid URI filename accepted");
    1221             :     }
    1222           2 :     catch(const wpkg_filename::wpkg_filename_exception_parameter& e)
    1223             :     {
    1224           1 :         CPPUNIT_ASSERT_MESSAGE(std::string("got \"") + e.what() + "\", expected \"$HOME path is not absolute; we cannot safely replace the ~ character.\"", std::string(e.what()) == "$HOME path is not absolute; we cannot safely replace the ~ character.");
    1225             :     }
    1226           1 :     putenv(const_cast<char *>(home));
    1227           1 : }
    1228             : 
    1229             : 
    1230             : namespace
    1231             : {
    1232             :     const char *common_segment_samples[][4] =
    1233             :     {
    1234             :         {
    1235             :             "test/common/segments/removal",
    1236             :             "test/common/segment/removal",
    1237             :             "segments/removal",
    1238             :             "segment/removal"
    1239             :         },
    1240             :         {
    1241             :             "c:test/common/segments/removal",
    1242             :             "c:test/common/segment/removal",
    1243             :             "segments/removal",
    1244             :             "segment/removal"
    1245             :         },
    1246             :         {
    1247             :             "c:test/common/segments/removal",
    1248             :             "d:test/common/segment/removal",
    1249             :             "C:test/common/segments/removal",
    1250             :             "D:test/common/segment/removal"
    1251             :         },
    1252             :         {
    1253             :             "/test/common/segments/removal",
    1254             :             "/test/common/segment/removal",
    1255             :             "segments/removal",
    1256             :             "segment/removal"
    1257             :         },
    1258             :         {
    1259             :             "c:/test/common/segments/removal",
    1260             :             "c:/test/common/segment/removal",
    1261             :             "segments/removal",
    1262             :             "segment/removal"
    1263             :         },
    1264             :         {
    1265             :             "c:/test/common/segments/removal",
    1266             :             "d:/test/common/segment/removal",
    1267             :             "C:/test/common/segments/removal",
    1268             :             "D:/test/common/segment/removal"
    1269             :         },
    1270             :         {
    1271             :             "c:test/common/segments/removal",
    1272             :             "d:test/common/segment/removal",
    1273             :             "C:test/common/segments/removal",
    1274             :             "D:test/common/segment/removal"
    1275             :         },
    1276             :         {
    1277             :             "c:/test/common/segments/removal",
    1278             :             "c:/against/common/segment/removal",
    1279             :             "/test/common/segments/removal",
    1280             :             "/against/common/segment/removal"
    1281             :         },
    1282             :         {
    1283             :             "http://www.m2osw.com/test/common/segments/removal",
    1284             :             "http://www.m2osw.com/test/common/segment/removal",
    1285             :             "segments/removal",
    1286             :             "segment/removal"
    1287             :         },
    1288             :         {
    1289             :             "http://www.m2osw.com:8800/test/common/segments/removal",
    1290             :             "http://www.m2osw.com:8800/test/common/segment/removal",
    1291             :             "segments/removal",
    1292             :             "segment/removal"
    1293             :         },
    1294             :         {
    1295             :             "http://alexis:secret@www.m2osw.com/test/common/segments/removal",
    1296             :             "http://alexis:secret@www.m2osw.com/test/common/segment/removal",
    1297             :             "segments/removal",
    1298             :             "segment/removal"
    1299             :         },
    1300             :         {
    1301             :             "http://alexis:secret@www.m2osw.com:8080/test/common/segments/removal",
    1302             :             "http://alexis:secret@www.m2osw.com:8080/test/common/segment/removal",
    1303             :             "segments/removal",
    1304             :             "segment/removal"
    1305             :         },
    1306             :         {
    1307             :             "http://www.m2osw.com/test/common/segments/removal",
    1308             :             "https://www.m2osw.com/test/common/segment/removal",
    1309             :             "http://www.m2osw.com/test/common/segments/removal",
    1310             :             "https://www.m2osw.com/test/common/segment/removal"
    1311             :         },
    1312             :         {
    1313             :             "http://www.m2osw.com/test/common/segments/removal",
    1314             :             "http://ww2.m2osw.com/test/common/segment/removal",
    1315             :             "http://www.m2osw.com/test/common/segments/removal",
    1316             :             "http://ww2.m2osw.com/test/common/segment/removal"
    1317             :         },
    1318             :         {
    1319             :             "http://www.m2osw.com:80/test/common/segments/removal",
    1320             :             "http://www.m2osw.com/test/common/segment/removal",
    1321             :             "http://www.m2osw.com:80/test/common/segments/removal",
    1322             :             "http://www.m2osw.com/test/common/segment/removal"
    1323             :         },
    1324             :         {
    1325             :             "http://alexis:secret@www.m2osw.com/test/common/segments/removal",
    1326             :             "http://alexis:secretz@www.m2osw.com/test/common/segment/removal",
    1327             :             "http://alexis:secret@www.m2osw.com/test/common/segments/removal",
    1328             :             "http://alexis:secretz@www.m2osw.com/test/common/segment/removal"
    1329             :         },
    1330             :         {
    1331             :             "http://alexis:secret@www.m2osw.com/test/common/segments/removal",
    1332             :             "http://alexif:secret@www.m2osw.com/test/common/segment/removal",
    1333             :             "http://alexis:secret@www.m2osw.com/test/common/segments/removal",
    1334             :             "http://alexif:secret@www.m2osw.com/test/common/segment/removal"
    1335             :         }
    1336             :     };
    1337             : }
    1338             : 
    1339           1 : void URIFilenameUnitTests::common_segments()
    1340             : {
    1341          18 :     for(size_t i(0); i < sizeof(common_segment_samples) / sizeof(common_segment_samples[0]); ++i)
    1342             :     {
    1343          17 :         wpkg_filename::uri_filename a(common_segment_samples[i][0]);
    1344          17 :         wpkg_filename::uri_filename b(common_segment_samples[i][1]);
    1345          17 :         wpkg_filename::uri_filename c(a.remove_common_segments(b));
    1346          17 :         CPPUNIT_ASSERT_MESSAGE("got: \"" + c.full_path() + "\", expected: \"" + common_segment_samples[i][2] + "\"", c.full_path() == common_segment_samples[i][2]);
    1347          17 :         wpkg_filename::uri_filename d(b.remove_common_segments(a));
    1348          17 :         CPPUNIT_ASSERT_MESSAGE("got: \"" + d.full_path() + "\", expected: \"" + common_segment_samples[i][3] + "\"", d.full_path() == common_segment_samples[i][3]);
    1349          17 :     }
    1350           4 : }
    1351             : 
    1352             : 
    1353             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.9

The wpkg tool is an open source tool created by Made to Order Software Corporation.