Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
XCOMM $TOG: Imakefile /main/3 1997/09/05 11:32:58 samborn $
XCOMM ** WARNING **
XCOMM
XCOMM The files named here may appear in many different Imakefiles.
XCOMM If you add or remove a file, be sure to update all locations.
XCOMM It's unfortunate, but all this redundancy serves a purpose.
XCOMM
XCOMM Other possible locations are:
XCOMM .../lib/DtMmdb/Imakefile
XCOMM .../lib/DtMmdb/<subdir>/Imakefile
XCOMM .../programs/dtinfo/mmdb/Imakefile
XCOMM .../programs/dtinfo/mmdb/<subdir>/Imakefile
#define DoNormalLib YES
#define DoSharedLib NO
#define DoDebugLib NO
#define DoProfileLib NO
#define LibName MMDB
#define LibHeaders NO
#define LibCreate NO
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
#if defined(SunArchitecture) && CplusplusCompilerMajorVersion > 3
EXCEPTION_DEFINES = -DHAS_TERMINATE
#endif
DEFINES = -DCC_VERSION=30 -DCHECK_INITIALIZED $(EXCEPTION_DEFINES)
INCLUDES = -I$(DTMMDBSRC)/dti_excs
LinkSourceFile(Jump_Environment.C,$(DTMMDBSRC)/dti_excs)
LinkSourceFile(Exceptions.C,$(DTMMDBSRC)/dti_excs)
LinkSourceFile(Exception.C,$(DTMMDBSRC)/dti_excs)
LinkSourceFile(Destructable.C,$(DTMMDBSRC)/dti_excs)
LinkSourceFile(terminate.C,$(DTMMDBSRC)/dti_excs)
BASE_SRCS = \
Jump_Environment.C Exceptions.C Exception.C \
Destructable.C terminate.C
SRCS = $(BASE_SRCS)
OBJS = $(BASE_SRCS:.C=.o)
#include <Library.tmpl>
SubdirLibraryRule($(OBJS))
DependTarget()
#ifdef TEST
tests: $(TESTS)
CPlusPlusProgram(test0,test0.o,$(OBJS))
CPlusPlusProgram(test1,test1.o,$(OBJS))
CPlusPlusProgram(test2,test2.o,$(OBJS))
CPlusPlusProgram(test3,test3.o,$(OBJS))
CPlusPlusProgram(test4,test4.o,$(OBJS))
CPlusPlusProgram(test5,test5.o,$(OBJS))
CPlusPlusProgram(test6,test6.o,$(OBJS))
CPlusPlusProgram(test7,test7.o,$(OBJS))
CPlusPlusProgram(test8,test8.o,$(OBJS))
CPlusPlusProgram(test9,test9.o,$(OBJS))
CPlusPlusProgram(test10,test10.o,$(OBJS))
CPlusPlusProgram(test11,test11.o,$(OBJS))
CPlusPlusProgram(test12,test12.o,$(OBJS))
CPlusPlusProgram(test13,test13.o,$(OBJS))
CPlusPlusProgram(test14,test14.o,$(OBJS))
CPlusPlusProgram(test15,test15.o,$(OBJS))
CPlusPlusProgram(test16,test16.o,$(OBJS))
CPlusPlusProgram(test17,test17.o,$(OBJS))
CPlusPlusProgram(test18,test18.o,$(OBJS))
CPlusPlusProgram(test19,test19.o,$(OBJS))
CPlusPlusProgram(test20,test20.o,$(OBJS))
CPlusPlusProgram(test21,test21.o,$(OBJS))
CPlusPlusProgram(test22,test22.o,$(OBJS))
CPlusPlusProgram(test23,test23.o,$(OBJS))
CPlusPlusProgram(test24,test24.o,$(OBJS))
CPlusPlusProgram(test25,test25.o,$(OBJS))
CPlusPlusProgram(test26,test26.o,$(OBJS))
CPlusPlusProgram(test27,test27.o,$(OBJS))
CPlusPlusProgram(test28,test28.o,$(OBJS))
CPlusPlusProgram(test29,test29.o,$(OBJS))
#endif

View File

@@ -0,0 +1,19 @@
// $XConsortium: test0.cc /main/3 1996/06/11 16:52:21 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
int
main()
{
INIT_EXCEPTIONS();
try
{
puts ("Trying something");
}
catch (Exception &,e)
{
puts ("Caught an exception");
}
end_try;
}

View File

@@ -0,0 +1,38 @@
// $XConsortium: test1.C /main/4 1996/10/04 15:40:56 drk $
#include <stdio.h>
#include "Exceptions.hh"
int
main()
{
INIT_EXCEPTIONS();
#ifndef NATIVE_EXCEPTIONS
printf ("Unwind_Record size = %ld\n", (long)sizeof (Unwind_Record));
#endif
printf ("Exception size = %ld\n", (long)sizeof (Exception));
puts ("CODE Exception e");
Exception e;
// Test Destructable copy constructor.
puts ("CODE Exception b = e");
Exception b = e;
puts ("CODE Exception *z = new Exception()");
Exception *z = new Exception();
// Test Destructable assignment operator.
puts ("CODE Exception *z = b");
*z = b;
puts ("CODE delete z");
delete z;
try
{
puts ("Trying something");
throw (Exception());
}
catch (Exception &,e)
{
puts ("Caught an exception");
}
end_try;
}

View File

@@ -0,0 +1,60 @@
// $XConsortium: test10.cc /main/3 1996/06/11 16:52:32 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class foo : public Destructable
{
public:
foo (char *s);
~foo();
char *name;
};
foo::foo (char *s)
{
name = s;
printf ("constructing <%s>\n", name);
}
foo::~foo()
{
printf ("destructing <%s>\n", name);
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing stack unwinding and illegal rethrow out of main.");
foo foo_main ("Main");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
foo foo_try ("Try");
throw (Exception());
}
catch (Exception &,e)
{
puts ("Caught exception.");
foo foo_catch ("Catch");
rethrow;
}
end_try;
}

View File

@@ -0,0 +1,50 @@
// $XConsortium: test11.cc /main/3 1996/06/11 16:52:38 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
void
do_something()
{
try
{
throw (Exception());
}
catch (Exception &,e)
{
puts ("Caught in do_something, rethrowing.");
rethrow;
}
end_try;
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing mult-depth rethrow.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
catch (Exception &,e)
{
puts ("Caught exception back in main.");
}
end_try;
}

View File

@@ -0,0 +1,72 @@
// $XConsortium: test12.cc /main/3 1996/06/11 16:52:43 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
try
{
throw (ErrorString ("<error message from do_something>"));
}
// Catch the more general exception first -- a definite mistake.
catch (Exception &,e)
{
puts ("Caught in do_something, rethrowing.");
rethrow;
}
catch (ErrorString &,e)
{
puts ("This will never be printed.");
}
end_try;
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing mult-depth throws of different exceptions.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,92 @@
// $XConsortium: test13.C /main/5 1996/10/04 15:39:41 drk $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class StackFixer
{
public:
StackFixer()
{ printf ("I'm at address %p\n", this); }
};
class SomeClass : public Destructable
{
public:
SomeClass()
{ puts ("Constructing SomeClass"); }
~SomeClass()
{ puts ("Destructing SomeClass"); }
};
class SomeOtherClass : public Destructable
{
public:
SomeClass some_class;
SomeOtherClass()
{ puts ("Constructing SomeOtherClass"); }
~SomeOtherClass()
{ puts ("Destructing SomeOtherClass"); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
SomeOtherClass some_other_class;
// SomeClass some_class;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing cleanup of nested destructable objects.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,99 @@
// $XConsortium: test14.cc /main/3 1996/06/11 16:52:54 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class BaseClass : public Destructable
{
public:
BaseClass()
{ puts ("Constructing BaseClass"); }
~BaseClass()
{ puts ("Destructing BaseClass"); }
};
class BaseClass2 : public Destructable
{
public:
BaseClass2()
{ puts ("Constructing BaseClass2"); }
~BaseClass2()
{ puts ("Destructing BaseClass2"); }
};
class DerivedClass : public BaseClass
{
public:
DerivedClass()
{ puts ("Constructing DerivedClass"); }
~DerivedClass()
{ puts ("Destructing DerivedClass"); }
};
class DerivedClass2 : public BaseClass, public BaseClass2
{
public:
DerivedClass2()
{ puts ("Constructing DerivedClass2"); }
~DerivedClass2()
{ puts ("Destructing DerivedClass2"); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
DerivedClass derived_class;
DerivedClass2 derived_class2;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing destruction with single and multiple inheritance.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,97 @@
// $XConsortium: test15.C /main/4 1996/08/21 15:48:27 drk $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
/* This test contains a throw in a constructor which is officially not
supported by the exceptions library. Throws in the constructor will
tend to work when the object that throws is not the last destructable
object in another destructable because the destructors of later
destructable members will be called. See test18.C.
17:50 22-May-93 DJB
*/
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
static int serial;
class SomeClass : public Destructable
{
public:
int id;
SomeClass()
{ id = serial++; printf ("Constructing SomeClass %d\n", id); }
~SomeClass()
{ printf ("Destructing SomeClass %d\n", id); }
};
class SomeOtherClass : public Destructable
{
public:
SomeClass some_class;
int id;
SomeOtherClass()
{ id = serial++;
throw (Exception());
printf ("Constructing SomeOtherClass %d\n", id); }
~SomeOtherClass()
{ printf ("Destructing SomeOtherClass %d\n", id); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
SomeOtherClass some_other_class;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing descruction of object members.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will be printed.");
}
end_try;
}

View File

@@ -0,0 +1,95 @@
// $XConsortium: test16.cc /main/3 1996/06/11 16:53:06 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
static int serial;
class AClass : public Destructable
{
public:
int id;
AClass()
{ id = serial++; printf ("Constructing AClass %d\n", id); }
~AClass()
{ printf ("Destructing AClass %d\n", id); }
};
class AnotherClass : public Destructable
{
public:
int id;
AnotherClass()
{ id = serial++; printf ("Constructing AnotherClass %d\n", id); }
~AnotherClass()
{ printf ("Destructing AnotherClass %d\n", id); }
};
class SomeOtherClass : public AClass, public AnotherClass
{
public:
int id;
SomeOtherClass()
{ id = serial++; printf ("Constructing SomeOtherClass %d\n", id); }
~SomeOtherClass()
{ printf ("Destructing SomeOtherClass %d\n", id); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
SomeOtherClass some_other_class;
// SomeClass some_class;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing clean up of non-virtual multiply inherited destructable.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,105 @@
// $XConsortium: test17.C /main/5 1996/09/27 19:03:16 drk $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
/* Throwing from constructor is not supported. See test18.C. */
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class MemberClass : public Destructable
{
public:
char *name;
MemberClass (char *s)
: name(s)
{ printf ("Constructing MemberClass `%s' @ 0x%p\n", name, this);
throw (Exception()); }
~MemberClass()
{ printf ("Destructing MemberClass\n", name); }
};
class BaseClass : public Destructable
{
public:
MemberClass m1;
BaseClass()
: m1("m1")
{
puts ("Constructing BaseClass");
throw (Exception());
}
~BaseClass()
{ puts ("Destructing BaseClass"); }
};
class DerivedClass : public BaseClass
{
public:
MemberClass m3;
DerivedClass()
: m3("m3")
{ puts ("Constructing DerivedClass"); }
~DerivedClass()
{ puts ("Destructing DerivedClass"); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
printf ("Calling do_something()\n");
DerivedClass derived_class;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
printf ("Sizeof Destructable = %d\n", (int)sizeof (Destructable));
puts ("Testing destructor calling sequence during throw.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("Caught a vanilla exception.");
}
end_try;
}

View File

@@ -0,0 +1,129 @@
// $XConsortium: test18.C /main/4 1996/09/27 19:03:20 drk $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
/*
This test case illustrates a problem that isn't handled by the current
exceptions library. BaseClass contains two Destructable members whose
constructor throws an exception. When this happens, the exceptions
library calls the destructors of all members, constructed or not. This
means that the Destructable destructor of m2 is called even though it
wasn't constructed. This is probably just dumb luck, because nothing
says that the virtual table of m2 should already have the pointer to
the destructor filled in. For some reason it does. It seems like the
compiler should be smarter about this and maybe not call it, but we're
kind of stuck.
One way to handle this would be to remember all Destructable objects
that are constructed on the Jump_Environment stack, but only destroy
those that don't have the f_registered (or f_destroy) flag set. Then
we can tell if an object has been constructed by comparing it's address
to the object on the top of the stack. Actually, we'd need two separate
stacks because with one stack the members would have been removed before
we get to the object that contains them. We're not going to implement
this because throwing an exception from a constructor is too dangerous
with the current language language definition anyhow.
16:56 22-May-93 DJB
*/
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class MemberClass : public Destructable
{
public:
char *name;
MemberClass (char *s)
: name(s)
{ printf ("Constructing MemberClass `%s' @ 0x%p\n", name, this);
throw (Exception()); }
~MemberClass()
{ printf ("Destructing MemberClass\n", name); }
};
class BaseClass : public Destructable
{
public:
MemberClass m1, m2;
BaseClass()
: m1("m1"), m2("m2")
{
puts ("Constructing BaseClass");
throw (Exception());
}
~BaseClass()
{ puts ("Destructing BaseClass"); }
};
class DerivedClass : public BaseClass
{
public:
MemberClass m3;
DerivedClass()
: m3("m3")
{ puts ("Constructing DerivedClass"); }
~DerivedClass()
{ puts ("Destructing DerivedClass"); }
};
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
printf ("Calling do_something()\n");
DerivedClass derived_class;
throw (ErrorString ("Tossed my cookies in do_something"));
}
int
main()
{
INIT_EXCEPTIONS();
printf ("Sizeof Destructable = %d\n", (int)sizeof (Destructable));
puts ("Test of throw from multiple member constructor.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("Caught a vanilla exception.");
}
end_try;
}

View File

@@ -0,0 +1,47 @@
// $XConsortium: test19.cc /main/3 1996/06/11 16:53:23 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class BigException : public Exception
{
public:
DECLARE_EXCEPTION (BigException, Exception);
BigException() { }
int waste_space[300];
};
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
printf ("Sucking up a lot of memory to test internal allocator.\n");
try
{
// Should run out of memory trying to allocate this one.
throw (BigException());
}
catch (Exception &,e)
{
puts ("Caught an exception reference");
}
catch (Exception *,e)
{
puts ("Caught an exception pointer");
}
end_try;
}

View File

@@ -0,0 +1,30 @@
// $XConsortium: test2.cc /main/3 1996/06/11 16:53:29 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (0);
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,25 @@
// $XConsortium: test20.cc /main/3 1996/06/11 16:53:34 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
int
main()
{
INIT_EXCEPTIONS();
printf ("Throw of new'ed exception.\n");
Exception *z = new Exception();
try
{
puts ("Trying something");
throw ((*z));
}
catch (Exception &,e)
{
puts ("Caught an exception");
}
end_try;
delete z;
}

View File

@@ -0,0 +1,67 @@
// $XConsortium: test21.cc /main/3 1996/06/11 16:53:41 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
void
do_something()
{
try
{
throw (ErrorString ("<error message from do_something>"));
}
catch (ErrorString &,e)
{
puts ("Caught ErrorString exception.");
throw (Exception());
}
end_try;
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing mult-depth throws of different exceptions.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("This is not printed.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will be printed.");
}
end_try;
}

View File

@@ -0,0 +1,44 @@
// $XConsortium: test22.cc /main/3 1996/06/11 16:53:47 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
#include <string.h>
void
catch_abort(int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
// Test of throw in error handler.
void
error_handler (const char *[], int)
{
puts ("Throwing an exception from the error handler.");
throw (Exception());
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing throw from error handler.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
Exceptions::set_error_handler (error_handler);
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,51 @@
// $XConsortium: test23.cc /main/3 1996/06/11 16:53:52 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
#include <string.h>
void
catch_abort(int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
// Test of throw in error handler.
void
error_handler (const char *[], int)
{
puts ("Throwing an exception from the error handler.");
throw (Exception());
}
void terminator()
{
puts ("I'll be back!");
throw (Exception());
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing throw from error handler AND terminate.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
Exceptions::set_error_handler (error_handler);
set_terminate (terminator);
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,33 @@
// $XConsortium: test24.cc /main/3 1996/06/11 16:53:58 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort(int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
int
main()
{
puts ("Test of something without initialize.");
// INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
puts ("Trying something");
}
catch (Exception &,e)
{
puts ("Caught an exception");
}
end_try;
}

View File

@@ -0,0 +1,51 @@
// $XConsortium: test25.cc /main/3 1996/06/11 16:54:03 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
#include <string.h>
void
catch_abort(int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
// Test of throw in error handler.
void
error_handler (const char *[], int)
{
puts ("Got into the error handler OK.");
throw (Exception());
}
void terminator()
{
puts ("I'll be back!");
throw (Exception());
}
int
main()
{
// INIT_EXCEPTIONS();
puts ("Test of error handler with no INIT.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
Exceptions::set_error_handler (error_handler);
set_terminate (terminator);
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,58 @@
// $XConsortium: test26.cc /main/3 1996/06/11 16:54:09 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class foo : public Destructable
{
public:
~foo() { puts ("Destructing foo."); }
};
void
cleanup()
{
try
{
throw (Exception());
}
catch_any()
{
puts ("clean up caught");
}
end_try;
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
puts ("Testing nested try in catch.");
try
{
foo bar;
throw (Exception());
}
catch (Exception &,e)
{
puts ("Cleaning up");
cleanup();
}
end_try;
}

View File

@@ -0,0 +1,49 @@
// $XConsortium: test27.C /main/4 1996/09/27 19:03:26 drk $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class foo : virtual public Destructable
{
public:
foo();
~foo() { puts ("Destructing foo."); }
};
foo::foo()
{
printf ("Construct foo @ 0x%p\n", this);
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
puts ("Testing virtual inheritance of Destructable.");
try
{
foo bar;
throw (Exception());
}
catch (Exception &,e)
{
puts ("Got it.");
}
end_try;
}

View File

@@ -0,0 +1,82 @@
// $XConsortium: test28.cc /main/3 1996/06/11 16:54:19 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
ErrorString (char *s)
{ msg = s; }
char *msg;
};
class BogusError : public ErrorString
{
public:
DECLARE_EXCEPTION (BogusError, ErrorString);
BogusError (char *msg, int b)
: ErrorString (msg), bogusity (b)
{ }
int bogusity;
};
void
do_something()
{
try
{
throw (ErrorString ("<error message from do_something>"));
}
// Catch the more general exception first -- a definite mistake.
catch (Exception &,e)
{
puts ("Caught in do_something, rethrowing.");
rethrow;
}
catch (ErrorString &,e)
{
puts ("This will never be printed.");
}
end_try;
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing mult-depth throws of different exceptions.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,88 @@
// $XConsortium: test29.cc /main/4 1996/08/08 19:55:36 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class ErrorString : public Exception
{
public:
DECLARE_EXCEPTION (ErrorString, Exception);
virtual void name()
{ puts ("ErrorString"); }
ErrorString (char *s)
{ msg = s; }
char *msg;
};
class ErrorThing : public ErrorString
{
public:
DECLARE_EXCEPTION (ErrorThing,ErrorString);
ErrorThing (char *s)
: ErrorString (s) { }
virtual void name()
{ puts ("ErrorThing"); }
};
void
do_something()
{
try
{
throw (ErrorThing ("<error message from do_something>"));
}
// Catch the more general exception first -- a definite mistake.
catch (Exception &,e)
{
puts ("Caught in do_something, rethrowing.");
rethrow;
}
catch (ErrorString &,e)
{
puts ("This will never be printed.");
}
end_try;
}
int
main()
{
puts ("Testing mult-depth throws of different exceptions.");
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
try
{
do_something();
}
// Do it right in this section.
catch (ErrorString &,e)
{
puts ("Caught exception back in main.");
e.name();
puts (e.msg);
}
catch (Exception &,e)
{
puts ("This will never be printed.");
}
end_try;
}

View File

@@ -0,0 +1,48 @@
// $XConsortium: test3.cc /main/3 1996/06/11 16:54:31 cde-hal $
#define DEBUG_THROW
#define DEBUG_CATCH
#include <stdio.h>
#include "Exceptions.hh"
int
main()
{
INIT_EXCEPTIONS();
int retry = 3;
puts ("Testing throw and catch debugging.");
while (retry)
{
try
{
switch (retry--)
{
case 3:
puts ("Throwing exception object");
throw (Exception());
case 2:
{
Exception e;
Exception *ep = &e;
puts ("Throwing exception pointer");
// NOTE: This isn't normally a good idea, since ep
// points to a stack based value.
throw (ep);
}
case 1:
puts ("Not throwing a damn thing.");
}
}
catch (Exception &,e)
{
puts ("Caught an exception reference");
}
catch (Exception *,e)
{
puts ("Caught an exception pointer");
}
end_try;
}
}

View File

@@ -0,0 +1,45 @@
// $XConsortium: test4.cc /main/3 1996/06/11 16:54:36 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
int
main()
{
INIT_EXCEPTIONS();
int retry = 10000;
printf ("Executing %d iterations of the try loop.\n", retry);
while (retry)
{
// printf ("Iter = %d\n", retry);
try
{
switch (retry-- % 3)
{
case 2:
// puts ("Throwing exception object");
throw (Exception());
case 1:
{
Exception e;
Exception *ep = &e;
// puts ("Throwing exception pointer");
throw (ep);
}
// case 0:
// puts ("Not throwing a damn thing.");
}
}
catch (Exception &,e)
{
// puts ("Caught an exception reference");
}
catch (Exception *,e)
{
// puts ("Caught an exception pointer");
}
end_try;
}
}

View File

@@ -0,0 +1,38 @@
// $XConsortium: test5.cc /main/3 1996/06/11 16:54:41 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
void
terminate_handler()
{
throw (Exception());
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
set_terminate (terminate_handler);
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,74 @@
// $XConsortium: test6.cc /main/3 1996/06/11 16:54:47 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
#include <string.h>
void
catch_abort(int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
// Test function to print the error in a cool box.
void
error_handler (const char *line[], int nlines)
{
int i, n, maxlen = 0;
static char border[100];
for (i = 0; i < nlines; i++)
if (strlen (line[i]) > maxlen)
maxlen = strlen (line[i]);
maxlen += 6;
border[0] = border[maxlen-1] = '+';
border[maxlen] = '\n';
border[maxlen+1] = '\0';
for (i = 1; i < maxlen - 1; i++)
border[i] = '-';
fputs (border, stderr);
border[0] = border[maxlen-1] = '|';
for (n = 0; n < nlines; n++)
{
for (i = 1; i < maxlen - 1; i++)
border[i] = ' ';
for (i = 0; i < strlen (line[n]); i++)
border[i+3] = line[n][i];
fputs (border, stderr);
}
for (i = 1; i < maxlen - 1; i++)
border[i] = '-';
border[0] = border[maxlen-1] = '+';
fputs (border, stderr);
}
int
main()
{
INIT_EXCEPTIONS();
puts ("Testing the custom error handler functionality.");
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
Exceptions::set_error_handler (error_handler);
try
{
puts ("Trying something");
throw (Exception());
}
end_try;
}

View File

@@ -0,0 +1,25 @@
// $XConsortium: test7.cc /main/3 1996/06/11 16:54:53 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
puts ("Throw with no exception...");
rethrow;
}

View File

@@ -0,0 +1,31 @@
// $XConsortium: test8.cc /main/3 1996/06/11 16:54:58 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
puts ("Testing catch with no try.");
if (0) {
// remember that catch expands to an "else if"
catch (Exception &,e)
{
puts ("The should never be printed");
}
}
}

View File

@@ -0,0 +1,49 @@
// $XConsortium: test9.cc /main/3 1996/06/11 16:55:04 cde-hal $
#include <stdio.h>
#include "Exceptions.hh"
#include <signal.h>
void
catch_abort (int, ...)
{
puts ("Abort (core not dumped)");
// Exit normally so Purify can report.
exit (1);
}
class foo : public Destructable
{
public:
~foo();
};
foo::~foo()
{
puts ("Called foo destructor.");
throw (Exception());
}
int
main()
{
INIT_EXCEPTIONS();
#ifdef MUST_EXIT
signal (SIGABRT, catch_abort);
#endif
puts ("Testing illegal throw from destructor.");
try
{
foo bar;
throw (Exception());
}
catch (Exception &,e)
{
puts ("This should never be printed.");
}
end_try;
}