File: test_backup.rb

package info (click to toggle)
ruby-sqlite3 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 680 kB
  • sloc: ruby: 4,827; ansic: 1,868; sh: 91; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "helper"

module SQLite3
  if defined?(SQLite3::Backup)
    class TestBackup < SQLite3::TestCase
      def setup
        @sdb = SQLite3::Database.new(":memory:")
        @ddb = SQLite3::Database.new(":memory:")
        @sdb.execute("CREATE TABLE foo (idx, val);")
        @data = ("A".."Z").map { |x| x * 40 }
        @data.each_with_index do |v, i|
          @sdb.execute("INSERT INTO foo (idx, val) VALUES (?, ?);", [i, v])
        end
      end

      def test_backup_step
        b = SQLite3::Backup.new(@ddb, "main", @sdb, "main")
        while b.step(1) == SQLite3::Constants::ErrorCode::OK
          assert_not_equal(0, b.remaining)
        end
        assert_equal(0, b.remaining)
        b.finish
        assert_equal(@data.length, @ddb.execute("SELECT * FROM foo;").length)
      end

      def test_backup_all
        b = SQLite3::Backup.new(@ddb, "main", @sdb, "main")
        assert_equal(SQLite3::Constants::ErrorCode::DONE, b.step(-1))
        assert_equal(0, b.remaining)
        b.finish
        assert_equal(@data.length, @ddb.execute("SELECT * FROM foo;").length)
      end
    end
  end
end