PropertiesExtendTester.mesa
Last Edited by:
Bob Hagmann, March 20, 1985 11:35:18 am PST
DIRECTORY
File,
FileInternal,
Random,
Rope,
SafeStorage;
PropertiesExtendTester: CEDAR PROGRAM
IMPORTS File, Random, SafeStorage
= BEGIN
DoTest: PROC [numberOfExtends: INT, maxNumberOfPages: INT ] = {
file: File.Handle;
fileFP: File.FP;
propPages: File.PageCount;
props: File.PropertyStorage;
randomStream: Random.RandomStream;
volume: File.Volume;
offset: WORD;
randomStream ← Random.Create[range: 10000, seed: -1] ;
offset ← Random.ChooseInt[randomStream, 1, 1000];
volume ← File.SystemVolume[];
file ← File.Create[volume: volume, size: 30] ;
[fp: fileFP] ← File.Info[file];
[prop: props, nPages: propPages] ← File.GetProperties[file: file];
IF propPages # 1 THEN ERROR;
setProps[file, offset, props, File.wordsPerPage];
file ← NIL;
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
FOR loopCount: INT IN [0 .. numberOfExtends) DO
growAmount: INT;
nowProps: File.PropertyStorage;
nowPropPages: File.PageCount;
nowWords: CARDINAL;
growAmount ← Random.ChooseInt[randomStream, 1, maxNumberOfPages];
file ← File.Open[volume: volume, fp: fileFP];
[prop: nowProps, nPages: nowPropPages] ← File.GetProperties[file: file];
IF nowPropPages # propPages THEN ERROR;
nowWords ← nowPropPages * File.wordsPerPage;
testProps[offset, nowProps, nowWords];
propPages ← propPages + growAmount;
file.SetPropertiesSize[nPages: propPages];
[prop: nowProps, nPages: nowPropPages] ← File.GetProperties[file: file];
IF nowPropPages # propPages THEN ERROR;
setProps[file, offset, nowProps, propPages*File.wordsPerPage];
file ← NIL;
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
SafeStorage.ReclaimCollectibleObjects[suspendMe: TRUE, traceAndSweep: FALSE];
ENDLOOP;
file ← File.Open[volume: volume, fp: fileFP];
file.Delete[];
};
testProps: PROC [offset: WORD, props: File.PropertyStorage, propWords: CARDINAL] = TRUSTED {
FOR ptr: CARDINAL IN [0..propWords) DO
IF props[ptr] # ptr+offset THEN ERROR;
ENDLOOP;
};
setProps: PROC [file: File.Handle, offset: WORD, props: File.PropertyStorage, propWords: CARDINAL] = TRUSTED {
FOR ptr: CARDINAL IN [0..propWords) DO
props[ptr] ← ptr+offset;
ENDLOOP;
file.WriteProperties[];
};
Start code
END.