/*****************************************************************************
 * $Id: dlist2.cc,v 1.1 2006/10/21 00:19:08 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Test of Dlist template class.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#define TESTING 1
#include "test.hh"
#include "gfx_list.hh"

class Class
{
public:
	char*	string;
};

/*****************************************************************************
 * Test
 *****************************************************************************/
namespace gfx {
bool
TestList( void )
{
	// This test is supposed to crash.
	// It tests catching errors using type signatures in the Dlist class.
	// The error is attempting to use a deleted list using a stale pointer.
	// ~Dlist() should change the type signature to invalid which
	// Dlist::Append() should catch.

	cerr << "-- testing deleting a list of lists -- \n";
	cerr << "-- Indeed, this test is SUPPOSED TO DUMP CORE -- \n";
    Dlist<Class>* dlist = new Dlist<Class>;
	Class* s = new Class;
	dlist->Append( s );
	delete dlist;
	dlist->Append( new Class ); // oops, list was deleted !!!
	return false; // this point should not be reached
}
} // namespace gfx

/*****************************************************************************
 * main.
 *****************************************************************************/
int
main( int argc, char** argv )
{
	GFX_INIT( argv[0] );
	int res = 1;
	if ( TestList() )
	{
		cerr << "Test PASSED. \n";
		res = 0;
	}
	else
	{
		cerr << "Test FAILED! \n";
		res = 1;
	}
	GFX_CLEANUP();
	exit( res );
}
