Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/ext/rbu/rbudiff.test

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # 2015-07-31
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 # Tests for the [sqldiff --rbu] command.
13 #
14 #
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
17 }
18 source $testdir/tester.tcl
19 set testprefix rbudiff
20
21 if {$tcl_platform(platform)=="windows"} {
22 set PROG "sqldiff.exe"
23 } else {
24 set PROG "./sqldiff"
25 }
26 if {![file exe $PROG]} {
27 puts "rbudiff.test cannot run because $PROG is not available"
28 finish_test
29 return
30 }
31 db close
32
33 proc get_rbudiff_sql {db1 db2} {
34 exec $::PROG --rbu $db1 $db2
35 }
36
37 proc step_rbu {target rbu} {
38 while 1 {
39 sqlite3rbu rbu $target $rbu
40 set rc [rbu step]
41 rbu close
42 if {$rc != "SQLITE_OK"} break
43 }
44 set rc
45 }
46
47 proc apply_rbudiff {sql target} {
48 forcedelete rbu.db
49 sqlite3 rbudb rbu.db
50 rbudb eval $sql
51 rbudb close
52 step_rbu $target rbu.db
53 }
54
55 proc rbudiff_cksum {db1} {
56 set txt ""
57
58 sqlite3 dbtmp $db1
59 foreach tbl [dbtmp eval {SELECT name FROM sqlite_master WHERE type='table'}] {
60 set cols [list]
61 dbtmp eval "PRAGMA table_info = $tbl" { lappend cols "quote( $name )" }
62 append txt [dbtmp eval \
63 "SELECT [join $cols {||'.'||}] FROM $tbl ORDER BY 1"
64 ]
65 }
66 dbtmp close
67
68 md5 $txt
69 }
70
71 foreach {tn init mod} {
72 1 {
73 CREATE TABLE t1(a PRIMARY KEY, b, c);
74 INSERT INTO t1 VALUES(1, 2, 3);
75 INSERT INTO t1 VALUES(4, 5, 6);
76
77 CREATE TABLE t2(a, b, c, PRIMARY KEY(b, c));
78 INSERT INTO t2 VALUES(1, 2, 3);
79 INSERT INTO t2 VALUES(4, 5, 6);
80 } {
81 INSERT INTO t1 VALUES(7, 8, 9);
82 DELETE FROM t1 WHERE a=4;
83 UPDATE t1 SET c = 11 WHERE a = 1;
84
85 INSERT INTO t2 VALUES(7, 8, 9);
86 DELETE FROM t2 WHERE a=4;
87 UPDATE t2 SET c = 11 WHERE a = 1;
88 }
89
90 2 {
91 CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b, c));
92 INSERT INTO t1 VALUES('u', 'v', 'w');
93 INSERT INTO t1 VALUES('x', 'y', 'z');
94 } {
95 DELETE FROM t1 WHERE a='u';
96 INSERT INTO t1 VALUES('a', 'b', 'c');
97 }
98
99 3 {
100 CREATE TABLE t1(i INTEGER PRIMARY KEY, x);
101 INSERT INTO t1 VALUES(1,
102 X'0000000000000000111111111111111122222222222222223333333333333333'
103 );
104 CREATE TABLE t2(y INTEGER PRIMARY KEY, x);
105 INSERT INTO t2 VALUES(1,
106 X'0000000000000000111111111111111122222222222222223333333333333333'
107 );
108 } {
109 DELETE FROM t1;
110 INSERT INTO t1 VALUES(1,
111 X'0000000000000000111111111111111122222555555552223333333333333333'
112 );
113 DELETE FROM t2;
114 INSERT INTO t2 VALUES(1,
115 X'0000000000000000111111111111111122222222222222223333333FFF333333'
116 );
117 }
118
119 } {
120 catch { db close }
121
122 forcedelete test.db test.db2
123 sqlite3 db test.db
124 db eval "$init"
125 sqlite3 db test.db2
126 db eval "$init ; $mod"
127 db close
128
129 do_test 1.$tn.2 {
130 set sql [get_rbudiff_sql test.db test.db2]
131 apply_rbudiff $sql test.db
132 } {SQLITE_DONE}
133 do_test 1.$tn.3 { rbudiff_cksum test.db } [rbudiff_cksum test.db2]
134
135 forcedelete test.db test.db2
136 sqlite3 db test.db
137 db eval "$init ; $mod"
138 sqlite3 db test.db2
139 db eval "$init"
140 db close
141
142 do_test 1.$tn.4 {
143 set sql [get_rbudiff_sql test.db test.db2]
144 apply_rbudiff $sql test.db
145 } {SQLITE_DONE}
146 do_test 1.$tn.5 { rbudiff_cksum test.db } [rbudiff_cksum test.db2]
147 }
148
149 finish_test
150
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698