From: wolf Date: Thu, 30 Jun 2005 20:22:03 +0000 (+0000) Subject: Add a test for backtraces. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4177312bf64d20446a490518139ff9120e0ea2a9;p=dealii-svn.git Add a test for backtraces. git-svn-id: https://svn.dealii.org/trunk@11013 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/base/stack_trace.cc b/tests/base/stack_trace.cc new file mode 100644 index 0000000000..2fb025c193 --- /dev/null +++ b/tests/base/stack_trace.cc @@ -0,0 +1,74 @@ +//---------------------------- stack_trace.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- stack_trace.cc --------------------------- + + +#include "../tests.h" +#include +#include +#include +#include + +// test the stack trace generation when hitting an Assert(...) + + +void test1a () +{ + int i = 0; + Assert (i!=0, ExcMessage ("Gotcha!")); +} + + +void test1b () +{ + int i = 0; + AssertThrow (i!=0, ExcMessage ("Gotcha!")); +} + + +void test2 () +{ + + // access an invalid + // component. should trigger an + // Assert() + ConstantFunction<2>(1.).value (Point<2>(), 2); +} + + + +int main () +{ + std::ofstream logfile("stack_trace.output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try { test1a (); } + catch (std::exception &exc) { + deallog << " caught exception:" << std::endl + << exc.what() << std::endl; + } + + try { test1b (); } + catch (std::exception &exc) { + deallog << " caught exception:" << std::endl + << exc.what() << std::endl; + } + + try { test2 (); } + catch (std::exception &exc) { + deallog << " caught exception:" << std::endl + << exc.what() << std::endl; + } +} +