1
0

tkt3457.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # 2008 October 29
  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.
  12. #
  13. # $Id: tkt3457.test,v 1.3 2009/06/26 07:12:07 danielk1977 Exp $
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. if {$tcl_platform(platform) != "unix"} {
  17. finish_test
  18. return
  19. }
  20. #-----------------------------------------------------------------------
  21. # To roll back a hot-journal file, the application needs read and write
  22. # permission on the journal file in question. The following tests test
  23. # the outcome of trying to rollback a hot-journal file when this is not
  24. # the case.
  25. #
  26. # tkt3457-1.2: Application has neither read, nor write permission on
  27. # the hot-journal file. Result: SQLITE_CANTOPEN.
  28. #
  29. # tkt3457-1.3: Application has write but not read permission on
  30. # the hot-journal file. Result: SQLITE_CANTOPEN.
  31. #
  32. # tkt3457-1.4: Application has read but not write permission on
  33. # the hot-journal file. Result: SQLITE_CANTOPEN.
  34. #
  35. # tkt3457-1.5: Application has read/write permission on the hot-journal
  36. # file. Result: SQLITE_OK.
  37. #
  38. do_test tkt3457-1.1 {
  39. execsql {
  40. CREATE TABLE t1(a, b, c);
  41. INSERT INTO t1 VALUES(1, 2, 3);
  42. BEGIN;
  43. INSERT INTO t1 VALUES(4, 5, 6);
  44. }
  45. forcecopy test.db bak.db
  46. forcecopy test.db-journal bak.db-journal
  47. # Fix the first journal-header in the journal-file. Because the
  48. # journal file has not yet been synced, the 8-byte magic string at the
  49. # start of the first journal-header has not been written by SQLite.
  50. # So write it now.
  51. set fd [open bak.db-journal a+]
  52. fconfigure $fd -encoding binary -translation binary
  53. seek $fd 0
  54. puts -nonewline $fd "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7"
  55. close $fd
  56. execsql COMMIT
  57. } {}
  58. # Disable fchmod to make sure SQLite itself does not try to change the
  59. # permission bits on us
  60. #
  61. catch {
  62. test_syscall install fchmod
  63. test_syscall fault 1 1
  64. }
  65. do_test tkt3457-1.2 {
  66. forcecopy bak.db-journal test.db-journal
  67. file attributes test.db-journal -permissions ---------
  68. catchsql { SELECT * FROM t1 }
  69. } {1 {unable to open database file}}
  70. do_test tkt3457-1.3 {
  71. forcecopy bak.db-journal test.db-journal
  72. file attributes test.db-journal -permissions -w--w--w-
  73. catchsql { SELECT * FROM t1 }
  74. } {1 {unable to open database file}}
  75. do_test tkt3457-1.4 {
  76. forcecopy bak.db-journal test.db-journal
  77. file attributes test.db-journal -permissions r--r--r--
  78. catchsql { SELECT * FROM t1 }
  79. } {1 {unable to open database file}}
  80. do_test tkt3457-1.5 {
  81. forcecopy bak.db-journal test.db-journal
  82. file attributes test.db-journal -permissions rw-rw-rw-
  83. catchsql { SELECT * FROM t1 }
  84. } {0 {1 2 3 4 5 6}}
  85. # Reenable fchmod
  86. catch {
  87. test_syscall uninstall
  88. test_syscall fault 0 0
  89. }
  90. finish_test