update.
[chise/ruby.git] / ext / test.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 $VERBOSE = true
5 $LOAD_PATH.unshift("..")
6 require "test/unit"
7 require "libchise_c"
8 require "chise/qp"
9
10 class TestLibChise < Test::Unit::TestCase
11   def test_libchise
12     db_dir = CHISE::DB_DIR
13     assert_equal("/cygdrive/c/chise/chise-db", db_dir)
14
15     @ds = CHISE::DataSource.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755)
16     assert_instance_of(CHISE::DataSource, @ds)
17
18     char_id = @ds.decode_char("=daikanwa", 364)
19     assert_equal(0x4ECF, char_id)
20
21     ccs = @ds.get_ccs("=daikanwa")
22     assert_instance_of(CHISE::CCS, ccs)
23     char_id = ccs.decode(364)
24     assert_equal(0x4ECF, char_id)
25
26     feature = @ds.get_feature("ideographic-structure")
27     assert_instance_of(CHISE::Feature, feature)
28     value = feature.get_value(char_id)
29     assert_instance_of(CHISE::Value, value)
30     assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value.to_s)
31
32     @ds.each_feature_name {|name|
33       assert_instance_of(String, name)
34     }
35
36     feature = @ds.get_feature("numeric-value")
37     feature.each_char {|cid, valdatum|
38       assert_kind_of(Numeric, cid)
39       assert_instance_of(CHISE::Value, valdatum)
40
41       ucs = @ds.get_feature("=ucs").get_value(cid)
42       if ucs
43         assert_instance_of(CHISE::Value, ucs)
44       else
45         ucs = @ds.get_feature("=>ucs").get_value(cid)
46         if ucs
47           assert_instance_of(CHISE::Value, ucs)
48         end
49       end
50
51       name = @ds.get_feature("name").get_value(cid)
52       if name
53         assert_instance_of(CHISE::Value, name)
54       end
55     }
56
57     @ds.close
58   end
59 end