test/CharacterSetTest.rb in rubyfb-0.5.7 vs test/CharacterSetTest.rb in rubyfb-0.5.8
- old
+ new
@@ -7,58 +7,53 @@
require 'rubyfb'
include Rubyfb
class CharacterSetTest < Test::Unit::TestCase
- CURDIR = "#{Dir.getwd}"
- DB_FILE = "#{CURDIR}#{File::SEPARATOR}cxnarset_unit_test.fdb"
- CHAR_SET = 'WIN1251'
-
- def setup
- puts "#{self.class.name} started." if TEST_LOGGING
- if File::exist?(DB_FILE)
- Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
- end
+ DB_FILE = File.join(DB_DIR, "cxnarset_unit_test.fdb")
+ CHAR_SET = 'WIN1251'
- @database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024,
- CHAR_SET)
- end
-
- def teardown
- if File::exist?(DB_FILE)
- Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
- end
- puts "#{self.class.name} finished." if TEST_LOGGING
- end
+ def setup
+ puts "#{self.class.name} started." if TEST_LOGGING
+ if File::exist?(DB_FILE)
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
+ end
+ @database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, CHAR_SET)
+ end
- def test01
- db = Database.new(DB_FILE, CHAR_SET)
+ def teardown
+ if File::exist?(DB_FILE)
+ Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
+ end
+ puts "#{self.class.name} finished." if TEST_LOGGING
+ end
- assert(db.character_set = CHAR_SET)
+ def test01
+ db = Database.new(DB_FILE, CHAR_SET)
- db.character_set = 'ASCII'
- assert(db.character_set == 'ASCII')
- end
+ assert(db.character_set = CHAR_SET)
- def test02
- db = Database.new(DB_FILE, CHAR_SET)
+ db.character_set = 'ASCII'
+ assert(db.character_set == 'ASCII')
+ end
- begin
- win1251_str = 'Кириличка'
- db.connect("SYSDBA", "masterkey") do |cxn|
- cxn.start_transaction do |tr|
- cxn.execute("CREATE TABLE SAMPLE_TABLE(SAMPLE_FIELD VARCHAR(100))",tr)
- end
- cxn.start_transaction do |tr|
- cxn.execute("INSERT INTO SAMPLE_TABLE VALUES ('#{win1251_str}')",tr)
- cxn.execute("SELECT * FROM SAMPLE_TABLE WHERE SAMPLE_FIELD = "\
- "'#{win1251_str}'",tr) do |row|
- # here we have an exception:
- some_var = row['SAMPLE_FIELD']
- end
- end
- end
-# rescue => error
-# assert("Character set unit test failure.", false)
+ def test02
+ db = Database.new(DB_FILE, CHAR_SET)
+
+ win1251_str = 'Кириличка'
+ db.connect("SYSDBA", "masterkey") do |cxn|
+ cxn.start_transaction do |tr|
+ cxn.execute("CREATE TABLE SAMPLE_TABLE(SAMPLE_FIELD VARCHAR(100) CHARACTER SET UTF8)", tr)
+ end
+ cxn.start_transaction do |tr|
+ cxn.execute("INSERT INTO SAMPLE_TABLE VALUES ('#{win1251_str}')", tr)
+ row_count = 0
+ cxn.execute("SELECT * FROM SAMPLE_TABLE WHERE SAMPLE_FIELD = '#{win1251_str}'", tr) do |row|
+ assert(row['SAMPLE_FIELD']==win1251_str, "Database encoding failed")
+ row_count += 1
+ end
+ assert(1==row_count)
end
- end
+ end
+ end
end
+