test_backup.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. require 'helper'
  2. module SQLite3
  3. class TestBackup < SQLite3::TestCase
  4. def setup
  5. @sdb = SQLite3::Database.new(':memory:')
  6. @ddb = SQLite3::Database.new(':memory:')
  7. @sdb.execute('CREATE TABLE foo (idx, val);');
  8. @data = ('A'..'Z').map{|x|x * 40}
  9. @data.each_with_index do |v, i|
  10. @sdb.execute('INSERT INTO foo (idx, val) VALUES (?, ?);', [i, v])
  11. end
  12. end
  13. def test_backup_step
  14. b = SQLite3::Backup.new(@ddb, 'main', @sdb, 'main')
  15. while b.step(1) == SQLite3::Constants::ErrorCode::OK
  16. assert_not_equal(0, b.remaining)
  17. end
  18. assert_equal(0, b.remaining)
  19. b.finish
  20. assert_equal(@data.length, @ddb.execute('SELECT * FROM foo;').length)
  21. end
  22. def test_backup_all
  23. b = SQLite3::Backup.new(@ddb, 'main', @sdb, 'main')
  24. assert_equal(SQLite3::Constants::ErrorCode::DONE, b.step(-1))
  25. assert_equal(0, b.remaining)
  26. b.finish
  27. assert_equal(@data.length, @ddb.execute('SELECT * FROM foo;').length)
  28. end
  29. end if defined?(SQLite3::Backup)
  30. end