-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
116 lines (102 loc) · 3.73 KB
/
Copy pathtest.cpp
File metadata and controls
116 lines (102 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*--------------------------------------------------------------------------*/
/*----------------------------- File test.cpp ------------------------------*/
/*--------------------------------------------------------------------------*/
/** @file
* Simple test on MultiStageStochasticBlock.
*
* \author Donato Meoli \n
* Dipartimento di Informatica \n
* Universita' di Pisa \n
*
* \copyright © by Donato Meoli
*/
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "MultiStageStochasticBlock.h"
#include <iostream>
#include <typeinfo>
/*--------------------------------------------------------------------------*/
/*-------------------------------- USING -----------------------------------*/
/*--------------------------------------------------------------------------*/
using namespace std;
using namespace SMSpp_di_unipi_it;
/*--------------------------------------------------------------------------*/
/// Custom terminate function to print the exception message
void smspp_terminate( void ) {
std::cerr << "Uncaught exception in executing SMS++:\n";
try {
std::rethrow_exception( std::current_exception() );
}
catch( const std::exception & e ) {
std::cerr << "\tException type: " << typeid( e ).name() << "\n";
std::cerr << "\tException message: " << e.what() << "\n";
} catch( ... ) {
std::cerr << "\tUnknown exception" << std::endl;
}
std::abort();
}
/*--------------------------------------------------------------------------*/
/*--------------------------------- MAIN -----------------------------------*/
/*--------------------------------------------------------------------------*/
int main( int argc , char ** argv )
{
// override the default terminate handler to print the exception message
std::set_terminate( smspp_terminate );
cout << "=== MultiStageStochasticBlock Factory Test ===" << endl << endl;
// Test 1: Direct construction
cout << "Test 1: Direct construction...";
auto * mssb1 = new MultiStageStochasticBlock();
if( mssb1 ) {
cout << " SUCCESS" << endl;
delete mssb1;
} else {
cout << " FAILED" << endl;
return( 1 );
}
// Test 2: Factory registration check
cout << "Test 2: Factory registration...";
try {
auto * mssb2 = dynamic_cast< MultiStageStochasticBlock * >(
Block::new_Block( "MultiStageStochasticBlock" , nullptr ) );
if( mssb2 ) {
cout << " SUCCESS" << endl;
delete mssb2;
} else {
cout << " FAILED: wrong type" << endl;
return( 1 );
}
} catch( const exception & e ) {
cout << " FAILED: " << e.what() << endl;
return( 1 );
}
// Test 3: Load from nc4 file if provided
if( argc > 1 ) {
cout << "Test 3: Loading from " << argv[ 1 ] << "...";
try {
netCDF::NcFile dataFile( argv[ 1 ] , netCDF::NcFile::read );
auto * block = Block::new_Block( dataFile , nullptr );
if( block ) {
auto * mssb3 = dynamic_cast< MultiStageStochasticBlock * >( block );
if( mssb3 ) {
cout << " SUCCESS (sub-Blocks: " << mssb3->get_number_sub_blocks()
<< ")" << endl;
} else {
cout << " FAILED: not a MultiStageStochasticBlock" << endl;
}
delete block;
} else {
cout << " FAILED: new_Block returned nullptr" << endl;
return( 1 );
}
} catch( const exception & e ) {
cout << " FAILED: " << e.what() << endl;
return( 1 );
}
}
cout << endl << "=== All tests passed ===" << endl;
return( 0 );
}
/*--------------------------------------------------------------------------*/
/*--------------------------- End File test.cpp ----------------------------*/
/*--------------------------------------------------------------------------*/