# HG changeset patch # User Jacob Carlborg # Date 1313247995 -7200 # Node ID 70df72d2299ad61e4eb04b376e952e6f8e27b918 # Parent 715cd0264c15fdaa5bbf773e21e921d550dacd79 Added unit tests for events. diff -r 715cd0264c15 -r 70df72d2299a tests/Events.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/Events.d Sat Aug 13 17:06:35 2011 +0200 @@ -0,0 +1,89 @@ +/** + * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. + * Authors: Jacob Carlborg + * Version: Initial created: Aug 7, 2011 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module tests.Events; + +import orange.core._; +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 b; +int c; + +class Events +{ + int a; + int d; + + void serializing () + { + a = 3; + } + + mixin OnSerializing!(serializing); + + void serialized () + { + b = 4; + } + + mixin OnSerialized!(serialized); + + void deserializing () + { + c = 5; + } + + mixin OnDeserializing!(deserializing); + + void deserialized () + { + d = 6; + } + + mixin OnDeserialized!(deserialized); +} + +Events events; + +unittest +{ + archive = new XMLArchive!(char); + serializer = new Serializer(archive); + + events = new Events; + + describe("serialize a class with event handlers") in { + it("should return serialized class with the correct values set by the event handlers") in { + serializer.reset; + serializer.serialize(events); + + assert(archive.data().containsDefaultXmlContent()); + assert(archive.data().containsXmlTag("object", `runtimeType="tests.Events.Events" type="Events" key="0" id="0"`)); + assert(archive.data().containsXmlTag("int", `key="a" id="1"`, "3")); + assert(archive.data().containsXmlTag("int", `key="d" id="2"`, "0")); + + assert(b == 4); + }; + }; + + describe("deserialize class with a base class") in { + it("should return a deserialized string equal to the original string") in { + auto eventsDeserialized = serializer.deserialize!(Events)(archive.untypedData); + + assert(eventsDeserialized.a == 3); + assert(eventsDeserialized.d == 6); + + assert(c == 5); + }; + }; +} \ No newline at end of file