Skip to content

Commit

Permalink
Add tests of the previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
kubo committed May 25, 2012
1 parent 8ffca1c commit e55cc41
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2012-05-25 KUBO Takehiro <kubo@jiubao.org>
* test/setup_test_object.sql, test/test_all.rb, test/test_object.rb:
Add tests of the previous commit.

2012-05-25 KUBO Takehiro <kubo@jiubao.org>
* ext/oci8/lob.c: Merge pull request #13 from timon/temp_lob at github.
If 's' is a temporary lob, use OCILobLocatorAssign instead.

2012-05-20 KUBO Takehiro <kubo@jiubao.org>
* ext/oci8/oci8.c, test/test_oci8.rb: add OCI8's class variables:
@@environment_handle and @@process_handle.
Expand Down
6 changes: 6 additions & 0 deletions test/setup_test_object.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ create type rb_test_obj as object (
bflt_val binary_float,
str_val varchar2(50),
raw_val raw(50),
clob_val clob,
nclob_val nclob,
blob_val blob,
obj_val rb_test_obj_elem,
int_array_val rb_test_int_array,
flt_array_val rb_test_flt_array,
Expand Down Expand Up @@ -84,6 +87,9 @@ create or replace type body rb_test_obj is
self.bflt_val := n;
self.str_val := to_char(n);
self.raw_val := utl_raw.cast_to_raw(to_char(n));
self.clob_val := to_clob(n);
self.nclob_val := to_clob(n);
self.blob_val := to_blob(utl_raw.cast_to_raw(to_char(n)));
self.obj_val := rb_test_obj_elem(n, n + 1);
self.date_val := to_test_date(n);
if self.int_val != 1 then
Expand Down
1 change: 1 addition & 0 deletions test/test_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require "#{srcdir}/test_oracle_version"
require "#{srcdir}/test_error"
require "#{srcdir}/test_connection_pool"
require "#{srcdir}/test_object"

if OCI8.respond_to? :encoding
require "#{srcdir}/test_encoding"
Expand Down
69 changes: 58 additions & 11 deletions test/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@
require 'test/unit'
require File.dirname(__FILE__) + '/config'

conn = OCI8.new($dbuser, $dbpass, $dbname)
begin
conn.describe_type('rb_test_int_array')
conn.describe_type('rb_test_flt_array')
conn.describe_type('rb_test_num_array')
conn.describe_type('rb_test_bdbl_array')
conn.describe_type('rb_test_bflt_array')
conn.describe_type('rb_test_str_array')
conn.describe_type('rb_test_raw_array')
conn.describe_type('rb_test_obj_elem_array')
conn.describe_type('rb_test_obj_elem_ary_of_ary')
conn.describe_type('rb_test_obj')
conn.describe_table('rb_test_obj_tab1')
conn.describe_table('rb_test_obj_tab2')
rescue OCIError
raise if $!.code != 4043
raise <<EOS
#{$!}
You need to execute SQL statements in #{File.dirname(__FILE__)}/setup_test_object.sql as follows:
$ sqlplus USERNAME/PASSWORD
SQL> @test/setup_test_object.sql
EOS
ensure
conn.logoff
end

class RbTestObj < OCI8::Object::Base
end

Expand Down Expand Up @@ -40,6 +69,9 @@ class ExpectedVal
attr_reader :bflt_val
attr_reader :str_val
attr_reader :raw_val
attr_reader :clob_val
attr_reader :nclob_val
attr_reader :blob_val
attr_reader :obj_val
attr_reader :int_array_val
attr_reader :flt_array_val
Expand Down Expand Up @@ -80,6 +112,9 @@ def next
@str_val = @n.to_s
@str_val = $` if /.0$/ =~ @str_val
@raw_val = @str_val
@clob_val = @str_val
@nclob_val = @str_val
@blob_val = @str_val
@obj_val = ExpectedValObjElem.new(@int_val, @int_val + 1)
@date_val = to_test_date(@n)
if @int_val == 1
Expand Down Expand Up @@ -132,17 +167,20 @@ def should_be_equal(val)
bflt_val = val[4]
str_val = val[5]
raw_val = val[6]
obj_val = val[7]
int_array_val = val[8]
flt_array_val = val[9]
num_array_val = val[10]
bdbl_array_val = val[11]
bflt_array_val = val[12]
str_array_val = val[13]
raw_array_val = val[14]
obj_array_val = val[15]
obj_ary_of_ary_val = val[16]
date_val = val[17]
clob_val = val[7] && val[7].read
nclob_val = val[8] && val[8].read
blob_val = val[9] && val[9].read
obj_val = val[10]
int_array_val = val[11]
flt_array_val = val[12]
num_array_val = val[13]
bdbl_array_val = val[14]
bflt_array_val = val[15]
str_array_val = val[16]
raw_array_val = val[17]
obj_array_val = val[18]
obj_ary_of_ary_val = val[19]
date_val = val[20]
# date_array_val = val[18]
else
assert_instance_of(RbTestObj, val)
Expand All @@ -153,6 +191,9 @@ def should_be_equal(val)
bflt_val = val.bflt_val
str_val = val.str_val
raw_val = val.raw_val
clob_val = val.clob_val && val.clob_val.read
nclob_val = val.nclob_val && val.nclob_val.read
blob_val = val.blob_val && val.blob_val.read
obj_val = val.obj_val
int_array_val = val.int_array_val
flt_array_val = val.flt_array_val
Expand All @@ -174,6 +215,9 @@ def should_be_equal(val)
assert_in_delta(@bflt_val, bflt_val, Delta)
assert_equal(@str_val, str_val)
assert_equal(@raw_val, raw_val)
assert_equal(@clob_val, clob_val)
assert_equal(@nclob_val, nclob_val)
assert_equal(@blob_val, blob_val)
assert_equal(@obj_val, obj_val)
assert_equal(@int_array_val, int_array_val && int_array_val.to_ary)
assert_array_in_delta(@flt_array_val, flt_array_val && flt_array_val.to_ary)
Expand Down Expand Up @@ -302,6 +346,9 @@ def _test_class_proc2
obj.bflt_val = expected_val.bflt_val
obj.str_val = expected_val.str_val
obj.raw_val = expected_val.raw_val
obj.clob_val = expected_val.clob_val
obj.nclob_val = expected_val.nclob_val
obj.blob_val = expected_val.blob_val
obj.obj_val = expected_val.obj_val
obj.int_array_val = expected_val.int_array_val
obj.flt_array_val = expected_val.flt_array_val
Expand Down

0 comments on commit e55cc41

Please sign in to comment.