COPASI API  4.16.103
test000101.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/sbml/unittests/test000101.cpp,v $
3 // $Revision: 1.3 $
4 // $Name: $
5 // $Author: bergmann $
6 // $Date: 2012/04/19 15:00:10 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include "test000101.h"
15 
16 #include <iostream>
17 #ifndef WIN32
18 #include <signal.h>
19 #endif
20 #include <stdexcept>
21 
24 
25 // Since this bug leads to segmentation fault
26 // we need to make sure that the call to abort made by assert does not end the program.
27 // For this we change the signal handler to one that throws an exception.
28 // The current version is specific to linux. If these tests are to be run under windows,
29 // the mechanism for setting the signal handler will probably have to be modified.
31 {
32  throw std::runtime_error("Received SIGSEGV signal.");
33 }
34 
35 #ifndef WIN32
36 struct sigaction* test000101::pOldAct = new struct sigaction();
37 struct sigaction* test000101::pNewAct = new struct sigaction();
38 #endif
40 {
41 #ifndef WIN32
42  // set a new action handler for SIGABRT that throws an exception
43  // instead of terminating the program. This is needed to handle failed assertions
44  // in debug versions.
45  pNewAct->sa_handler = &test000101::abort_handler;
46  int x = sigaction(SIGSEGV, test000101::pNewAct, test000101::pOldAct);
47 
48  if (x != 0)
49  {
50  std::cerr << "Setting the signal handler failed." << std::endl;
51  }
52 
53 #endif
54  // Create the root container.
55  CCopasiRootContainer::init(0, NULL, false);
57 }
58 
60 {
61 #ifndef WIN32
63  // restore the old action handler
64  int x = sigaction(SIGSEGV, test000101::pOldAct, NULL);
65 
66  if (x != 0)
67  {
68  std::cerr << "Resetting the signal handler failed." << std::endl;
69  }
70 
71 #endif
72 }
73 
74 
75 
77 {
79  pDataModel->exportSBMLToString(NULL, 3, 1);
80 
81  try
82  {
83  // the second export crashes without a bug fix
84  pDataModel->exportSBMLToString(NULL, 3, 1);
85  }
86  catch (const std::runtime_error& e)
87  {
88  CPPUNIT_ASSERT_MESSAGE("The second export to Level 3 Version 1 failed.", false);
89  }
90 }
91 
92 const char* test000101::SBML_STRING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
93  "<sbml xmlns=\"http://www.sbml.org/sbml/level3/version1/core\" level=\"3\" version=\"1\">\n"
94  " <model id=\"Module_1_RL2_1\" name=\"Module_1_RL2\">\n"
95  " <listOfReactions>\n"
96  " <reaction fast=\"false\" id=\"reaction_0\" name=\"reaction_0\" reversible=\"false\">\n"
97  " </reaction>\n"
98  " </listOfReactions>\n"
99  " </model>\n"
100  "</sbml>\n";
101 
static struct sigaction * pOldAct
Definition: test000101.h:44
std::string exportSBMLToString(CProcessReport *pExportHandler, int sbmlLevel, int sbmlVersion)
void tearDown()
Definition: test000101.cpp:59
static struct sigaction * pNewAct
Definition: test000101.h:43
void test_bug1740()
Definition: test000101.cpp:76
static const char * SBML_STRING
Definition: test000101.h:39
static void abort_handler(int)
Definition: test000101.cpp:30
static CCopasiDataModel * addDatamodel()
void setUp()
Definition: test000101.cpp:39
bool importSBMLFromString(const std::string &sbmlDocumentText, CProcessReport *pImportHandler=NULL, const bool &deleteOldData=true)
static void init(int argc, char *argv[], const bool &withGui=false)
CCopasiDataModel * pDataModel
Definition: test000101.h:41