-- TestTestSubject.mesa December 6, 1985 11:23:33 am PST
-- Sturgis, January 3, 1986 3:05:08 pm PST
DIRECTORY
Commander USING[CommandProc, Register],
FS USING[StreamOpen],
IO USING[Close, STREAM],
KipperSupport USING[CreateKipperer, CreateUnKipperer, Kipperer, UnKipperer, KipperRope, UnKipperRope],
Rope USING[ROPE, Equal, FromRefText, Substr],
TestSubject USING[A, ABody, KipperA, UnKipperA, B, KipperB, UnKipperB, z, s, Kippers, UnKippers, X1, KipperX1, UnKipperX1, Z1, KipperZ1, UnKipperZ1, W1, Item, ItemBody, W2];
TestTestSubject: CEDAR PROGRAM IMPORTS Commander, FS, IO, KipperSupport, Rope, TestSubject =
BEGIN
CompareA: PROC[old, new: TestSubject.A] =
BEGIN
oldP: TestSubject.A ← old;
newP: TestSubject.A ← new;
IF newP.prev # NIL THEN ERROR;
WHILE oldP # NIL AND newP # NIL DO
IF oldP.x # newP.x OR oldP.y # newP.y THEN ERROR;
IF newP.next # NIL THEN
{IF newP.next.prev # newP THEN ERROR};
oldP ← oldP.next;
newP ← newP.next;
ENDLOOP;
IF oldP # NIL OR newP # NIL THEN ERROR;
END;
Compares: PROC[old, new: TestSubject.s] =
BEGIN
oldCell: TestSubject.s ← old;
newCell: TestSubject.s ← new;
WHILE oldCell # NIL DO
IF oldCell.first # newCell.first THEN ERROR;
oldCell ← oldCell.rest;
newCell ← newCell.rest;
ENDLOOP;
IF newCell # NIL THEN ERROR;
END;
CompareB: PROC[old, new: TestSubject.B] =
BEGIN
oldCell1: TestSubject.B ← old;
newCell1: TestSubject.B ← new;
WHILE oldCell1 # NIL DO
oldCell2: LIST OF TestSubject.z ← oldCell1.first;
newCell2: LIST OF TestSubject.z ← newCell1.first;
WHILE oldCell2 # NIL DO
IF oldCell2.first # newCell2.first THEN ERROR;
oldCell2 ← oldCell2.rest;
newCell2 ← newCell2.rest;
ENDLOOP;
oldCell1 ← oldCell1.rest;
newCell1 ← newCell1.rest;
ENDLOOP;
IF newCell1 # NIL THEN ERROR;
END;
CompareX1: PROC[old, new: TestSubject.X1] =
BEGIN
IF NOT Rope.Equal[old^, new^] THEN ERROR;
END;
CompareW1: PROC[old, new: REF TestSubject.W1] =
BEGIN
IF old.x # new.x THEN ERROR;
IF old.y # new.y THEN ERROR;
IF old.nItems # new.nItems THEN ERROR;
FOR I: CARDINAL IN [0..old.nItems) DO
CompareItem[old.s[I], new.s[I]];
ENDLOOP;
END;
CompareW2: PROC[old, new: REF TestSubject.W2] =
BEGIN
IF old.cardinal # new.cardinal THEN ERROR;
IF old.int # new.int THEN ERROR;
IF old.boolean # new.boolean THEN ERROR;
IF NOT Rope.Equal[old.rope, new.rope] THEN ERROR;
IF old.bool # new.bool THEN ERROR;
IF old.char # new.char THEN ERROR;
IF old.character # new.character THEN ERROR;
IF old.integer # new.integer THEN ERROR;
IF old.nat # new.nat THEN ERROR;
IF old.real # new.real THEN ERROR;
IF old.word # new.word THEN ERROR;
IF old.card # new.card THEN ERROR;
END;
CompareItem: PROC[old, new: TestSubject.Item] =
BEGIN
IF old = NIL AND new = NIL THEN RETURN;
IF old.z # new.z THEN ERROR;
IF old.b # new.b THEN ERROR;
END;
CompareZ1: PROC[old, new: TestSubject.Z1] =
BEGIN
oldCell: TestSubject.Z1 ← old;
newCell: TestSubject.Z1 ← new;
WHILE oldCell # NIL DO
CompareRefAny[oldCell.first, newCell.first];
oldCell ← oldCell.rest;
newCell ← newCell.rest;
ENDLOOP;
IF newCell # NIL THEN ERROR;
END;
CompareRefAny: PROC[old, new: REF ANY] =
BEGIN
IF old = NIL AND new = NIL THEN RETURN;
WITH old SELECT FROM
refText: REF TEXT => IF NOT Rope.Equal[Rope.FromRefText[NARROW[old]], Rope.FromRefText[NARROW[new]]] THEN ERROR;
rope: Rope.ROPE => IF NOT Rope.Equal[NARROW[old], NARROW[new]] THEN ERROR;
oldA: TestSubject.A => CompareA[NARROW[old], NARROW[new]];
olds: TestSubject.s => Compares[NARROW[old], NARROW[new]];
oldB: TestSubject.B => CompareB[NARROW[old], NARROW[new]];
oldX1: TestSubject.X1 => CompareX1[NARROW[old], NARROW[new]];
oldZ1: TestSubject.Z1 => CompareZ1[NARROW[old], NARROW[new]];
oldW1: REF TestSubject.W1 => CompareW1[NARROW[old], NARROW[new]];
oldItem: TestSubject.Item => CompareItem[NARROW[old], NARROW[new]];
oldW2: REF TestSubject.W2 => CompareW2[NARROW[old], NARROW[new]];
ENDCASE => ERROR;
END;
Test: Commander.CommandProc = TRUSTED
BEGIN
chain: TestSubject.A ← NIL;
s: IO.STREAM ← FS.StreamOpen["testFile", create];
m: KipperSupport.Kipperer ← KipperSupport.CreateKipperer[s];
t: IO.STREAM;
um: KipperSupport.UnKipperer;
newChain: TestSubject.A ← NIL;
list: TestSubject.s ← NIL;
newList: TestSubject.s ← NIL;
listList: TestSubject.B ← NIL;
newListList: TestSubject.B ← NIL;
x1: TestSubject.X1;
newX1: TestSubject.X1;
z1: TestSubject.Z1;
newz1: TestSubject.Z1;
w11: REF TestSubject.W1;
w12: REF TestSubject.W1;
rope1, rope2, rope3: Rope.ROPE;
newRope1, newRope2, newRope3: Rope.ROPE;
FOR I: CARDINAL IN [0..100) DO
chain ← NEW[TestSubject.ABody←[I, 2*I, NIL, chain]];
IF chain.next # NIL THEN chain.next.prev ← chain;
ENDLOOP;
FOR I: CARDINAL IN [0..1000) DO
list ← CONS[I, list];
ENDLOOP;
listList ← LIST[LIST[b, c, c], LIST[a, b, b, b], LIST[a]];
x1 ← NEW[Rope.ROPE ← "This is a long rope, designed to exceed the text buffer size in the marshall code by a few characters."];
w11 ← NEW[TestSubject.W1[5] ← [27, FALSE, ]];
w11.s[0] ← NIL;
w11.s[1] ← NEW[TestSubject.ItemBody←[45, 67]];
w11.s[2] ← NEW[TestSubject.ItemBody←[34, 4]];
w11.s[3] ← NEW[TestSubject.ItemBody←[5, 345]];
w11.s[4] ← NEW[TestSubject.ItemBody←[198, -9]];
w12 ← NEW[TestSubject.W1[1] ← [34, TRUE, ]];
w12.s[0] ← NEW[TestSubject.ItemBody←[45, 5678]];
z1 ← LIST[listList, NIL, "xxy", w11, w12, NEW[TestSubject.W2←[9, -9, FALSE, "xx", TRUE, 'x, 'y, LAST[INTEGER], LAST[NAT], 4.56, 56B, 32345670123B]]];
rope1 ← "abcdefg";
rope2 ← rope1; -- designed so that rope1 EQ rope2
rope3 ← Rope.Substr["abcdefgh", 0, 7]; -- not an EQ, but an EQUAL
TestSubject.KipperA[m, chain];
TestSubject.Kippers[m, list];
TestSubject.KipperB[m, listList];
TestSubject.KipperX1[m, x1];
TestSubject.KipperZ1[m, z1];
KipperSupport.KipperRope[m, rope1];
KipperSupport.KipperRope[m, rope2];
KipperSupport.KipperRope[m, rope3];
IO.Close[s];
t ← FS.StreamOpen["testFile"];
um ← KipperSupport.CreateUnKipperer[t];
newChain ← TestSubject.UnKipperA[um];
newList ← TestSubject.UnKippers[um];
newListList ← TestSubject.UnKipperB[um];
newX1 ← TestSubject.UnKipperX1[um];
newz1 ← TestSubject.UnKipperZ1[um];
newRope1 ← KipperSupport.UnKipperRope[um];
newRope2 ← KipperSupport.UnKipperRope[um];
newRope3 ← KipperSupport.UnKipperRope[um];
IO.Close[t];
CompareA[chain, newChain];
Compares[list, newList];
CompareB[listList, newListList];
CompareX1[x1, newX1];
CompareZ1[z1, newz1];
CompareRefAny[rope1, newRope1];
CompareRefAny[rope2, newRope2];
CompareRefAny[rope3, newRope3];
IF newRope1 # newRope2 THEN ERROR;
IF newRope1 = newRope3 THEN ERROR;
IF NOT Rope.Equal[newRope1, newRope3] THEN ERROR;
END;
Commander.Register["TestSubject", Test];
END..