File: exceptiontest.c

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (155 lines) | stat: -rw-r--r-- 3,500 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * File:        exceptionclient.c
 * Copyright:   (c) 2001 The Regents of the University of California
 * Revision:    @(#) $Revision: 4434 $
 * Date:        $Date: 2005-03-17 09:05:29 -0800 (Thu, 17 Mar 2005) $
 * Description: Exception Test C client
 *
 */

#include <stdio.h>
#include "sidl_Exception.h"
#include "sidl_String.h"
#include "ExceptionTest_Fib.h"
#include "synch.h"

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif


static void declare_part(synch_RegOut tracker,
                         int * part_no )
{
  synch_RegOut_startPart(tracker, ++(*part_no));
}

static void end_part(synch_RegOut tracker, int part_no, 
                     enum synch_ResultType__enum result)
{
  synch_RegOut_endPart(tracker, part_no, result);
}

static void traceback(sidl_BaseInterface _ex)
{
  sidl_BaseException be = sidl_BaseException__cast(_ex);
  char* msg = NULL;
  if (be) {
    msg = sidl_BaseException_getNote(be);
    printf("%s\n", msg);
    sidl_String_free(msg);

    msg = sidl_BaseException_getTrace(be);
    printf("%s\n", msg);
    sidl_String_free(msg);
  }
}

#define CHECK(FUNC,COMMENT)                   \
  declare_part(tracker, &part_no);             \
  synch_RegOut_writeComment(tracker, COMMENT); \
  result = (FUNC) ? synch_ResultType_PASS : synch_ResultType_FAIL;            \
  end_part(tracker, part_no, result);

int runTest1(ExceptionTest_Fib f)
{
  int x;
  sidl_BaseInterface _ex = NULL;

  x = ExceptionTest_Fib_getFib(f, 10, 25, 200, 0, &_ex); SIDL_CHECK(_ex);
  return TRUE;

  EXIT:;
    traceback(_ex);
    SIDL_CLEAR(_ex);
    return FALSE;
}

int runTest2(ExceptionTest_Fib f)
{
  int x;
  sidl_BaseInterface _ex = NULL;

  x = ExceptionTest_Fib_getFib(f, -1, 10, 10, 0, &_ex);
  if (SIDL_CATCH(_ex, "ExceptionTest.NegativeValueException")) {
    traceback(_ex);
    SIDL_CLEAR(_ex);
  } else if (_ex == NULL) {
    return FALSE;
  }
  SIDL_CHECK(_ex);
  return TRUE;

  EXIT:;
    traceback(_ex);
    SIDL_CLEAR(_ex);
    return FALSE;
}

int runTest3(ExceptionTest_Fib f)
{
  int x;
  sidl_BaseInterface _ex = NULL;

  x = ExceptionTest_Fib_getFib(f, 10, 1, 100, 0, &_ex);
  if (SIDL_CATCH(_ex, "ExceptionTest.TooDeepException")) {
    traceback(_ex);
    SIDL_CLEAR(_ex);
  } else if (_ex == NULL) {
    return FALSE;
  }
  SIDL_CHECK(_ex);
  return TRUE;

  EXIT:;
    traceback(_ex);
    SIDL_CLEAR(_ex);
    return FALSE;
}

int runTest4(ExceptionTest_Fib f)
{
  int x;
  sidl_BaseInterface _ex = NULL;

  x = ExceptionTest_Fib_getFib(f, 10, 100, 1, 0, &_ex);
  if (SIDL_CATCH(_ex, "ExceptionTest.TooBigException")) {
    traceback(_ex);
    SIDL_CLEAR(_ex);
  } else if (_ex == NULL) {
    return FALSE;
  }
  SIDL_CHECK(_ex);
  return TRUE;

  EXIT:;
    traceback(_ex);
    SIDL_CLEAR(_ex);
    return FALSE;
}

int main(int argc, char**argv)
{ 
  enum synch_ResultType__enum result       = synch_ResultType_PASS; 
  int magicNumber  = 1;
  int part_no      = 0;

  ExceptionTest_Fib fib = ExceptionTest_Fib__create ();
  synch_RegOut tracker = synch_RegOut__create();

  (void) argc;
  (void) argv;
  synch_RegOut_setExpectations(tracker, 4);
  CHECK(runTest1(fib), "checking no exception thrown");
  CHECK(runTest2(fib), "checking ExceptionTest.NegativeValueException");
  CHECK(runTest3(fib), "checking ExceptionTest.TooDeepException");
  CHECK(runTest4(fib), "checking ExceptionTest.TooBigException");
  synch_RegOut_close(tracker);
  synch_RegOut_deleteRef(tracker);

  ExceptionTest_Fib_deleteRef (fib);
  return 0;
}