SHSTestImpl.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Chauser, April 16, 1992 2:45 pm PDT
Willie-s, October 27, 1992 10:14 am PST
DIRECTORY
Basics,
IO,
Rope,
SHS ;
SHSTestImpl: CEDAR PROGRAM
IMPORTS IO, SHS
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Test Procedures
ASStreamData: TYPE ~ REF ASStreamDataRep;
ASStreamDataRep: TYPE ~ RECORD [
length: CARD ¬ 1000000,
index: CARD ¬ 0
];
ASStreamProcs: REF IO.StreamProcs ¬ IO.CreateStreamProcs[variety~input, class~$MillionAS, getChar~GetAnA, getIndex~GetIndex, setIndex~SetIndex, getLength~GetLength, setLength~SetLength, endOf~EndOf];
GetAnA: PROC [self: IO.STREAM] RETURNS [CHAR] ~ {
d: ASStreamData ~ NARROW[self.streamData];
IF d.index < d.length THEN { d.index ¬ d.index+1; RETURN['a] } ELSE ERROR IO.EndOfStream[self];
};
GetIndex: PROC [self: IO.STREAM] RETURNS [INT] ~ {
d: ASStreamData ~ NARROW[self.streamData];
RETURN[d.index];
};
SetIndex: PROC [self: IO.STREAM, index: INT] ~ {
d: ASStreamData ~ NARROW[self.streamData];
d.index ¬ index;
};
GetLength: PROC [self: IO.STREAM] RETURNS [INT] ~ {
d: ASStreamData ~ NARROW[self.streamData];
RETURN[d.length];
};
SetLength: PROC [self: IO.STREAM, length: INT] ~ {
d: ASStreamData ~ NARROW[self.streamData];
d.length ¬ length;
};
EndOf: PROC [self: IO.STREAM] RETURNS [BOOL] ~ {
d: ASStreamData ~ NARROW[self.streamData];
RETURN[d.index>=d.length]
};
Example2: PROC [] RETURNS [BOOL] ~ {
m: ROPE ~ "abc";
ans: SHS.FiveWords ¬ NEW[SHS.FiveWordsRep ¬ [0164b8a9H, 14cd2a5eH, 74c4f7ffH, 082c4d97H, 0f1edf880H]];
in: IO.STREAM ¬ IO.RIS[m];
RETURN [ Eq[SHS.WholeMessage[in], ans] ];
};
Example3: PROC [] RETURNS [BOOL] ~ {
m: ROPE ~ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
ans: SHS.FiveWords ¬ NEW[SHS.FiveWordsRep ¬ [0d2516ee1H, 0acfa5bafH, 33dfc1c4H, 71e43844H, 9ef134c8H]];
in: IO.STREAM ¬ IO.RIS[m];
RETURN [ Eq[SHS.WholeMessage[in], ans] ];
};
Example4: PROC [] RETURNS [BOOL] ~ {
ans: SHS.FiveWords ¬ NEW[SHS.FiveWordsRep ¬ [3232affaH, 48628a26H, 653b5aaaH, 44541fd9H, 0d690603H]];
in: IO.STREAM ¬ IO.CreateStream[ASStreamProcs, NEW[ASStreamDataRep ¬ []]];
RETURN [ Eq[SHS.WholeMessage[in], ans] ];
};
Eq: PROC [d1, d2: SHS.FiveWords] RETURNS [BOOL] ~ {
FOR i: INT IN [0..5) DO
IF d1[i]#d2[i] THEN RETURN[FALSE]
ENDLOOP;
RETURN[TRUE];
};
END.