class TC_Mysql

Public Instance Methods

setup() click to toggle source
# File test.rb, line 8
def setup()
  @host, @user, @pass, db, port, sock, flag = ARGV
  @db = db || "test"
  @port = port.to_i
  @sock = sock.nil? || sock.empty? ? nil : sock
  @flag = flag.to_i
end
teardown() click to toggle source
# File test.rb, line 15
def teardown()
end
test_client_info() click to toggle source
# File test.rb, line 54
def test_client_info()
  assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.client_info())
end
test_connect() click to toggle source
# File test.rb, line 32
def test_connect()
  assert_nothing_raised{@m = Mysql.connect(@host, @user, @pass, @db, @port, @sock, @flag)}
  assert_nothing_raised{@m.close}
end
test_connect2() click to toggle source
# File test.rb, line 88
def test_connect2()
  @m = Mysql.init
  assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
  @m.close
end
test_escape_string() click to toggle source
# File test.rb, line 42
def test_escape_string()
  assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.escape_string("abc'def\"ghi\0jkl%mno"))
end
test_get_client_info() click to toggle source
# File test.rb, line 50
def test_get_client_info()
  assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.get_client_info())
end
test_init() click to toggle source
# File test.rb, line 22
def test_init()
  assert_nothing_raised{@m = Mysql.init}
  assert_nothing_raised{@m.close}
end
test_new() click to toggle source
# File test.rb, line 37
def test_new()
  assert_nothing_raised{@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)}
  assert_nothing_raised{@m.close}
end
test_options() click to toggle source
# File test.rb, line 58
  def test_options()
    @m = Mysql.init
    assert_equal(@m, @m.options(Mysql::INIT_COMMAND, "SET AUTOCOMMIT=0"))
    assert_equal(@m, @m.options(Mysql::OPT_COMPRESS))
    assert_equal(@m, @m.options(Mysql::OPT_CONNECT_TIMEOUT, 10))
    assert_equal(@m, @m.options(Mysql::GUESS_CONNECTION)) if defined? Mysql::GUESS_CONNECTION
    assert_equal(@m, @m.options(Mysql::OPT_LOCAL_INFILE, true))
#   assert_equal(@m, @m.options(Mysql::OPT_NAMED_PIPE))
#   assert_equal(@m, @m.options(Mysql::OPT_PROTOCOL, 1))
    assert_equal(@m, @m.options(Mysql::OPT_READ_TIMEOUT, 10)) if defined? Mysql::OPT_READ_TIMEOUT
    assert_equal(@m, @m.options(Mysql::OPT_USE_EMBEDDED_CONNECTION)) if defined? Mysql::OPT_USE_EMBEDDED_CONNECTION
    assert_equal(@m, @m.options(Mysql::OPT_USE_REMOTE_CONNECTION)) if defined? Mysql::OPT_USE_REMOTE_CONNECTION
    assert_equal(@m, @m.options(Mysql::OPT_WRITE_TIMEOUT, 10)) if defined? Mysql::OPT_WRITE_TIMEOUT
#   assert_equal(@m, @m.options(Mysql::READ_DEFAULT_FILE, "/tmp/hoge"))
    assert_equal(@m, @m.options(Mysql::READ_DEFAULT_GROUP, "test"))
    assert_equal(@m, @m.options(Mysql::SECURE_AUTH, true)) if defined? Mysql::SECURE_AUTH
#   assert_equal(@m, @m.options(Mysql::SET_CHARSET_DIR, "??"))
    assert_equal(@m, @m.options(Mysql::SET_CHARSET_NAME, "latin1"))
    assert_equal(@m, @m.options(Mysql::SET_CLIENT_IP, "127.0.0.1")) if defined? Mysql::SET_CLIENT_IP
#   assert_equal(@m, @m.options(Mysql::SHARED_MEMORY_BASE_NAME, "xxx"))
    assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag))
    @m.close
  end
test_quote() click to toggle source
# File test.rb, line 46
def test_quote()
  assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.quote("abc'def\"ghi\0jkl%mno"))
end
test_real_connect() click to toggle source
# File test.rb, line 27
def test_real_connect()
  assert_nothing_raised{@m = Mysql.real_connect(@host, @user, @pass, @db, @port, @sock, @flag)}
  assert_nothing_raised{@m.close}
end
test_real_connect2() click to toggle source
# File test.rb, line 82
def test_real_connect2()
  @m = Mysql.init
  assert_equal(@m, @m.real_connect(@host, @user, @pass, @db, @port, @sock, @flag))
  @m.close
end
test_version() click to toggle source
# File test.rb, line 18
def test_version()
  assert_equal(20802, Mysql::VERSION)
end