os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/ptrchng.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/ptrchng.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,223 @@
     1.4 +# 2007 April 27
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.
    1.15 +#
    1.16 +# The focus of the tests in this file are to verify that the
    1.17 +# underlying TEXT or BLOB representation of an sqlite3_value
    1.18 +# changes appropriately when APIs from the following set are
    1.19 +# called:
    1.20 +#
    1.21 +#     sqlite3_value_text()
    1.22 +#     sqlite3_value_text16()
    1.23 +#     sqlite3_value_blob()
    1.24 +#     sqlite3_value_bytes()
    1.25 +#     sqlite3_value_bytes16()
    1.26 +#
    1.27 +# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $
    1.28 +
    1.29 +set testdir [file dirname $argv0]
    1.30 +source $testdir/tester.tcl
    1.31 +
    1.32 +ifcapable !bloblit {
    1.33 +  finish_test
    1.34 +  return
    1.35 +}
    1.36 +
    1.37 +# Register the "pointer_change" SQL function.
    1.38 +#
    1.39 +sqlite3_create_function db
    1.40 +
    1.41 +do_test ptrchng-1.1 {
    1.42 +  execsql {
    1.43 +    CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
    1.44 +    INSERT INTO t1 VALUES(1, 'abc');
    1.45 +    INSERT INTO t1 VALUES(2, 
    1.46 +       'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
    1.47 +    INSERT INTO t1 VALUES(3, x'626c6f62');
    1.48 +    INSERT INTO t1 VALUES(4,
    1.49 + x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
    1.50 +    );
    1.51 +    SELECT count(*) FROM t1;
    1.52 +  }
    1.53 +} {4}
    1.54 +
    1.55 +# For the short entries that fit in the Mem.zBuf[], the pointer should
    1.56 +# never change regardless of what type conversions occur.
    1.57 +#
    1.58 +# UPDATE: No longer true, as Mem.zBuf[] has been removed.
    1.59 +#
    1.60 +do_test ptrchng-2.1 {
    1.61 +  execsql {
    1.62 +    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
    1.63 +  }
    1.64 +} {0}
    1.65 +do_test ptrchng-2.2 {
    1.66 +  execsql {
    1.67 +    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
    1.68 +  }
    1.69 +} {0}
    1.70 +ifcapable utf16 {
    1.71 +  do_test ptrchng-2.3 {
    1.72 +    execsql {
    1.73 +      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
    1.74 +    }
    1.75 +  } {1}
    1.76 +  do_test ptrchng-2.4 {
    1.77 +    execsql {
    1.78 +      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
    1.79 +    }
    1.80 +  } {1}
    1.81 +  do_test ptrchng-2.5 {
    1.82 +    execsql {
    1.83 +      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
    1.84 +    }
    1.85 +  } {0}
    1.86 +  do_test ptrchng-2.6 {
    1.87 +    execsql {
    1.88 +      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
    1.89 +    }
    1.90 +  } {1}
    1.91 +}
    1.92 +do_test ptrchng-2.11 {
    1.93 +  execsql {
    1.94 +    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
    1.95 +  }
    1.96 +} {0}
    1.97 +do_test ptrchng-2.12 {
    1.98 +  execsql {
    1.99 +    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
   1.100 +  }
   1.101 +} {0}
   1.102 +ifcapable utf16 {
   1.103 +  do_test ptrchng-2.13 {
   1.104 +    execsql {
   1.105 +      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
   1.106 +    }
   1.107 +  } {1}
   1.108 +  do_test ptrchng-2.14 {
   1.109 +    execsql {
   1.110 +      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
   1.111 +    }
   1.112 +  } {1}
   1.113 +  do_test ptrchng-2.15 {
   1.114 +    execsql {
   1.115 +      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
   1.116 +    }
   1.117 +  } {0}
   1.118 +  do_test ptrchng-2.16 {
   1.119 +    execsql {
   1.120 +      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
   1.121 +    }
   1.122 +  } {1}
   1.123 +}
   1.124 +
   1.125 +# For the long entries that do not fit in the Mem.zBuf[], the pointer
   1.126 +# should change sometimes.
   1.127 +#
   1.128 +do_test ptrchng-3.1 {
   1.129 +  execsql {
   1.130 +    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
   1.131 +  }
   1.132 +} {0}
   1.133 +do_test ptrchng-3.2 {
   1.134 +  execsql {
   1.135 +    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
   1.136 +  }
   1.137 +} {0}
   1.138 +ifcapable utf16 {
   1.139 +  do_test ptrchng-3.3 {
   1.140 +    execsql {
   1.141 +      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
   1.142 +    }
   1.143 +  } {1}
   1.144 +  do_test ptrchng-3.4 {
   1.145 +    execsql {
   1.146 +      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
   1.147 +    }
   1.148 +  } {1}
   1.149 +  do_test ptrchng-3.5 {
   1.150 +    execsql {
   1.151 +      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
   1.152 +    }
   1.153 +  } {0}
   1.154 +  do_test ptrchng-3.6 {
   1.155 +    execsql {
   1.156 +      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
   1.157 +    }
   1.158 +  } {1}
   1.159 +}
   1.160 +do_test ptrchng-3.11 {
   1.161 +  execsql {
   1.162 +    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
   1.163 +  }
   1.164 +} {0}
   1.165 +do_test ptrchng-3.12 {
   1.166 +  execsql {
   1.167 +    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
   1.168 +  }
   1.169 +} {0}
   1.170 +ifcapable utf16 {
   1.171 +  do_test ptrchng-3.13 {
   1.172 +    execsql {
   1.173 +      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
   1.174 +    }
   1.175 +  } {1}
   1.176 +  do_test ptrchng-3.14 {
   1.177 +    execsql {
   1.178 +      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
   1.179 +    }
   1.180 +  } {1}
   1.181 +  do_test ptrchng-3.15 {
   1.182 +    execsql {
   1.183 +      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
   1.184 +    }
   1.185 +  } {0}
   1.186 +  do_test ptrchng-3.16 {
   1.187 +    execsql {
   1.188 +      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
   1.189 +    }
   1.190 +  } {1}
   1.191 +}
   1.192 +
   1.193 +# A call to _bytes() should never reformat a _text() or _blob().
   1.194 +#
   1.195 +do_test ptrchng-4.1 {
   1.196 +  execsql {
   1.197 +    SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
   1.198 +  }
   1.199 +} {0 0 0 0}
   1.200 +do_test ptrchng-4.2 {
   1.201 +  execsql {
   1.202 +    SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
   1.203 +  }
   1.204 +} {0 0 0 0}
   1.205 +
   1.206 +# A call to _blob() should never trigger a reformat
   1.207 +#
   1.208 +do_test ptrchng-5.1 {
   1.209 +  execsql {
   1.210 +    SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
   1.211 +  }
   1.212 +} {0 0 0 0}
   1.213 +ifcapable utf16 {
   1.214 +  do_test ptrchng-5.2 {
   1.215 +    execsql {
   1.216 +      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
   1.217 +    }
   1.218 +  } {0 0 0 0}
   1.219 +  do_test ptrchng-5.3 {
   1.220 +    execsql {
   1.221 +      SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
   1.222 +    }
   1.223 +  } {0 0 0 0}
   1.224 +}
   1.225 +
   1.226 +finish_test