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

Side by Side Diff: third_party/sqlite/test/jrnlmode.test

Issue 3108030: Move bundled copy of sqlite one level deeper to better separate it... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/test/journal1.test ('k') | third_party/sqlite/test/jrnlmode2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # 2008 April 17
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 focus
12 # of these tests is the journal mode pragma.
13 #
14 # $Id: jrnlmode.test,v 1.16 2009/06/05 17:09:12 drh Exp $
15
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18
19 ifcapable {!pager_pragmas} {
20 finish_test
21 return
22 }
23
24 if {[info exists TEMP_STORE] && $TEMP_STORE>=2} {
25 set temp_persist memory
26 set temp_delete memory
27 set temp_truncate memory
28 set temp_off off
29 } else {
30 set temp_persist persist
31 set temp_delete delete
32 set temp_truncate truncate
33 set temp_off off
34 }
35
36 proc temp_journal_mode {newmode} {
37 if {[info exists ::TEMP_STORE] && $::TEMP_STORE>=2} {
38 if {$newmode ne "off" && $newmode ne "memory"} {
39 execsql {PRAGMA temp.journal_mode}
40 set newmode [db one {PRAGMA temp.journal_mode}]
41 }
42 }
43 set newmode
44 }
45
46 #----------------------------------------------------------------------
47 # Test cases jrnlmode-1.X test the PRAGMA logic.
48 #
49 do_test jrnlmode-1.0 {
50 execsql {
51 PRAGMA journal_mode;
52 PRAGMA main.journal_mode;
53 PRAGMA temp.journal_mode;
54 }
55 } [list delete delete [temp_journal_mode delete]]
56 do_test jrnlmode-1.1 {
57 execsql {
58 PRAGMA journal_mode = persist;
59 }
60 } {persist}
61 do_test jrnlmode-1.2 {
62 execsql {
63 PRAGMA journal_mode;
64 PRAGMA main.journal_mode;
65 PRAGMA temp.journal_mode;
66 }
67 } [list persist persist [temp_journal_mode persist]]
68 do_test jrnlmode-1.4 {
69 execsql {
70 PRAGMA journal_mode = off;
71 }
72 } {off}
73 do_test jrnlmode-1.5 {
74 execsql {
75 PRAGMA journal_mode;
76 PRAGMA main.journal_mode;
77 PRAGMA temp.journal_mode;
78 }
79 } [list off off [temp_journal_mode off]]
80 do_test jrnlmode-1.6 {
81 execsql {
82 PRAGMA journal_mode = delete;
83 }
84 } {delete}
85 do_test jrnlmode-1.7 {
86 execsql {
87 PRAGMA journal_mode;
88 PRAGMA main.journal_mode;
89 PRAGMA Temp.journal_mode;
90 }
91 } [list delete delete [temp_journal_mode delete]]
92 do_test jrnlmode-1.7.1 {
93 execsql {
94 PRAGMA journal_mode = truncate;
95 }
96 } {truncate}
97 do_test jrnlmode-1.7.2 {
98 execsql {
99 PRAGMA journal_mode;
100 PRAGMA main.journal_mode;
101 PRAGMA temp.journal_mode;
102 }
103 } [list truncate truncate [temp_journal_mode truncate]]
104 do_test jrnlmode-1.8 {
105 execsql {
106 PRAGMA journal_mode = off;
107 PRAGMA journal_mode = invalid;
108 }
109 } {off off}
110 ifcapable attach {
111 do_test jrnlmode-1.9 {
112 execsql {
113 PRAGMA journal_mode = PERSIST;
114 ATTACH ':memory:' as aux1;
115 }
116 execsql {
117 PRAGMA main.journal_mode;
118 PRAGMA aux1.journal_mode;
119 }
120 } {persist memory}
121 do_test jrnlmode-1.10 {
122 execsql {
123 PRAGMA main.journal_mode = OFF;
124 }
125 execsql {
126 PRAGMA main.journal_mode;
127 PRAGMA temp.journal_mode;
128 PRAGMA aux1.journal_mode;
129 }
130 } [list off [temp_journal_mode persist] memory]
131 do_test jrnlmode-1.11 {
132 execsql {
133 PRAGMA journal_mode;
134 }
135 } {persist}
136 do_test jrnlmode-1.12 {
137 execsql {
138 ATTACH ':memory:' as aux2;
139 }
140 execsql {
141 PRAGMA main.journal_mode;
142 PRAGMA aux1.journal_mode;
143 PRAGMA aux2.journal_mode;
144 }
145 } {off memory memory}
146 do_test jrnlmode-1.13 {
147 # The journal-mode used by in-memory databases cannot be changed.
148 execsql {
149 PRAGMA aux1.journal_mode = DELETE;
150 }
151 execsql {
152 PRAGMA main.journal_mode;
153 PRAGMA aux1.journal_mode;
154 PRAGMA aux2.journal_mode;
155 }
156 } {off memory memory}
157 do_test jrnlmode-1.14 {
158 execsql {
159 PRAGMA journal_mode = delete;
160 }
161 execsql {
162 PRAGMA main.journal_mode;
163 PRAGMA temp.journal_mode;
164 PRAGMA aux1.journal_mode;
165 PRAGMA aux2.journal_mode;
166 }
167 } [list delete [temp_journal_mode delete] memory memory]
168 do_test jrnlmode-1.15 {
169 execsql {
170 ATTACH ':memory:' as aux3;
171 }
172 execsql {
173 PRAGMA main.journal_mode;
174 PRAGMA temp.journal_mode;
175 PRAGMA aux1.journal_mode;
176 PRAGMA aux2.journal_mode;
177 PRAGMA aux3.journal_mode;
178 }
179 } [list delete [temp_journal_mode delete] memory memory memory]
180 do_test jrnlmode-1.16 {
181 execsql {
182 PRAGMA journal_mode = TRUNCATE;
183 }
184 execsql {
185 PRAGMA main.journal_mode;
186 PRAGMA temp.journal_mode;
187 PRAGMA aux1.journal_mode;
188 PRAGMA aux2.journal_mode;
189 PRAGMA aux3.journal_mode;
190 }
191 } [list truncate [temp_journal_mode truncate] memory memory memory]
192
193 do_test jrnlmode-1.99 {
194 execsql {
195 DETACH aux1;
196 DETACH aux2;
197 DETACH aux3;
198 }
199 } {}
200 }
201
202 ifcapable attach {
203 file delete -force test2.db
204 do_test jrnlmode-2.1 {
205 execsql {
206 ATTACH 'test2.db' AS aux;
207 PRAGMA main.journal_mode = persist;
208 PRAGMA aux.journal_mode = persist;
209 CREATE TABLE abc(a, b, c);
210 CREATE TABLE aux.def(d, e, f);
211 }
212 execsql {
213 BEGIN;
214 INSERT INTO abc VALUES(1, 2, 3);
215 INSERT INTO def VALUES(4, 5, 6);
216 COMMIT;
217 }
218 list [file exists test.db-journal] [file exists test2.db-journal]
219 } {1 1}
220
221 do_test jrnlmode-2.2 {
222 file size test.db-journal
223 } {0}
224
225 do_test jrnlmode-2.3 {
226 execsql {
227 SELECT * FROM abc;
228 }
229 } {1 2 3}
230
231 do_test jrnlmode-2.4 {
232 file size test.db-journal
233 } {0}
234
235 do_test jrnlmode-2.5 {
236 execsql {
237 SELECT * FROM def;
238 }
239 } {4 5 6}
240
241 #----------------------------------------------------------------------
242 # Test caes jrnlmode-3.X verify that ticket #3127 has been fixed.
243 #
244 db close
245 file delete -force test2.db
246 file delete -force test.db
247 sqlite3 db test.db
248
249 do_test jrnlmode-3.1 {
250 execsql {
251 CREATE TABLE x(n INTEGER);
252 ATTACH 'test2.db' AS a;
253 create table a.x ( n integer );
254 insert into a.x values(1);
255 insert into a.x values (2);
256 insert into a.x values (3);
257 insert into a.x values (4);
258 }
259 } {}
260
261 do_test jrnlmode-3.2 {
262 execsql { PRAGMA journal_mode=off; }
263 execsql {
264 BEGIN IMMEDIATE;
265 INSERT OR IGNORE INTO main.x SELECT * FROM a.x;
266 COMMIT;
267 }
268 } {}
269 }
270
271 ifcapable autovacuum&&pragma {
272 db close
273 file delete -force test.db
274 sqlite3 db test.db
275 do_test jrnlmode-4.1 {
276 execsql {
277 PRAGMA cache_size = 1;
278 PRAGMA auto_vacuum = 1;
279 CREATE TABLE abc(a, b, c);
280 }
281 execsql { PRAGMA page_count }
282 } {3}
283
284 do_test jrnlmode-4.2 {
285 execsql { PRAGMA journal_mode = off }
286 } {off}
287
288 do_test jrnlmode-4.3 {
289 execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) }
290 } {}
291
292 # This will attempt to truncate the database file. Check that this
293 # is not a problem when journal_mode=off.
294 do_test jrnlmode-4.4 {
295 execsql { DELETE FROM abc }
296 } {}
297
298 integrity_check jrnlmode-4.5
299 }
300
301 #------------------------------------------------------------------------
302 # The following test caes, jrnlmode-5.*, test the journal_size_limit
303 # pragma.
304 ifcapable pragma {
305 db close
306 file delete -force test.db test2.db test3.db
307 sqlite3 db test.db
308
309 do_test jrnlmode-5.1 {
310 execsql {pragma page_size=1024}
311 execsql {pragma journal_mode=persist}
312 } {persist}
313
314 do_test jrnlmode-5.2 {
315 execsql { PRAGMA journal_size_limit }
316 } {-1}
317 do_test jrnlmode-5.3 {
318 execsql {
319 ATTACH 'test2.db' AS aux;
320 PRAGMA aux.journal_size_limit;
321 }
322 } {-1}
323 do_test jrnlmode-5.4.1 {
324 execsql { PRAGMA aux.journal_size_limit = 999999999999 }
325 } {999999999999}
326 do_test jrnlmode-5.4.2 {
327 execsql { PRAGMA aux.journal_size_limit = 10240 }
328 } {10240}
329 do_test jrnlmode-5.5 {
330 execsql { PRAGMA main.journal_size_limit = 20480 }
331 } {20480}
332 do_test jrnlmode-5.6 {
333 execsql { PRAGMA journal_size_limit }
334 } {20480}
335 do_test jrnlmode-5.7 {
336 execsql { PRAGMA aux.journal_size_limit }
337 } {10240}
338
339 do_test jrnlmode-5.8 {
340 execsql { ATTACH 'test3.db' AS aux2 }
341 } {}
342
343 do_test jrnlmode-5.9 {
344 execsql {
345 CREATE TABLE main.t1(a, b, c);
346 CREATE TABLE aux.t2(a, b, c);
347 CREATE TABLE aux2.t3(a, b, c);
348 }
349 } {}
350 do_test jrnlmode-5.10 {
351 list \
352 [file exists test.db-journal] \
353 [file exists test2.db-journal] \
354 [file exists test3.db-journal]
355 } {1 1 1}
356 do_test jrnlmode-5.11 {
357 execsql {
358 BEGIN;
359 INSERT INTO t3 VALUES(randomblob(1000),randomblob(1000),randomblob(1000));
360 INSERT INTO t3
361 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
362 INSERT INTO t3
363 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
364 INSERT INTO t3
365 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
366 INSERT INTO t3
367 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
368 INSERT INTO t3
369 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
370 INSERT INTO t2 SELECT * FROM t3;
371 INSERT INTO t1 SELECT * FROM t2;
372 COMMIT;
373 }
374 list \
375 [file exists test.db-journal] \
376 [file exists test2.db-journal] \
377 [file exists test3.db-journal] \
378 [file size test.db-journal] \
379 [file size test2.db-journal] \
380 [file size test3.db-journal]
381 } {1 1 1 0 0 0}
382
383 do_test jrnlmode-5.12 {
384 execsql {
385 BEGIN;
386 UPDATE t1 SET a = randomblob(1000);
387 }
388 expr {[file size test.db-journal]>30000}
389 } {1}
390 do_test jrnlmode-5.13 {
391 execsql COMMIT
392 file size test.db-journal
393 } {20480}
394
395 do_test jrnlmode-5.14 {
396 execsql {
397 BEGIN;
398 UPDATE t2 SET a = randomblob(1000);
399 }
400 expr {[file size test2.db-journal]>30000}
401 } {1}
402 do_test jrnlmode-5.15 {
403 execsql COMMIT
404 file size test2.db-journal
405 } {10240}
406
407 do_test jrnlmode-5.16 {
408 execsql {
409 BEGIN;
410 UPDATE t3 SET a = randomblob(1000);
411 }
412 set journalsize [file size test3.db-journal]
413 expr {$journalsize>30000}
414 } {1}
415 do_test jrnlmode-5.17 {
416 execsql COMMIT
417 set sz [file size test3.db-journal]
418 expr {$sz>=$journalsize}
419 } {1}
420
421 do_test jrnlmode-5.18 {
422 execsql {
423 PRAGMA journal_size_limit = -4;
424 BEGIN;
425 UPDATE t1 SET a = randomblob(1000);
426 }
427 set journalsize [file size test.db-journal]
428 expr {$journalsize>30000}
429 } {1}
430 do_test jrnlmode-5.19 {
431 execsql COMMIT
432 set sz [file size test.db-journal]
433 expr {$sz>=$journalsize}
434 } {1}
435
436 # Test a size-limit of 0.
437 #
438 do_test jrnlmode-5.20 {
439 execsql {
440 PRAGMA journal_size_limit = 0;
441 BEGIN;
442 UPDATE t1 SET a = randomblob(1000);
443 }
444 } {0}
445 do_test jrnlmode-5.21 {
446 expr {[file size test.db-journal] > 1024}
447 } {1}
448 do_test jrnlmode-5.22 {
449 execsql COMMIT
450 list [file exists test.db-journal] [file size test.db-journal]
451 } {1 0}
452 }
453
454 ifcapable pragma {
455 # These tests are not run as part of the "journaltest" permutation,
456 # as the test_journal.c layer is incompatible with in-memory journaling.
457 if {[catch {set ::permutations_test_prefix} z] || $z ne "journaltest"} {
458
459 do_test jrnlmode-6.1 {
460 execsql {
461 PRAGMA journal_mode = truncate;
462 CREATE TABLE t4(a, b);
463 BEGIN;
464 INSERT INTO t4 VALUES(1, 2);
465 PRAGMA journal_mode = memory;
466 }
467 } {truncate truncate}
468 do_test jrnlmode-6.2 {
469 file exists test.db-journal
470 } {1}
471 do_test jrnlmode-6.3 {
472 execsql {
473 COMMIT;
474 SELECT * FROM t4;
475 }
476 } {1 2}
477 do_test jrnlmode-6.4 {
478 file exists test.db-journal
479 } {1}
480 do_test jrnlmode-6.5 {
481 execsql {
482 PRAGMA journal_mode = MEMORY;
483 BEGIN;
484 INSERT INTO t4 VALUES(3, 4);
485 }
486 file exists test.db-journal
487 } {1}
488 do_test jrnlmode-6.7 {
489 execsql {
490 COMMIT;
491 SELECT * FROM t4;
492 }
493 } {1 2 3 4}
494 do_test jrnlmode-6.8 {
495 file exists test.db-journal
496 } {1}
497 do_test jrnlmode-6.9 {
498 execsql {
499 PRAGMA journal_mode = DELETE;
500 BEGIN IMMEDIATE; COMMIT;
501 }
502 file exists test.db-journal
503 } {0}
504 }
505 }
506
507 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/test/journal1.test ('k') | third_party/sqlite/test/jrnlmode2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698