summaryrefslogtreecommitdiffstats
path: root/ruby/tests
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-08-15 08:37:09 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-08-15 10:34:23 +0100
commit49b89eec45780eceea5b72ad1a466f9549e788eb (patch)
tree6af3f71d6cc3a1a330ca9a65c2b70f083a66e9d5 /ruby/tests
parent422d46d06a84d0b8194a53de4ad242dbeea85c52 (diff)
Add Ruby bindings.
Diffstat (limited to 'ruby/tests')
-rw-r--r--ruby/tests/tc_010_load.rb28
-rw-r--r--ruby/tests/tc_021_close.rb29
-rw-r--r--ruby/tests/tc_200_write.rb46
-rw-r--r--ruby/tests/tc_210_setvalue.rb68
4 files changed, 171 insertions, 0 deletions
diff --git a/ruby/tests/tc_010_load.rb b/ruby/tests/tc_010_load.rb
new file mode 100644
index 0000000..113ab69
--- /dev/null
+++ b/ruby/tests/tc_010_load.rb
@@ -0,0 +1,28 @@
+# hivex Ruby bindings -*- ruby -*-
+# Copyright (C) 2009-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+require 'test/unit'
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex"))
+require 'hivex'
+
+class TestLoad < Test::Unit::TestCase
+ def test_load
+ h = Hivex::open("../images/minimal", {})
+ assert_not_nil (h)
+ end
+end
diff --git a/ruby/tests/tc_021_close.rb b/ruby/tests/tc_021_close.rb
new file mode 100644
index 0000000..a089cf3
--- /dev/null
+++ b/ruby/tests/tc_021_close.rb
@@ -0,0 +1,29 @@
+# hivex Ruby bindings -*- ruby -*-
+# Copyright (C) 2009-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+require 'test/unit'
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex"))
+require 'hivex'
+
+class TestClose < Test::Unit::TestCase
+ def test_close
+ h = Hivex::open("../images/minimal", {})
+ assert_not_nil (h)
+ h.close()
+ end
+end
diff --git a/ruby/tests/tc_200_write.rb b/ruby/tests/tc_200_write.rb
new file mode 100644
index 0000000..b46dc7b
--- /dev/null
+++ b/ruby/tests/tc_200_write.rb
@@ -0,0 +1,46 @@
+# hivex Ruby bindings -*- ruby -*-
+# Copyright (C) 2009-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+require 'test/unit'
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex"))
+require 'hivex'
+
+class TestWrite < Test::Unit::TestCase
+ def test_write
+ h = Hivex::open("../images/minimal", {:write => 1})
+ assert_not_nil (h)
+
+ root = h.root()
+ assert (root)
+
+ h.node_add_child(root, "A")
+ h.node_add_child(root, "B")
+ b = h.node_get_child(root, "B")
+ assert (b)
+
+ values = [
+ { :key => "Key1", :type => 3, :value => "ABC" },
+ { :key => "Key2", :type => 3, :value => "DEF" }
+ ]
+ h.node_set_values(b, values)
+
+ # Don't actually commit here because that would overwrite
+ # the original file.
+ # h.commit()
+ end
+end
diff --git a/ruby/tests/tc_210_setvalue.rb b/ruby/tests/tc_210_setvalue.rb
new file mode 100644
index 0000000..e55e5fe
--- /dev/null
+++ b/ruby/tests/tc_210_setvalue.rb
@@ -0,0 +1,68 @@
+# hivex Ruby bindings -*- ruby -*-
+# Copyright (C) 2009-2011 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+require 'test/unit'
+$:.unshift(File::join(File::dirname(__FILE__), "..", "lib"))
+$:.unshift(File::join(File::dirname(__FILE__), "..", "ext", "hivex"))
+require 'hivex'
+
+class TestSetValue < Test::Unit::TestCase
+ def test_set_value
+ h = Hivex::open("../images/minimal", {:write => 1})
+ assert_not_nil (h)
+
+ root = h.root()
+ assert (root)
+
+ h.node_add_child(root, "B")
+ b = h.node_get_child(root, "B")
+
+ values = [
+ { :key => "Key1", :type => 3, :value => "ABC" },
+ { :key => "Key2", :type => 2, :value => "DEF" }
+ ]
+ h.node_set_values(b, values)
+
+ value1 = { :key => "Key3", :type => 3, :value => "GHI" }
+ h.node_set_value(b, value1)
+
+ value2 = { :key => "Key1", :type => 3, :value => "JKL" }
+ h.node_set_value(b, value2)
+
+ val = h.node_get_value(b, "Key1")
+ hash = h.value_value(val)
+ assert (hash[:type] == 3)
+ assert (hash[:value] == "JKL")
+ assert (hash[:len] == 3)
+
+ val = h.node_get_value(b, "Key2")
+ hash = h.value_value(val)
+ assert (hash[:type] == 2)
+ assert (hash[:value] == "DEF")
+ assert (hash[:len] == 3)
+
+ val = h.node_get_value(b, "Key3")
+ hash = h.value_value(val)
+ assert (hash[:type] == 3)
+ assert (hash[:value] == "GHI")
+ assert (hash[:len] == 3)
+
+ # Don't actually commit here because that would overwrite
+ # the original file.
+ # h.commit()
+ end
+end