gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/overlay/win32longpath.test (about)

     1  # 2013 August 27
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  # This file implements regression tests for SQLite library.  The
    12  # focus of this script is testing the file name handling provided
    13  # by the "win32-longpath" VFS.
    14  #
    15  
    16  if {$tcl_platform(platform)!="windows"} return
    17  
    18  proc get_goversion {} {
    19    if {$::tcl_platform(platform) eq "windows"} {
    20      if {[info exists ::env(ComSpec)]} {
    21        set comSpec $::env(ComSpec)
    22      } else {
    23        # NOTE: Hard-code the typical default value.
    24        set comSpec {C:\Windows\system32\cmd.exe}
    25      }
    26      return [string map [list \\ /] \
    27          [string trim [exec -- $comSpec /c go version ]]]
    28    } else {
    29      return [go version]
    30    }
    31  }
    32  
    33  set goVer [get_goversion]
    34  set testdir [file dirname $argv0]
    35  source $testdir/tester.tcl
    36  set testprefix win32longpath
    37  
    38  do_test 1.0 {
    39    file_control_vfsname db
    40  } win32
    41  
    42  db close
    43  set rawPath [get_pwd]
    44  set path [file nativename $rawPath]
    45  sqlite3 db [file join $path test.db] -vfs win32-longpath
    46  
    47  do_test 1.1 {
    48    file_control_vfsname db
    49  } win32-longpath
    50  
    51  do_test 1.2 {
    52    db eval {
    53      BEGIN EXCLUSIVE;
    54      CREATE TABLE t1(x);
    55      INSERT INTO t1 VALUES(1);
    56      INSERT INTO t1 VALUES(2);
    57      INSERT INTO t1 VALUES(3);
    58      INSERT INTO t1 VALUES(4);
    59      SELECT x FROM t1 ORDER BY x;
    60      COMMIT;
    61    }
    62  } {1 2 3 4}
    63  
    64  set longPath(1) \\\\?\\$path\\[pid]
    65  set uriPath(1a) %5C%5C%3F%5C$path\\[pid]
    66  set uriPath(1b) %5C%5C%3F%5C$rawPath/[pid]
    67  
    68  make_win32_dir $longPath(1)
    69  
    70  set longPath(2) $longPath(1)\\[string repeat X 255]
    71  set uriPath(2a) $uriPath(1a)\\[string repeat X 255]
    72  set uriPath(2b) $uriPath(1b)/[string repeat X 255]
    73  
    74  make_win32_dir $longPath(2)
    75  
    76  set longPath(3) $longPath(2)\\[string repeat Y 255]
    77  set uriPath(3a) $uriPath(2a)\\[string repeat Y 255]
    78  set uriPath(3b) $uriPath(2b)/[string repeat Y 255]
    79  
    80  make_win32_dir $longPath(3)
    81  
    82  set fileName $longPath(3)\\test.db
    83  
    84  set uri(1a) file:$uriPath(3a)\\test.db
    85  set uri(1b) file:$uriPath(3b)/test.db
    86  set uri(1c) file:///$uriPath(3a)\\test.db
    87  set uri(1d) file:///$uriPath(3b)/test.db
    88  set uri(1e) file://localhost/$uriPath(3a)\\test.db
    89  set uri(1f) file://localhost/$uriPath(3b)/test.db
    90  
    91  # Starting with Windows 10 v1607 OSBuild 14393, long paths are supported
    92  # Go 1.17+ utilizes this capability and a result this test will fail
    93  # because the path CAN be created.
    94  
    95  if { ([string first "1.17" $goVer] < 0) && ([string first "1.18" $goVer] < 0) && ([string first "1.19" $goVer] < 0) } {
    96  
    97    do_test 1.3 {
    98      list [catch {sqlite3 db2 [string range $fileName 4 end]} msg] $msg
    99    } {1 {unable to open database file}}
   100  } else {
   101      puts "win32longpath-1.3... skipped"
   102  }
   103  
   104  sqlite3 db3 $fileName -vfs win32-longpath
   105  
   106  do_test 1.4 {
   107    db3 eval {
   108      BEGIN EXCLUSIVE;
   109      CREATE TABLE t1(x);
   110      INSERT INTO t1 VALUES(5);
   111      INSERT INTO t1 VALUES(6);
   112      INSERT INTO t1 VALUES(7);
   113      INSERT INTO t1 VALUES(8);
   114      SELECT x FROM t1 ORDER BY x;
   115      COMMIT;
   116    }
   117  } {5 6 7 8}
   118  
   119  db3 close
   120  # puts "  Database exists \{[exists_win32_path $fileName]\}"
   121  
   122  sqlite3 db3 $fileName -vfs win32-longpath
   123  
   124  do_test 1.5 {
   125    db3 eval {
   126      PRAGMA journal_mode = WAL;
   127    }
   128  } {wal}
   129  
   130  do_test 1.6 {
   131    db3 eval {
   132      BEGIN EXCLUSIVE;
   133      INSERT INTO t1 VALUES(9);
   134      INSERT INTO t1 VALUES(10);
   135      INSERT INTO t1 VALUES(11);
   136      INSERT INTO t1 VALUES(12);
   137      SELECT x FROM t1 ORDER BY x;
   138      COMMIT;
   139    }
   140  } {5 6 7 8 9 10 11 12}
   141  
   142  db3 close
   143  # puts "  Database exists \{[exists_win32_path $fileName]\}"
   144  
   145  foreach tn {1a 1b 1c 1d 1e 1f} {
   146    sqlite3 db3 $uri($tn) -vfs win32-longpath -uri 1 -translatefilename 0
   147  
   148    do_test 1.7.$tn {
   149      db3 eval {
   150        SELECT x FROM t1 ORDER BY x;
   151      }
   152    } {5 6 7 8 9 10 11 12}
   153  
   154    db3 close
   155  }
   156  
   157  do_delete_win32_file $fileName
   158  # puts "  Files remaining \{[find_win32_file $longPath(3)\\*]\}"
   159  
   160  do_remove_win32_dir $longPath(3)
   161  do_remove_win32_dir $longPath(2)
   162  do_remove_win32_dir $longPath(1)
   163  
   164  finish_test