]> git.mxchange.org Git - simgear.git/blob - simgear/environment/test_metar.cxx
Merge branch 'next' of git://gitorious.org/fg/simgear into next
[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 FUZZY_COMPARE(a, b, epsilon) \
34     if (fabs(a - b) > epsilon) { \
35         cerr << "failed:" << #a << " != " << #b << endl; \
36         cerr << "\tgot:" << a << endl; \
37         cerr << "\tepsilon:" << epsilon << endl; \
38     }
39
40 #define VERIFY(a) \
41     if (!(a))  { \
42         cerr << "failed:" << #a << endl; \
43         exit(1); \
44     }
45
46 const double TEST_EPSILON = 1e-9;
47
48 void test_basic()
49 {
50     SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 VCSH FEW025CB SCT048 10/05 Q1025 TEMPO VRB03KT");
51     COMPARE(m1.getYear(), 2011);
52     COMPARE(m1.getMonth(), 10);
53     COMPARE(m1.getDay(), 20);
54     COMPARE(m1.getHour(), 11);
55     COMPARE(m1.getMinute(), 25);
56     COMPARE(m1.getReportType(), -1); // should default to NIL?
57     
58     COMPARE(m1.getWindDir(), 270);
59     FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON);
60     
61     FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON);
62     FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON);
63     FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON);
64 }
65
66 int main(int argc, char* argv[])
67 {
68     try {
69     test_basic();
70     } catch (sg_exception& e) {
71         cerr << "got exception:" << e.getMessage() << endl;
72         return -1;
73     }
74     
75     return 0;
76 }