/* ciitestcleanup.c
* Copyright (C) 1993 by Xerox Corporation.  All rights reserved.
* Michael Plass, October 15, 1993 12:02 pm PDT
*/

#include "cii.h"
#define NIL ((void*)0);

#define CHK(x) {res=x; if (CII←RES←ok!=res) return(res);}

typedef struct Bye←Data←Rep {
    CII←RectangleRep rect;
    float gray;
} Bye←Data←Rep;

/* Normally a cleanup routine would not do any actual imaging, but this is a convenient way to test out the cleanup feature. */
static CII←RES
Bye(CII←CleanupObject self, CII←Handle h) {
    CII←RES res = CII←RES←ok;
    Bye←Data←Rep* data = self->data;
    CHK(CII←SetGray(h, &(data->gray)));
    CHK(CII←MaskRectangle(h, &(data->rect)));
    data->rect.x = data->rect.x+(data->rect.w/2.0);
    data->rect.y = data->rect.y+(data->rect.h/2.0);
    data->gray = (data->gray) * 0.8;
    return(res);
}

CII←CleanupObjectRep clean1, clean2;

Bye←Data←Rep data1 = {
  { 60.0, 100.0, 30.0, 20.0 },
  0.9
};

Bye←Data←Rep data2 = {
  { 50.0, 114.0, 100.0, 3.0 },
  0.0
};

extern CII←RES
register←ciitestcleanup(CII←Handle h) {
	CII←RES res = CII←RES←ok;
	clean1.data = &data1;
	clean1.Cleanup = Bye;
	CHK(CII←RegisterCleanupObject(h, &clean1));
	clean2.data = &data2;
	clean2.Cleanup = Bye;
	CHK(CII←RegisterCleanupObject(h, &clean2));
	CHK(CII←RegisterCleanupObject(h, &clean2));
	CHK(CII←RegisterCleanupObject(h, &clean1));
	CHK(CII←RegisterCleanupObject(h, &clean1));
	CHK(CII←UnRegisterCleanupObject(h, &clean1));
	CHK(CII←UnRegisterCleanupObject(h, &clean2));
	return(res);
}

extern void run←ciiicecream(CII←Handle);

void
XR←run←ciitestcleanup()
{
	CII←Handle h = (CII←Handle)CII←TestDevice();
	register←ciitestcleanup(h);
	run←ciiicecream(h);
	CII←Destroy(h);
}