ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Stack_Trace_Test.cpp
blobec14d0dc9e4c7153f44c2f8d977d135fe303a37c
1 // ============================================================================
2 //
3 // = LIBRARY
4 // tests
5 //
6 // = DESCRIPTION
7 // This program exercises the ACE_Stack_Trace class.
8 //
9 // = AUTHOR
10 // Chris Cleeland <cleeland @ ociweb . com>
12 // ============================================================================
14 #include "ace/Stack_Trace.h"
15 #include "ace/OS_NS_string.h"
16 #include "test_config.h"
21 * Ultra-basic test of stack trace.
23 * Other things to test:
24 * - throwing exceptions that contain the stack trace, and catching
25 * - capturing multiple traces
26 * - capture traces with different numbers of frames
27 * - capture traces with different numbers of skipped frames
31 struct SomeException
33 static const ssize_t SKIP = 1; //@TODO: #ifdef this for MACOSX which needs 2
34 SomeException () : where_(SKIP), explanation_ ("") { }
35 SomeException (const char *explanation)
36 : where_(SKIP), explanation_(explanation) { }
37 ACE_Stack_Trace where_;
38 const char *explanation_;
41 void
42 func ()
44 throw SomeException();
47 int
48 run_main (int, ACE_TCHAR *[])
50 ACE_START_TEST (ACE_TEXT ("Stack_Trace_Test"));
52 ACE_Stack_Trace t1;
53 ACE_DEBUG ((LM_DEBUG, "t1 trace is %C\n", t1.c_str()));
55 ACE_Stack_Trace t2(t1);
56 ACE_DEBUG ((LM_DEBUG, "t2 (copied) trace is %C\n",
57 (ACE_OS::strcmp (t1.c_str(), t2.c_str()) == 0) ? "same" : "different"));
59 ACE_Stack_Trace t3;
60 ACE_DEBUG ((LM_DEBUG, "t3 trace before assignment is %C\n",
61 (ACE_OS::strcmp (t1.c_str(), t3.c_str()) == 0) ? "same" : "different"));
62 t3 = t1;
63 ACE_DEBUG ((LM_DEBUG, "t3 trace after assignment is %C\n",
64 (ACE_OS::strcmp (t1.c_str(), t3.c_str()) == 0) ? "same" : "different"));
66 try {
67 func();
69 catch (SomeException& e) {
70 ACE_DEBUG ((LM_DEBUG,
71 "SomeException caught at\n%?\n; thrown at\n%C",
72 e.where_.c_str()));
75 ACE_Stack_Trace one_frame_only(0, 1);
76 ACE_DEBUG ((LM_DEBUG,
77 "stack trace of only one frame:\n%C",
78 one_frame_only.c_str()));
80 ACE_DEBUG ((LM_DEBUG, "getting ready to end the test at %?\n"));
82 ACE_END_TEST;
83 return 0;