rdbxml 0.1 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  This package provides wrapper functions to the C++ APIS for BDB XML (Dbxml) and
4
4
  BDB (Db) as well as pure-Ruby convenience functions (RDBXML). While the wrapper
5
- layer should be more or less complete, the Ruby interface only supports basic
6
- documents operations in this version of the library.
5
+ layer should be more or less complete, the Ruby interface is still a work in
6
+ progress.
7
7
 
8
8
  == Requirements
9
9
  * Rake[http://rake.rubyforge.org] >= 7.0
@@ -14,7 +14,7 @@ documents operations in this version of the library.
14
14
  === The Easy Way
15
15
 
16
16
  RDBXML is distributed as a Ruby Gem for easy installation, e.g.
17
- sudo gem install rdbxml
17
+ sudo gem install rdbxml
18
18
 
19
19
  This will attempt to find the DBXML libaries/headers in the standard paths (plus
20
20
  /usr/local/) and will use the interface files taken from the dbxml-2.2.13
@@ -39,10 +39,11 @@ Sleepycat[http://dev.sleepycat.com/downloads/releasehistorybdbxml.html]), e.g.:
39
39
  sudo ldconfig
40
40
 
41
41
  This will ensure that you have the correct versions of the various BDB and
42
- BDBXML libraries, as well as the current SWIG Interface definitions included in the
42
+ BDBXML libraries, as well as the current SWIG Interface definitions included in
43
43
  the DBXML distribution.
44
44
 
45
- You then pass the location of the (built) DBXML distribution to the RDBXML build system:
45
+ You then pass the location of the (built) DBXML distribution to the RDBXML build
46
+ system:
46
47
  DBXML_DIST=/tmp/dbxml-2.2.13 sudo gem install rdbxml
47
48
 
48
49
  This will build, test, and install the RDBXML gem.
@@ -68,13 +69,12 @@ This will build, test, and install the RDBXML gem.
68
69
 
69
70
  == Disclaimer
70
71
 
71
- This is an *alpha* relesae, intended to test the build system and the BDBXML API
72
- wrappers. The Ruby-style interface is not yet terribly useful (you can read and
73
- write whole documents), but I wanted to get this basic version released before I
74
- went back and started adding functionality.
75
-
76
- Please report any issues on the RDBXML Website[http://rubyforge.org/projects/rdbxml].
72
+ This release is still far from feature completeness, and is primarily
73
+ intended to test the build system and the BDBXML API wrappers. Please report
74
+ any issues on the RDBXML Website[http://rubyforge.org/projects/rdbxml].
77
75
 
78
76
  Author:: Steve Sloan (mailto:steve@finagle.org)
77
+ Website:: http://rdbxml.rubyforge.org
78
+ Rubyforge:: http://rubyforge.org/projects/rdbxml
79
79
  Copyright:: Copyright (c) 2006 Steve Sloan
80
80
  License:: MIT
data/Rakefile CHANGED
@@ -23,7 +23,6 @@ end
23
23
 
24
24
  desc "Build the interface extension"
25
25
  task :extensions => [:db, :dbxml]
26
- CLEAN.include 'ext/*_wrap.cc'
27
26
 
28
27
  desc "Build the BDB interface extension"
29
28
  Rake::SWIGExtensionTask.new :db do |t|
@@ -34,16 +33,16 @@ end
34
33
  desc "Build the BDBXML interface extension"
35
34
  Rake::SWIGExtensionTask.new :dbxml do |t|
36
35
  t.dir = 'ext'
37
- t.deps << 'dbxml_ruby.i'
36
+ t.deps[:dbxml] << :dbxml_ruby
38
37
  t.link_libs += ['db', 'db_cxx', 'dbxml', 'xquery', 'xerces-c', 'pathan']
39
38
  end
40
39
 
41
40
  task :test => :extensions
42
41
  Rake::TestTask.new do |t|
43
42
  t.libs << "ext"
44
- t.test_files = FileList['test/*_test.rb']
43
+ t.test_files = FileList['test/test_*.rb']
45
44
  t.verbose = true
46
- CLEAN.include 'test/*_test.db'
45
+ CLEAN.include 'test/test_*.db'
47
46
  end
48
47
 
49
48
  task :install => [:test, :clean] do end
@@ -55,15 +54,15 @@ rd = Rake::RDocTask.new :rdoc do |rdoc|
55
54
  rdoc.rdoc_files.include 'README', 'MIT-LICENSE'
56
55
  rdoc.rdoc_files.include 'lib/**/*.rb'
57
56
  rdoc.rdoc_files.include 'docs/**/*.rb', 'docs/**/*.rdoc'
58
- rdoc.rdoc_files.include 'rake/**/*.rb'
57
+ rdoc.rdoc_files.include 'rake/**/*task.rb'
59
58
  end
60
59
 
61
- GEM_VERSION = '0.1'
60
+ GEM_VERSION = '0.5'
62
61
  GEM_FILES = rd.rdoc_files + FileList[
63
62
  'Rakefile',
64
63
  'ext/**/*.i',
65
64
  'rake/**/*.rb',
66
- 'test/**/*_test.rb',
65
+ 'test/**/test_*.rb',
67
66
  ]
68
67
 
69
68
  spec = Gem::Specification.new do |s|
@@ -77,7 +76,7 @@ spec = Gem::Specification.new do |s|
77
76
  END
78
77
  s.files = GEM_FILES.to_a.delete_if {|f| f.include?('.svn')}
79
78
  s.autorequire = 'rdbxml'
80
- s.test_files = Dir["test/*_test.rb"]
79
+ s.test_files = Dir["test/test_*.rb"]
81
80
  s.add_dependency 'rake', '> 0.7.0'
82
81
 
83
82
  s.extensions << './extconf.rb'
@@ -95,6 +94,6 @@ end
95
94
  task :default => :extensions
96
95
  task :all => :extensions
97
96
 
98
- #load 'publish.rf' if File.exist? 'publish.rf'
97
+ load 'publish.rf' if File.exist? 'publish.rf'
99
98
 
100
99
 
data/ext/dbxml_ruby.i CHANGED
@@ -1,6 +1,27 @@
1
1
  %module dbxml
2
2
  %include "std_string.i"
3
3
 
4
+ %alias XmlManager::createQueryContext "create_query_context";
5
+
6
+ %alias XmlContainer::getManager "manager";
7
+
8
+ %alias XmlDocument::getContentAsString "to_s";
9
+ %alias XmlDocument::getName "name";
10
+ %alias XmlDocument::setName "name=";
11
+ %alias XmlDocument::getContent "content";
12
+ %alias XmlDocument::setContent "content=";
13
+
14
+ %alias XmlQueryContext::getNamespace "get_namespace";
15
+ %alias XmlQueryContext::setNamespace "set_namespace";
16
+ %alias XmlQueryContext::getDefaultCollection "default_collection";
17
+ %alias XmlQueryContext::setDefaultCollection "default_collection=";
18
+ %alias XmlQueryContext::getVariableValue "[]";
19
+ %alias XmlQueryContext::setVariableValue "[]=";
20
+
21
+ %alias XmlValue::asString "to_s";
22
+ %alias XmlValue::asNumber "to_f";
23
+ %alias XmlValue::asDocument "to_doc";
24
+
4
25
  %exception {
5
26
  try {
6
27
  $action
data/lib/rdbxml.rb CHANGED
@@ -38,14 +38,95 @@ module RDBXML
38
38
  end
39
39
  end
40
40
 
41
- class Dbxml::XmlManager
42
- # Opens the container named +name+, creating it if it doesn't exist.
43
- def []( name )
44
- openContainer name.to_s, Dbxml::DB_CREATE
41
+ class Dbxml::XmlValue
42
+ def to_i ; self.to_f.to_i ; end
43
+
44
+ def ==( that )
45
+ if isNumber
46
+ self.asNumber == that
47
+ elsif isBoolean
48
+ self.asBoolean == that
49
+ else
50
+ self.asString == that.to_s
51
+ end
52
+ end
53
+ end
54
+
55
+ class Dbxml::XmlResults
56
+ include Enumerable
57
+
58
+ def each( &block )
59
+ self.reset
60
+ while self.hasNext
61
+ yield self.next
62
+ end
63
+ end
64
+
65
+ def first
66
+ self.reset
67
+ self.hasNext ? self.next : nil
68
+ end
69
+
70
+ def to_s
71
+ collect { |v| v.to_s }.join "\n"
72
+ end
73
+ end
74
+
75
+ class Dbxml::XmlDocument
76
+ @@namespaces = {}
77
+
78
+ class MetaData
79
+ include Enumerable
80
+
81
+ def initialize(doc)
82
+ @doc = doc
83
+ end
84
+
85
+ def [](name, ns = '')
86
+ v = XmlValue.new
87
+ @doc.getMetaData( ns, name.to_s, v ) ? v : nil
88
+ end
89
+
90
+ def []=(name, *args)
91
+ opts = {}
92
+ val = args.pop
93
+ ns = args.shift || ''
94
+ if val
95
+ @doc.setMetaData ns, name.to_s, XmlValue.new(val)
96
+ else
97
+ delete name, ns
98
+ end
99
+ end
100
+
101
+ def delete(name, ns = '')
102
+ #puts "removeMetaData: #{name.inspect}, #{ns.inspect}"
103
+ @doc.removeMetaData ns, name.to_s
104
+ end
105
+
106
+ def each(&block)
107
+ i = @doc.getMetaDataIterator
108
+ while (xmd = i.next)
109
+ yield xmd.get_name.to_sym, xmd.get_value, xmd.get_uri
110
+ end
111
+ end
112
+
113
+ def size
114
+ s = 0
115
+ i = @doc.getMetaDataIterator
116
+ while i.next do s += 1 end
117
+ s
118
+ end
119
+ end
120
+
121
+ def meta
122
+ @Meta ||= MetaData.new(self)
45
123
  end
124
+
46
125
  end
47
126
 
48
127
  class Dbxml::XmlContainer
128
+ include Enumerable
129
+
49
130
  # Returns the document named +name+, or +nil+ if it doesn't exist.
50
131
  def []( name )
51
132
  begin
@@ -56,24 +137,52 @@ class Dbxml::XmlContainer
56
137
  end
57
138
  end
58
139
 
59
- # Creates/updates the document named +name+ with the string +content+.
140
+ # Creates/updates the document named +name+ with +content+ (either String or XmlDocument).
60
141
  def []=( name, content )
142
+ doc = nil
143
+ if String === content
144
+ doc = manager.createDocument
145
+ doc.name = name
146
+ doc.content = content
147
+ elsif content.kind_of? XmlDocument
148
+ doc = content
149
+ else
150
+ raise ArgumentError, "content must be a String or XmlDocument"
151
+ end
152
+ self << doc
153
+ end
154
+
155
+ # Creates/updates the document +doc+.
156
+ def <<( doc )
61
157
  ctx = getManager.createUpdateContext
62
158
  begin
63
- putDocument name, content, ctx, 0
159
+ putDocument doc, ctx, 0
64
160
  rescue XmlException => ex
65
161
  raise unless ex.to_s =~ /document exists/i
66
- doc = getManager.createDocument
67
- doc.setName name
68
- doc.setContent content
69
- updateDocument doc, ctx
162
+ d = self[doc.name]
163
+ d.content = doc.content
164
+ updateDocument d, ctx
70
165
  end
71
166
  end
167
+
168
+ # Iterates over each document in the collection
169
+ def each( &block )
170
+ getAllDocuments.each(block)
171
+ end
72
172
  end
73
173
 
74
- class Dbxml::XmlDocument
75
- # Returns the document XML as a string.
76
- def to_s
77
- getContentAsString
174
+ class Dbxml::XmlManager
175
+ # Opens the container named +name+, creating it if it doesn't exist.
176
+ def []( name )
177
+ openContainer name.to_s, Dbxml::DB_CREATE
178
+ end
179
+
180
+ def query( xquery, opts = {}, &block )
181
+ opts[:ctx] ||= create_query_context
182
+ q = self.prepare xquery, opts[:ctx]
183
+ res = q.execute( opts[:ctx], 0 )
184
+ #puts "#{xquery} -> #{res}"
185
+ res.each(block) if block_given?
186
+ res
78
187
  end
79
188
  end
@@ -10,9 +10,10 @@ module Rake
10
10
  # from rbconfig (note: examples assume *nix file extensions).
11
11
  #
12
12
  # *Note*: Strings vs Symbols
13
- # In places where filenames are expected (i.e. lib_name and objs), +String+s are used
14
- # as verbatim filenames, while, +Symbol+s have the platform-dependant extension
15
- # appended (e.g. '.so' for libraries and '.o' for objects).
13
+ # In places where filenames are expected (e.g. lib_name and objs), Strings are used
14
+ # as verbatim filenames, while, Symbols have the platform-dependant extension
15
+ # appended (e.g. '.so' for libraries and '.o' for objects). Also, only Symbols
16
+ # have #dir prepended to them.
16
17
  #
17
18
  # Example:
18
19
  # desc "build sample extension"
@@ -20,8 +21,6 @@ module Rake
20
21
  # Rake::ExtensionTask.new :sample => :foo do |t|
21
22
  # # all extension files under this directory
22
23
  # t.dir = 'ext'
23
- # # don't include, but rebuild library if it changes
24
- # t.deps << 'config.h'
25
24
  # # link libraries (libbar.so)
26
25
  # t.link_libs << 'bar'
27
26
  # end
@@ -40,10 +39,6 @@ module Rake
40
39
  # Object files to build and link into the extension.
41
40
  attr_accessor :objs
42
41
 
43
- # Depency files that aren't linked into the library, but cause it to be
44
- # rebuilt when they change.
45
- attr_accessor :deps
46
-
47
42
  # The directory where the extension files (source, output, and
48
43
  # intermediate) are stored.
49
44
  attr_accessor :dir
@@ -55,20 +50,6 @@ module Rake
55
50
  # Additional link libraries
56
51
  attr_accessor :link_libs
57
52
 
58
-
59
- # List of paths to object files to build
60
- def output_objs
61
- @objs.collect do |o|
62
- f = (Symbol === o) ? "#{o}.#{env[:objext]}" : o
63
- File.join( dir, f )
64
- end
65
- end
66
-
67
- # Path to the output library file
68
- def output_lib
69
- File.join( dir, lib_name )
70
- end
71
-
72
53
  # Same arguments as Rake::define_task
73
54
  def initialize( args, &blk )
74
55
  @env = @@DefaultEnv.dup
@@ -83,22 +64,25 @@ module Rake
83
64
  #
84
65
  # Defaults:
85
66
  # - lib_name: name.so
86
- # - objs: name.o
67
+ # - objs: name.o (<- name.{c,cxx,cpp,cc})
87
68
  # - dir: .
69
+ # - link_libs: <none>
88
70
  def set_defaults
89
- @lib_name = (Symbol === name) ? "#{name}.#{env[:dlext]}" : name
90
- @objs = [name.to_sym]
91
- @dir = '.'
92
- @deps, @link_libs = [], []
71
+ @lib_name ||= name.to_sym
72
+ @objs ||= [name.to_sym]
73
+ @dir ||= '.'
74
+ @link_libs ||= []
93
75
  end
94
76
 
95
77
  # Defines the library task.
96
78
  def define_tasks
97
- task name => (deps.collect { |d| File.join( dir, d ) } << output_lib) do end
79
+ output_objs = @objs.collect { |obj| filepath obj, :objext }
80
+ output_lib = filepath lib_name, :dlext
98
81
 
99
- file output_lib => output_objs do |t|
100
- sh_cmd :ldshared, {'-L' => :libdirs}, '-o', t.name, t.prerequisites,
101
- {'-l' => link_libs}, :libs, :dlibs
82
+ task name => output_lib do end
83
+ file output_lib => output_objs do |t|
84
+ sh_cmd :ldshared, {'-L' => :libdirs}, '-o', output_lib, output_objs,
85
+ {'-l' => link_libs}, :libs #, :dldlibs, :librubyarg_shared
102
86
  end
103
87
 
104
88
  CLEAN.include output_objs
@@ -132,21 +116,24 @@ module Rake
132
116
  @@DefaultEnv = {
133
117
  :cxx => ENV['CXX'] || 'c++',
134
118
  :cxxflags => ENV['CXXFLAGS'] || '',
135
-
136
119
  :c_exts => ['c'],
137
120
  :cpp_exts => ['cc', 'cxx', 'cpp'],
138
- :swig => 'swig',
139
- :swig_flags => ['-ruby', '-c++'],
140
- :swig_includedirs => ['.'],
141
-
142
- :includedirs => [], #['/usr/local/include'],
143
- :libdirs => [], #['/usr/local/lib'],
121
+ :includedirs => [],
122
+ :libdirs => [],
144
123
  }
145
124
  Config::CONFIG.each { |k, v| @@DefaultEnv[k.downcase.to_sym] = v }
146
125
  end
147
126
 
148
127
  protected
149
128
 
129
+ # Handles convenience filenames:
130
+ # * f (String) => f
131
+ # * f (Symbol) => dir/f.ext
132
+ def filepath( f, ext )
133
+ ext = env[ext] if Symbol === ext
134
+ Symbol === f ? File.join( dir, "#{f}.#{ext}" ) : f
135
+ end
136
+
150
137
  # Convenience function for cnstructing command lines for build tools.
151
138
  def optify( *opts )
152
139
  return optify(*opts.first) if opts.size == 1 and opts.first.kind_of? Array
@@ -4,7 +4,7 @@ require 'rake/extensiontask'
4
4
  module Rake
5
5
 
6
6
  # Create a build task that will generate a Ruby wrapper extension from
7
- # a SWIG interface definition. Requires SWIG[http://www.swig.org] version 1.3.x.
7
+ # SWIG interface definition(s). Requires SWIG[http://www.swig.org] version 1.3.x.
8
8
  #
9
9
  # See ExtensionTask for more information.
10
10
  #
@@ -13,8 +13,8 @@ module Rake
13
13
  # Rake::SWIGExtensionTask.new :dbxml do |t|
14
14
  # # keep it all under ext/
15
15
  # t.dir = 'ext'
16
- # # dbxml.i includes dbxml_ruby.i -- rebuild if it changes
17
- # t.deps << 'dbxml_ruby.i'
16
+ # # dbxml.i includes dbxml_ruby.i so rebuild if it changes
17
+ # t.deps[:dbxml] << :dbxml_ruby
18
18
  # # link in dbxml libraries
19
19
  # t.link_libs += ['db', 'db_cxx', 'dbxml', 'xquery', 'xerces-c', 'pathan']
20
20
  # end
@@ -23,28 +23,66 @@ module Rake
23
23
  # Copyright:: Copyright (c) 2006 Steve Sloan
24
24
  # License:: GPL
25
25
  class SWIGExtensionTask < ExtensionTask
26
+
27
+ # An Array of interface filenames (Symbol or String) to build and link into
28
+ # the extension.
29
+ attr_accessor :ifaces
30
+
31
+ # A Hash of interface filenames and their dependencies, i.e. files which
32
+ # are not built or linked, but cause the corresponding interface to be
33
+ # rebuild if any of them change.
34
+ attr_accessor :deps
35
+
26
36
  # Defaults:
27
37
  # - lib_name: name.so
28
- # - objs: name_wrap.o
29
- # - deps: name.i
38
+ # - ifaces: name.i
39
+ # - deps: <none>
30
40
  # - dir: .
41
+ # - link_libs: <none>
31
42
  def set_defaults
32
43
  super
33
- @lib_name = (Symbol === name) ? "#{name}.#{env[:dlext]}" : name
34
- @objs = ["#{name}_wrap".to_sym]
35
- @deps = ["#{name}.i"]
44
+ @objs ||= []
45
+ @ifaces ||= [name.to_sym]
46
+ @deps ||= Hash.new []
47
+ end
48
+
49
+ def define_tasks
50
+ for iface in @ifaces
51
+ deps = @deps[iface]
52
+ iface = filepath(iface, :swigext)
53
+ src = iface.sub(/\.#{env[:swigext]}$/, env[:swig_cppext])
54
+
55
+ deps = [deps] unless deps.kind_of? Enumerable
56
+ if deps and deps.any?
57
+ file src => deps.collect { |dep| filepath(dep, :swigext) } << iface
58
+ end
59
+ CLEAN.include src
60
+
61
+ @objs << src.sub(/\.[^.]+$/, '.'+env[:objext])
62
+ end
63
+ super
36
64
  end
37
65
 
38
66
  # Add rule for generating C++ wrapper code (_wrap.cc) from SWIG interface definition (.i).
39
67
  def define_rules
40
68
  verify_swig_version
41
- Rake::Task.create_rule( '_wrap.cc' => [proc {|t| t.gsub /_wrap\.cc$/, '.i' }] ) do |r|
69
+ super
70
+ Rake::Task.create_rule(
71
+ /#{env[:swig_cppext]}$/ => [proc {|t| t.sub /#{env[:swig_cppext]}$/, '.'+env[:swigext] }]
72
+ ) do |r|
42
73
  sh_cmd :swig, :swig_flags, {'-I' => :swig_includedirs}, {'-I' => :includedirs},
43
74
  '-o', r.name, r.sources
44
75
  end
45
- super
46
76
  end
47
77
 
78
+ ExtensionTask.env.update(
79
+ :swig => 'swig',
80
+ :swigext => 'i',
81
+ :swig_cppext => '_wrap.cc',
82
+ :swig_flags => ['-ruby', '-c++'],
83
+ :swig_includedirs => ['.']
84
+ )
85
+
48
86
  protected
49
87
 
50
88
  # Raise an exception unless we have SWIG version 1.3 or later.
File without changes
File without changes
@@ -0,0 +1,186 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'rdbxml'
4
+
5
+ class XmlValueTest < Test::Unit::TestCase
6
+ def test_new_i
7
+ v = XmlValue.new 123
8
+ assert v.isNumber, v.getType
9
+ assert !v.isString && !v.isBoolean && !v.isBinary && !v.isNode
10
+ assert_equal v, 123
11
+ end
12
+
13
+ def test_new_f
14
+ v = XmlValue.new 123.456
15
+ assert v.isNumber
16
+ assert !v.isString && !v.isBoolean && !v.isBinary && !v.isNode
17
+ assert_equal v, 123.456
18
+ end
19
+
20
+ def test_new_s
21
+ v = XmlValue.new 'foo'
22
+ assert v.isString
23
+ assert !v.isNumber && !v.isBoolean && !v.isBinary && !v.isNode
24
+ assert_equal v, 'foo'
25
+ end
26
+
27
+ def test_new_b
28
+ v = XmlValue.new true
29
+ assert v.isBoolean
30
+ assert !v.isNumber && !v.isString && !v.isBinary && !v.isNode
31
+ assert_equal v, true
32
+
33
+ v = XmlValue.new false
34
+ assert v.isBoolean
35
+ assert !v.isNumber && !v.isString && !v.isBinary && !v.isNode
36
+ assert_equal v, false
37
+ end
38
+
39
+ def test_to_s
40
+ assert_equal '123', XmlValue.new(123).to_s
41
+ assert_equal '456.789', XmlValue.new(456.789).to_s
42
+ assert_equal 'foo', XmlValue.new('foo').to_s
43
+ end
44
+
45
+ def test_to_i
46
+ assert_equal 123, XmlValue.new(123).to_i
47
+ assert_equal 456, XmlValue.new(456.789).to_i
48
+ assert_raise(FloatDomainError) { XmlValue.new('foo').to_i }
49
+ end
50
+
51
+ def test_to_f
52
+ assert_equal 123.0, XmlValue.new(123).to_f
53
+ assert_equal 456.789, XmlValue.new(456.789).to_f
54
+ assert XmlValue.new('foo').to_f.nan?
55
+ end
56
+ end
57
+
58
+ class XmlResultsTest < Test::Unit::TestCase
59
+ def setup
60
+ @db = RDBXML::XmlManager.new
61
+ @rng = 3..9
62
+ @res = @db.query "(#{@rng.first} to #{@rng.last})"
63
+ end
64
+
65
+ def test_to_s
66
+ assert_equal @rng.to_a.join("\n"), @res.to_s
67
+ end
68
+
69
+ def test_size
70
+ assert_equal @rng.last - @rng.first + 1, @res.size
71
+ end
72
+
73
+ def test_to_a
74
+ assert_equal @rng.to_a.first, @res.to_a.first
75
+ assert_equal @rng.to_a, @res.to_a
76
+ end
77
+
78
+ def test_first
79
+ assert_equal @rng.first, @res.first
80
+ assert_equal @rng.first.to_s, @res.first.to_s
81
+ end
82
+
83
+ def test_each
84
+ v = @rng.first
85
+ @res.each do |r|
86
+ assert_equal r, v
87
+ v += 1
88
+ end
89
+ end
90
+ end
91
+
92
+ class XmlDocumentTest < Test::Unit::TestCase
93
+ def setup
94
+ @dir = File.join( File.dirname(__FILE__), File.basename(__FILE__, '.rb') + '.db' )
95
+ Dir.mkdir @dir unless File.exists? @dir
96
+ @env = RDBXML::env(@dir)
97
+ @db = RDBXML::XmlManager.new @env, 0
98
+ @docs = @db['test']
99
+ end
100
+
101
+ def test_metadata
102
+ doc = @db.createDocument
103
+ doc.name = "Test#{rand(10000)}"
104
+ doc.content = '<test>This is a test</test>'
105
+ doc.meta[:foo] = 123
106
+ doc.meta['bar:stuff', 'http://nowhere.invalid/namespaces/bar'] = 'Some Stuff'
107
+ doc.meta['baaz:stuff', 'http://nowhere.invalid/namespaces/baaz'] = 'Other Stuff'
108
+
109
+ assert_equal doc.meta[:foo], 123
110
+ assert_equal doc.meta['bar:stuff', 'http://nowhere.invalid/namespaces/bar'], 'Some Stuff'
111
+ assert_equal doc.meta['baaz:stuff', 'http://nowhere.invalid/namespaces/baaz'], 'Other Stuff'
112
+ @docs << doc
113
+
114
+ doc = @docs[doc.name]
115
+ assert_equal 4, doc.meta.size
116
+ doc.meta[:foo] = nil
117
+ doc.meta['bar:stuff', 'http://nowhere.invalid/namespaces/bar'] = nil
118
+ doc.meta.delete 'baaz:stuff', 'http://nowhere.invalid/namespaces/baaz'
119
+
120
+ assert_nil doc.meta[:foo]
121
+ assert_nil doc.meta['bar:stuff', 'http://nowhere.invalid/namespaces/bar']
122
+ assert_nil doc.meta['baaz:stuff', 'http://nowhere.invalid/namespaces/baaz']
123
+
124
+ # @docs << doc
125
+ # doc = @docs[doc.name]
126
+ # assert_nil doc.meta[:foo]
127
+ # assert_nil doc.meta['bar:stuff', 'http://nowhere.invalid/namespaces/bar']
128
+ # assert_nil doc.meta['baaz:stuff', 'http://nowhere.invalid/namespaces/baaz']
129
+ # assert_equal 1, doc.meta.size
130
+ end
131
+ end
132
+
133
+ class XmlContainerTest < Test::Unit::TestCase
134
+ def setup
135
+ @dir = File.join( File.dirname(__FILE__), File.basename(__FILE__, '.rb') + '.db' )
136
+ Dir.mkdir @dir unless File.exists? @dir
137
+ @env = RDBXML::env(@dir)
138
+
139
+ @db = RDBXML::XmlManager.new @env, 0
140
+ @db.setDefaultContainerType RDBXML::XmlContainer::WholedocContainer
141
+ @container = 'test'
142
+ @docs = @db['test']
143
+
144
+ @doc_name = "Test#{rand(10000)}"
145
+ @content = '<test>This is a test</test>'
146
+ end
147
+
148
+ def test_put_get_document
149
+ assert_not_nil @docs
150
+
151
+ @docs[@doc_name] = @content
152
+ doc = @docs[@doc_name]
153
+ assert_not_nil doc
154
+ assert_equal doc.to_s, @content
155
+ end
156
+
157
+ def test_append_get_document
158
+ assert_not_nil @docs
159
+
160
+ doc = @db.createDocument
161
+ doc.name, doc.content = @doc_name, @content
162
+ @docs << doc
163
+
164
+ doc = @docs[@doc_name]
165
+ assert_not_nil doc
166
+ assert_equal doc.to_s, @content
167
+ end
168
+
169
+ def test_update_document
170
+ assert_not_nil @docs
171
+
172
+ for content in [@content, @content.upcase]
173
+ @docs[@doc_name] = content
174
+ doc = @docs[@doc_name]
175
+ assert_not_nil doc
176
+ assert_equal doc.to_s, content
177
+ end
178
+ end
179
+
180
+ def test_query
181
+ xq = "count(collection('#{@container}')/*)"
182
+ ctx = @db.createQueryContext
183
+ q = @db.prepare xq, ctx
184
+ res = q.execute ctx, 0
185
+ end
186
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rdbxml
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2006-05-07 00:00:00 -07:00
6
+ version: "0.5"
7
+ date: 2006-05-14 00:00:00 -07:00
8
8
  summary: Provides wrappers for the BDBXML (and BDB) C++ APIs, plus pure Ruby extensions
9
9
  require_paths:
10
10
  - lib
@@ -40,13 +40,13 @@ files:
40
40
  - ext/dbxml.i
41
41
  - ext/db.i
42
42
  - ext/dbxml_ruby.i
43
- - test/db_test.rb
44
- - test/dbxml_test.rb
45
- - test/rdbxml_test.rb
43
+ - test/test_rdbxml.rb
44
+ - test/test_db.rb
45
+ - test/test_dbxml.rb
46
46
  test_files:
47
- - test/db_test.rb
48
- - test/dbxml_test.rb
49
- - test/rdbxml_test.rb
47
+ - test/test_rdbxml.rb
48
+ - test/test_db.rb
49
+ - test/test_dbxml.rb
50
50
  rdoc_options:
51
51
  - --line-numbers
52
52
  - --inline-source
data/test/rdbxml_test.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'test/unit'
2
- require 'fileutils'
3
- require 'rdbxml'
4
-
5
- class RDBXMLTest < Test::Unit::TestCase
6
-
7
- def setup
8
- @dir = File.join( File.dirname(__FILE__), File.basename(__FILE__, '.rb') + '.db' )
9
- Dir.mkdir @dir unless File.exists? @dir
10
- @env = RDBXML::env(@dir)
11
-
12
- @db = RDBXML::XmlManager.new @env, 0
13
- @db.setDefaultContainerType RDBXML::XmlContainer::WholedocContainer
14
- @docs = @db['test']
15
-
16
- @name = "test document ##{rand(10000)}"
17
- @content = '<test>This is a test</test>'
18
- end
19
-
20
- def test_put_get_document
21
- assert_not_nil @docs
22
-
23
- @docs[name] = @content
24
- doc = @docs[name]
25
- assert_not_nil doc
26
- assert_equal doc.to_s, @content
27
- end
28
-
29
- def test_update_document
30
- assert_not_nil @docs
31
-
32
- for content in [@content, @content.upcase]
33
- @docs[name] = content
34
- doc = @docs[name]
35
- assert_not_nil doc
36
- assert_equal doc.to_s, content
37
- end
38
- end
39
-
40
- end