1 /* $Id: test_stacktrace.cpp 534857 2017-05-03 12:26:07Z ivanov $ 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government have not placed any restriction on its use or reproduction. 13 * 14 * Although all reasonable efforts have been taken to ensure the accuracy 15 * and reliability of the software and data, the NLM and the U.S. 16 * Government do not and cannot warrant the performance or results that 17 * may be obtained by using this software or data. The NLM and the U.S. 18 * Government disclaim all warranties, express or implied, including 19 * warranties of performance, merchantability or fitness for any particular 20 * purpose. 21 * 22 * Please cite the author in any work or product based on this material. 23 * 24 * =========================================================================== 25 * 26 * Author: Mike DiCuccio 27 * 28 * File Description: 29 * Stack-trace test 30 */ 31 32 #include <ncbi_pch.hpp> 33 #include <corelib/ncbistd.hpp> 34 #include <corelib/ncbiapp.hpp> 35 #include <corelib/ncbienv.hpp> 36 #include <corelib/ncbiargs.hpp> 37 #include <corelib/ncbi_stack.hpp> 38 39 #include <common/test_assert.h> /* This header must go last */ 40 41 42 USING_NCBI_SCOPE; 43 44 45 class CTestStackTrace : public CNcbiApplication 46 { 47 public: 48 49 virtual void Init(void); 50 virtual int Run (void); 51 52 virtual void Func1(); 53 virtual void Func2(int i); 54 virtual void Func3(double d); 55 virtual void Func4(const string& str); 56 virtual void Func5(const char* char_ptr); 57 }; 58 Func1()59void CTestStackTrace::Func1() 60 { 61 Func2(9); 62 } 63 Func2(int i)64void CTestStackTrace::Func2(int i) 65 { 66 Func3(i/2.0); 67 } 68 Func3(double d)69void CTestStackTrace::Func3(double d) 70 { 71 Func4(NStr::DoubleToString(d)); 72 } 73 Func4(const string & str)74void CTestStackTrace::Func4(const string& str) 75 { 76 Func5(str.c_str()); 77 } 78 Func5(const char * char_ptr)79void CTestStackTrace::Func5(const char* char_ptr) 80 { 81 CStackTrace trace("\t"); 82 83 cout << "Func5(" << char_ptr << ") stacktrace:" << endl << trace; 84 85 ERR_POST(Warning 86 << "Func5(" << char_ptr << ") stacktrace:\n" 87 << trace); 88 } 89 Init(void)90void CTestStackTrace::Init(void) 91 { 92 unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions); 93 SetupArgDescriptions(arg_desc.release()); 94 } 95 96 Run(void)97int CTestStackTrace::Run(void) 98 { 99 Func1(); 100 return 0; 101 } 102 103 104 ///////////////////////////////////////////////////////////////////////////// 105 // MAIN 106 main(int argc,const char * argv[])107int main(int argc, const char* argv[]) 108 { 109 return CTestStackTrace().AppMain(argc, argv); 110 } 111