/*  src/test.cpp  */


/*
 * Author: Philogelos A. <Philogelos@yahoo.com>
 * Maintainer: Philogelos A.
 * Keywords: C++, library, containers
 *
 * Copyright (C) 1998 Philogelos A.
 *
 * This file is part of Quercus Robusta.
 *
 * Quercus Robusta is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this software; see the file COPYING.LIB.  If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 */

static char cvsid[] = "@(#)$Id: test.cpp,v 1.5 1999/05/22 13:00:32 philogelos Exp $";
static char debugFileId[] = __FILE__;


#include "OGuard.hpp"
#include "Debug.hpp"
#include "String.hpp"
#include "Integer.hpp"
#include "StringEnumeration.hpp"
#include "iter/enumerations/Enumeration.hpp"
#include "iter/iterators/Iterator.hpp"
#include "iter/iterators/EnumerationIterator.hpp"
#include "iter/iterables/EchoIterable.hpp"
#include "iter/iterables/PrettyPrintIterable.hpp"
#include "containers/Stack.hpp"
#include "containers/Pair.hpp"
#include "containers/Empty.hpp"
#include "containers/arrays/CArray.hpp"
#include "containers/Singleton.hpp"
#include "containers/MutablePositionEnumeration.hpp"
#include "containers/MutablePosition.hpp"
#include "containers/lists/List.hpp"
#include "containers/dicts/DumbDictionary.hpp"
#include "algorithms/enumerations/EnumerationAlgorithms.hpp"
#include "algorithms/parse/WordParser.hpp"
#include "observe/ObservableAdapter.hpp"
#include "platform/Platform.hpp"
#include "MemoryMonitor.hpp"
#include "MemoryAllocator.hpp"
#include "containers/Set.hpp"
#include "new-operator.hpp"

#include "Backtrace.hpp"

#include "algorithms/string/StringAlgorithms.hpp"
#include "algorithms/string/IdentityFilter.hpp"
#include "algorithms/string/OneOfFilter.hpp"

#include <stdio.h>

int main( int, char **argv )
{
  try
	{
	  /* test_( false ); */
	  //  Debug::getLogger() -> log( "Hello world!\n" );
	  for( int i = 0 ; i < 1000 ; ++i )
		{
		  Platform::getInstance() -> setImageName( argv[ 0 ] );
		  Backtrace::initBacktrace();
		  
		  SAlg::get() -> tester( 0 );
		  {
			WordParser *parser;

			parser = new WordParser
			  ( new StringEnumeration( "Statly plump" ) );
			OGuard _parser( parser, parser );
			parser -> tester( 0 );
		  }
		  {
			OneOfFilter( new IdentityFilter( "blablablafoobarbaz" ), "abo" ).tester( 0 );
		  }
		  {
			String().tester( 20 );
		  }
		  {
			List *list;
			list = new List();
			OGuard _list( list, list );
			if( !list -> tester( 0 ) )
			  {
				Debug::getLogger() -> log( "no!" );
				break;
			  }
		  }
		  {
			Stack *pdl;

			pdl = new Stack();
			OGuard _pdl( pdl, pdl );
			pdl -> tester( 0 );
		  }
		  {
			Object *obj;

			obj = new Object();
			OGuard _obj( obj, obj );
			obj -> tester( 0 );
		  }
		  {
			ObservableAdapter *publisher;
			publisher = new ObservableAdapter();
			OGuard _publisher( publisher, publisher );

			publisher -> tester( 0 );
		  }
		  {
			PrettyPrintIterable *ppi;

			ppi = new PrettyPrintIterable( "(", ", ", ")", &Top::getString );
			OGuard _ppi( ppi, ppi );
			if( !ppi -> tester( 0 ) )
			  {
				Debug::getLogger() -> log( "no!" );
				break;
			  }
		  }

		  DumbDictionary *dummy;
		  dummy = new DumbDictionary();
		  OGuard _dummy( dummy, dummy );
		  if( ! ( dummy -> tester( 0 ) ) )
			{
			  Debug::getLogger() -> log( "no!" );
			  break;
			}
		  Integer *dummyInt;

		  dummyInt = new Integer( 0 );
		  OGuard _dummyInt( dummyInt, dummyInt );
		  if( ! ( dummyInt -> tester( 0 ) ) )
			{
			  Debug::getLogger() -> log( "no!" );
			  break;
			}
		  Empty *em;
		  CArray *ar;
		  Set  *set;

		  set = new Set();
		  OGuard _set( set, set );
		  if( !( set -> tester( 0 ) ) )
			{
			  Debug::getLogger() -> log( "no!" );
			  break;
			}

		  em = new Empty();
		  OGuard _em( em, em );
		  if( !em -> tester( 0 ) )
			{
			  Debug::getLogger() -> log( "no!" );
			  break;
			}

		  ar = new CArray( 0, 1 );
		  OGuard _ar( ar, ar );
		  if( !ar -> tester( 0 ) )
			{
			  Debug::getLogger() -> log( "no!" );
			  break;
			}
  
		  EAlg::get() -> tester( 0 );
#if 0
		  
		  {
			Backtrace *trace;
			
			trace = new Backtrace();
			OGuard _trace( trace, trace );
			
			trace -> tester( 0 );
		  }
#endif
		  Debug::getLogger() -> log( "------------------------------------" );
#if defined( MEMORY_LEAK_TEST )
		  Top::dumpAllocated();
#endif
#if defined( USE_ALLOC_CHAIN )
		  dumpAllocatedByNew();
#endif
		  Debug::getLogger() -> log( "------------------------------------" );
		  Debug::getLogger() -> logObject( Platform::getInstance() );
#if 0 && defined( PROFILE_MEM_ALLOC )
		  if( ( i % 10 ) == 0 )
			{
			  MemoryMonitor::dumpStatistics();
			  MemoryAllocator::dumpStatistics();
			}
#endif
		}
	}
  catch( Exception *anEx )
	{
	  OGuard _ex( anEx, anEx );
	  Debug::getLogger() -> exception( anEx );
	}
  catch( Throwable *thrown )
	{
	  Debug::getLogger() -> log( "Throwable catched" );
	}
  catch( ... )
	{
	  Debug::getLogger() -> log( "Unidentified exception catched" );
	}
}


#if defined(_INLINE)
#include "../src/Debug.ipp"
#endif


#if defined(_INLINE)
#include "../src/String.ipp"
#endif