Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Stack_Trace_Test.cpp
blob57cda976c315844dc9ecaafabf28a617ab55851a
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"
20 * Ultra-basic test of stack trace.
22 * Other things to test:
23 * - throwing exceptions that contain the stack trace, and catching
24 * - capturing multiple traces
25 * - capture traces with different numbers of frames
26 * - capture traces with different numbers of skipped frames
30 struct SomeException
32 static const ssize_t SKIP = 1; //@TODO: #ifdef this for MACOSX which needs 2
33 SomeException () : where_(SKIP), explanation_ ("") { }
34 SomeException (const char *explanation)
35 : where_(SKIP), explanation_(explanation) { }
36 ACE_Stack_Trace where_;
37 const char *explanation_;
40 void
41 func ()
43 throw SomeException();
46 int
47 run_main (int, ACE_TCHAR *[])
49 ACE_START_TEST (ACE_TEXT ("Stack_Trace_Test"));
51 ACE_Stack_Trace t1;
52 ACE_DEBUG ((LM_DEBUG, "t1 trace is %C\n", t1.c_str()));
54 ACE_Stack_Trace t2(t1);
55 ACE_DEBUG ((LM_DEBUG, "t2 (copied) trace is %C\n",
56 (ACE_OS::strcmp (t1.c_str(), t2.c_str()) == 0) ? "same" : "different"));
58 ACE_Stack_Trace t3;
59 ACE_DEBUG ((LM_DEBUG, "t3 trace before assignment is %C\n",
60 (ACE_OS::strcmp (t1.c_str(), t3.c_str()) == 0) ? "same" : "different"));
61 t3 = t1;
62 ACE_DEBUG ((LM_DEBUG, "t3 trace after assignment is %C\n",
63 (ACE_OS::strcmp (t1.c_str(), t3.c_str()) == 0) ? "same" : "different"));
65 try {
66 func();
68 catch (SomeException& e) {
69 ACE_DEBUG ((LM_DEBUG,
70 "SomeException caught at\n%?\n; thrown at\n%C",
71 e.where_.c_str()));
74 ACE_Stack_Trace one_frame_only(0, 1);
75 ACE_DEBUG ((LM_DEBUG,
76 "stack trace of only one frame:\n%C",
77 one_frame_only.c_str()));
79 ACE_DEBUG ((LM_DEBUG, "getting ready to end the test at %?\n"));
81 ACE_END_TEST;
82 return 0;