aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2006-11-22 18:38:36 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2006-11-22 18:38:36 +0000
commitbc31972e8c19b43d9861efa7ea00181a95081742 (patch)
tree4dd575081430f01d95c129c48dd3f7bd741996c0
parent1c64fe1dffda380a6ef52e9e6bb93e06102caf17 (diff)
downloadpaludis-bc31972e8c19b43d9861efa7ea00181a95081742.tar.gz
paludis-bc31972e8c19b43d9861efa7ea00181a95081742.tar.xz
Add check before casting to LogLevel in ruby binding.
-rw-r--r--ruby/log.cc10
-rw-r--r--ruby/log_TEST.rb14
2 files changed, 20 insertions, 4 deletions
diff --git a/ruby/log.cc b/ruby/log.cc
index b270f22..2940b1a 100644
--- a/ruby/log.cc
+++ b/ruby/log.cc
@@ -40,7 +40,10 @@ namespace
VALUE
log_log_level_set(VALUE self, VALUE value)
{
- Log::get_instance()->set_log_level(static_cast<LogLevel>(NUM2INT(value)));
+ int l = NUM2INT(value);
+ if (l < 0 || l >= last_ll)
+ rb_raise(rb_eTypeError, "Log.level= expects a valid LogLevel");
+ Log::get_instance()->set_log_level(static_cast<LogLevel>(l));
return self;
}
@@ -54,7 +57,10 @@ namespace
VALUE
log_message(VALUE self, VALUE log_level, VALUE message)
{
- Log::get_instance()->message(static_cast<LogLevel>(NUM2INT(log_level)), lc_no_context,
+ int l = NUM2INT(log_level);
+ if (l < 0 || l >= last_ll)
+ rb_raise(rb_eTypeError, "Log.log_message expects a valid LogLevel as the first parameter");
+ Log::get_instance()->message(static_cast<LogLevel>(l), lc_no_context,
stringify(StringValuePtr(message)));
return self;
}
diff --git a/ruby/log_TEST.rb b/ruby/log_TEST.rb
index b064af7..fbc1c47 100644
--- a/ruby/log_TEST.rb
+++ b/ruby/log_TEST.rb
@@ -56,12 +56,18 @@ module Paludis
end
def test_log_level_set
- Log.instance.log_level = LogLevel::Debug;
+ Log.instance.log_level = LogLevel::Debug
assert_equal LogLevel::Debug, Log.instance.log_level
- Log.instance.log_level = LogLevel::Warning;
+ Log.instance.log_level = LogLevel::Warning
assert_equal LogLevel::Warning, Log.instance.log_level
end
+
+ def test_error
+ assert_raise TypeError do
+ Log.instance.log_level = 456
+ end
+ end
end
class TestCase_LogMessage < Test::Unit::TestCase
@@ -77,6 +83,10 @@ module Paludis
assert_raise TypeError do
Log.instance.message "Warning", "This should fail"
end
+
+ assert_raise TypeError do
+ Log.instance.message 456, "This should fail"
+ end
end
end
end