From e655d418175a50272041de7b4c985305cf3d7768 Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Sun, 4 Dec 2016 14:38:47 +0100 Subject: [PATCH] Rename the COMPARE, COMPARE_EP, COMPARE_EP2 and VERIFY test macros COMPARE -> SG_CHECK_EQUAL COMPARE_EP -> SG_CHECK_EQUAL_EP COMPARE_EP2 -> SG_CHECK_EQUAL_EP2 VERIFY -> SG_VERIFY Also remove duplicate private definitions of these macros in test modules, using instead those defined in simgear/misc/test_macros.hxx. --- simgear/bucket/test_bucket.cxx | 239 +++++++++--------- simgear/environment/test_metar.cxx | 78 +++--- simgear/io/test_DNS.cxx | 15 +- simgear/io/test_HTTP.cxx | 212 ++++++++-------- simgear/io/test_binobj.cxx | 105 ++++---- simgear/io/test_untar.cxx | 4 +- simgear/io/text_DNS.cxx | 210 ++++++++------- simgear/math/SGMathTest.cxx | 32 +-- simgear/misc/CSSBorder_test.cxx | 30 +-- simgear/misc/path_test.cxx | 178 ++++++------- simgear/misc/test_macros.hxx | 8 +- simgear/package/CatalogTest.cxx | 184 +++++++------- simgear/props/easing_functions_test.cxx | 12 +- simgear/props/props_test.cxx | 189 ++++++++------ .../scene/material/parseBlendFunc_test.cxx | 42 +-- simgear/scene/model/animation_test.cxx | 17 +- simgear/scene/util/parse_color_test.cxx | 24 +- simgear/structure/expression_test.cxx | 8 +- simgear/structure/state_machine_test.cxx | 57 +++-- 19 files changed, 785 insertions(+), 859 deletions(-) diff --git a/simgear/bucket/test_bucket.cxx b/simgear/bucket/test_bucket.cxx index b2bd8d08..81990069 100644 --- a/simgear/bucket/test_bucket.cxx +++ b/simgear/bucket/test_bucket.cxx @@ -35,123 +35,124 @@ using std::endl; void testBucketSpans() { - COMPARE(sg_bucket_span(0.0), 0.125); - COMPARE(sg_bucket_span(-20), 0.125); - COMPARE(sg_bucket_span(-40), 0.25); - COMPARE(sg_bucket_span(89.9), 12.0); - COMPARE(sg_bucket_span(88.1), 4.0); - COMPARE(sg_bucket_span(-89.9), 12.0); + SG_CHECK_EQUAL(sg_bucket_span(0.0), 0.125); + SG_CHECK_EQUAL(sg_bucket_span(-20), 0.125); + SG_CHECK_EQUAL(sg_bucket_span(-40), 0.25); + SG_CHECK_EQUAL(sg_bucket_span(89.9), 12.0); + SG_CHECK_EQUAL(sg_bucket_span(88.1), 4.0); + SG_CHECK_EQUAL(sg_bucket_span(-89.9), 12.0); } void testBasic() { SGBucket b1(5.1, 55.05); - COMPARE(b1.get_chunk_lon(), 5); - COMPARE(b1.get_chunk_lat(), 55); - COMPARE(b1.get_x(), 0); - COMPARE(b1.get_y(), 0); - COMPARE(b1.gen_index(), 3040320); - COMPARE(b1.gen_base_path(), "e000n50/e005n55"); - VERIFY(b1.isValid()); + SG_CHECK_EQUAL(b1.get_chunk_lon(), 5); + SG_CHECK_EQUAL(b1.get_chunk_lat(), 55); + SG_CHECK_EQUAL(b1.get_x(), 0); + SG_CHECK_EQUAL(b1.get_y(), 0); + SG_CHECK_EQUAL(b1.gen_index(), 3040320); + SG_CHECK_EQUAL(b1.gen_base_path(), "e000n50/e005n55"); + SG_VERIFY(b1.isValid()); SGBucket b2(-10.1, -43.8); - COMPARE(b2.get_chunk_lon(), -11); - COMPARE(b2.get_chunk_lat(), -44); - COMPARE(b2.get_x(), 3); - COMPARE(b2.get_y(), 1); // latitude chunks numbered bottom to top, it seems - COMPARE(b2.gen_base_path(), "w020s50/w011s44"); - VERIFY(b2.isValid()); + SG_CHECK_EQUAL(b2.get_chunk_lon(), -11); + SG_CHECK_EQUAL(b2.get_chunk_lat(), -44); + SG_CHECK_EQUAL(b2.get_x(), 3); + // Latitude chunks numbered bottom to top, it seems + SG_CHECK_EQUAL(b2.get_y(), 1); + SG_CHECK_EQUAL(b2.gen_base_path(), "w020s50/w011s44"); + SG_VERIFY(b2.isValid()); SGBucket b3(123.48, 9.01); - COMPARE(b3.get_chunk_lon(), 123); - COMPARE(b3.get_chunk_lat(), 9); - COMPARE(b3.get_x(), 3); - COMPARE(b3.get_y(), 0); - COMPARE(b3.gen_base_path(), "e120n00/e123n09"); - VERIFY(b3.isValid()); + SG_CHECK_EQUAL(b3.get_chunk_lon(), 123); + SG_CHECK_EQUAL(b3.get_chunk_lat(), 9); + SG_CHECK_EQUAL(b3.get_x(), 3); + SG_CHECK_EQUAL(b3.get_y(), 0); + SG_CHECK_EQUAL(b3.gen_base_path(), "e120n00/e123n09"); + SG_VERIFY(b3.isValid()); SGBucket defBuck; - VERIFY(!defBuck.isValid()); + SG_VERIFY(!defBuck.isValid()); b3.make_bad(); - VERIFY(!b3.isValid()); + SG_VERIFY(!b3.isValid()); SGBucket atAntiMeridian(180.0, 12.3); - VERIFY(atAntiMeridian.isValid()); - COMPARE(atAntiMeridian.get_chunk_lon(), -180); - COMPARE(atAntiMeridian.get_x(), 0); - + SG_VERIFY(atAntiMeridian.isValid()); + SG_CHECK_EQUAL(atAntiMeridian.get_chunk_lon(), -180); + SG_CHECK_EQUAL(atAntiMeridian.get_x(), 0); + SGBucket atAntiMeridian2(-180.0, -78.1); - VERIFY(atAntiMeridian2.isValid()); - COMPARE(atAntiMeridian2.get_chunk_lon(), -180); - COMPARE(atAntiMeridian2.get_x(), 0); - + SG_VERIFY(atAntiMeridian2.isValid()); + SG_CHECK_EQUAL(atAntiMeridian2.get_chunk_lon(), -180); + SG_CHECK_EQUAL(atAntiMeridian2.get_x(), 0); + // check comparisom operator overload SGBucket b4(5.11, 55.1); - VERIFY(b1 == b4); // should be equal - VERIFY(b1 == b1); - VERIFY(b1 != defBuck); - VERIFY(b1 != b2); + SG_VERIFY(b1 == b4); // should be equal + SG_VERIFY(b1 == b1); + SG_VERIFY(b1 != defBuck); + SG_VERIFY(b1 != b2); // check wrapping/clipping of inputs SGBucket wrapMeridian(-200.0, 45.0); - COMPARE(wrapMeridian.get_chunk_lon(), 160); - + SG_CHECK_EQUAL(wrapMeridian.get_chunk_lon(), 160); + SGBucket clipPole(48.9, 91); - COMPARE(clipPole.get_chunk_lat(), 89); + SG_CHECK_EQUAL(clipPole.get_chunk_lat(), 89); } void testPolar() { SGBucket b1(0.0, 89.92); SGBucket b2(10.0, 89.96); - COMPARE(b1.get_chunk_lat(), 89); - COMPARE(b1.get_chunk_lon(), 0); - COMPARE(b1.get_x(), 0); - COMPARE(b1.get_y(), 7); + SG_CHECK_EQUAL(b1.get_chunk_lat(), 89); + SG_CHECK_EQUAL(b1.get_chunk_lon(), 0); + SG_CHECK_EQUAL(b1.get_x(), 0); + SG_CHECK_EQUAL(b1.get_y(), 7); - COMPARE_EP(b1.get_highest_lat(), 90.0); - COMPARE_EP(b1.get_width_m(), 10.0); + SG_CHECK_EQUAL_EP(b1.get_highest_lat(), 90.0); + SG_CHECK_EQUAL_EP(b1.get_width_m(), 10.0); - COMPARE(b2.get_chunk_lat(), 89); - COMPARE(b2.get_chunk_lon(), 0); - COMPARE(b2.get_x(), 0); - COMPARE(b2.get_y(), 7); + SG_CHECK_EQUAL(b2.get_chunk_lat(), 89); + SG_CHECK_EQUAL(b2.get_chunk_lon(), 0); + SG_CHECK_EQUAL(b2.get_x(), 0); + SG_CHECK_EQUAL(b2.get_y(), 7); - COMPARE(b1.gen_index(), b2.gen_index()); + SG_CHECK_EQUAL(b1.gen_index(), b2.gen_index()); SGGeod actualNorthPole1 = b1.get_corner(2); SGGeod actualNorthPole2 = b1.get_corner(3); - COMPARE_EP(actualNorthPole1.getLatitudeDeg(), 90.0); - COMPARE_EP(actualNorthPole1.getLongitudeDeg(), 12.0); - COMPARE_EP(actualNorthPole2.getLatitudeDeg(), 90.0); - COMPARE_EP(actualNorthPole2.getLongitudeDeg(), 0.0); + SG_CHECK_EQUAL_EP(actualNorthPole1.getLatitudeDeg(), 90.0); + SG_CHECK_EQUAL_EP(actualNorthPole1.getLongitudeDeg(), 12.0); + SG_CHECK_EQUAL_EP(actualNorthPole2.getLatitudeDeg(), 90.0); + SG_CHECK_EQUAL_EP(actualNorthPole2.getLongitudeDeg(), 0.0); SGBucket b3(-2, 89.88); SGBucket b4(-7, 89.88); - COMPARE(b3.gen_index(), b4.gen_index()); + SG_CHECK_EQUAL(b3.gen_index(), b4.gen_index()); // south pole SGBucket b5(-170, -89.88); SGBucket b6(-179, -89.88); - COMPARE(b5.get_chunk_lat(), -90); - COMPARE(b5.get_chunk_lon(), -180); - COMPARE(b5.get_x(), 0); - COMPARE(b5.get_y(), 0); - COMPARE(b5.gen_index(), b6.gen_index()); - COMPARE_EP(b5.get_highest_lat(), -90.0); - COMPARE_EP(b5.get_width_m(), 10.0); + SG_CHECK_EQUAL(b5.get_chunk_lat(), -90); + SG_CHECK_EQUAL(b5.get_chunk_lon(), -180); + SG_CHECK_EQUAL(b5.get_x(), 0); + SG_CHECK_EQUAL(b5.get_y(), 0); + SG_CHECK_EQUAL(b5.gen_index(), b6.gen_index()); + SG_CHECK_EQUAL_EP(b5.get_highest_lat(), -90.0); + SG_CHECK_EQUAL_EP(b5.get_width_m(), 10.0); SGGeod actualSouthPole1 = b5.get_corner(0); SGGeod actualSouthPole2 = b5.get_corner(1); - COMPARE_EP(actualSouthPole1.getLatitudeDeg(), -90.0); - COMPARE_EP(actualSouthPole1.getLongitudeDeg(), -180); - COMPARE_EP(actualSouthPole2.getLatitudeDeg(), -90.0); - COMPARE_EP(actualSouthPole2.getLongitudeDeg(), -168); + SG_CHECK_EQUAL_EP(actualSouthPole1.getLatitudeDeg(), -90.0); + SG_CHECK_EQUAL_EP(actualSouthPole1.getLongitudeDeg(), -180); + SG_CHECK_EQUAL_EP(actualSouthPole2.getLatitudeDeg(), -90.0); + SG_CHECK_EQUAL_EP(actualSouthPole2.getLongitudeDeg(), -168); SGBucket b7(200, 89.88); - COMPARE(b7.get_chunk_lon(), -168); + SG_CHECK_EQUAL(b7.get_chunk_lon(), -168); } @@ -160,15 +161,15 @@ void testNearPolar() { SGBucket b1(1, 88.5); SGBucket b2(-1, 88.8); - COMPARE(b1.get_chunk_lon(), 0); - COMPARE(b1.get_chunk_lat(), 88); - VERIFY(b1.gen_index() != b2.gen_index()); + SG_CHECK_EQUAL(b1.get_chunk_lon(), 0); + SG_CHECK_EQUAL(b1.get_chunk_lat(), 88); + SG_VERIFY(b1.gen_index() != b2.gen_index()); SGBucket b3(176.1, 88.5); - COMPARE(b3.get_chunk_lon(), 176); + SG_CHECK_EQUAL(b3.get_chunk_lon(), 176); SGBucket b4(-178, 88.5); - COMPARE(b4.get_chunk_lon(), -180); + SG_CHECK_EQUAL(b4.get_chunk_lon(), -180); } void testOffset() @@ -176,74 +177,74 @@ void testOffset() // bucket just below the 22 degree cutoff, so the next tile north // is twice the width SGBucket b1(-59.8, 21.9); - COMPARE(b1.get_chunk_lat(), 21); - COMPARE(b1.get_chunk_lon(), -60); - COMPARE(b1.get_x(), 1); - COMPARE(b1.get_y(), 7); + SG_CHECK_EQUAL(b1.get_chunk_lat(), 21); + SG_CHECK_EQUAL(b1.get_chunk_lon(), -60); + SG_CHECK_EQUAL(b1.get_x(), 1); + SG_CHECK_EQUAL(b1.get_y(), 7); // offset vertically SGBucket b2(b1.sibling(0, 1)); - COMPARE(b2.get_chunk_lat(), 22); - COMPARE(b2.get_chunk_lon(), -60); - COMPARE(b2.get_x(), 0); - COMPARE(b2.get_y(), 0); + SG_CHECK_EQUAL(b2.get_chunk_lat(), 22); + SG_CHECK_EQUAL(b2.get_chunk_lon(), -60); + SG_CHECK_EQUAL(b2.get_x(), 0); + SG_CHECK_EQUAL(b2.get_y(), 0); - COMPARE(b2.gen_index(), sgBucketOffset(-59.8, 21.9, 0, 1)); + SG_CHECK_EQUAL(b2.gen_index(), sgBucketOffset(-59.8, 21.9, 0, 1)); // offset vertically and horizontally. We compute horizontal (x) // movement at the target latitude, so this should move 0.25 * -3 degrees, // NOT 0.125 * -3 degrees. SGBucket b3(b1.sibling(-3, 1)); - COMPARE(b3.get_chunk_lat(), 22); - COMPARE(b3.get_chunk_lon(), -61); - COMPARE(b3.get_x(), 1); - COMPARE(b3.get_y(), 0); + SG_CHECK_EQUAL(b3.get_chunk_lat(), 22); + SG_CHECK_EQUAL(b3.get_chunk_lon(), -61); + SG_CHECK_EQUAL(b3.get_x(), 1); + SG_CHECK_EQUAL(b3.get_y(), 0); - COMPARE(b3.gen_index(), sgBucketOffset(-59.8, 21.9, -3, 1)); + SG_CHECK_EQUAL(b3.gen_index(), sgBucketOffset(-59.8, 21.9, -3, 1)); } void testPolarOffset() { SGBucket b1(-11.7, -89.6); - COMPARE(b1.get_chunk_lat(), -90); - COMPARE(b1.get_chunk_lon(), -12); - COMPARE(b1.get_x(), 0); - COMPARE(b1.get_y(), 3); + SG_CHECK_EQUAL(b1.get_chunk_lat(), -90); + SG_CHECK_EQUAL(b1.get_chunk_lon(), -12); + SG_CHECK_EQUAL(b1.get_x(), 0); + SG_CHECK_EQUAL(b1.get_y(), 3); // offset horizontally SGBucket b2(b1.sibling(-2, 0)); - COMPARE(b2.get_chunk_lat(), -90); - COMPARE(b2.get_chunk_lon(), -36); - COMPARE(b2.get_x(), 0); - COMPARE(b2.get_y(), 3); + SG_CHECK_EQUAL(b2.get_chunk_lat(), -90); + SG_CHECK_EQUAL(b2.get_chunk_lon(), -36); + SG_CHECK_EQUAL(b2.get_x(), 0); + SG_CHECK_EQUAL(b2.get_y(), 3); - COMPARE(b2.gen_index(), sgBucketOffset(-11.7, -89.6, -2, 0)); + SG_CHECK_EQUAL(b2.gen_index(), sgBucketOffset(-11.7, -89.6, -2, 0)); // offset and wrap SGBucket b3(-170, 89.1); SGBucket b4(b3.sibling(-1, 0)); - COMPARE(b4.get_chunk_lat(), 89); - COMPARE(b4.get_chunk_lon(), 168); - COMPARE(b4.get_x(), 0); - COMPARE(b4.get_y(), 0); + SG_CHECK_EQUAL(b4.get_chunk_lat(), 89); + SG_CHECK_EQUAL(b4.get_chunk_lon(), 168); + SG_CHECK_EQUAL(b4.get_x(), 0); + SG_CHECK_EQUAL(b4.get_y(), 0); - COMPARE(b4.gen_index(), sgBucketOffset(-170, 89.1, -1, 0)); + SG_CHECK_EQUAL(b4.gen_index(), sgBucketOffset(-170, 89.1, -1, 0)); SGBucket b5(177, 87.3); SGBucket b6(b5.sibling(1, 1)); - COMPARE(b6.get_chunk_lat(), 87); - COMPARE(b6.get_chunk_lon(), -180); - COMPARE(b6.get_x(), 0); - COMPARE(b6.get_y(), 3); + SG_CHECK_EQUAL(b6.get_chunk_lat(), 87); + SG_CHECK_EQUAL(b6.get_chunk_lon(), -180); + SG_CHECK_EQUAL(b6.get_x(), 0); + SG_CHECK_EQUAL(b6.get_y(), 3); - COMPARE(b6.gen_index(), sgBucketOffset(177, 87.3, 1, 1)); + SG_CHECK_EQUAL(b6.gen_index(), sgBucketOffset(177, 87.3, 1, 1)); // offset vertically towards the pole SGBucket b7(b1.sibling(0, -5)); - VERIFY(!b7.isValid()); + SG_VERIFY(!b7.isValid()); - VERIFY(!SGBucket(0, 90).sibling(0, 1).isValid()); + SG_VERIFY(!SGBucket(0, 90).sibling(0, 1).isValid()); } // test behaviour of bucket-offset near the anti-meridian (180-meridian) @@ -251,17 +252,17 @@ void testOffsetWrap() { // near the equator SGBucket b1(-179.8, 16.8); - COMPARE(b1.get_chunk_lat(), 16); - COMPARE(b1.get_chunk_lon(), -180); - COMPARE(b1.get_x(), 1); - COMPARE(b1.get_y(), 6); + SG_CHECK_EQUAL(b1.get_chunk_lat(), 16); + SG_CHECK_EQUAL(b1.get_chunk_lon(), -180); + SG_CHECK_EQUAL(b1.get_x(), 1); + SG_CHECK_EQUAL(b1.get_y(), 6); SGBucket b2(b1.sibling(-2, 0)); - COMPARE(b2.get_chunk_lat(), 16); - COMPARE(b2.get_chunk_lon(), 179); - COMPARE(b2.get_x(), 7); - COMPARE(b2.get_y(), 6); - COMPARE(b2.gen_index(), sgBucketOffset(-179.8, 16.8, -2, 0)); + SG_CHECK_EQUAL(b2.get_chunk_lat(), 16); + SG_CHECK_EQUAL(b2.get_chunk_lon(), 179); + SG_CHECK_EQUAL(b2.get_x(), 7); + SG_CHECK_EQUAL(b2.get_y(), 6); + SG_CHECK_EQUAL(b2.gen_index(), sgBucketOffset(-179.8, 16.8, -2, 0)); } diff --git a/simgear/environment/test_metar.cxx b/simgear/environment/test_metar.cxx index 41934188..f97a3d18 100644 --- a/simgear/environment/test_metar.cxx +++ b/simgear/environment/test_metar.cxx @@ -4,6 +4,7 @@ #endif #include +#include #include #include @@ -23,75 +24,56 @@ using std::cerr; using std::endl; using std::string; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:" << a << endl; \ - exit(1); \ - } - -#define FUZZY_COMPARE(a, b, epsilon) \ - if (fabs(a - b) > epsilon) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:" << a << endl; \ - cerr << "\tepsilon:" << epsilon << endl; \ - } - -#define VERIFY(a) \ - if (!(a)) { \ - cerr << "failed:" << #a << endl; \ - exit(1); \ - } const double TEST_EPSILON = 1e-9; void test_basic() { SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 VCSH FEW025CB SCT048 10/05 Q1025 TEMPO VRB03KT"); - COMPARE(m1.getYear(), 2011); - COMPARE(m1.getMonth(), 10); - COMPARE(m1.getDay(), 20); - COMPARE(m1.getHour(), 11); - COMPARE(m1.getMinute(), 25); - COMPARE(m1.getReportType(), -1); // should default to NIL? - - COMPARE(m1.getWindDir(), 270); - FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON); - - COMPARE(m1.getWeather().size(), 1); - COMPARE(m1.getClouds().size(), 2); + SG_CHECK_EQUAL(m1.getYear(), 2011); + SG_CHECK_EQUAL(m1.getMonth(), 10); + SG_CHECK_EQUAL(m1.getDay(), 20); + SG_CHECK_EQUAL(m1.getHour(), 11); + SG_CHECK_EQUAL(m1.getMinute(), 25); + SG_CHECK_EQUAL(m1.getReportType(), -1); // should default to NIL? - FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON); - FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON); - FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON); + SG_CHECK_EQUAL(m1.getWindDir(), 270); + SG_CHECK_EQUAL_EP2(m1.getWindSpeed_kt(), 12, TEST_EPSILON); + + SG_CHECK_EQUAL(m1.getWeather().size(), 1); + SG_CHECK_EQUAL(m1.getClouds().size(), 2); + + SG_CHECK_EQUAL_EP2(m1.getTemperature_C(), 10, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getDewpoint_C(), 5, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getPressure_hPa(), 1025, TEST_EPSILON); } void test_sensor_failure_weather() { SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 // FEW025CB SCT048 10/05 Q1025"); - COMPARE(m1.getWindDir(), 270); - FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON); + SG_CHECK_EQUAL(m1.getWindDir(), 270); + SG_CHECK_EQUAL_EP2(m1.getWindSpeed_kt(), 12, TEST_EPSILON); - COMPARE(m1.getWeather().size(), 0); - COMPARE(m1.getClouds().size(), 2); + SG_CHECK_EQUAL(m1.getWeather().size(), 0); + SG_CHECK_EQUAL(m1.getClouds().size(), 2); - FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON); - FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON); - FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getTemperature_C(), 10, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getDewpoint_C(), 5, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getPressure_hPa(), 1025, TEST_EPSILON); } void test_sensor_failure_cloud() { SGMetar m1("2011/10/20 11:25 EHAM 201125Z 27012KT 240V300 9999 FEW025CB/// SCT048/// 10/05 Q1025"); - COMPARE(m1.getWindDir(), 270); - FUZZY_COMPARE(m1.getWindSpeed_kt(), 12, TEST_EPSILON); + SG_CHECK_EQUAL(m1.getWindDir(), 270); + SG_CHECK_EQUAL_EP2(m1.getWindSpeed_kt(), 12, TEST_EPSILON); - COMPARE(m1.getWeather().size(), 0); - COMPARE(m1.getClouds().size(), 2); + SG_CHECK_EQUAL(m1.getWeather().size(), 0); + SG_CHECK_EQUAL(m1.getClouds().size(), 2); - FUZZY_COMPARE(m1.getTemperature_C(), 10, TEST_EPSILON); - FUZZY_COMPARE(m1.getDewpoint_C(), 5, TEST_EPSILON); - FUZZY_COMPARE(m1.getPressure_hPa(), 1025, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getTemperature_C(), 10, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getDewpoint_C(), 5, TEST_EPSILON); + SG_CHECK_EQUAL_EP2(m1.getPressure_hPa(), 1025, TEST_EPSILON); } int main(int argc, char* argv[]) diff --git a/simgear/io/test_DNS.cxx b/simgear/io/test_DNS.cxx index 63d7d117..0712d863 100644 --- a/simgear/io/test_DNS.cxx +++ b/simgear/io/test_DNS.cxx @@ -18,6 +18,7 @@ #include #include #include +#include using std::cout; using std::cerr; @@ -25,12 +26,6 @@ using std::endl; using namespace simgear; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:'" << a << "'" << endl; \ - exit(1); \ - } class Watchdog { @@ -127,11 +122,11 @@ int main(int argc, char* argv[]) int order = -1, preference = -1; for( DNS::NAPTRRequest::NAPTR_list::const_iterator it = naptrRequest->entries.begin(); it != naptrRequest->entries.end(); ++it ) { // currently only support "U" which implies empty replacement - COMPARE((*it)->flags, "U" ); - COMPARE(naptrRequest->entries[0]->replacement, "" ); + SG_CHECK_EQUAL((*it)->flags, "U" ); + SG_CHECK_EQUAL(naptrRequest->entries[0]->replacement, "" ); // currently only support ws20 - COMPARE((*it)->service, "ws20" ); + SG_CHECK_EQUAL((*it)->service, "ws20" ); if( (*it)->order < order ) { cerr << "NAPTR entries not ascending for field 'order'" << endl; @@ -174,7 +169,7 @@ int main(int argc, char* argv[]) cerr << "timeout testing non-existing record." << endl; return EXIT_FAILURE; } - COMPARE(naptrRequest->entries.size(), 0 ); + SG_CHECK_EQUAL(naptrRequest->entries.size(), 0 ); } cout << "all tests passed ok" << endl; diff --git a/simgear/io/test_HTTP.cxx b/simgear/io/test_HTTP.cxx index 3aad7603..3bf9947d 100644 --- a/simgear/io/test_HTTP.cxx +++ b/simgear/io/test_HTTP.cxx @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -41,18 +42,6 @@ const char* BODY3 = "Cras ut neque nulla. Duis ut velit neque, sit amet " const unsigned int body2Size = 8 * 1024; char body2[body2Size]; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:'" << a << "'" << endl; \ - exit(1); \ - } - -#define VERIFY(a) \ - if (!(a)) { \ - cerr << "failed:" << #a << endl; \ - exit(1); \ - } class TestRequest : public HTTP::Request { @@ -126,8 +115,9 @@ public: d << contentStr; push(d.str().c_str()); } else if (path == "/test_headers") { - COMPARE(requestHeaders["X-Foo"], string("Bar")); - COMPARE(requestHeaders["X-AnotherHeader"], string("A longer value")); + SG_CHECK_EQUAL(requestHeaders["X-Foo"], string("Bar")); + SG_CHECK_EQUAL(requestHeaders["X-AnotherHeader"], + string("A longer value")); string contentStr(BODY1); stringstream d; @@ -304,7 +294,7 @@ public: } else if (path == "/test_put") { std::cerr << "sending PUT response" << std::endl; - COMPARE(buffer, BODY3); + SG_CHECK_EQUAL(buffer, BODY3); stringstream d; d << "HTTP/1.1 " << 204 << " " << reasonForCode(204) << "\r\n"; d << "\r\n"; // final CRLF to terminate the headers @@ -314,7 +304,7 @@ public: std::string entityStr = "http://localhost:2000/something.txt"; - COMPARE(buffer, BODY3); + SG_CHECK_EQUAL(buffer, BODY3); stringstream d; d << "HTTP/1.1 " << 201 << " " << reasonForCode(201) << "\r\n"; d << "Location:" << entityStr << "\r\n"; @@ -385,18 +375,18 @@ int main(int argc, char* argv[]) // test URL parsing TestRequest* tr1 = new TestRequest("http://localhost.woo.zar:2000/test1?foo=bar"); - COMPARE(tr1->scheme(), "http"); - COMPARE(tr1->hostAndPort(), "localhost.woo.zar:2000"); - COMPARE(tr1->host(), "localhost.woo.zar"); - COMPARE(tr1->port(), 2000); - COMPARE(tr1->path(), "/test1"); + SG_CHECK_EQUAL(tr1->scheme(), "http"); + SG_CHECK_EQUAL(tr1->hostAndPort(), "localhost.woo.zar:2000"); + SG_CHECK_EQUAL(tr1->host(), "localhost.woo.zar"); + SG_CHECK_EQUAL(tr1->port(), 2000); + SG_CHECK_EQUAL(tr1->path(), "/test1"); TestRequest* tr2 = new TestRequest("http://192.168.1.1/test1/dir/thing/file.png"); - COMPARE(tr2->scheme(), "http"); - COMPARE(tr2->hostAndPort(), "192.168.1.1"); - COMPARE(tr2->host(), "192.168.1.1"); - COMPARE(tr2->port(), 80); - COMPARE(tr2->path(), "/test1/dir/thing/file.png"); + SG_CHECK_EQUAL(tr2->scheme(), "http"); + SG_CHECK_EQUAL(tr2->hostAndPort(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->host(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->port(), 80); + SG_CHECK_EQUAL(tr2->path(), "/test1/dir/thing/file.png"); // basic get request { @@ -405,11 +395,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } { @@ -418,11 +408,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY3)); - COMPARE(tr->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY3)); } { @@ -430,7 +420,7 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseCode(), 200); } { @@ -441,11 +431,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } // larger get request @@ -458,9 +448,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseBytesReceived(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseBytesReceived(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } cerr << "testing chunked transfer encoding" << endl; @@ -470,12 +460,12 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseBytesReceived(), 30); - COMPARE(tr->bodyData, "ABCDEFGHABCDEFABCDSTUVABCDSTUV"); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseBytesReceived(), 30); + SG_CHECK_EQUAL(tr->bodyData, "ABCDEFGHABCDEFABCDSTUVABCDSTUV"); // check trailers made it too - COMPARE(tr->headers["x-foobar"], string("wibble")); + SG_CHECK_EQUAL(tr->headers["x-foobar"], string("wibble")); } // test 404 @@ -484,9 +474,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 404); - COMPARE(tr->responseReason(), string("not found")); - COMPARE(tr->responseLength(), 0); + SG_CHECK_EQUAL(tr->responseCode(), 404); + SG_CHECK_EQUAL(tr->responseReason(), string("not found")); + SG_CHECK_EQUAL(tr->responseLength(), 0); } cout << "done 404 test" << endl; @@ -496,7 +486,7 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseCode(), 200); } cout << "done1" << endl; @@ -506,9 +496,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } cout << "done2" << endl; @@ -518,9 +508,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } cout << "done3" << endl; // test connectToHost failure @@ -534,7 +524,7 @@ int main(int argc, char* argv[]) const int HOST_NOT_FOUND_CODE = CURLE_COULDNT_RESOLVE_HOST; - COMPARE(tr->responseCode(), HOST_NOT_FOUND_CODE); + SG_CHECK_EQUAL(tr->responseCode(), HOST_NOT_FOUND_CODE); } cout << "testing abrupt close" << endl; @@ -546,7 +536,7 @@ int main(int argc, char* argv[]) waitForFailed(&cl, tr); const int SERVER_NO_DATA_CODE = CURLE_GOT_NOTHING; - COMPARE(tr->responseCode(), SERVER_NO_DATA_CODE); + SG_CHECK_EQUAL(tr->responseCode(), SERVER_NO_DATA_CODE); } cout << "testing proxy close" << endl; @@ -557,9 +547,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } { @@ -568,9 +558,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseBytesReceived(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseBytesReceived(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } // pipelining @@ -595,17 +585,17 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr3); waitForComplete(&cl, tr3); - VERIFY(tr->complete); - VERIFY(tr2->complete); - COMPARE(tr->bodyData, string(BODY1)); + SG_VERIFY(tr->complete); + SG_VERIFY(tr2->complete); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseLength(), strlen(BODY3)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr2->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY3)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); - COMPARE(testServer.connectCount(), 1); + SG_CHECK_EQUAL(testServer.connectCount(), 1); } // multiple requests with an HTTP 1.0 server @@ -626,17 +616,17 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr3); waitForComplete(&cl, tr3); - VERIFY(tr->complete); - VERIFY(tr2->complete); + SG_VERIFY(tr->complete); + SG_VERIFY(tr2->complete); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseLength(), strlen(BODY3)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->bodyData, string(BODY3)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr2->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } // POST @@ -648,7 +638,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 204); + SG_CHECK_EQUAL(tr->responseCode(), 204); } // PUT @@ -660,7 +650,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 204); + SG_CHECK_EQUAL(tr->responseCode(), 204); } { @@ -671,7 +661,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 201); + SG_CHECK_EQUAL(tr->responseCode(), 201); } // test_zero_length_content @@ -681,9 +671,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->bodyData, string()); - COMPARE(tr->responseBytesReceived(), 0); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->bodyData, string()); + SG_CHECK_EQUAL(tr->responseBytesReceived(), 0); } // test cancel @@ -711,12 +701,12 @@ cout << "testing proxy close" << endl; waitForComplete(&cl, tr3); - COMPARE(tr->responseCode(), -1); - COMPARE(tr2->responseReason(), "my reason 2"); + SG_CHECK_EQUAL(tr->responseCode(), -1); + SG_CHECK_EQUAL(tr2->responseReason(), "my reason 2"); - COMPARE(tr3->responseLength(), strlen(BODY1)); - COMPARE(tr3->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } // test cancel @@ -742,16 +732,16 @@ cout << "testing proxy close" << endl; waitForComplete(&cl, tr3); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseCode(), -1); + SG_CHECK_EQUAL(tr2->responseCode(), -1); - COMPARE(tr3->responseLength(), strlen(BODY1)); - COMPARE(tr3->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } { @@ -776,12 +766,12 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr2); waitForComplete(&cl, tr2); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->bodyData, string(BODY3)); - COMPARE(tr->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->responseCode(), 200); - COMPARE(tr2->bodyData, string(BODY1)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseCode(), 200); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY1)); } cout << "all tests passed ok" << endl; diff --git a/simgear/io/test_binobj.cxx b/simgear/io/test_binobj.cxx index 9e02d127..4a5b8ce0 100644 --- a/simgear/io/test_binobj.cxx +++ b/simgear/io/test_binobj.cxx @@ -14,6 +14,7 @@ #endif #include +#include #include "sg_binobj.hxx" @@ -22,19 +23,7 @@ using std::cerr; using std::endl; using std::string; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:" << a << endl; \ - exit(1); \ - } -#define VERIFY(a) \ - if (!(a)) { \ - cerr << "failed:" << #a << endl; \ - exit(1); \ - } - void generate_points(int count, std::vector& vec) { for (int i=0; i& b) { for (unsigned int i=1; i& b) cout << pos << endl; } - VERIFY(equivalent(pos, b[i], 0.1)); + SG_VERIFY(equivalent(pos, b[i], 0.1)); } } @@ -90,7 +79,7 @@ void compareTexCoords(const SGBinObject& rd, const std::vector& b) { for (unsigned int i=1; i 2^16 - COMPARE(rd.get_wgs84_nodes().size(), points.size()); - COMPARE(rd.get_texcoords().size(), texCoords.size()); - + SG_VERIFY( ok); + // Should be version 10 since indices are > 2^16 + SG_CHECK_EQUAL(rd.get_version(), 10); + SG_CHECK_EQUAL(rd.get_wgs84_nodes().size(), points.size()); + SG_CHECK_EQUAL(rd.get_texcoords().size(), texCoords.size()); + comparePoints(rd, points); compareTexCoords(rd, texCoords); compareTris(basic, rd); @@ -263,15 +254,16 @@ void test_big() generate_tris(basic, 200000); bool ok = basic.write_bin_file(path); - VERIFY( ok ); + SG_VERIFY( ok ); SGBinObject rd; ok = rd.read_bin(path) ; - VERIFY( ok); - COMPARE(rd.get_version(), 10); // should be version 10 since indices are > 2^16 - COMPARE(rd.get_wgs84_nodes().size(), points.size()); - COMPARE(rd.get_texcoords().size(), texCoords.size()); - + SG_VERIFY( ok); + // Should be version 10 since indices are > 2^16 + SG_CHECK_EQUAL(rd.get_version(), 10); + SG_CHECK_EQUAL(rd.get_wgs84_nodes().size(), points.size()); + SG_CHECK_EQUAL(rd.get_texcoords().size(), texCoords.size()); + comparePoints(rd, points); compareTexCoords(rd, texCoords); compareTris(basic, rd); @@ -300,15 +292,15 @@ void test_some_objects() generate_tris(basic, 30000); // a number smaller than 2^15! bool ok = basic.write_bin_file(path); - VERIFY( ok ); + SG_VERIFY( ok ); SGBinObject rd; ok = rd.read_bin(path) ; - VERIFY( ok); - COMPARE(rd.get_version(), 7); // since we have less than 2^15 tris - COMPARE(rd.get_wgs84_nodes().size(), points.size()); - COMPARE(rd.get_texcoords().size(), texCoords.size()); - + SG_VERIFY( ok); + SG_CHECK_EQUAL(rd.get_version(), 7); // since we have less than 2^15 tris + SG_CHECK_EQUAL(rd.get_wgs84_nodes().size(), points.size()); + SG_CHECK_EQUAL(rd.get_texcoords().size(), texCoords.size()); + comparePoints(rd, points); compareTexCoords(rd, texCoords); compareTris(basic, rd); @@ -337,15 +329,16 @@ void test_many_objects() generate_tris(basic, 200000); bool ok = basic.write_bin_file(path); - VERIFY( ok ); + SG_VERIFY( ok ); SGBinObject rd; ok = rd.read_bin(path) ; - VERIFY( ok); - COMPARE(rd.get_version(), 10); // should be version 10 since indices are > 2^16 - COMPARE(rd.get_wgs84_nodes().size(), points.size()); - COMPARE(rd.get_texcoords().size(), texCoords.size()); - + SG_VERIFY( ok); + // Should be version 10 since indices are > 2^16 + SG_CHECK_EQUAL(rd.get_version(), 10); + SG_CHECK_EQUAL(rd.get_wgs84_nodes().size(), points.size()); + SG_CHECK_EQUAL(rd.get_texcoords().size(), texCoords.size()); + comparePoints(rd, points); compareTexCoords(rd, texCoords); compareTris(basic, rd); diff --git a/simgear/io/test_untar.cxx b/simgear/io/test_untar.cxx index c9d22440..5fb21511 100644 --- a/simgear/io/test_untar.cxx +++ b/simgear/io/test_untar.cxx @@ -30,7 +30,7 @@ void testTarGz() uint8_t* buf = (uint8_t*) alloca(8192); size_t bufSize = f.read((char*) buf, 8192); - VERIFY(TarExtractor::isTarData(buf, bufSize)); + SG_VERIFY(TarExtractor::isTarData(buf, bufSize)); } @@ -45,7 +45,7 @@ void testPlainTar() uint8_t* buf = (uint8_t*) alloca(8192); size_t bufSize = f.read((char*) buf, 8192); - VERIFY(TarExtractor::isTarData(buf, bufSize)); + SG_VERIFY(TarExtractor::isTarData(buf, bufSize)); } diff --git a/simgear/io/text_DNS.cxx b/simgear/io/text_DNS.cxx index 6a6dc31e..cabc4813 100644 --- a/simgear/io/text_DNS.cxx +++ b/simgear/io/text_DNS.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -41,18 +42,6 @@ const char* BODY3 = "Cras ut neque nulla. Duis ut velit neque, sit amet " const unsigned int body2Size = 8 * 1024; char body2[body2Size]; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - cerr << "\tgot:'" << a << "'" << endl; \ - exit(1); \ - } - -#define VERIFY(a) \ - if (!(a)) { \ - cerr << "failed:" << #a << endl; \ - exit(1); \ - } class TestRequest : public HTTP::Request { @@ -126,8 +115,9 @@ public: d << contentStr; push(d.str().c_str()); } else if (path == "/test_headers") { - COMPARE(requestHeaders["X-Foo"], string("Bar")); - COMPARE(requestHeaders["X-AnotherHeader"], string("A longer value")); + SG_CHECK_EQUAL(requestHeaders["X-Foo"], string("Bar")); + SG_CHECK_EQUAL(requestHeaders["X-AnotherHeader"], + string("A longer value")); string contentStr(BODY1); stringstream d; @@ -304,7 +294,7 @@ public: } else if (path == "/test_put") { std::cerr << "sending PUT response" << std::endl; - COMPARE(buffer, BODY3); + SG_CHECK_EQUAL(buffer, BODY3); stringstream d; d << "HTTP/1.1 " << 204 << " " << reasonForCode(204) << "\r\n"; d << "\r\n"; // final CRLF to terminate the headers @@ -314,7 +304,7 @@ public: std::string entityStr = "http://localhost:2000/something.txt"; - COMPARE(buffer, BODY3); + SG_CHECK_EQUAL(buffer, BODY3); stringstream d; d << "HTTP/1.1 " << 201 << " " << reasonForCode(201) << "\r\n"; d << "Location:" << entityStr << "\r\n"; @@ -385,18 +375,18 @@ int main(int argc, char* argv[]) // test URL parsing TestRequest* tr1 = new TestRequest("http://localhost.woo.zar:2000/test1?foo=bar"); - COMPARE(tr1->scheme(), "http"); - COMPARE(tr1->hostAndPort(), "localhost.woo.zar:2000"); - COMPARE(tr1->host(), "localhost.woo.zar"); - COMPARE(tr1->port(), 2000); - COMPARE(tr1->path(), "/test1"); + SG_CHECK_EQUAL(tr1->scheme(), "http"); + SG_CHECK_EQUAL(tr1->hostAndPort(), "localhost.woo.zar:2000"); + SG_CHECK_EQUAL(tr1->host(), "localhost.woo.zar"); + SG_CHECK_EQUAL(tr1->port(), 2000); + SG_CHECK_EQUAL(tr1->path(), "/test1"); TestRequest* tr2 = new TestRequest("http://192.168.1.1/test1/dir/thing/file.png"); - COMPARE(tr2->scheme(), "http"); - COMPARE(tr2->hostAndPort(), "192.168.1.1"); - COMPARE(tr2->host(), "192.168.1.1"); - COMPARE(tr2->port(), 80); - COMPARE(tr2->path(), "/test1/dir/thing/file.png"); + SG_CHECK_EQUAL(tr2->scheme(), "http"); + SG_CHECK_EQUAL(tr2->hostAndPort(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->host(), "192.168.1.1"); + SG_CHECK_EQUAL(tr2->port(), 80); + SG_CHECK_EQUAL(tr2->path(), "/test1/dir/thing/file.png"); // basic get request { @@ -405,11 +395,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } { @@ -418,11 +408,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY3)); - COMPARE(tr->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY3)); } { @@ -430,7 +420,7 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseCode(), 200); } { @@ -441,11 +431,11 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } // larger get request @@ -458,9 +448,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseBytesReceived(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseBytesReceived(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } cerr << "testing chunked transfer encoding" << endl; @@ -470,12 +460,12 @@ int main(int argc, char* argv[]) cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseReason(), string("OK")); - COMPARE(tr->responseBytesReceived(), 30); - COMPARE(tr->bodyData, "ABCDEFGHABCDEFABCDSTUVABCDSTUV"); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseReason(), string("OK")); + SG_CHECK_EQUAL(tr->responseBytesReceived(), 30); + SG_CHECK_EQUAL(tr->bodyData, "ABCDEFGHABCDEFABCDSTUVABCDSTUV"); // check trailers made it too - COMPARE(tr->headers["x-foobar"], string("wibble")); + SG_CHECK_EQUAL(tr->headers["x-foobar"], string("wibble")); } // test 404 @@ -484,9 +474,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 404); - COMPARE(tr->responseReason(), string("not found")); - COMPARE(tr->responseLength(), 0); + SG_CHECK_EQUAL(tr->responseCode(), 404); + SG_CHECK_EQUAL(tr->responseReason(), string("not found")); + SG_CHECK_EQUAL(tr->responseLength(), 0); } cout << "done 404 test" << endl; @@ -496,7 +486,7 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseCode(), 200); } cout << "done1" << endl; @@ -506,9 +496,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } cout << "done2" << endl; @@ -518,9 +508,9 @@ int main(int argc, char* argv[]) HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); } cout << "done3" << endl; // test connectToHost failure @@ -532,7 +522,7 @@ int main(int argc, char* argv[]) waitForFailed(&cl, tr); const int HOST_NOT_FOUND_CODE = CURLE_COULDNT_RESOLVE_HOST; - COMPARE(tr->responseCode(), HOST_NOT_FOUND_CODE); + SG_CHECK_EQUAL(tr->responseCode(), HOST_NOT_FOUND_CODE); } cout << "testing abrupt close" << endl; @@ -544,7 +534,7 @@ int main(int argc, char* argv[]) waitForFailed(&cl, tr); const int SERVER_NO_DATA_CODE = CURLE_GOT_NOTHING; - COMPARE(tr->responseCode(), SERVER_NO_DATA_CODE); + SG_CHECK_EQUAL(tr->responseCode(), SERVER_NO_DATA_CODE); } cout << "testing proxy close" << endl; @@ -555,9 +545,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } { @@ -566,9 +556,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseBytesReceived(), body2Size); - COMPARE(tr->bodyData, string(body2, body2Size)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseBytesReceived(), body2Size); + SG_CHECK_EQUAL(tr->bodyData, string(body2, body2Size)); } // pipelining @@ -593,17 +583,17 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr3); waitForComplete(&cl, tr3); - VERIFY(tr->complete); - VERIFY(tr2->complete); - COMPARE(tr->bodyData, string(BODY1)); + SG_VERIFY(tr->complete); + SG_VERIFY(tr2->complete); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseLength(), strlen(BODY3)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr2->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY3)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); - COMPARE(testServer.connectCount(), 1); + SG_CHECK_EQUAL(testServer.connectCount(), 1); } // multiple requests with an HTTP 1.0 server @@ -624,17 +614,17 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr3); waitForComplete(&cl, tr3); - VERIFY(tr->complete); - VERIFY(tr2->complete); + SG_VERIFY(tr->complete); + SG_VERIFY(tr2->complete); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseLength(), strlen(BODY3)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->bodyData, string(BODY3)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr2->responseLength(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } // POST @@ -646,7 +636,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 204); + SG_CHECK_EQUAL(tr->responseCode(), 204); } // PUT @@ -658,7 +648,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 204); + SG_CHECK_EQUAL(tr->responseCode(), 204); } { @@ -669,7 +659,7 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 201); + SG_CHECK_EQUAL(tr->responseCode(), 201); } // test_zero_length_content @@ -679,9 +669,9 @@ cout << "testing proxy close" << endl; HTTP::Request_ptr own(tr); cl.makeRequest(tr); waitForComplete(&cl, tr); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->bodyData, string()); - COMPARE(tr->responseBytesReceived(), 0); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->bodyData, string()); + SG_CHECK_EQUAL(tr->responseBytesReceived(), 0); } // test cancel @@ -709,12 +699,12 @@ cout << "testing proxy close" << endl; waitForComplete(&cl, tr3); - COMPARE(tr->responseCode(), -1); - COMPARE(tr2->responseReason(), "my reason 2"); + SG_CHECK_EQUAL(tr->responseCode(), -1); + SG_CHECK_EQUAL(tr2->responseReason(), "my reason 2"); - COMPARE(tr3->responseLength(), strlen(BODY1)); - COMPARE(tr3->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } // test cancel @@ -740,16 +730,16 @@ cout << "testing proxy close" << endl; waitForComplete(&cl, tr3); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->responseLength(), strlen(BODY1)); - COMPARE(tr->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->bodyData, string(BODY1)); - COMPARE(tr2->responseCode(), -1); + SG_CHECK_EQUAL(tr2->responseCode(), -1); - COMPARE(tr3->responseLength(), strlen(BODY1)); - COMPARE(tr3->responseBytesReceived(), strlen(BODY1)); - COMPARE(tr3->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr3->responseLength(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr3->bodyData, string(BODY1)); } { @@ -774,12 +764,12 @@ cout << "testing proxy close" << endl; cl.makeRequest(tr2); waitForComplete(&cl, tr2); - COMPARE(tr->responseCode(), 200); - COMPARE(tr->bodyData, string(BODY3)); - COMPARE(tr->responseBytesReceived(), strlen(BODY3)); - COMPARE(tr2->responseCode(), 200); - COMPARE(tr2->bodyData, string(BODY1)); - COMPARE(tr2->responseBytesReceived(), strlen(BODY1)); + SG_CHECK_EQUAL(tr->responseCode(), 200); + SG_CHECK_EQUAL(tr->bodyData, string(BODY3)); + SG_CHECK_EQUAL(tr->responseBytesReceived(), strlen(BODY3)); + SG_CHECK_EQUAL(tr2->responseCode(), 200); + SG_CHECK_EQUAL(tr2->bodyData, string(BODY1)); + SG_CHECK_EQUAL(tr2->responseBytesReceived(), strlen(BODY1)); } cout << "all tests passed ok" << endl; diff --git a/simgear/math/SGMathTest.cxx b/simgear/math/SGMathTest.cxx index 3308a009..247d9e72 100644 --- a/simgear/math/SGMathTest.cxx +++ b/simgear/math/SGMathTest.cxx @@ -276,26 +276,26 @@ void doRectTest() { SGRect rect(10, 15, 20, 25); - COMPARE(rect.x(), 10) - COMPARE(rect.y(), 15) - COMPARE(rect.width(), 20) - COMPARE(rect.height(), 25) + SG_CHECK_EQUAL(rect.x(), 10) + SG_CHECK_EQUAL(rect.y(), 15) + SG_CHECK_EQUAL(rect.width(), 20) + SG_CHECK_EQUAL(rect.height(), 25) - COMPARE(rect.pos(), SGVec2(10, 15)) - COMPARE(rect.size(), SGVec2(20, 25)) + SG_CHECK_EQUAL(rect.pos(), SGVec2(10, 15)) + SG_CHECK_EQUAL(rect.size(), SGVec2(20, 25)) - COMPARE(rect.l(), 10) - COMPARE(rect.t(), 15) - COMPARE(rect.r(), 30) - COMPARE(rect.b(), 40) + SG_CHECK_EQUAL(rect.l(), 10) + SG_CHECK_EQUAL(rect.t(), 15) + SG_CHECK_EQUAL(rect.r(), 30) + SG_CHECK_EQUAL(rect.b(), 40) - VERIFY(rect == rect) - VERIFY(rect == SGRect(10, 15, 20, 25)) - VERIFY(rect != SGRect(11, 15, 20, 25)) + SG_VERIFY(rect == rect) + SG_VERIFY(rect == SGRect(10, 15, 20, 25)) + SG_VERIFY(rect != SGRect(11, 15, 20, 25)) - VERIFY(rect.contains(10, 15)) - VERIFY(!rect.contains(9, 15)) - VERIFY(rect.contains(9, 15, 1)) + SG_VERIFY(rect.contains(10, 15)) + SG_VERIFY(!rect.contains(9, 15)) + SG_VERIFY(rect.contains(9, 15, 1)) } bool diff --git a/simgear/misc/CSSBorder_test.cxx b/simgear/misc/CSSBorder_test.cxx index bfb0cb79..9d0d85b6 100644 --- a/simgear/misc/CSSBorder_test.cxx +++ b/simgear/misc/CSSBorder_test.cxx @@ -4,30 +4,18 @@ #include #include +#include -#define COMPARE(a, b) \ - if( std::fabs((a) - (b)) > 1e-4 ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << " != " << #b << " d = " << ((a) - (b)) << std::endl; \ - return 1; \ - } +#define COMPARE(a, b) SG_CHECK_EQUAL_EP2((a), (b), 1e-4) -#define VERIFY(a) \ - if( !(a) ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << std::endl; \ - return 1; \ - } using namespace simgear; int main (int ac, char ** av) { CSSBorder b = CSSBorder::parse("5"); - VERIFY(b.isValid()); - VERIFY(!b.isNone()); + SG_VERIFY(b.isValid()); + SG_VERIFY(!b.isNone()); CSSBorder::Offsets o = b.getAbsOffsets(SGRect()); COMPARE(o.t, 5); COMPARE(o.r, 5); @@ -81,8 +69,8 @@ int main (int ac, char ** av) COMPARE(o.r, 0); COMPARE(o.b, 0); COMPARE(o.l, 0); - VERIFY(b.getKeyword().empty()); - VERIFY(b.isNone()); + SG_VERIFY(b.getKeyword().empty()); + SG_VERIFY(b.isNone()); b = CSSBorder::parse("none"); o = b.getRelOffsets(SGRect(0,0,200,200)); @@ -90,11 +78,11 @@ int main (int ac, char ** av) COMPARE(o.r, 0); COMPARE(o.b, 0); COMPARE(o.l, 0); - VERIFY(b.getKeyword().empty()); - VERIFY(b.isNone()); + SG_VERIFY(b.getKeyword().empty()); + SG_VERIFY(b.isNone()); CSSBorder b2; - VERIFY(!b2.isValid()); + SG_VERIFY(!b2.isValid()); o = b.getAbsOffsets(SGRect(0,0,200,200)); COMPARE(o.t, 0); COMPARE(o.r, 0); diff --git a/simgear/misc/path_test.cxx b/simgear/misc/path_test.cxx index fb9c4dae..a544fa9f 100644 --- a/simgear/misc/path_test.cxx +++ b/simgear/misc/path_test.cxx @@ -19,12 +19,12 @@ void test_dir() simgear::Dir temp = simgear::Dir::tempDir("foo"); cout << "created:" << temp.path() << endl; - VERIFY(temp.exists()); - VERIFY(temp.path().isDir()); - VERIFY(!temp.path().isFile()); + SG_VERIFY(temp.exists()); + SG_VERIFY(temp.path().isDir()); + SG_VERIFY(!temp.path().isFile()); SGPath fileInDir = temp.file("foobaz"); - VERIFY(!fileInDir.exists()); + SG_VERIFY(!fileInDir.exists()); if (!temp.remove(true)) { cout << "remove failed!" << endl; @@ -40,11 +40,11 @@ void test_dir() << "\n - Pictures: " << SGPath::standardLocation(SGPath::PICTURES) << std::endl; - VERIFY( !SGPath::standardLocation(SGPath::HOME ).isNull() ); - VERIFY( !SGPath::standardLocation(SGPath::DESKTOP ).isNull() ); - VERIFY( !SGPath::standardLocation(SGPath::DOWNLOADS).isNull() ); - VERIFY( !SGPath::standardLocation(SGPath::DOCUMENTS).isNull() ); - VERIFY( !SGPath::standardLocation(SGPath::PICTURES ).isNull() ); + SG_VERIFY( !SGPath::standardLocation(SGPath::HOME ).isNull() ); + SG_VERIFY( !SGPath::standardLocation(SGPath::DESKTOP ).isNull() ); + SG_VERIFY( !SGPath::standardLocation(SGPath::DOWNLOADS).isNull() ); + SG_VERIFY( !SGPath::standardLocation(SGPath::DOCUMENTS).isNull() ); + SG_VERIFY( !SGPath::standardLocation(SGPath::PICTURES ).isNull() ); } SGPath::Permissions validateNone(const SGPath&) @@ -77,176 +77,176 @@ void test_path_dir() temp.remove(true); SGPath p = temp.path(); - VERIFY(p.isAbsolute()); - COMPARE(p.create_dir(0755), 0); + SG_VERIFY(p.isAbsolute()); + SG_CHECK_EQUAL(p.create_dir(0755), 0); SGPath sub = p / "subA" / "subB"; - VERIFY(!sub.exists()); + SG_VERIFY(!sub.exists()); SGPath subFile = sub / "fileABC.txt"; - COMPARE(subFile.create_dir(0755), 0); - VERIFY(!subFile.exists()); + SG_CHECK_EQUAL(subFile.create_dir(0755), 0); + SG_VERIFY(!subFile.exists()); sub.set_cached(false); - VERIFY(sub.exists()); - VERIFY(sub.isDir()); + SG_VERIFY(sub.exists()); + SG_VERIFY(sub.isDir()); SGPath sub2 = p / "subA" / "fileA"; { sg_ofstream os(sub2); - VERIFY(os.is_open()); + SG_VERIFY(os.is_open()); for (int i = 0; i < 50; ++i) { os << "ABCD" << endl; } } - VERIFY(sub2.isFile()); - COMPARE(sub2.sizeInBytes(), 250); + SG_VERIFY(sub2.isFile()); + SG_CHECK_EQUAL(sub2.sizeInBytes(), 250); SGPath sub3 = p / "subß" / "file𝕽"; sub3.create_dir(0755); { sg_ofstream os(sub3); - VERIFY(os.is_open()); + SG_VERIFY(os.is_open()); for (int i = 0; i < 20; ++i) { os << "EFGH" << endl; } } sub3.set_cached(false); - VERIFY(sub3.exists()); - COMPARE(sub3.sizeInBytes(), 100); - COMPARE(sub3.file(), "file𝕽"); + SG_VERIFY(sub3.exists()); + SG_CHECK_EQUAL(sub3.sizeInBytes(), 100); + SG_CHECK_EQUAL(sub3.file(), "file𝕽"); simgear::Dir subD(p / "subA"); simgear::PathList dirChildren = subD.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); - COMPARE(dirChildren.size(), 1); - COMPARE(dirChildren[0], subD.path() / "subB"); + SG_CHECK_EQUAL(dirChildren.size(), 1); + SG_CHECK_EQUAL(dirChildren[0], subD.path() / "subB"); simgear::PathList fileChildren = subD.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); - COMPARE(fileChildren.size(), 1); - COMPARE(fileChildren[0], subD.path() / "fileA"); + SG_CHECK_EQUAL(fileChildren.size(), 1); + SG_CHECK_EQUAL(fileChildren[0], subD.path() / "fileA"); simgear::Dir subS(sub3.dirPath()); fileChildren = subS.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); - COMPARE(fileChildren.size(), 1); - COMPARE(fileChildren[0], subS.path() / "file𝕽"); + SG_CHECK_EQUAL(fileChildren.size(), 1); + SG_CHECK_EQUAL(fileChildren[0], subS.path() / "file𝕽"); } int main(int argc, char* argv[]) { SGPath pa; - VERIFY(pa.isNull()); - COMPARE(pa.exists(), false); + SG_VERIFY(pa.isNull()); + SG_CHECK_EQUAL(pa.exists(), false); // test basic parsing SGPath pb("/Foo/bar/something.png"); - COMPARE(pb.utf8Str(), std::string("/Foo/bar/something.png")); - COMPARE(pb.local8BitStr(), std::string("/Foo/bar/something.png")); - COMPARE(pb.dir(), std::string("/Foo/bar")); - COMPARE(pb.file(), std::string("something.png")); - COMPARE(pb.base(), std::string("/Foo/bar/something")); - COMPARE(pb.file_base(), std::string("something")); - COMPARE(pb.extension(), std::string("png")); - VERIFY(pb.isAbsolute()); - VERIFY(!pb.isRelative()); + SG_CHECK_EQUAL(pb.utf8Str(), std::string("/Foo/bar/something.png")); + SG_CHECK_EQUAL(pb.local8BitStr(), std::string("/Foo/bar/something.png")); + SG_CHECK_EQUAL(pb.dir(), std::string("/Foo/bar")); + SG_CHECK_EQUAL(pb.file(), std::string("something.png")); + SG_CHECK_EQUAL(pb.base(), std::string("/Foo/bar/something")); + SG_CHECK_EQUAL(pb.file_base(), std::string("something")); + SG_CHECK_EQUAL(pb.extension(), std::string("png")); + SG_VERIFY(pb.isAbsolute()); + SG_VERIFY(!pb.isRelative()); // relative paths SGPath ra("where/to/begin.txt"); - COMPARE(ra.utf8Str(), std::string("where/to/begin.txt")); - COMPARE(ra.local8BitStr(), std::string("where/to/begin.txt")); - COMPARE(ra.dir(), std::string("where/to")); - COMPARE(ra.file(), std::string("begin.txt")); - COMPARE(ra.file_base(), std::string("begin")); - VERIFY(!ra.isAbsolute()); - VERIFY(ra.isRelative()); + SG_CHECK_EQUAL(ra.utf8Str(), std::string("where/to/begin.txt")); + SG_CHECK_EQUAL(ra.local8BitStr(), std::string("where/to/begin.txt")); + SG_CHECK_EQUAL(ra.dir(), std::string("where/to")); + SG_CHECK_EQUAL(ra.file(), std::string("begin.txt")); + SG_CHECK_EQUAL(ra.file_base(), std::string("begin")); + SG_VERIFY(!ra.isAbsolute()); + SG_VERIFY(ra.isRelative()); // dots in paths / missing extensions SGPath pk("/Foo/bar.dot/thing"); - COMPARE(pk.dir(), std::string("/Foo/bar.dot")); - COMPARE(pk.file(), std::string("thing")); - COMPARE(pk.base(), std::string("/Foo/bar.dot/thing")); - COMPARE(pk.file_base(), std::string("thing")); - COMPARE(pk.extension(), std::string()); + SG_CHECK_EQUAL(pk.dir(), std::string("/Foo/bar.dot")); + SG_CHECK_EQUAL(pk.file(), std::string("thing")); + SG_CHECK_EQUAL(pk.base(), std::string("/Foo/bar.dot/thing")); + SG_CHECK_EQUAL(pk.file_base(), std::string("thing")); + SG_CHECK_EQUAL(pk.extension(), std::string()); // multiple file extensions SGPath pj("/Foo/zot.dot/thing.tar.gz"); - COMPARE(pj.dir(), std::string("/Foo/zot.dot")); - COMPARE(pj.file(), std::string("thing.tar.gz")); - COMPARE(pj.base(), std::string("/Foo/zot.dot/thing.tar")); - COMPARE(pj.file_base(), std::string("thing")); - COMPARE(pj.extension(), std::string("gz")); - COMPARE(pj.complete_lower_extension(), std::string("tar.gz")); + SG_CHECK_EQUAL(pj.dir(), std::string("/Foo/zot.dot")); + SG_CHECK_EQUAL(pj.file(), std::string("thing.tar.gz")); + SG_CHECK_EQUAL(pj.base(), std::string("/Foo/zot.dot/thing.tar")); + SG_CHECK_EQUAL(pj.file_base(), std::string("thing")); + SG_CHECK_EQUAL(pj.extension(), std::string("gz")); + SG_CHECK_EQUAL(pj.complete_lower_extension(), std::string("tar.gz")); // path fixing SGPath rd("where\\to\\begin.txt"); - COMPARE(rd.utf8Str(), std::string("where/to/begin.txt")); + SG_CHECK_EQUAL(rd.utf8Str(), std::string("where/to/begin.txt")); // test modification // append SGPath d1("/usr/local"); SGPath pc = d1; - COMPARE(pc.utf8Str(), std::string("/usr/local")); + SG_CHECK_EQUAL(pc.utf8Str(), std::string("/usr/local")); pc.append("include"); - COMPARE(pc.utf8Str(), std::string("/usr/local/include")); - COMPARE(pc.file(), std::string("include")); + SG_CHECK_EQUAL(pc.utf8Str(), std::string("/usr/local/include")); + SG_CHECK_EQUAL(pc.file(), std::string("include")); // concat SGPath pd = pb; pd.concat("-1"); - COMPARE(pd.utf8Str(), std::string("/Foo/bar/something.png-1")); + SG_CHECK_EQUAL(pd.utf8Str(), std::string("/Foo/bar/something.png-1")); // create with relative path SGPath rb(d1, "include/foo"); - COMPARE(rb.utf8Str(), std::string("/usr/local/include/foo")); - VERIFY(rb.isAbsolute()); + SG_CHECK_EQUAL(rb.utf8Str(), std::string("/usr/local/include/foo")); + SG_VERIFY(rb.isAbsolute()); // lower-casing of file extensions SGPath extA("FOO.ZIP"); - COMPARE(extA.base(), "FOO"); - COMPARE(extA.extension(), "ZIP"); - COMPARE(extA.lower_extension(), "zip"); - COMPARE(extA.complete_lower_extension(), "zip"); + SG_CHECK_EQUAL(extA.base(), "FOO"); + SG_CHECK_EQUAL(extA.extension(), "ZIP"); + SG_CHECK_EQUAL(extA.lower_extension(), "zip"); + SG_CHECK_EQUAL(extA.complete_lower_extension(), "zip"); SGPath extB("BAH/FOO.HTML.GZ"); - COMPARE(extB.extension(), "GZ"); - COMPARE(extB.base(), "BAH/FOO.HTML"); - COMPARE(extB.lower_extension(), "gz"); - COMPARE(extB.complete_lower_extension(), "html.gz"); + SG_CHECK_EQUAL(extB.extension(), "GZ"); + SG_CHECK_EQUAL(extB.base(), "BAH/FOO.HTML"); + SG_CHECK_EQUAL(extB.lower_extension(), "gz"); + SG_CHECK_EQUAL(extB.complete_lower_extension(), "html.gz"); #ifdef _WIN32 SGPath winAbs("C:\\Windows\\System32"); - COMPARE(winAbs.local8BitStr(), std::string("C:/Windows/System32")); + SG_CHECK_EQUAL(winAbs.local8BitStr(), std::string("C:/Windows/System32")); #endif // paths with only the file components SGPath pf("something.txt.gz"); - COMPARE(pf.base(), "something.txt"); - COMPARE(pf.file(), "something.txt.gz"); - COMPARE(pf.dir(), ""); - COMPARE(pf.lower_extension(), "gz"); - COMPARE(pf.complete_lower_extension(), "txt.gz"); + SG_CHECK_EQUAL(pf.base(), "something.txt"); + SG_CHECK_EQUAL(pf.file(), "something.txt.gz"); + SG_CHECK_EQUAL(pf.dir(), ""); + SG_CHECK_EQUAL(pf.lower_extension(), "gz"); + SG_CHECK_EQUAL(pf.complete_lower_extension(), "txt.gz"); - COMPARE(pf.canRead(), true); - COMPARE(pf.canWrite(), true); + SG_CHECK_EQUAL(pf.canRead(), true); + SG_CHECK_EQUAL(pf.canWrite(), true); SGPath pp(&validateNone); - COMPARE(pp.canRead(), false); - COMPARE(pp.canWrite(), false); + SG_CHECK_EQUAL(pp.canRead(), false); + SG_CHECK_EQUAL(pp.canWrite(), false); pp.append("./test-dir/file.txt"); - COMPARE(pp.create_dir(0700), -3); + SG_CHECK_EQUAL(pp.create_dir(0700), -3); pp.setPermissionChecker(&validateRead); - COMPARE(pp.canRead(), true); - COMPARE(pp.canWrite(), false); - COMPARE(pp.create_dir(0700), -3); + SG_CHECK_EQUAL(pp.canRead(), true); + SG_CHECK_EQUAL(pp.canWrite(), false); + SG_CHECK_EQUAL(pp.create_dir(0700), -3); pp.setPermissionChecker(&validateWrite); - COMPARE(pp.canRead(), false); - COMPARE(pp.canWrite(), true); + SG_CHECK_EQUAL(pp.canRead(), false); + SG_CHECK_EQUAL(pp.canWrite(), true); test_dir(); diff --git a/simgear/misc/test_macros.hxx b/simgear/misc/test_macros.hxx index 1fe545a2..12ac8f43 100644 --- a/simgear/misc/test_macros.hxx +++ b/simgear/misc/test_macros.hxx @@ -4,7 +4,7 @@ #include // for fabs() -#define COMPARE(a, b) \ +#define SG_CHECK_EQUAL(a, b) \ if ((a) != (b)) { \ std::cerr << "failed:" << #a << " != " << #b << std::endl; \ std::cerr << "\tgot:'" << a << "'" << std::endl; \ @@ -12,14 +12,14 @@ exit(1); \ } -#define VERIFY(a) \ +#define SG_VERIFY(a) \ if (!(a)) { \ std::cerr << "failed:" << #a << std::endl; \ std::cerr << "\tat:" << __FILE__ << ":" << __LINE__ << std::endl; \ exit(1); \ } -#define COMPARE_EP(a, b) \ +#define SG_CHECK_EQUAL_EP(a, b) \ if (fabs(a - b) > SG_EPSILON) { \ std::cerr << "failed with epsilon:" << #a << " != " << #b << std::endl; \ std::cerr << "\tgot:'" << a << "'" << std::endl; \ @@ -27,7 +27,7 @@ exit(1); \ } -#define COMPARE_EP2(a, b, ep) \ +#define SG_CHECK_EQUAL_EP2(a, b, ep) \ if (fabs(a - b) > ep) { \ std::cerr << "failed with epsilon:" << #a << " != " << #b << std::endl; \ std::cerr << "\tgot:'" << a << "'" << std::endl; \ diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 85c10f1f..619561ca 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -126,46 +126,46 @@ int parseTest() pkg::Root* root = new pkg::Root(rootPath, "8.1.12"); pkg::CatalogRef cat = pkg::Catalog::createFromPath(root, SGPath(SRC_DIR "/catalogTest1")); - VERIFY(cat.valid()); + SG_VERIFY(cat.valid()); - COMPARE(cat->id(), "org.flightgear.test.catalog1"); - COMPARE(cat->url(), "http://localhost:2000/catalogTest1/catalog.xml"); - COMPARE(cat->description(), "First test catalog"); + SG_CHECK_EQUAL(cat->id(), "org.flightgear.test.catalog1"); + SG_CHECK_EQUAL(cat->url(), "http://localhost:2000/catalogTest1/catalog.xml"); + SG_CHECK_EQUAL(cat->description(), "First test catalog"); // check the packages too - COMPARE(cat->packages().size(), 4); + SG_CHECK_EQUAL(cat->packages().size(), 4); pkg::PackageRef p1 = cat->packages().front(); - COMPARE(p1->catalog(), cat.ptr()); + SG_CHECK_EQUAL(p1->catalog(), cat.ptr()); - COMPARE(p1->id(), "alpha"); - COMPARE(p1->qualifiedId(), "org.flightgear.test.catalog1.alpha"); - COMPARE(p1->name(), "Alpha package"); - COMPARE(p1->revision(), 8); - COMPARE(p1->fileSizeBytes(), 593); + SG_CHECK_EQUAL(p1->id(), "alpha"); + SG_CHECK_EQUAL(p1->qualifiedId(), "org.flightgear.test.catalog1.alpha"); + SG_CHECK_EQUAL(p1->name(), "Alpha package"); + SG_CHECK_EQUAL(p1->revision(), 8); + SG_CHECK_EQUAL(p1->fileSizeBytes(), 593); pkg::PackageRef p2 = cat->getPackageById("c172p"); - VERIFY(p2.valid()); - COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p"); - COMPARE(p2->description(), "A plane made by Cessna on Jupiter"); + SG_VERIFY(p2.valid()); + SG_CHECK_EQUAL(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p"); + SG_CHECK_EQUAL(p2->description(), "A plane made by Cessna on Jupiter"); pkg::Package::ThumbnailVec thumbs = p2->thumbnailsForVariant(0); - COMPARE(thumbs.size(), 3); + SG_CHECK_EQUAL(thumbs.size(), 3); auto index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t) { return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); }); - VERIFY(index != thumbs.end()); - COMPARE(index->path, "thumb-exterior.png"); - COMPARE(index->url, "http://foo.bar.com/thumb-exterior.png"); - VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); + SG_VERIFY(index != thumbs.end()); + SG_CHECK_EQUAL(index->path, "thumb-exterior.png"); + SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-exterior.png"); + SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); index = std::find_if(thumbs.begin(), thumbs.end(), [](const pkg::Package::Thumbnail& t) { return (t.type == pkg::Package::Thumbnail::Type::PANEL); }); - VERIFY(index != thumbs.end()); - COMPARE(index->path, "thumb-panel.png"); - COMPARE(index->url, "http://foo.bar.com/thumb-panel.png"); - VERIFY(index->type == pkg::Package::Thumbnail::Type::PANEL); + SG_VERIFY(index != thumbs.end()); + SG_CHECK_EQUAL(index->path, "thumb-panel.png"); + SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-panel.png"); + SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::PANEL); // test variants try { @@ -176,80 +176,84 @@ int parseTest() } unsigned int skisVariantFull = p2->indexOfVariant("org.flightgear.test.catalog1.c172p-skis"); - VERIFY(skisVariantFull > 0); + SG_VERIFY(skisVariantFull > 0); unsigned int skisVariant = p2->indexOfVariant("c172p-skis"); - VERIFY(skisVariant > 0); + SG_VERIFY(skisVariant > 0); - COMPARE(skisVariant, skisVariantFull); - - COMPARE(p2->getLocalisedProp("description", skisVariant), "A plane with skis"); - COMPARE(p2->getLocalisedProp("author", skisVariant), "Standard author"); + SG_CHECK_EQUAL(skisVariant, skisVariantFull); + + SG_CHECK_EQUAL(p2->getLocalisedProp("description", skisVariant), + "A plane with skis"); + SG_CHECK_EQUAL(p2->getLocalisedProp("author", skisVariant), + "Standard author"); unsigned int floatsVariant = p2->indexOfVariant("c172p-floats"); - VERIFY(floatsVariant > 0); + SG_VERIFY(floatsVariant > 0); - COMPARE(p2->getLocalisedProp("description", floatsVariant), "A plane with floats"); - COMPARE(p2->getLocalisedProp("author", floatsVariant), "Floats variant author"); + SG_CHECK_EQUAL(p2->getLocalisedProp("description", floatsVariant), + "A plane with floats"); + SG_CHECK_EQUAL(p2->getLocalisedProp("author", floatsVariant), + "Floats variant author"); pkg::Package::ThumbnailVec thumbs2 = p2->thumbnailsForVariant(skisVariant); - COMPARE(thumbs2.size(), 2); + SG_CHECK_EQUAL(thumbs2.size(), 2); index = std::find_if(thumbs2.begin(), thumbs2.end(), [](const pkg::Package::Thumbnail& t) { return (t.type == pkg::Package::Thumbnail::Type::EXTERIOR); }); - VERIFY(index != thumbs2.end()); - COMPARE(index->path, "thumb-exterior-skis.png"); - COMPARE(index->url, "http://foo.bar.com/thumb-exterior-skis.png"); - VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); + SG_VERIFY(index != thumbs2.end()); + SG_CHECK_EQUAL(index->path, "thumb-exterior-skis.png"); + SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-exterior-skis.png"); + SG_VERIFY(index->type == pkg::Package::Thumbnail::Type::EXTERIOR); // test filtering / searching too string_set tags(p2->tags()); - COMPARE(tags.size(), 4); - VERIFY(tags.find("ifr") != tags.end()); - VERIFY(tags.find("cessna") != tags.end()); - VERIFY(tags.find("jet") == tags.end()); + SG_CHECK_EQUAL(tags.size(), 4); + SG_VERIFY(tags.find("ifr") != tags.end()); + SG_VERIFY(tags.find("cessna") != tags.end()); + SG_VERIFY(tags.find("jet") == tags.end()); SGPropertyNode_ptr queryA(new SGPropertyNode); queryA->setStringValue("tag", "ifr"); - VERIFY(p2->matches(queryA.ptr())); + SG_VERIFY(p2->matches(queryA.ptr())); SGPropertyNode_ptr queryB(new SGPropertyNode); queryB->setStringValue("name", "ces"); - VERIFY(p2->matches(queryB.ptr())); + SG_VERIFY(p2->matches(queryB.ptr())); SGPropertyNode_ptr queryC(new SGPropertyNode); queryC->setStringValue("name", "foo"); - VERIFY(!p2->matches(queryC.ptr())); + SG_VERIFY(!p2->matches(queryC.ptr())); SGPropertyNode_ptr queryD(new SGPropertyNode); queryD->setIntValue("rating-FDM", 3); - VERIFY(p2->matches(queryD.ptr())); + SG_VERIFY(p2->matches(queryD.ptr())); SGPropertyNode_ptr queryE(new SGPropertyNode); queryE->setIntValue("rating-model", 5); queryE->setStringValue("description", "cessna"); - VERIFY(p2->matches(queryE.ptr())); + SG_VERIFY(p2->matches(queryE.ptr())); { SGPropertyNode_ptr queryText(new SGPropertyNode); queryText->setStringValue("any-of/text", "jupiter"); - VERIFY(p2->matches(queryText.ptr())); + SG_VERIFY(p2->matches(queryText.ptr())); } { SGPropertyNode_ptr queryText(new SGPropertyNode); queryText->setStringValue("any-of/tag", "twin-engine"); queryText->setStringValue("any-of/tag", "ga"); - VERIFY(p2->matches(queryText.ptr())); + SG_VERIFY(p2->matches(queryText.ptr())); } // match variant descriptions { SGPropertyNode_ptr queryText(new SGPropertyNode); queryText->setStringValue("any-of/description", "float"); - VERIFY(p2->matches(queryText.ptr())); + SG_VERIFY(p2->matches(queryText.ptr())); } delete root; return EXIT_SUCCESS; @@ -276,16 +280,16 @@ void testAddCatalog(HTTP::Client* cl) SGPath p(rootPath); p.append("org.flightgear.test.catalog1"); p.append("catalog.xml"); - VERIFY(p.exists()); - COMPARE(root->allPackages().size(), 4); - COMPARE(root->catalogs().size(), 1); + SG_VERIFY(p.exists()); + SG_CHECK_EQUAL(root->allPackages().size(), 4); + SG_CHECK_EQUAL(root->catalogs().size(), 1); pkg::PackageRef p1 = root->getPackageById("alpha"); - COMPARE(p1->id(), "alpha"); + SG_CHECK_EQUAL(p1->id(), "alpha"); pkg::PackageRef p2 = root->getPackageById("org.flightgear.test.catalog1.c172p"); - COMPARE(p2->id(), "c172p"); - COMPARE(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p"); + SG_CHECK_EQUAL(p2->id(), "c172p"); + SG_CHECK_EQUAL(p2->qualifiedId(), "org.flightgear.test.catalog1.c172p"); } @@ -306,14 +310,14 @@ void testInstallPackage(HTTP::Client* cl) pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.c172p"); pkg::InstallRef ins = p1->install(); - VERIFY(ins->isQueued()); + SG_VERIFY(ins->isQueued()); waitForUpdateComplete(cl, root); - VERIFY(p1->isInstalled()); - VERIFY(p1->existingInstall() == ins); + SG_VERIFY(p1->isInstalled()); + SG_VERIFY(p1->existingInstall() == ins); pkg::PackageRef commonDeps = root->getPackageById("common-sounds"); - VERIFY(commonDeps->existingInstall()); + SG_VERIFY(commonDeps->existingInstall()); // verify on disk state SGPath p(rootPath); @@ -321,17 +325,17 @@ void testInstallPackage(HTTP::Client* cl) p.append("Aircraft"); p.append("c172p"); - COMPARE(p, ins->path()); + SG_CHECK_EQUAL(p, ins->path()); p.append("c172p-floats-set.xml"); - VERIFY(p.exists()); + SG_VERIFY(p.exists()); SGPath p2(rootPath); p2.append("org.flightgear.test.catalog1"); p2.append("Aircraft"); p2.append("sounds"); p2.append("sharedfile.txt"); - VERIFY(p2.exists()); + SG_VERIFY(p2.exists()); } void testUninstall(HTTP::Client* cl) @@ -352,11 +356,11 @@ void testUninstall(HTTP::Client* cl) waitForUpdateComplete(cl, root); - VERIFY(p1->isInstalled()); + SG_VERIFY(p1->isInstalled()); ins->uninstall(); - VERIFY(!ins->path().exists()); + SG_VERIFY(!ins->path().exists()); } void testRemoveCatalog(HTTP::Client* cl) @@ -380,7 +384,7 @@ void testRemoveCatalog(HTTP::Client* cl) waitForUpdateComplete(cl, root); - VERIFY(p1->isInstalled()); + SG_VERIFY(p1->isInstalled()); } root->removeCatalogById("org.flightgear.test.catalog1"); @@ -388,13 +392,13 @@ void testRemoveCatalog(HTTP::Client* cl) SGPath p2(rootPath); p2.append("org.flightgear.test.catalog1"); - VERIFY(!p2.exists()); + SG_VERIFY(!p2.exists()); - VERIFY(root->allPackages().empty()); - VERIFY(root->catalogs().empty()); + SG_VERIFY(root->allPackages().empty()); + SG_VERIFY(root->catalogs().empty()); pkg::CatalogRef c = root->getCatalogById("org.flightgear.test.catalog1"); - COMPARE(c, pkg::CatalogRef()); + SG_CHECK_EQUAL(c, pkg::CatalogRef()); } template @@ -428,37 +432,39 @@ void testRefreshCatalog(HTTP::Client* cl) waitForUpdateComplete(cl, root); - VERIFY(p1->isInstalled()); - VERIFY(p2->isInstalled()); + SG_VERIFY(p1->isInstalled()); + SG_VERIFY(p2->isInstalled()); } - VERIFY(root->packagesNeedingUpdate().empty()); + SG_VERIFY(root->packagesNeedingUpdate().empty()); global_catalogVersion = 2; - VERIFY(!cl->hasActiveRequests()); + SG_VERIFY(!cl->hasActiveRequests()); root->refresh(); // should be a no-op due to catalog age testing - VERIFY(!cl->hasActiveRequests()); + SG_VERIFY(!cl->hasActiveRequests()); // force it this time root->refresh(true); - VERIFY(cl->hasActiveRequests()); + SG_VERIFY(cl->hasActiveRequests()); waitForUpdateComplete(cl, root); pkg::CatalogRef c = root->getCatalogById("org.flightgear.test.catalog1"); - COMPARE(c->ageInSeconds(), 0); + SG_CHECK_EQUAL(c->ageInSeconds(), 0); - VERIFY(root->getPackageById("dc3") != pkg::PackageRef()); - COMPARE(root->packagesNeedingUpdate().size(), 2); + SG_VERIFY(root->getPackageById("dc3") != pkg::PackageRef()); + SG_CHECK_EQUAL(root->packagesNeedingUpdate().size(), 2); pkg::PackageList needingUpdate = root->packagesNeedingUpdate(); - VERIFY(contains(needingUpdate, root->getPackageById("common-sounds"))); - VERIFY(contains(needingUpdate, root->getPackageById("org.flightgear.test.catalog1.alpha"))); + SG_VERIFY(contains(needingUpdate, root->getPackageById("common-sounds"))); + SG_VERIFY( + contains(needingUpdate, + root->getPackageById("org.flightgear.test.catalog1.alpha"))); pkg::InstallRef ins = root->getPackageById("alpha")->existingInstall(); - VERIFY(ins->hasUpdate()); + SG_VERIFY(ins->hasUpdate()); for (pkg::PackageList::const_iterator it = needingUpdate.begin(); it != needingUpdate.end(); ++it) @@ -468,8 +474,8 @@ void testRefreshCatalog(HTTP::Client* cl) waitForUpdateComplete(cl, root); - VERIFY(root->packagesNeedingUpdate().empty()); - COMPARE(root->getPackageById("common-sounds")->revision(), 11); + SG_VERIFY(root->packagesNeedingUpdate().empty()); + SG_CHECK_EQUAL(root->getPackageById("common-sounds")->revision(), 11); } void testInstallTarPackage(HTTP::Client* cl) @@ -487,14 +493,14 @@ void testInstallTarPackage(HTTP::Client* cl) waitForUpdateComplete(cl, root); pkg::PackageRef p1 = root->getPackageById("org.flightgear.test.catalog1.b737-NG"); - COMPARE(p1->id(), "b737-NG"); + SG_CHECK_EQUAL(p1->id(), "b737-NG"); pkg::InstallRef ins = p1->install(); - VERIFY(ins->isQueued()); + SG_VERIFY(ins->isQueued()); waitForUpdateComplete(cl, root); - VERIFY(p1->isInstalled()); - VERIFY(p1->existingInstall() == ins); + SG_VERIFY(p1->isInstalled()); + SG_VERIFY(p1->existingInstall() == ins); // verify on disk state SGPath p(rootPath); @@ -502,10 +508,10 @@ void testInstallTarPackage(HTTP::Client* cl) p.append("Aircraft"); p.append("b737NG"); - COMPARE(p, ins->path()); + SG_CHECK_EQUAL(p, ins->path()); p.append("b737-900-set.xml"); - VERIFY(p.exists()); + SG_VERIFY(p.exists()); } diff --git a/simgear/props/easing_functions_test.cxx b/simgear/props/easing_functions_test.cxx index f4862931..58ce073c 100644 --- a/simgear/props/easing_functions_test.cxx +++ b/simgear/props/easing_functions_test.cxx @@ -11,14 +11,10 @@ #include #include -#define VERIFY_CLOSE(a, b) \ - if( std::fabs(a - b) > 1e-5 ) \ - { \ - std::cerr << "failed: line " << __LINE__ << ": "\ - << a << " != " << b\ - << std::endl; \ - return 1; \ - } +#include + +#define VERIFY_CLOSE(a, b) SG_CHECK_EQUAL_EP2((a), (b), 1e-5) + int main(int argc, char* argv[]) { diff --git a/simgear/props/props_test.cxx b/simgear/props/props_test.cxx index e0eba17a..38318734 100644 --- a/simgear/props/props_test.cxx +++ b/simgear/props/props_test.cxx @@ -535,19 +535,19 @@ void testListener() tree->getNode("controls/engine[2]/starter")->addChangeListener(&l); tree->setBoolValue("controls/engine[2]/starter", true); - COMPARE(l.checkValueChangeCount("controls/engine[2]/starter"), 1); - COMPARE(l.checkValueChangeCount("position/body/c"), 0); + SG_CHECK_EQUAL(l.checkValueChangeCount("controls/engine[2]/starter"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/c"), 0); tree->setIntValue("position/body/c", 123); - COMPARE(l.checkValueChangeCount("controls/engine[2]/starter"), 1); - COMPARE(l.checkValueChangeCount("position/body/c"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("controls/engine[2]/starter"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/c"), 1); // verify that changing non-listened props doesn't affect anything tree->setIntValue("position/body/a", 19); tree->setBoolValue("controls/engine[1]/starter", true); - COMPARE(l.checkValueChangeCount("controls/engine[2]/starter"), 1); - COMPARE(l.checkValueChangeCount("position/body/c"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("controls/engine[2]/starter"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/c"), 1); } @@ -556,8 +556,8 @@ void testListener() TestListener l(tree.get()); tree->getNode("velocity/body/y")->addChangeListener(&l, true); tree->getNode("controls/engine[2]/starter")->addChangeListener(&l, true); - COMPARE(l.checkValueChangeCount("controls/engine[2]/starter"), 1); - COMPARE(l.checkValueChangeCount("velocity/body/y"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("controls/engine[2]/starter"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("velocity/body/y"), 1); } // delete listener while listening, should be fine @@ -567,13 +567,15 @@ void testListener() tree->getNode("velocity/body/z")->addChangeListener(l.get()); tree->getNode("controls/engine[2]/starter")->addChangeListener(l.get()); - COMPARE(tree->getNode("position/body/c")->nListeners(), 1); - COMPARE(tree->getNode("controls/engine[2]/starter")->nListeners(), 1); + SG_CHECK_EQUAL(tree->getNode("position/body/c")->nListeners(), 1); + SG_CHECK_EQUAL( + tree->getNode("controls/engine[2]/starter")->nListeners(), 1); l.reset(); - COMPARE(tree->getNode("position/body/c")->nListeners(), 0); - COMPARE(tree->getNode("controls/engine[2]/starter")->nListeners(), 0); + SG_CHECK_EQUAL(tree->getNode("position/body/c")->nListeners(), 0); + SG_CHECK_EQUAL( + tree->getNode("controls/engine[2]/starter")->nListeners(), 0); tree->getNode("position/body/c")->setIntValue(49.0); tree->getNode("controls/engine[2]/starter")->setBoolValue(true); @@ -587,21 +589,23 @@ void testListener() tree->getNode("velocity/body")->addChangeListener(&l); tree->setDoubleValue("controls/pitch", 0.5); - VERIFY(l.checkAdded("controls", tree->getNode("controls/pitch"))); + SG_VERIFY(l.checkAdded("controls", tree->getNode("controls/pitch"))); tree->setIntValue("controls/yaw", 12); - VERIFY(l.checkAdded("controls", tree->getNode("controls/yaw"))); + SG_VERIFY(l.checkAdded("controls", tree->getNode("controls/yaw"))); // branch as well as leaf nodes should work the same tree->setBoolValue("controls/gears/gear[1]/locked", true); - VERIFY(l.checkAdded("controls", tree->getNode("controls/gears"))); + SG_VERIFY(l.checkAdded("controls", tree->getNode("controls/gears"))); SGPropertyNode_ptr rm = tree->getNode("velocity/body/z"); tree->getNode("velocity/body")->removeChild("z"); - VERIFY(l.checkRemoved("velocity/body", rm.get())); + SG_VERIFY(l.checkRemoved("velocity/body", rm.get())); - COMPARE(l.checkRemoved("velocity/body", tree->getNode("velocity/body/x")), false); + SG_CHECK_EQUAL( + l.checkRemoved("velocity/body", tree->getNode("velocity/body/x")), + false); } tree = new SGPropertyNode; @@ -613,16 +617,17 @@ void testListener() tree->getNode("position/body")->addChangeListener(&l); tree->getNode("controls/")->addChangeListener(&l); - COMPARE(l.checkValueChangeCount("position/body/a"), 0); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 0); tree->setIntValue("position/body/a", 111); tree->setIntValue("position/body/z", 43); - COMPARE(l.checkValueChangeCount("position/body/a"), 0); - COMPARE(l.checkValueChangeCount("position/body/z"), 0); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 0); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/z"), 0); tree->getNode("position/body/new", true); - VERIFY(l.checkAdded("position/body", tree->getNode("position/body/new"))); + SG_VERIFY(l.checkAdded("position/body", + tree->getNode("position/body/new"))); } tree = new SGPropertyNode; @@ -633,64 +638,75 @@ void testListener() tree->getNode("position/body")->addChangeListener(&l); tree->getNode("controls/")->addChangeListener(&l); - COMPARE(l.checkValueChangeCount("position/body/a"), 0); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 0); tree->setIntValue("position/body/a", 111); tree->setIntValue("position/body/z", 43); - COMPARE(l.checkValueChangeCount("position/body/a"), 1); - COMPARE(l.checkValueChangeCount("position/body/z"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/z"), 1); - VERIFY(l.checkAdded("position/body", tree->getNode("position/body/z"))); + SG_VERIFY(l.checkAdded("position/body", + tree->getNode("position/body/z"))); tree->setBoolValue("controls/engine[3]/starter", true); - COMPARE(l.checkValueChangeCount("controls/engine[3]/starter"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("controls/engine[3]/starter"), 1); tree->setBoolValue("controls/engines[1]/fuel-cutoff", true); - VERIFY(l.checkAdded("controls/engines[1]", tree->getNode("controls/engines[1]/fuel-cutoff"))); + SG_VERIFY( + l.checkAdded("controls/engines[1]", + tree->getNode("controls/engines[1]/fuel-cutoff"))); - COMPARE(l.checkValueChangeCount("controls/engines[1]/fuel-cutoff"), 1); + SG_CHECK_EQUAL( + l.checkValueChangeCount("controls/engines[1]/fuel-cutoff"), 1); tree->setDoubleValue("controls/doors/door[2]/position-norm", 0.5); - COMPARE(l.checkValueChangeCount("controls/doors/door[2]/position-norm"), 1); + SG_CHECK_EQUAL( + l.checkValueChangeCount("controls/doors/door[2]/position-norm"), 1); SGPropertyNode_ptr door2Node = tree->getNode("controls/doors/door[2]"); SGPropertyNode_ptr door2PosNode = tree->getNode("controls/doors/door[2]/position-norm"); tree->getNode("controls/doors")->removeChild(door2Node); - VERIFY(l.checkRemoved("controls/doors", door2Node)); + SG_VERIFY(l.checkRemoved("controls/doors", door2Node)); // default is not recurse for children - COMPARE(l.checkRemoved(door2Node, door2PosNode), false); + SG_CHECK_EQUAL(l.checkRemoved(door2Node, door2PosNode), false); // adds *are* seen recursively tree->setStringValue("controls/lights/light[3]/foo/state", "dim"); - VERIFY(l.checkAdded("controls/lights/light[3]/foo", tree->getNode("controls/lights/light[3]/foo/state"))); + SG_VERIFY( + l.checkAdded("controls/lights/light[3]/foo", + tree->getNode("controls/lights/light[3]/foo/state"))); // remove a listener tree->getNode("controls")->removeChangeListener(&l); // removing listener does not trigger remove notifications - VERIFY(!l.checkRemoved("controls", tree->getNode("controls/engine[3]"))); - VERIFY(!l.checkRemoved("controls/engine[3]", tree->getNode("controls/engine[3]/starter"))); + SG_VERIFY(!l.checkRemoved("controls", + tree->getNode("controls/engine[3]"))); + SG_VERIFY(!l.checkRemoved("controls/engine[3]", + tree->getNode("controls/engine[3]/starter"))); tree->setBoolValue("controls/engines[1]/fuel-cutoff", false); tree->setBoolValue("controls/engines[9]/fuel-cutoff", true); // values should be unchanged - COMPARE(l.checkValueChangeCount("controls/engines[1]/fuel-cutoff"), 1); - COMPARE(l.checkValueChangeCount("controls/engines[9]/fuel-cutoff"), 0); + SG_CHECK_EQUAL( + l.checkValueChangeCount("controls/engines[1]/fuel-cutoff"), 1); + SG_CHECK_EQUAL( + l.checkValueChangeCount("controls/engines[9]/fuel-cutoff"), 0); // ensure additional calls to fireChildrenRecursive don't cause multiple adds - VERIFY(ensureNListeners(tree->getNode("position/body"), 1)); - VERIFY(ensureNListeners(tree->getNode("controls"), 0)); + SG_VERIFY(ensureNListeners(tree->getNode("position/body"), 1)); + SG_VERIFY(ensureNListeners(tree->getNode("controls"), 0)); tree->getNode("position/body")->fireCreatedRecursive(); - VERIFY(ensureNListeners(tree->getNode("position/body"), 1)); + SG_VERIFY(ensureNListeners(tree->getNode("position/body"), 1)); } } @@ -708,12 +724,12 @@ void testAliasedListeners() tree->getNode("position/earth")->addChangeListener(&l); tree->setIntValue("position/body/a", 99); - COMPARE(tree->getIntValue("position/world/x"), 99); - COMPARE(l.checkValueChangeCount("position/world/x"), 1); + SG_CHECK_EQUAL(tree->getIntValue("position/world/x"), 99); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/world/x"), 1); tree->setIntValue("position/world/x", 101); - COMPARE(tree->getIntValue("position/body/a"), 101); - COMPARE(l.checkValueChangeCount("position/world/x"), 2); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 101); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/world/x"), 2); } class TiedPropertyDonor @@ -746,44 +762,47 @@ void tiedPropertiesTest() tree->tie("position/body/mass", SGRawValueMethods(donor, &TiedPropertyDonor::getWrappedB, nullptr)); // tie sets current values of the property onto the setter - COMPARE(tree->getStringValue("settings/render/foo"), std::string("flightgear")); - COMPARE(tree->getIntValue("position/body/a"), 42); + SG_CHECK_EQUAL(tree->getStringValue("settings/render/foo"), + std::string("flightgear")); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 42); // but can't write to this one! - COMPARE(tree->getDoubleValue("position/body/mass"), 1.23); + SG_CHECK_EQUAL(tree->getDoubleValue("position/body/mass"), 1.23); donor.setWrappedA("hello world"); donor.someMember = 13; - COMPARE(tree->getIntValue("position/body/a"), 13); - COMPARE(tree->getStringValue("settings/render/foo"), std::string("hello world")); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 13); + SG_CHECK_EQUAL(tree->getStringValue("settings/render/foo"), + std::string("hello world")); donor.someMember = 45; donor.wrappedMember = "apples"; donor.wrappedB = 5000.0; - COMPARE(tree->getIntValue("position/body/a"), 45); - COMPARE(tree->getStringValue("settings/render/foo"), std::string("apples")); - COMPARE(tree->getDoubleValue("position/body/mass"), 5000.0); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 45); + SG_CHECK_EQUAL(tree->getStringValue("settings/render/foo"), + std::string("apples")); + SG_CHECK_EQUAL(tree->getDoubleValue("position/body/mass"), 5000.0); // set value externally tree->setIntValue("position/body/a", 99); - COMPARE(donor.someMember, 99); + SG_CHECK_EQUAL(donor.someMember, 99); tree->setStringValue("settings/render/foo", "lemons"); - COMPARE(donor.wrappedMember, "lemons"); + SG_CHECK_EQUAL(donor.wrappedMember, "lemons"); // set read-only bool success = tree->setDoubleValue("position/body/mass", 10000.0); - VERIFY(!success); - COMPARE(donor.wrappedB, 5000.0); // must not have changed + SG_VERIFY(!success); + SG_CHECK_EQUAL(donor.wrappedB, 5000.0); // must not have changed // un-tieing tree->untie("position/body/a"); tree->untie("position/body/mass"); - COMPARE(tree->getIntValue("position/body/a"), 99); - COMPARE(tree->getDoubleValue("position/body/mass"), 5000.0); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 99); + SG_CHECK_EQUAL(tree->getDoubleValue("position/body/mass"), 5000.0); } void tiedPropertiesListeners() @@ -799,8 +818,9 @@ void tiedPropertiesListeners() tree->tie("position/body/mass", SGRawValueMethods(donor, &TiedPropertyDonor::getWrappedB, nullptr)); // tie sets current values of the property onto the setter - COMPARE(tree->getStringValue("settings/render/foo"), std::string("flightgear")); - COMPARE(tree->getIntValue("position/body/a"), 42); + SG_CHECK_EQUAL(tree->getStringValue("settings/render/foo"), + std::string("flightgear")); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 42); TestListener l(tree.get()); @@ -810,28 +830,29 @@ void tiedPropertiesListeners() // firstly test changes via setXXX API and verify they work tree->setIntValue("position/body/a", 99); - COMPARE(donor.someMember, 99); - COMPARE(l.checkValueChangeCount("position/body/a"), 1); + SG_CHECK_EQUAL(donor.someMember, 99); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); tree->setDoubleValue("position/body/mass", -123.0); - COMPARE(donor.wrappedB, 1.23); // read-only! - COMPARE(l.checkValueChangeCount("position/body/mass"), 0); + SG_CHECK_EQUAL(donor.wrappedB, 1.23); // read-only! + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/mass"), 0); tree->setStringValue("settings/render/foo", "thingA"); tree->setStringValue("settings/render/foo", "thingB"); - COMPARE(donor.wrappedMember, std::string("thingB")); - COMPARE(l.checkValueChangeCount("settings/render/foo"), 2); + SG_CHECK_EQUAL(donor.wrappedMember, std::string("thingB")); + SG_CHECK_EQUAL(l.checkValueChangeCount("settings/render/foo"), 2); // now change values from inside the donor and verify it doesn't fire // the listener donor.wrappedMember = "pineapples"; - COMPARE(tree->getStringValue("settings/render/foo"), std::string("pineapples")); - COMPARE(l.checkValueChangeCount("settings/render/foo"), 2); + SG_CHECK_EQUAL(tree->getStringValue("settings/render/foo"), + std::string("pineapples")); + SG_CHECK_EQUAL(l.checkValueChangeCount("settings/render/foo"), 2); donor.someMember = 256; - COMPARE(tree->getIntValue("position/body/a"), 256); - COMPARE(l.checkValueChangeCount("position/body/a"), 1); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 256); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); // now fire value changed l.resetChangeCounts(); @@ -839,27 +860,30 @@ void tiedPropertiesListeners() tree->getNode("position/body/a")->fireValueChanged(); - COMPARE(l.checkValueChangeCount("position/body/a"), 1); - COMPARE(tree->getIntValue("position/body/a"), 256); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); + SG_CHECK_EQUAL(tree->getIntValue("position/body/a"), 256); l.resetChangeCounts(); tree->getNode("position/body/a")->fireValueChanged(); - COMPARE(l.checkValueChangeCount("position/body/a"), 1); + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); tree->setDoubleValue("position/body/mass", 4.000000001); - COMPARE(l.checkValueChangeCount("position/body/mass"), 0); // not changed - + // Not changed + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/mass"), 0); + donor.someMember = 970; - COMPARE(l.checkValueChangeCount("position/body/a"), 1); // not changed + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 1); // not changed tree->getNode("position/body/a")->fireValueChanged(); - COMPARE(l.checkValueChangeCount("position/body/a"), 2); // changed + SG_CHECK_EQUAL(l.checkValueChangeCount("position/body/a"), 2); // changed donor.wrappedMember = "pears"; - COMPARE(l.checkValueChangeCount("settings/render/foo"), 0); // not changed + // Not changed + SG_CHECK_EQUAL(l.checkValueChangeCount("settings/render/foo"), 0); tree->getNode("settings/render/foo")->fireValueChanged(); - COMPARE(l.checkValueChangeCount("settings/render/foo"), 1); // changed + // Changed + SG_CHECK_EQUAL(l.checkValueChangeCount("settings/render/foo"), 1); } @@ -876,14 +900,15 @@ void testDeleterListener() tree->getNode("position/body")->addChangeListener(l); tree->getNode("controls/")->addChangeListener(l); - COMPARE(l->checkValueChangeCount("position/body/a"), 0); + SG_CHECK_EQUAL(l->checkValueChangeCount("position/body/a"), 0); // create additional children tree->setFloatValue("position/body/sub/theta", 0.1234); - VERIFY(l->checkAdded("position/body/sub", tree->getNode("position/body/sub/theta"))); + SG_VERIFY(l->checkAdded("position/body/sub", + tree->getNode("position/body/sub/theta"))); - COMPARE(l->checkValueChangeCount("position/body/sub/theta"), 1); + SG_CHECK_EQUAL(l->checkValueChangeCount("position/body/sub/theta"), 1); delete l; @@ -891,7 +916,7 @@ void testDeleterListener() tree->setIntValue("position/body/a", 33); // verify no listeners at all - VERIFY(ensureNListeners(tree, 0)); + SG_VERIFY(ensureNListeners(tree, 0)); } } diff --git a/simgear/scene/material/parseBlendFunc_test.cxx b/simgear/scene/material/parseBlendFunc_test.cxx index 4993c5b3..22adba4e 100644 --- a/simgear/scene/material/parseBlendFunc_test.cxx +++ b/simgear/scene/material/parseBlendFunc_test.cxx @@ -1,43 +1,27 @@ #include +#include #include "parseBlendFunc.hxx" #include #include -#include -#define COMPARE(a, b) \ - if( (a) != (b) ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << " != " << #b << std::endl; \ - return 1; \ - } - -#define VERIFY(a) \ - if( !(a) ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << std::endl; \ - return 1; \ - } - int main (int ac, char ** av) { osg::ref_ptr ss = new osg::StateSet; // default blendfunc - VERIFY( simgear::parseBlendFunc(ss) ); + SG_VERIFY( simgear::parseBlendFunc(ss) ); osg::BlendFunc* bf = dynamic_cast( ss->getAttribute(osg::StateAttribute::BLENDFUNC) ); - VERIFY( bf ); - COMPARE(bf->getSource(), osg::BlendFunc::SRC_ALPHA); - COMPARE(bf->getDestination(), osg::BlendFunc::ONE_MINUS_SRC_ALPHA); - COMPARE(bf->getSource(), bf->getSourceAlpha()); - COMPARE(bf->getDestination(), bf->getDestinationAlpha()); + SG_VERIFY( bf ); + SG_CHECK_EQUAL(bf->getSource(), osg::BlendFunc::SRC_ALPHA); + SG_CHECK_EQUAL(bf->getDestination(), osg::BlendFunc::ONE_MINUS_SRC_ALPHA); + SG_CHECK_EQUAL(bf->getSource(), bf->getSourceAlpha()); + SG_CHECK_EQUAL(bf->getDestination(), bf->getDestinationAlpha()); // now set some values SGPropertyNode_ptr src = new SGPropertyNode, @@ -46,17 +30,17 @@ int main (int ac, char ** av) src->setStringValue("src-alpha"); dest->setStringValue("constant-color"); - VERIFY( simgear::parseBlendFunc(ss, src, dest) ); + SG_VERIFY( simgear::parseBlendFunc(ss, src, dest) ); bf = dynamic_cast( ss->getAttribute(osg::StateAttribute::BLENDFUNC) ); - VERIFY( bf ); - COMPARE(bf->getSource(), osg::BlendFunc::SRC_ALPHA); - COMPARE(bf->getDestination(), osg::BlendFunc::CONSTANT_COLOR); - COMPARE(bf->getSource(), bf->getSourceAlpha()); - COMPARE(bf->getDestination(), bf->getDestinationAlpha()); + SG_VERIFY( bf ); + SG_CHECK_EQUAL(bf->getSource(), osg::BlendFunc::SRC_ALPHA); + SG_CHECK_EQUAL(bf->getDestination(), osg::BlendFunc::CONSTANT_COLOR); + SG_CHECK_EQUAL(bf->getSource(), bf->getSourceAlpha()); + SG_CHECK_EQUAL(bf->getDestination(), bf->getDestinationAlpha()); std::cout << "all tests passed successfully!" << std::endl; return 0; diff --git a/simgear/scene/model/animation_test.cxx b/simgear/scene/model/animation_test.cxx index 9c6ade02..051806dd 100644 --- a/simgear/scene/model/animation_test.cxx +++ b/simgear/scene/model/animation_test.cxx @@ -3,21 +3,10 @@ #include #include -#define VERIFY_CLOSE(a, b) \ - if( norm((a) - (b)) > 1e-5 ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << " != " << #b\ - << " [" << (a) << " != " << (b) << "]" << std::endl; \ - return 1; \ - } +#include + +#define VERIFY_CLOSE(a, b) SG_VERIFY( norm((a) - (b)) <= 1e-5 ) -#define VERIFY(a) \ - if( !(a) ) \ - { \ - std::cerr << "failed: line " << __LINE__ << ": " << #a << std::endl; \ - return 1; \ - } struct AnimationTest: public SGAnimation diff --git a/simgear/scene/util/parse_color_test.cxx b/simgear/scene/util/parse_color_test.cxx index 36ec882f..a08fdfc1 100644 --- a/simgear/scene/util/parse_color_test.cxx +++ b/simgear/scene/util/parse_color_test.cxx @@ -3,32 +3,18 @@ #include "parse_color.hxx" #include "ColorInterpolator.hxx" #include +#include #include -#define COMPARE(a, b) \ - if( (a) != (b) ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << " != " << #b << std::endl; \ - return 1; \ - } - -#define VERIFY(a) \ - if( !(a) ) \ - { \ - std::cerr << "line " << __LINE__ << ": failed: "\ - << #a << std::endl; \ - return 1; \ - } #define VERIFY_COLOR(str, r, g, b, a) \ - VERIFY(simgear::parseColor(str, color)) \ - COMPARE(color, osg::Vec4(r, g, b, a)) + SG_VERIFY(simgear::parseColor(str, color)) \ + SG_CHECK_EQUAL(color, osg::Vec4(r, g, b, a)) #define VERIFY_NODE_STR(node, str) \ - COMPARE(node.getStringValue(), std::string(str)) - + SG_CHECK_EQUAL(node.getStringValue(), std::string(str)) + int main (int ac, char ** av) { osg::Vec4 color; diff --git a/simgear/structure/expression_test.cxx b/simgear/structure/expression_test.cxx index a8bb9fe5..0ee10154 100644 --- a/simgear/structure/expression_test.cxx +++ b/simgear/structure/expression_test.cxx @@ -89,12 +89,12 @@ void testParse() std::set deps; expr->collectDependentProperties(deps); - COMPARE(deps.size(), 3); + SG_CHECK_EQUAL(deps.size(), 3); SGPropertyNode* barProp = propertyTree->getNode("group-a/bar"); - VERIFY(deps.find(barProp) != deps.end()); + SG_VERIFY(deps.find(barProp) != deps.end()); - VERIFY(deps.find(propertyTree->getNode("group-a/zot")) != deps.end()); - VERIFY(deps.find(propertyTree->getNode("group-b/thing-1")) != deps.end()); + SG_VERIFY(deps.find(propertyTree->getNode("group-a/zot")) != deps.end()); + SG_VERIFY(deps.find(propertyTree->getNode("group-b/thing-1")) != deps.end()); } int main(int argc, char* argv[]) diff --git a/simgear/structure/state_machine_test.cxx b/simgear/structure/state_machine_test.cxx index 0703ce62..b3402ed9 100644 --- a/simgear/structure/state_machine_test.cxx +++ b/simgear/structure/state_machine_test.cxx @@ -87,55 +87,55 @@ void testBasic() { BUILD_MACHINE_1(); //////////////////////////////////////////// - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); - COMPARE(sm->indexOfState(stateA), 0); - COMPARE(sm->findStateByName("c"), stateC); + SG_CHECK_EQUAL(sm->indexOfState(stateA), 0); + SG_CHECK_EQUAL(sm->findStateByName("c"), stateC); sm->changeToState(stateC); - COMPARE(sm->state(), stateC); + SG_CHECK_EQUAL(sm->state(), stateC); trigger3->_state = true; sm->update(1.0); - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); trigger3->_state = false; trigger1->_state = true; sm->update(1.0); trigger1->_state = false; - COMPARE(sm->state()->name(), "b"); + SG_CHECK_EQUAL(sm->state()->name(), "b"); trigger3->_state = true; sm->update(1.0); - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); trigger3->_state = false; trigger1->_state = true; sm->update(1.0); trigger1->_state = false; - COMPARE(sm->state()->name(), "b"); + SG_CHECK_EQUAL(sm->state()->name(), "b"); trigger2->_state = true; sm->update(1.0); trigger2->_state = false; - COMPARE(sm->state()->name(), "c"); + SG_CHECK_EQUAL(sm->state()->name(), "c"); ////////////////////////////////////////// - COMPARE(sm->root()->getIntValue("current-index"), 2); - COMPARE(sm->root()->getStringValue("current-name"), string("c")); + SG_CHECK_EQUAL(sm->root()->getIntValue("current-index"), 2); + SG_CHECK_EQUAL(sm->root()->getStringValue("current-name"), string("c")); sm->root()->setStringValue("current-name", "b"); - COMPARE(sm->state()->name(), "b"); + SG_CHECK_EQUAL(sm->state()->name(), "b"); //////////////////////////////////////// - COMPARE(sm->findStateByName("foo"), NULL); - COMPARE(sm->indexOfState(StateMachine::State_ptr()), -1); + SG_CHECK_EQUAL(sm->findStateByName("foo"), NULL); + SG_CHECK_EQUAL(sm->indexOfState(StateMachine::State_ptr()), -1); - COMPARE(sm->stateByIndex(1), stateB); + SG_CHECK_EQUAL(sm->stateByIndex(1), stateB); try { sm->stateByIndex(44); - VERIFY(false && "should have raised an exception"); + SG_VERIFY(false && "should have raised an exception"); } catch (sg_exception& e){ // expected! } @@ -150,16 +150,16 @@ void testNoSourcesTransition() t4->setTriggerCondition(trigger4); \ sm->init(); - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); trigger1->_state = true; sm->update(1.0); trigger1->_state = false; - COMPARE(sm->state()->name(), "b"); + SG_CHECK_EQUAL(sm->state()->name(), "b"); trigger4->_state = true; sm->update(1.0); trigger4->_state = false; - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); } void testBindings() @@ -176,25 +176,25 @@ void testBindings() stateC->addEntryBinding(new SGBinding("dummy")); //////////////////////// - COMPARE(sm->state()->name(), "a"); + SG_CHECK_EQUAL(sm->state()->name(), "a"); trigger1->_state = true; sm->update(1.0); trigger1->_state = false; - COMPARE(sm->state()->name(), "b"); - COMPARE(thing.dummy_cmd_state, 1); // exit state A + SG_CHECK_EQUAL(sm->state()->name(), "b"); + SG_CHECK_EQUAL(thing.dummy_cmd_state, 1); // exit state A trigger2->_state = true; sm->update(1.0); trigger2->_state = false; - COMPARE(thing.dummy_cmd_state, 3); // fire transition 2, enter state C + SG_CHECK_EQUAL(thing.dummy_cmd_state, 3); // fire transition 2, enter state C thing.dummy_cmd_state = 0; sm->changeToState(stateA); - COMPARE(thing.dummy_cmd_state, 1); // enter state A + SG_CHECK_EQUAL(thing.dummy_cmd_state, 1); // enter state A trigger1->_state = true; sm->update(1.0); trigger1->_state = false; - COMPARE(thing.dummy_cmd_state, 2); // exit state A + SG_CHECK_EQUAL(thing.dummy_cmd_state, 2); // exit state A //////////////////////// t3->addBinding(new SGBinding("dummy")); @@ -206,7 +206,8 @@ void testBindings() trigger3->_state = true; sm->update(1.0); trigger3->_state = false; - COMPARE(thing.dummy_cmd_state, 4); // three transition bindings, enter A + // Three transition bindings, enter A + SG_CHECK_EQUAL(thing.dummy_cmd_state, 4); } void testParse() @@ -227,8 +228,8 @@ void testParse() SGPropertyNode_ptr root(new SGPropertyNode); StateMachine_ptr sm = StateMachine::createFromPlist(desc, root); - VERIFY(sm->findStateByName("one") != NULL); - VERIFY(sm->findStateByName("two") != NULL); + SG_VERIFY(sm->findStateByName("one") != NULL); + SG_VERIFY(sm->findStateByName("two") != NULL); } int main(int argc, char* argv[])