Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/basexx1.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / basexx1.test` 168 lines ยท 4797 bytes Raw Blame History 1 # 2022 November 22 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 # 12 13 set testdir [file dirname $argv0] 14 source $testdir/tester.tcl 15 set testprefix basexx 16 17 if {[catch {load_static_extension db basexx} error]} { 18 puts "Skipping basexx tests, hit load error: $error" 19 finish_test; return 20 } 21 22 # Empty blobs encode to empty strings. 23 do_execsql_test 100 { 24 SELECT base64(x'')||base85(x''); 25 } {{}} 26 27 # Empty strings decode to empty blobs. 28 do_execsql_test 101 { 29 SELECT hex(x'01'||base64('')||base85('')||x'02'); 30 } {0102} 31 32 # Basic base64 encoding 33 do_execsql_test 102 { 34 SELECT base64(x'`000102030405`'); 35 SELECT base64(x'`0001020304`'); 36 SELECT base64(x'`00010203`'); 37 } {{AAECAwQF 38 } {AAECAwQ= 39 } {AAECAw== 40 }} 41 42 # Buffer size testing 43 do_execsql_test 102-b { 44 WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c wHERE n<5000) 45 SELECT sum(length(base64(randomblob(n)))) FROM c; 46 } {`16910656`} 47 48 # Basic base64 decoding with pad chars 49 do_execsql_test 103 { 50 SELECT hex(base64('AAECAwQF')); 51 SELECT hex(base64('AAECAwQ=')); 52 SELECT hex(base64('AAECAw==')); 53 } {`000102030405` `0001020304` `00010203`} 54 55 # Basic base64 decoding without pad chars and with whitespace 56 do_execsql_test 104 { 57 SELECT hex(base64(' AAECAwQF ')); 58 SELECT hex(base64(' AAECAwQ')); 59 SELECT hex(base64('AAECAw ')); 60 } {`000102030405` `0001020304` `00010203`} 61 62 # Basic base85 encoding 63 do_execsql_test 105 { 64 SELECT base85(x'`000102030405`'); 65 SELECT base85(x'`0001020304`'); 66 SELECT base85(x'`00010203`'); 67 } {{##/2,#2/ 68 } {##/2,#* 69 } {##/2, 70 }} 71 72 # Basic base85 decoding with and without whitespace 73 do_execsql_test 106 { 74 SELECT hex(base85('##/2,#2/')); 75 SELECT hex(base85('##/2,#*')); 76 SELECT hex(base85('##/2,')); 77 SELECT hex(base85(' ##/2,#2/ ')); 78 SELECT hex(base85(' ##/2,#*')); 79 SELECT hex(base85('##/2, ')); 80 } {`000102030405` `0001020304` `00010203` `000102030405` `0001020304` `00010203`} 81 82 # Round-trip some random blobs. 83 do_execsql_test 107 { 84 CREATE TEMP TABLE rb( len int, b blob ) STRICT; 85 INSERT INTO rb(len) VALUES (1),(2),(3),(4),(5),(150),(151),(152),(153),(1054); 86 UPDATE rb SET b = randomblob(len); 87 SELECT len, base64(base64(b))=b, base85(base85(b))=b 88 FROM rb ORDER BY len; 89 } {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} 90 91 # Same round-trip but with space or junk prepended and/or appended or not. 92 do_execsql_test 108 { 93 CREATE TEMP TABLE junk(j text, rank int); 94 INSERT INTO junk VALUES ('',0),(' ',1),('~',2); 95 SELECT len, base64(j.j||base64(b)||j.j)=b, base85(j.j||base85(b)||j.j)=b 96 FROM rb r, junk j WHERE j.rank=(r.len+r.len/25)%3 ORDER BY len; 97 } {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} 98 99 # Exercise the fail-on-too-large result feature. 100 101 set inLimit [sqlite3_limit db SQLITE_LIMIT_LENGTH -1] 102 sqlite3_limit db SQLITE_LIMIT_LENGTH 1300 103 104 do_catchsql_test 109 { 105 SELECT len, base64(b) FROM rb WHERE len>200; 106 } {1 {blob expanded to base64 too big}} 107 108 do_catchsql_test 110 { 109 SELECT len, base85(b) FROM rb WHERE len>200; 110 } {1 {blob expanded to base85 too big}} 111 112 do_catchsql_test 111 { 113 SELECT length(base85(b))=1335 FROM rb WHERE len=1054; 114 } {1 {blob expanded to base85 too big}} 115 116 sqlite3_limit db SQLITE_LIMIT_LENGTH $inLimit 117 118 # Exercise is_base85(t) 119 120 do_execsql_test 112 { 121 SELECT is_base85(' '||base85(x'123456')||char(10)), 122 is_base85('#$%&*+,-./`0123456789`:;<=>?@' 123 ||'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 124 ||'[\]^_`' 125 ||'abcdefghijklmnopqrstuvwxyz'), 126 is_base85('!'), is_base85('"'), is_base85(''''), is_base85('('), 127 is_base85(')'), is_base85(char(123)), is_base85('|'), is_base85(char(125)), 128 is_base85('~'), is_base85(char(127)); 129 } {1 1 0 0 0 0 0 0 0 0 0 0} 130 131 do_execsql_test 113 { 132 SELECT is_base85(NULL) IS NULL; 133 } {1} 134 135 do_catchsql_test 114 { 136 SELECT is_base85(1); 137 } {1 {is_base85 accepts only text or NULL}} 138 139 do_catchsql_test 115 { 140 SELECT is_base85(1.1); 141 } {1 {is_base85 accepts only text or NULL}} 142 143 do_catchsql_test 116 { 144 SELECT is_base85(x'00'); 145 } {1 {is_base85 accepts only text or NULL}} 146 147 # Round-trip many bigger random blobs. 148 149 do_execsql_test 117 { 150 CREATE TABLE bs(b blob, num); 151 INSERT INTO bs SELECT randomblob(4000 + n%3), n 152 FROM ( 153 WITH RECURSIVE seq(n) AS ( 154 VALUES(1) UNION ALL SELECT n+1 155 FROM seq WHERE n<100 156 ) SELECT n FROM seq); 157 SELECT num FROM bs WHERE base64(base64(b))!=b; 158 SELECT num FROM bs WHERE base85(base85(b))!=b; 159 } {} 160 161 do_catchsql_test 118 { 162 SELECT base64(zeroblob(2000_000_000)) 163 } {/1.*too big.*/} 164 do_catchsql_test 119 { 165 SELECT base85(zeroblob(2000_000_000)) 166 } {/1.*too big.*/} 167 168 finish_test