trick/trick_source/sim_services/MonteCarlo/test/MonteCarlo_exceptions.cpp
Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
Changed all header file once include variables to follow the same naming
convention and not start with any underscores.  Also deleted old
incorrect copyright notices.  Also removed $Id: tags from all files.

Fixes #14.  Fixes #22.
2015-03-23 16:03:14 -05:00

102 lines
2.6 KiB
C++

#define protected public
#include <iostream>
#include <sys/types.h>
#include <signal.h>
#include "gtest/gtest.h"
#include "sim_services/MonteCarlo/include/MonteCarlo.hh"
#include "sim_services/MonteCarlo/include/MonteVar.hh"
#include "sim_services/MonteCarlo/include/MonteVarFile.hh"
#include "sim_services/MonteCarlo/include/MonteVarRandom.hh"
#include "sim_services/SimObject/include/SimObject.hh"
#include "sim_services/Executive/include/Exec_exception.hh"
void sig_hand(int sig) ;
void child_handler(int sig) ;
#if (__APPLE__ | __CYGWIN__ | __INTERIX )
void fpe_sig_handler(int sig) ;
#else
void fpe_sig_handler(int sig, siginfo_t * sip, void *uap) ;
#endif
namespace Trick {
class testSimObject : public Trick::SimObject {
public:
testSimObject() {}
} ;
class MonteCarloTest : public ::testing::Test {
protected:
Trick::MonteCarlo exec;
MonteCarloTest() {}
~MonteCarloTest() {}
} ;
TEST_F(MonteCarloTest, MonteVarFile_ColException) {
bool got_exception = false;
try {
Trick::MonteVarFile var("time_to_fire_1", "M_jet_firings_inline", 7) ;
var.get_next_value();
} catch (Trick::Exec_exception &e) {
std::cout << e.message << std::endl;
got_exception = true;
}
EXPECT_EQ(got_exception, true);
}
TEST_F(MonteCarloTest, MonteVarFile_BadFileException) {
bool got_exception = false;
try {
Trick::MonteVarFile var("time_to_fire_1", "_M_jet_firings_inline", 1) ;
var.get_next_value();
} catch (Trick::Exec_exception &e) {
std::cout << e.message << std::endl;
got_exception = true;
}
EXPECT_EQ(got_exception, true);
}
TEST_F(MonteCarloTest, MonteVarFile_FileException) {
bool got_exception = false;
try {
Trick::MonteVarFile var("time_to_fire_1", "M_jet_firings_inline", 1) ;
var.get_next_value();
var.input_file_stream->close();
var.get_next_value();
var.get_next_value();
} catch (Trick::Exec_exception &e) {
std::cout << e.message << std::endl;
got_exception = true;
}
EXPECT_EQ(got_exception, true);
}
TEST_F(MonteCarloTest, TestMonteVarRandom_Exception) {
bool got_exception = false;
try {
Trick::MonteVarRandom var1("time_to_fire_2", Trick::MonteVarRandom::GAUSSIAN) ;
var1.set_mu(4.0) ;
var1.set_min(4.0) ;
var1.set_max(4.000001) ;
exec.add_variable(&var1) ;
var1.get_next_value();
} catch (Trick::Exec_exception &e) {
std::cout << e.message;
got_exception = true;
}
EXPECT_EQ(got_exception, true);
}
}