Mercurial > projects > orange
changeset 42:8b9409423740
Added unit tests for (de)serializing events.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 07 Aug 2011 17:53:50 +0200 |
parents | b538d02578cb |
children | 6f35fb47ca24 |
files | .hgignore orange/serialization/Events.d orange/serialization/Serializer.d tests/Event.d tests/_.d unittest.sh |
diffstat | 6 files changed, 74 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sat Aug 06 13:38:26 2011 +0200 +++ b/.hgignore Sun Aug 07 17:53:50 2011 +0200 @@ -17,4 +17,5 @@ kandil lib import -unittest \ No newline at end of file +unittest +*.exe \ No newline at end of file
--- a/orange/serialization/Events.d Sat Aug 06 13:38:26 2011 +0200 +++ b/orange/serialization/Events.d Sun Aug 07 17:53:50 2011 +0200 @@ -41,7 +41,9 @@ } } -package const onDeserializedField = "__onDeserialized"; -package const onDeserializingField = "__onDeserializing"; -package const onSerializedField = "__onSerialized"; -package const onSerializingField = "__onSerializing"; \ No newline at end of file +package: + +const onDeserializedField = "__onDeserialized"; +const onDeserializingField = "__onDeserializing"; +const onSerializedField = "__onSerialized"; +const onSerializingField = "__onSerializing"; \ No newline at end of file
--- a/orange/serialization/Serializer.d Sat Aug 06 13:38:26 2011 +0200 +++ b/orange/serialization/Serializer.d Sun Aug 07 17:53:50 2011 +0200 @@ -453,7 +453,7 @@ nextId; archive.unarchiveObject(keyOrId, id, val, { - triggerEvents(deserializing, value, { + triggerEvents(deserializing, cast(T) val, { value = cast(T) val; auto runtimeType = value.classinfo.name;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/Event.d Sun Aug 07 17:53:50 2011 +0200 @@ -0,0 +1,63 @@ +/** + * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. + * Authors: Jacob Carlborg + * Version: Initial created: Aug 6, 2011 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module tests.Event; + +import orange.core.string; +import orange.serialization.Serializer; +import orange.serialization.Events; +import orange.serialization.archives.XMLArchive; +import orange.test.UnitTester; +import tests.Util; + +Serializer serializer; +XMLArchive!(char) archive; + +int[] arr; + +class Foo +{ + + void serializing () + { + arr ~= 1; + } + + void serialized () + { + arr ~= 2; + } + + void deserializing () + { + arr ~= 3; + } + + void deserialized () + { + arr ~= 4; + } + + mixin OnSerializing!(serializing); + mixin OnSerialized!(serialized); + mixin OnDeserializing!(deserializing); + mixin OnDeserialized!(deserialized); +} + +unittest +{ + archive = new XMLArchive!(char); + serializer = new Serializer(archive); + + describe("serialization events") in { + it("all four events should be triggered when serializing and deserializing") in { + serializer.serialize(new Foo); + serializer.deserialize!(Foo)(archive.untypedData); + + assert(arr == [1, 2, 3, 4]); + }; + }; +} \ No newline at end of file