#!/usr/bin/env ruby
# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")
require "qwik/test-common"
require "qwik/sitedb"

module Qwik
  class SiteDB
    def test(t)
      t.assert_instance_of(SQLite::Database, @db)
      @db.database_list {|row|
	t.assert_instance_of(Hash, row)
      }
    end
  end
end

class TC_SiteDB < Test::Unit::TestCase
  include TestSession

  def test_all
    db = @site.sitedb

    # test_quote
    assert_equal("''", db.quote("'")) # only this...
    assert_equal("BAhpAA==", db.encode(0)) # marshal and base64
    assert_equal(0, db.decode("BAhpAA=="))

    # test_sitedb
    db.test(self)
    assert_equal("2.8.15", SQLite::Database::VERSION)
    assert_equal("iso8859", SQLite::Database::ENCODING)
    db.table_create("test") unless db.table_exist?("test")
    db.set("test", "k", "v")
    assert_equal("v", db.get("test", "k"))
    db.delete("test", "k")
    assert_equal(nil, db.get("test", "k"))
  end
end
