[JEDI.NET-commits] main/Nunit/source NUnit.Jedi.System.pas,NONE,1.1
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-11-24 15:19:31
|
Update of /cvsroot/jedidotnet/main/Nunit/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3079/main/Nunit/source Added Files: NUnit.Jedi.System.pas Log Message: Added Jedi.Core unit test (Jedi.System namespace is currently the only one implemented) --- NEW FILE: NUnit.Jedi.System.pas --- unit NUnit.Jedi.System; interface uses System.ComponentModel, NUnit.Framework, Jedi.System; type [TestFixture] AttributeUtils = class strict protected List1: array of Attribute; List2: AttributeCollection; ListAfterAdd: array of Attribute; ListAfterAddAndReplace: array of Attribute; ListAfterDelete: array of Attribute; ListAfterReplace: array of Attribute; public [TestFixtureSetup] procedure TestSetup; [Test] procedure Combine_Add; [Test] procedure Combine_AddAndReplace; [Test] procedure Combine_Delete; [Test] procedure Combine_Replace; [Test] procedure RetrieveAttributeByType; [Test] procedure RetrieveAttributeByInstance; end; implementation {$REGION 'Test attributes'} type TestAttributeBase = class (Attribute) public constructor Create(value: &Object); public Value: &Object; end; TestAttribute1 = class (TestAttributeBase); TestAttribute2 = class (TestAttributeBase); TestAttribute3 = class (TestAttributeBase); TestAttribute4 = class (TestAttributeBase); TestAttribute5 = class (TestAttributeBase); TestAttribute6 = class (TestAttributeBase); TestAttribute7 = class (TestAttributeBase); TestAttribute8 = class (TestAttributeBase); TestAttribute9 = class (TestAttributeBase); TestAttribute11 = class (TestAttribute1); TestAttribute12 = class (TestAttribute1); TestAttribute111 = class (TestAttribute11); TestAttribute112 = class (TestAttribute11); TestAttribute121 = class (TestAttribute12); TestAttribute122 = class (TestAttribute12); TestAttribute21 = class (TestAttribute2); TestAttribute22 = class (TestAttribute2); TestAttribute211 = class (TestAttribute21); TestAttribute212 = class (TestAttribute21); TestAttribute221 = class (TestAttribute22); TestAttribute222 = class (TestAttribute22); {$REGION 'TestAttributeBase'} constructor TestAttributeBase.Create(value: &Object); begin inherited Create; Self.Value := value; end; {$ENDREGION} {$ENDREGION} {$REGION 'AttributeUtils'} procedure AttributeUtils.Combine_Add; var newList: array of Attribute; begin newList := Jedi.System.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Add); Assert.AreEqual(ListAfterAdd, newList); end; procedure AttributeUtils.Combine_AddAndReplace; var newList: array of Attribute; begin newList := Jedi.System.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.AddAndReplace); Assert.AreEqual(ListAfterAddAndReplace, newList); end; procedure AttributeUtils.Combine_Delete; var newList: array of Attribute; begin newList := Jedi.System.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Delete); Assert.AreEqual(ListAfterDelete, newList); end; procedure AttributeUtils.Combine_Replace; var newList: array of Attribute; begin newList := Jedi.System.AttributeUtils.CombineAttributes(List1, List2, AttributeCombineOperation.Replace); Assert.AreEqual(ListAfterReplace, newList); end; procedure AttributeUtils.RetrieveAttributeByType; var attr: Attribute; begin attr := Jedi.System.AttributeUtils.GetAttribute(List1, TypeOf(TestAttribute1)); Assert.AreSame(List1[0], attr, 'List1[0]'); attr := Jedi.System.AttributeUtils.GetAttribute(List2, TypeOf(TestAttribute1)); Assert.AreSame(List2[0], attr, 'List2[0]'); end; procedure AttributeUtils.RetrieveAttributeByInstance; var attr: Attribute; begin attr := TestAttribute1.Create('Attribute 1, list 1.'); attr := Jedi.System.AttributeUtils.GetAttribute(List1, attr); Assert.AreSame(List1[0], attr, 'List1[0]'); attr := TestAttribute1.Create('Attribute 1, list 2.'); attr := Jedi.System.AttributeUtils.GetAttribute(List2, attr); Assert.AreSame(List2[0], attr, 'List2[0]'); attr := TestAttribute1.Create('Attribute x, list 1.'); attr := Jedi.System.AttributeUtils.GetAttribute(List1, attr); Assert.IsNull( attr, 'Found an attribute for TestAttribute1(''Attribute x, list1.'')'); attr := TestAttribute1.Create('Attribute x, list 2.'); attr := Jedi.System.AttributeUtils.GetAttribute(List2, attr); Assert.IsNull( attr, 'Found an attribute for TestAttribute1(''Attribute x, list2.'')'); end; procedure AttributeUtils.TestSetup; begin List1 := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 1.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); List2 := AttributeCollection.Create(AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') )); ListAfterAdd := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 1.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') ); ListAfterAddAndReplace := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.'), TestAttribute11.Create('Attribute 2, list 2.'), TestAttribute2.Create('Attribute 3, list 2.'), TestAttribute6.Create('Attribute 4, list 2.'), TestAttribute7.Create('Attribute 5, list 2.') ); ListAfterDelete := AttributeArray.Create( TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); ListAfterReplace := AttributeArray.Create( TestAttribute1.Create('Attribute 1, list 2.'), TestAttribute212.Create('Attribute 2, list 1.'), TestAttribute3.Create('Attribute 3, list 1.'), TestAttribute4.Create('Attribute 4, list 1.'), TestAttribute5.Create('Attribute 5, list 1.') ); end; {$ENDREGION} end. |