summaryrefslogtreecommitdiff
path: root/gnu/usr.sbin/sendmail/libsm/t-exc.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-09-11 18:55:53 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-09-11 18:55:53 +0000
commit4643c616c81fb1198b29c3eaff4d697392c8dc4b (patch)
tree4afa26a5f1a2ef0e47061eb08b6d339bc7e8dad1 /gnu/usr.sbin/sendmail/libsm/t-exc.c
parent8afe339a41c898cc4a2d42d03d115b16f2053bad (diff)
sendmail 8.12.0 with $Id tags converted to $Sendmail
Diffstat (limited to 'gnu/usr.sbin/sendmail/libsm/t-exc.c')
-rw-r--r--gnu/usr.sbin/sendmail/libsm/t-exc.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/gnu/usr.sbin/sendmail/libsm/t-exc.c b/gnu/usr.sbin/sendmail/libsm/t-exc.c
new file mode 100644
index 00000000000..0194d87b95d
--- /dev/null
+++ b/gnu/usr.sbin/sendmail/libsm/t-exc.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ */
+
+#include <sm/gen.h>
+SM_IDSTR(id, "@(#)$Sendmail: t-exc.c,v 1.18 2001/07/05 22:46:35 gshapiro Exp $")
+
+#include <string.h>
+#include <sm/heap.h>
+#include <sm/io.h>
+#include <sm/test.h>
+
+const SM_EXC_TYPE_T EtypeTest1 =
+{
+ SmExcTypeMagic,
+ "E:test1",
+ "i",
+ sm_etype_printf,
+ "test1 exception argv[0]=%0",
+};
+
+const SM_EXC_TYPE_T EtypeTest2 =
+{
+ SmExcTypeMagic,
+ "E:test2",
+ "i",
+ sm_etype_printf,
+ "test2 exception argv[0]=%0",
+};
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ void *p;
+ int volatile x;
+ char *unknown, *cant;
+
+ sm_test_begin(argc, argv, "test exception handling");
+
+ /*
+ ** SM_TRY
+ */
+
+ cant = "can't happen";
+ x = 0;
+ SM_TRY
+ x = 1;
+ SM_END_TRY
+ SM_TEST(x == 1);
+
+ /*
+ ** SM_FINALLY-0
+ */
+
+ x = 0;
+ SM_TRY
+ x = 1;
+ SM_FINALLY
+ x = 2;
+ SM_END_TRY
+ SM_TEST(x == 2);
+
+ /*
+ ** SM_FINALLY-1
+ */
+
+ x = 0;
+ SM_TRY
+ SM_TRY
+ x = 1;
+ sm_exc_raisenew_x(&EtypeTest1, 17);
+ SM_FINALLY
+ x = 2;
+ sm_exc_raisenew_x(&EtypeTest2, 42);
+ SM_END_TRY
+ SM_EXCEPT(exc, "E:test2")
+ (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
+ "got exception test2: can't happen\n");
+ SM_EXCEPT(exc, "E:test1")
+ SM_TEST(x == 2 && exc->exc_argv[0].v_int == 17);
+ if (!(x == 2 && exc->exc_argv[0].v_int == 17))
+ {
+ (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
+ "can't happen: x=%d argv[0]=%d\n",
+ x, exc->exc_argv[0].v_int);
+ }
+ SM_EXCEPT(exc, "*")
+ {
+ unknown = "unknown exception: ";
+ SM_TEST(strcmp(unknown, cant) == 0);
+ }
+ SM_END_TRY
+
+ x = 3;
+ SM_TRY
+ x = 4;
+ sm_exc_raisenew_x(&EtypeTest1, 94);
+ SM_FINALLY
+ x = 5;
+ sm_exc_raisenew_x(&EtypeTest2, 95);
+ SM_EXCEPT(exc, "E:test2")
+ {
+ unknown = "got exception test2: ";
+ SM_TEST(strcmp(unknown, cant) == 0);
+ }
+ SM_EXCEPT(exc, "E:test1")
+ SM_TEST(x == 5 && exc->exc_argv[0].v_int == 94);
+ if (!(x == 5 && exc->exc_argv[0].v_int == 94))
+ {
+ (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
+ "can't happen: x=%d argv[0]=%d\n",
+ x, exc->exc_argv[0].v_int);
+ }
+ SM_EXCEPT(exc, "*")
+ {
+ unknown = "unknown exception: ";
+ SM_TEST(strcmp(unknown, cant) == 0);
+ }
+ SM_END_TRY
+
+ SM_TRY
+ sm_exc_raisenew_x(&SmEtypeErr, "test %d", 0);
+ SM_EXCEPT(exc, "*")
+#if DEBUG
+ (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
+ "test 0 got an exception, as expected:\n");
+ sm_exc_print(exc, smioout);
+#endif /* DEBUG */
+ return sm_test_end();
+ SM_END_TRY
+
+ p = sm_malloc_x((size_t)(-1));
+ (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
+ "sm_malloc_x unexpectedly succeeded, returning %p\n", p);
+ unknown = "sm_malloc_x unexpectedly succeeded";
+ SM_TEST(strcmp(unknown, cant) == 0);
+ return sm_test_end();
+}