]> git.mxchange.org Git - simgear.git/blob - simgear/environment/test_metar.cxx
bcdc772598d298ac23a54c6374338fd216587352
[simgear.git] / simgear / environment / test_metar.cxx
1
2 #ifdef HAVE_CONFIG_H
3 #  include <simgear_config.h>
4 #endif
5
6 #include <simgear/compiler.h>
7
8 #include <iostream>
9 #include <cstdlib>
10 #include <cstdio>
11
12 #ifdef _MSC_VER
13 #   define  random  rand
14 #endif
15
16 #include <simgear/misc/sg_dir.hxx>
17 #include <simgear/structure/exception.hxx>
18
19 #include "metar.hxx"
20
21 using std::cout;
22 using std::cerr;
23 using std::endl;
24 using std::string;
25
26 #define COMPARE(a, b) \
27     if ((a) != (b))  { \
28         cerr << "failed:" << #a << " != " << #b << endl; \
29         cerr << "\tgot:" << a << endl; \
30         exit(1); \
31     }
32
33 #define VERIFY(a) \
34     if (!(a))  { \
35         cerr << "failed:" << #a << endl; \
36         exit(1); \
37     }
38     
39
40 void test_basic()
41 {
42     SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 VCSH FEW025CB SCT048 10/05 Q1025 TEMPO VRB03KT");
43     COMPARE(m1.getYear(), 2011);
44     COMPARE(m1.getMonth(), 10);
45     COMPARE(m1.getDay(), 20);
46     COMPARE(m1.getHour(), 11);
47     COMPARE(m1.getMinute(), 25);
48     COMPARE(m1.getReportType(), -1); // should default to NIL?
49     
50     COMPARE(m1.getWindDir(), 270);
51     COMPARE(m1.getWindSpeed_kt(), 12);
52     
53     COMPARE(m1.getTemperature_C(), 10);
54     COMPARE(m1.getDewpoint_C(), 5);
55     COMPARE(m1.getPressure_hPa(), 1025);
56 }
57
58 int main(int argc, char* argv[])
59 {
60     try {
61     test_basic();
62     } catch (sg_exception& e) {
63         cerr << "got exception:" << e.getMessage() << endl;
64         return -1;
65     }
66     
67     return 0;
68 }