/
testsuite.cpp
132 lines (115 loc) · 3.18 KB
/
testsuite.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// main.cpp
// TestSuite
//
// Created by Feldkamp on 8/23/11.
// Copyright 2011 SLAC National Accelerator Laboratory. All rights reserved.
//
#include <iostream>
using std::cout;
using std::endl;
using std::cerr;
#include <string>
using std::string;
#include <sstream>
using std::ostringstream;
#include "tester.h"
void usage(){
cout << "====================usage============================" << endl;
cout << " -t<num> : test different features" << endl;
cout << " num=1 : testCrossCorrelator" << endl;
cout << " num=2 : testArrayClasses" << endl;
cout << " num=3 : testFourierTrafo" << endl;
cout << " num=4 : testIO" << endl;
cout << " num=5 : testDataTypes" << endl;
cout << " num=0 : test all" << endl;
cout << "=====================================================" << endl;
}
string argToString( char * const argument ){
//fill argument after the -<option letter> into a string
std::ostringstream osst;
int j = 2;
while ( argument[j] != '\0' ){
osst << argument[j];
j++;
}
string retstring = osst.str();
return retstring;
}
int main (int argc, char * const argv[]) {
cout << "Hello, World!\n";
if (argc < 2){
usage();
return 1;
} else {
for(int i = 1; i < argc; i++){ // check if all options are valid first
if (argv[i][0] != '-')
{
cout << "'" << argv[i] << "' does not start with a dash: not a valid option. Exiting." << endl;
usage();
return 1;
}
}
for(int i = 1; i < argc; i++){ //if all options are valid, proceed and evaluate
if (argv[i][1] == 't') {
cout << "---- testing option '" << argv[i][2] << "' ----" << endl;
//---------------------------------------------------
//run various tests
//---------------------------------------------------
string base = "";
char *home = getenv( "HOME" );
if (home){
base = home;
base += "/Desktop";
}
cout << "output directory '" << base << "'" << endl;
Tester *t = new Tester(base);
switch(argv[i][2]){
case '1':
t->testCrossCorrelator( 1 );
break;
case '2':
t->testArrayClasses();
break;
case '3':
t->testFourierTrafo();
break;
case '4':
{
int io_mode = 0; //general case: test all 2D formats
// io_mode = 1; //2D EDF
// io_mode = 2; //2D HDF5
// io_mode = 3; //2D TIFF
// io_mode = 4; //2D ASCII
// io_mode = 5; //special case...
// io_mode = 12; //test all 1D formats
t->testIO(io_mode);
}
break;
case '5':
t->testDataTypes();
break;
case '6':
t->testArraySpeed();
break;
case '0': // fall through to default
default:
t->testCrossCorrelator( 1 );
t->testArrayClasses();
t->testFourierTrafo();
t->testIO();
t->testDataTypes();
break;
}//end switch
cout << "---- testing done ----" << endl;
delete t;
return 0;
} else {
cout << "-" << argv[i][1] << " is not a valid option." << endl;
usage();
return 2;
}
}//end for i
}//end if
return 0;
}