Class: TC_Mysql

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



8
9
10
11
12
13
14
# File 'ext/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

#teardownObject



15
16
# File 'ext/test.rb', line 15

def teardown()
end

#test_client_infoObject



54
55
56
# File 'ext/test.rb', line 54

def test_client_info()
  assert_match(/^\d.\d+.\d+(-.*)?$/, Mysql.client_info())
end

#test_connectObject



32
33
34
35
# File 'ext/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_connect2Object



88
89
90
91
92
# File 'ext/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_stringObject



42
43
44
# File 'ext/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_infoObject



50
51
52
# File 'ext/test.rb', line 50

def test_get_client_info()
  assert_match(/^\d.\d+.\d+(-.*)?$/, Mysql.get_client_info())
end

#test_initObject



22
23
24
25
# File 'ext/test.rb', line 22

def test_init()
  assert_nothing_raised{@m = Mysql.init}
  assert_nothing_raised{@m.close}
end

#test_newObject



37
38
39
40
# File 'ext/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_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/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_quoteObject



46
47
48
# File 'ext/test.rb', line 46

def test_quote()
  assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.quote("abc'def\"ghi\0jkl%mno"))
end

#test_real_connectObject



27
28
29
30
# File 'ext/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_connect2Object



82
83
84
85
86
# File 'ext/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_versionObject



18
19
20
# File 'ext/test.rb', line 18

def test_version()
  assert_equal(20701, Mysql::VERSION)
end