summaryrefslogtreecommitdiff
path: root/swig/ruby/tests
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2012-08-16 21:20:18 +0800
committerGui Chen <gui.chen@intel.com>2012-08-16 21:20:18 +0800
commit3fbed28be806ffd390adaffe6a049f3dbd55b5aa (patch)
treed40b3cacac28f8814142edf60f062cf72a3401ea /swig/ruby/tests
parent857e712e5928c179e9da121e903b7df68029225e (diff)
downloadlibzypp-bindings-3fbed28be806ffd390adaffe6a049f3dbd55b5aa.tar.gz
libzypp-bindings-3fbed28be806ffd390adaffe6a049f3dbd55b5aa.tar.bz2
libzypp-bindings-3fbed28be806ffd390adaffe6a049f3dbd55b5aa.zip
Signed-off-by: Gui Chen <gui.chen@intel.com>
Diffstat (limited to 'swig/ruby/tests')
-rw-r--r--swig/ruby/tests/CMakeLists.txt11
-rw-r--r--swig/ruby/tests/arch.rb55
-rw-r--r--swig/ruby/tests/bytecount.rb25
-rw-r--r--swig/ruby/tests/commit_callbacks.rb46
-rw-r--r--swig/ruby/tests/loading.rb16
-rw-r--r--swig/ruby/tests/starting.rb22
-rw-r--r--swig/ruby/tests/target.rb44
7 files changed, 219 insertions, 0 deletions
diff --git a/swig/ruby/tests/CMakeLists.txt b/swig/ruby/tests/CMakeLists.txt
new file mode 100644
index 0000000..3b084df
--- /dev/null
+++ b/swig/ruby/tests/CMakeLists.txt
@@ -0,0 +1,11 @@
+#
+# CMakeLists.txt for libzypp-bindings/swig/ruby/tests
+#
+
+ENABLE_TESTING()
+
+ADD_TEST(bindings_ruby_loading ruby -C ${CMAKE_CURRENT_SOURCE_DIR} loading.rb)
+ADD_TEST(bindings_ruby_arch.rb ruby -C ${CMAKE_CURRENT_SOURCE_DIR} arch.rb)
+ADD_TEST(bindings_ruby_bytecount.rb ruby -C ${CMAKE_CURRENT_SOURCE_DIR} bytecount.rb)
+ADD_TEST(bindings_ruby_starting.rb ruby -C ${CMAKE_CURRENT_SOURCE_DIR} starting.rb)
+ADD_TEST(bindings_ruby_target.rb ruby -C ${CMAKE_CURRENT_SOURCE_DIR} target.rb)
diff --git a/swig/ruby/tests/arch.rb b/swig/ruby/tests/arch.rb
new file mode 100644
index 0000000..3e2f508
--- /dev/null
+++ b/swig/ruby/tests/arch.rb
@@ -0,0 +1,55 @@
+#
+# Arch
+#
+
+$:.unshift File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","build","swig","ruby"))
+
+require 'test/unit'
+require 'zypp'
+
+class Zypp::Arch
+ include Comparable
+end
+
+class ArchTest < Test::Unit::TestCase
+ include Zypp
+ def test_arch
+ # define i386, a builtin
+
+ a = Arch.new("i386")
+ assert a
+ assert_equal "i386", a.to_s
+ assert_equal true, a.is_builtin
+
+ # i486 is 'bigger' than i386
+
+ b = Arch.new("i486")
+ assert b
+ assert_equal "i486", b.to_s
+ assert b.is_builtin
+ if VERSION > 800
+ assert_equal a, b.base_arch
+ end
+ assert a < b
+ assert a.compatible_with?(b)
+
+ # A new, adventurous architecture
+ z = Arch.new("xyzzy")
+ assert z
+ assert_equal "xyzzy", z.to_s
+ assert_equal false, z.is_builtin
+
+ # predefined archs
+ assert_equal Arch.new("noarch"), Arch.noarch
+ assert_equal a, Arch.i386
+ assert_equal b, Arch.i486
+ assert_equal Arch.new("i586"), Arch.i586
+ assert_equal Arch.new("i686"), Arch.i686
+ assert_equal Arch.new("x86_64"), Arch.x86_64
+ assert_equal Arch.new("ia64"), Arch.ia64
+ assert_equal Arch.new("ppc"), Arch.ppc
+ assert_equal Arch.new("ppc64"), Arch.ppc64
+ assert_equal Arch.new("s390"), Arch.s390
+ assert_equal Arch.new("s390x"), Arch.s390x
+ end
+end
diff --git a/swig/ruby/tests/bytecount.rb b/swig/ruby/tests/bytecount.rb
new file mode 100644
index 0000000..5b46e14
--- /dev/null
+++ b/swig/ruby/tests/bytecount.rb
@@ -0,0 +1,25 @@
+#
+# Test Bytecount
+#
+
+$:.unshift "../../../build/swig/ruby"
+
+
+# test loading of extension
+require 'test/unit'
+
+class LoadTest < Test::Unit::TestCase
+ require 'zypp'
+ include Zypp
+
+ def test_bytecount
+ g = ByteCount.new(ByteCount.G)
+ assert g
+ gb = ByteCount.new(ByteCount.GB)
+ assert gb
+ k = ByteCount.new(ByteCount.K)
+ assert k.to_i == 1024
+ mb = ByteCount.new(ByteCount.MB)
+ assert mb.to_i == 1000*1000
+ end
+end
diff --git a/swig/ruby/tests/commit_callbacks.rb b/swig/ruby/tests/commit_callbacks.rb
new file mode 100644
index 0000000..74767ce
--- /dev/null
+++ b/swig/ruby/tests/commit_callbacks.rb
@@ -0,0 +1,46 @@
+#
+# Test commit callbacks
+#
+
+$:.unshift "../../../build/swig/ruby"
+
+
+require 'test/unit'
+require 'zypp'
+
+class CommitReceiver
+ # Define class function, we pass the class (not an instance of the class)
+ # to the CommitCallbacks
+ def self.removal_start resolvable
+ $stderr.puts "Starting to remove #{resolvable}"
+ end
+end
+
+class CommitCallbacksTest < Test::Unit::TestCase
+ def test_removal_callback
+ commit_callbacks = Zypp::CommitCallbacks.new
+ assert_equal nil, commit_callbacks.receiver
+ # In Ruby the class is also an object, so we connect to the class
+ commit_callbacks.connect CommitReceiver
+ assert_equal CommitReceiver, commit_callbacks.receiver
+
+ z = Zypp::ZYppFactory::instance.getZYpp
+
+ z.initializeTarget(Zypp::Pathname.new("/"))
+ t = z.target
+ t.load
+ t.buildCache
+
+ emitter = Zypp::CommitCallbacksEmitter.new
+ p = z.pool
+ p.each do |item|
+ puts "Emitting removal of ", item
+ puts item.methods.inspect
+ emitter.remove_start(item)
+ break
+ end
+
+ commit_callbacks.disconnect
+ assert_equal nil, commit_callbacks.receiver
+ end
+end
diff --git a/swig/ruby/tests/loading.rb b/swig/ruby/tests/loading.rb
new file mode 100644
index 0000000..01ae25a
--- /dev/null
+++ b/swig/ruby/tests/loading.rb
@@ -0,0 +1,16 @@
+#
+# Test loading of the bindings
+#
+
+$:.unshift "../../../build/swig/ruby"
+
+
+# test loading of extension
+require 'test/unit'
+
+class LoadTest < Test::Unit::TestCase
+ def test_loading
+ require 'zypp'
+ assert true
+ end
+end
diff --git a/swig/ruby/tests/starting.rb b/swig/ruby/tests/starting.rb
new file mode 100644
index 0000000..5f3afb2
--- /dev/null
+++ b/swig/ruby/tests/starting.rb
@@ -0,0 +1,22 @@
+#
+# Test starting of zypp
+#
+
+$:.unshift "../../../build/swig/ruby"
+
+
+# test loading of extension
+require 'test/unit'
+
+class LoadTest < Test::Unit::TestCase
+ def test_loading
+ require 'zypp'
+ zypp = Zypp::ZYppFactory::instance.getZYpp
+ assert zypp
+ zconfig = Zypp::ZConfig::instance
+ assert zconfig
+ puts zconfig.systemArchitecture
+ zconfig.setSystemArchitecture(Zypp::Arch.new("i686"))
+ puts zconfig.systemArchitecture
+ end
+end
diff --git a/swig/ruby/tests/target.rb b/swig/ruby/tests/target.rb
new file mode 100644
index 0000000..cfecfff
--- /dev/null
+++ b/swig/ruby/tests/target.rb
@@ -0,0 +1,44 @@
+#
+# Example for target
+#
+
+$:.unshift "../../../build/swig/ruby"
+
+
+# test loading of extension
+require 'test/unit'
+
+class LoadTest < Test::Unit::TestCase
+ require 'zypp'
+ include Zypp
+ def test_target
+ z = ZYppFactory::instance.getZYpp
+
+ assert z.homePath
+ assert z.tmpPath
+
+ z.initializeTarget(Zypp::Pathname.new("/"))
+ t = z.target
+ assert t
+ t.load
+ t.buildCache
+
+ p = z.pool
+ assert p
+ assert p.size > 0
+
+ # Iterate over pool, gives PoolItems
+ i = 0
+ puts "#{p.size} PoolItems:"
+ p.each do | pi |
+ i = i + 1
+ break if i > 10
+ puts pi
+ # PoolItems have status and a resolvable
+# r = pi.resolvable
+# puts "#{r.name}-#{r.edition}"
+ end
+
+ assert true
+ end
+end