#include "vcedit.h"
#include "comments.h"
+#define CHECK_CLOSED(o) \
+ if (!o->state) \
+ rb_raise (eClosed, "closed stream");
+
typedef struct {
vcedit_state *state;
VALUE comments;
static VALUE c_close (VALUE self);
-static VALUE cComments, eVT, eOpen, eInvalidData, eInvalidComment,
- eTempFile, eReopen;
+static VALUE cComments, eVT, eClosed, eOpen, eInvalidData,
+ eInvalidComment, eTempFile, eReopen;
static ID id_length;
static void
Data_Get_Struct (self, RbVorbisTagger, o);
+ CHECK_CLOSED (o);
+
vcedit_state_unref (o->state);
o->state = NULL;
Data_Get_Struct (self, RbVorbisTagger, o);
+ CHECK_CLOSED (o);
+
comments_sync (o->comments, o->state);
switch (vcedit_write (o->state)) {
Data_Get_Struct (self, RbVorbisTagger, o);
+ CHECK_CLOSED (o);
+
return o->comments;
}
rb_define_method (cVT, "comments", c_comments, 0);
eVT = rb_define_class_under (cVT, "TaggerError", eVorbis);
+ eClosed = rb_define_class_under (cVT, "ClosedStreamError", eVT);
eOpen = rb_define_class_under (cVT, "OpenError", eVT);
eInvalidData = rb_define_class_under (cVT, "InvalidDataError", eVT);
eInvalidComment = rb_define_class_under (cVT, "InvalidCommentError",
Ogg::Vorbis::Tagger.new(OGG_FILE).close
end
+ def test_close2
+ assert_raise(Ogg::Vorbis::Tagger::ClosedStreamError) do
+ Ogg::Vorbis::Tagger.new(OGG_FILE).close.close
+ end
+
+ assert_raise(Ogg::Vorbis::Tagger::ClosedStreamError) do
+ Ogg::Vorbis::Tagger.open(OGG_FILE) do |t|
+ t.close
+ end
+ end
+ end
+
def test_open_non_existing_file
assert_raises(Ogg::Vorbis::Tagger::OpenError) do
Ogg::Vorbis::Tagger.new("foo.bar")