aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-11-12 20:23:37 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-11-12 20:23:37 +0000
commitfca1d9a995915d620495e1c6953a44b34e700ece (patch)
tree118467c8e455d8a6ea23b7e1bf2b418c42fed553
parent20485b49854e932244a8602422c14ea3839e6a9c (diff)
downloadpaludis-fca1d9a995915d620495e1c6953a44b34e700ece.tar.gz
paludis-fca1d9a995915d620495e1c6953a44b34e700ece.tar.xz
Add type checking to value_to functions in ruby bindings.
-rw-r--r--ruby/dep_atom.cc7
-rw-r--r--ruby/dep_atom_TEST.rb3
-rw-r--r--ruby/qualified_package_name.cc7
-rw-r--r--ruby/qualified_package_name_TEST.rb6
-rw-r--r--ruby/repository_TEST.rb6
-rw-r--r--ruby/version_metadata.cc14
-rw-r--r--ruby/version_spec.cc7
7 files changed, 44 insertions, 6 deletions
diff --git a/ruby/dep_atom.cc b/ruby/dep_atom.cc
index 71e1626..e619766 100644
--- a/ruby/dep_atom.cc
+++ b/ruby/dep_atom.cc
@@ -196,12 +196,17 @@ paludis::ruby::value_to_package_dep_atom(VALUE v)
{
if (T_STRING == TYPE(v))
return PackageDepAtom::ConstPointer(new PackageDepAtom(StringValuePtr(v)));
- else
+ else if (rb_obj_is_kind_of(v, c_package_dep_atom))
{
PackageDepAtom::ConstPointer * v_ptr;
Data_Get_Struct(v, PackageDepAtom::ConstPointer, v_ptr);
return *v_ptr;
}
+ else
+ {
+ std::string message = "TypeError: can't convert " + std::string(rb_obj_classname(v)) + " into PackageDepAtom";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
}
VALUE
diff --git a/ruby/dep_atom_TEST.rb b/ruby/dep_atom_TEST.rb
index 6655860..a0be678 100644
--- a/ruby/dep_atom_TEST.rb
+++ b/ruby/dep_atom_TEST.rb
@@ -87,6 +87,9 @@ module Paludis
assert_raise PackageDepAtomError do
v = BlockDepAtom.new("=foo/bar")
end
+ assert_raise TypeError do
+ v = BlockDepAtom.new(PlainTextDepAtom.new('foo-bar/baz'))
+ end
end
def test_blocked_atom
diff --git a/ruby/qualified_package_name.cc b/ruby/qualified_package_name.cc
index 29a642e..97dfb78 100644
--- a/ruby/qualified_package_name.cc
+++ b/ruby/qualified_package_name.cc
@@ -129,12 +129,17 @@ paludis::ruby::value_to_qualified_package_name(VALUE v)
{
if (T_STRING == TYPE(v))
return QualifiedPackageName(StringValuePtr(v));
- else
+ else if (rb_obj_is_kind_of(v, c_qualified_package_name))
{
QualifiedPackageName * v_ptr;
Data_Get_Struct(v, QualifiedPackageName, v_ptr);
return *v_ptr;
}
+ else
+ {
+ std::string message = "TypeError: can't convert " + std::string(rb_obj_classname(v)) + " into QualifiedPackageName";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
}
VALUE
diff --git a/ruby/qualified_package_name_TEST.rb b/ruby/qualified_package_name_TEST.rb
index b93cce0..8404bd3 100644
--- a/ruby/qualified_package_name_TEST.rb
+++ b/ruby/qualified_package_name_TEST.rb
@@ -92,6 +92,12 @@ module Paludis
qpn.package = pkg_new
assert_equal pkg_new, qpn.package
end
+
+ def test_to_value_type_error
+ assert_raise TypeError do
+ QualifiedPackageName.new('foo-bar/baz') <=> PackageDepAtom.new('foo-bar/baz')
+ end
+ end
end
end
diff --git a/ruby/repository_TEST.rb b/ruby/repository_TEST.rb
index 81ee8cf..06d0262 100644
--- a/ruby/repository_TEST.rb
+++ b/ruby/repository_TEST.rb
@@ -60,6 +60,12 @@ module Paludis
assert ! repo.has_version?("foo/barbar", VersionSpec.new("1.0"))
assert ! repo.has_version?("foo/bar", VersionSpec.new("3.0"))
end
+
+ def test_has_version_error
+ assert_raise TypeError do
+ repo.has_version?('foo/bar', PackageDepAtom.new('foo-bar/baz'))
+ end
+ end
end
class TestCase_RepositoryHasCategoryNamed < Test::Unit::TestCase
diff --git a/ruby/version_metadata.cc b/ruby/version_metadata.cc
index dcf8a57..beddcdd 100644
--- a/ruby/version_metadata.cc
+++ b/ruby/version_metadata.cc
@@ -188,9 +188,17 @@ paludis::ruby::version_metadata_to_value(VersionMetadata::ConstPointer m)
VersionMetadata::ConstPointer
paludis::ruby::value_to_version_metadata(VALUE v)
{
- VersionMetadata::ConstPointer * v_ptr;
- Data_Get_Struct(v, VersionMetadata::ConstPointer, v_ptr);
- return *v_ptr;
+ if (rb_obj_is_kind_of(v, c_version_metadata))
+ {
+ VersionMetadata::ConstPointer * v_ptr;
+ Data_Get_Struct(v, VersionMetadata::ConstPointer, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ std::string message = "TypeError: can't convert " + std::string(rb_obj_classname(v)) + " into VersionMetadata";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
}
RegisterRubyClass::Register paludis_ruby_register_version_metadata PALUDIS_ATTRIBUTE((used))
diff --git a/ruby/version_spec.cc b/ruby/version_spec.cc
index 6eb66c3..12e7133 100644
--- a/ruby/version_spec.cc
+++ b/ruby/version_spec.cc
@@ -98,12 +98,17 @@ paludis::ruby::value_to_version_spec(VALUE v)
{
if (T_STRING == TYPE(v))
return VersionSpec(StringValuePtr(v));
- else
+ else if (rb_obj_is_kind_of(v, c_version_spec))
{
VersionSpec * v_ptr;
Data_Get_Struct(v, VersionSpec, v_ptr);
return *v_ptr;
}
+ else
+ {
+ std::string message = "TypeError: can't convert " + std::string(rb_obj_classname(v)) + "into VersionSpec";
+ rb_raise(rb_eTypeError, message.c_str());
+ }
}
VALUE