From db79481964d28b069139851500a7482f4f56bb54 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 9 Jun 2005 17:42:34 +0000 Subject: [PATCH] Raise BadElementError if Stream#serialize is called on a bad Stream object. --- ChangeLog | 5 ++++- ext/ext.c | 15 ++++++++++++--- test/test_stream.rb | 11 ++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bde4f3..26487df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,13 @@ -- -$Id: ChangeLog 61 2005-06-09 17:33:48Z tilman $ +$Id: ChangeLog 62 2005-06-09 17:42:34Z tilman $ ++ 2005-06-09 Tilman Sauerbeck (tilman at code-monkey de) * ext/ext.c: Object#to_eet: Don't put the final chunk in a stream again, it's not needed + * ext/ext.c, test/test_stream.rb: If Stream#serialize is called on + a stream that includes non-Chunk elements, BadElementError is + raised 2005-06-08 Tilman Sauerbeck (tilman at code-monkey de) * ext/ext.c, lib/eet.rb, test/test_basic.rb: diff --git a/ext/ext.c b/ext/ext.c index 22ccb19..8fe22e3 100644 --- a/ext/ext.c +++ b/ext/ext.c @@ -1,5 +1,5 @@ /* - * $Id: ext.c 61 2005-06-09 17:33:48Z tilman $ + * $Id: ext.c 62 2005-06-09 17:42:34Z tilman $ * * Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) * @@ -47,7 +47,8 @@ static VALUE c_close (VALUE self); static VALUE cStream, cChunk, - eEetError, eNameError, ePropError, + eEetError, eNameError, ePropError, eStreamError, + eBadElementError, sym_lossy, sym_level, sym_quality, sym_char, sym_short, sym_long_long, sym_double; static ID id_include, id_serialize, id_push, id_keys, @@ -450,7 +451,12 @@ stream_serialize (VALUE self) return ret; for (i = 0; i < stream->len; i++) { - VALUE str = rb_funcall (stream->ptr[i], id_serialize, 0, NULL); + VALUE str; + + if (rb_obj_is_kind_of (stream->ptr[i], cChunk) == Qfalse) + rb_raise (eBadElementError, "stream member is not a Chunk"); + + str = rb_funcall (stream->ptr[i], id_serialize, 0, NULL); rb_str_append (ret, str); } @@ -685,6 +691,9 @@ Init_eet_ext () eEetError = rb_define_class_under (m, "EetError", rb_eStandardError); eNameError = rb_define_class_under (m, "NameError", eEetError); ePropError = rb_define_class_under (m, "PropertyError", eEetError); + eStreamError = rb_define_class_under (m, "StreamError", eEetError); + eBadElementError = rb_define_class_under (m, "BadElementError", + eStreamError); id_include = rb_intern ("include?"); id_serialize = rb_intern ("serialize"); diff --git a/test/test_stream.rb b/test/test_stream.rb index 68e7ea4..d203d9d 100644 --- a/test/test_stream.rb +++ b/test/test_stream.rb @@ -1,4 +1,4 @@ -# $Id: test_stream.rb 1 2005-03-26 01:45:38Z tilman $ +# $Id: test_stream.rb 62 2005-06-09 17:42:34Z tilman $ require "eet" require "test/unit" @@ -39,4 +39,13 @@ class StreamTest < Test::Unit::TestCase assert_equal([], stream) end + + def test_broken_stream + stream = Eet::Stream.new + stream << "FooBarBaz" + + assert_raise(Eet::BadElementError) do + stream.serialize + end + end end -- 2.30.2