From a67b06c7f0dde82b74e2b59154e35e471644328a Mon Sep 17 00:00:00 2001 From: PepMS <jmarti@iri.upc.edu> Date: Thu, 9 Apr 2020 15:15:16 +0200 Subject: [PATCH] [tests] fixed: -> tests observations -> test navigations -> operators with struct arrays --- deps/RTKLIB | 2 +- include/gnss_utils/observations.h | 2 +- include/gnss_utils/utils/utils.h | 1 - src/examples/gnss_utils_test.cpp | 17 ++--- src/observations.cpp | 6 +- src/utils/utils.cpp | 106 +++++++++++++++++++++++++----- test/gtest_navigation.cpp | 94 +------------------------- test/gtest_observations.cpp | 84 ++++++++++++----------- 8 files changed, 150 insertions(+), 162 deletions(-) diff --git a/deps/RTKLIB b/deps/RTKLIB index b8d52b9..5f9fc9b 160000 --- a/deps/RTKLIB +++ b/deps/RTKLIB @@ -1 +1 @@ -Subproject commit b8d52b91639ef1ed3a8c676c43457164865a9df3 +Subproject commit 5f9fc9b46abc503ab95b4b0ea10f3385d7560404 diff --git a/include/gnss_utils/observations.h b/include/gnss_utils/observations.h index 766a72c..7e63286 100644 --- a/include/gnss_utils/observations.h +++ b/include/gnss_utils/observations.h @@ -49,7 +49,7 @@ public: bool hasSatellite(const unsigned char& i) const; - void print(obsd_t& _obs); + static void print(obsd_t& _obs); void printBySat(const int& _sat); void printByIdx(const int& _idx); void print(); diff --git a/include/gnss_utils/utils/utils.h b/include/gnss_utils/utils/utils.h index 43556de..06eba1b 100644 --- a/include/gnss_utils/utils/utils.h +++ b/include/gnss_utils/utils/utils.h @@ -195,5 +195,4 @@ bool operator!=(const erp_t& erp1, const erp_t& erp2); bool operator==(const nav_t& nav1, const nav_t& nav2); bool operator!=(const nav_t& nav1, const nav_t& nav2); - #endif // INCLUDE_GNSS_UTILS_UTILS_UTILS_H_ diff --git a/src/examples/gnss_utils_test.cpp b/src/examples/gnss_utils_test.cpp index 34277d8..fba3b7f 100644 --- a/src/examples/gnss_utils_test.cpp +++ b/src/examples/gnss_utils_test.cpp @@ -30,27 +30,24 @@ int main(int argc, char* argv[]) gtime_t t_start{ 0, 0 }; // no limit gtime_t t_end{ 0, 0 }; // no limit double dt = 0.0; // no limit - const char* opt = "-SYS=S"; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" - - + const char* opt = ""; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" // load observations from RINEX file observations.loadFromRinex("../src/examples/sample_data.obs", t_start, t_end, dt, opt); observations.print(); - - // RTKLIB trace - char str_file[80]; - snprintf(str_file, sizeof str_file, "../src/examples/trace"); - tracelevel(5); - traceopen(str_file); + // RTKLIB trace + // char str_file[80]; + // snprintf(str_file, sizeof str_file, "../src/examples/trace"); + // tracelevel(5); + // traceopen(str_file); // load navigation from RINEX file navigation.loadFromRinex("../src/examples/sample_data.nav", t_start, t_end, dt, opt); navigation.print(); // Trace close - traceclose(); + // traceclose(); /* Set processing options */ diff --git a/src/observations.cpp b/src/observations.cpp index 8f04ec1..f9d1e93 100644 --- a/src/observations.cpp +++ b/src/observations.cpp @@ -156,14 +156,18 @@ void Observations::removeObservationBySat(const int& _sat) assert(sat_2_idx_.size() == obs_.size()); } -void Observations::print(obsd_t& _obs) +static void Observations::print(obsd_t& _obs) { std::string msg = "Observation of satellite #" + std::to_string(_obs.sat); GnssUtils::print(msg); std::cout << "Time [s]: " << _obs.time.time << " + " << _obs.time.sec << "\n"; + std::cout << "Time valid: " << _obs.timevalid << std::endl; printArray("SNR: ", _obs.SNR, ARRAY_SIZE(_obs.SNR)); printArray("LLI: ", _obs.LLI, ARRAY_SIZE(_obs.LLI)); printArray("code: ", _obs.code, ARRAY_SIZE(_obs.code)); + printArray("code: ", _obs.qualL, ARRAY_SIZE(_obs.qualL)); + printArray("code: ", _obs.qualP, ARRAY_SIZE(_obs.qualP)); + printf("Freq. channel: %uc \n", _obs.freq); printArray("L: ", _obs.L, ARRAY_SIZE(_obs.L)); printArray("P: ", _obs.P, ARRAY_SIZE(_obs.P)); printArray("D: ", _obs.D, ARRAY_SIZE(_obs.D)); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 85f109b..49a7f38 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -75,16 +75,16 @@ bool operator!=(const gtime_t& time1, const gtime_t& time2) bool operator==(const obsd_t& obs1, const obsd_t& obs2) { return obs1.time == obs2.time && obs1.eventime == obs2.eventime && obs1.timevalid == obs2.timevalid && - obs1.sat == obs2.sat && obs1.rcv == obs2.rcv && memcmp(obs1.SNR, obs2.SNR, sizeof(obs1.SNR)) == 0 && - memcmp(obs1.LLI, obs2.LLI, sizeof(obs1.LLI)) == 0 && memcmp(obs1.code, obs2.code, sizeof(obs1.code)) == 0 && - memcmp(obs1.qualL, obs2.qualL, sizeof(obs1.qualL)) == 0 && - memcmp(obs1.qualP, obs2.qualP, sizeof(obs1.qualP)) == 0 && obs1.freq == obs2.freq && - GnssUtils::equalArray<double>( - obs1.L, obs2.L, sizeof(obs1.L) / sizeof(obs1.L[0]), sizeof(obs2.L) / sizeof(obs2.L[0])) && - GnssUtils::equalArray<double>( - obs1.P, obs2.P, sizeof(obs1.P) / sizeof(obs1.P[0]), sizeof(obs2.P) / sizeof(obs2.P[0])) && - GnssUtils::equalArray<float>( - obs1.D, obs2.D, sizeof(obs1.D) / sizeof(obs1.D[0]), sizeof(obs2.D) / sizeof(obs2.D[0])); + obs1.sat == obs2.sat && obs1.rcv == obs2.rcv && + GnssUtils::equalArray<unsigned char>(obs1.SNR, obs2.SNR, ARRAY_SIZE(obs1.SNR), ARRAY_SIZE(obs2.SNR)) && + GnssUtils::equalArray<unsigned char>(obs1.LLI, obs2.LLI, ARRAY_SIZE(obs1.LLI), ARRAY_SIZE(obs2.LLI)) && + GnssUtils::equalArray<unsigned char>(obs1.code, obs2.code, ARRAY_SIZE(obs1.code), ARRAY_SIZE(obs2.code)) && + GnssUtils::equalArray<unsigned char>(obs1.qualL, obs2.qualL, ARRAY_SIZE(obs1.qualL), ARRAY_SIZE(obs2.qualL)) && + GnssUtils::equalArray<unsigned char>(obs1.qualP, obs2.qualP, ARRAY_SIZE(obs1.qualP), ARRAY_SIZE(obs2.qualP)) && + obs1.freq == obs2.freq && + GnssUtils::equalArray<double>(obs1.L, obs2.L, ARRAY_SIZE(obs1.L), ARRAY_SIZE(obs2.L)) && + GnssUtils::equalArray<double>(obs1.P, obs2.P, ARRAY_SIZE(obs1.P), ARRAY_SIZE(obs2.P)) && + GnssUtils::equalArray<float>(obs1.D, obs2.D, ARRAY_SIZE(obs1.D), ARRAY_SIZE(obs2.D)); } bool operator!=(const obsd_t& obs1, const obsd_t& obs2) { @@ -93,8 +93,16 @@ bool operator!=(const obsd_t& obs1, const obsd_t& obs2) bool operator==(const obs_t& obs1, const obs_t& obs2) { - return obs1.n == obs2.n && obs1.nmax == obs2.nmax && obs1.flag == obs2.flag && obs1.rcvcount == obs2.rcvcount && - obs1.tmcount == obs2.tmcount && *(obs1.data) == *(obs2.data); + if (obs1.n != obs2.n) + return false; + for (int i = 0; i < obs1.n; ++i) + { + if (obs1.data[i] != obs2.data[i]) + return false; + } + + return obs1.nmax == obs2.nmax && obs1.flag == obs2.flag && obs1.rcvcount == obs2.rcvcount && + obs1.tmcount == obs2.tmcount; } bool operator!=(const obs_t& obs1, const obs_t& obs2) { @@ -273,12 +281,74 @@ bool operator!=(const erp_t& erp1, const erp_t& erp2) bool operator==(const nav_t& nav1, const nav_t& nav2) { - return nav1.n == nav2.n && nav1.nmax == nav2.nmax && nav1.ng == nav2.ng && nav1.ngmax == nav2.ngmax && - nav1.ns == nav2.ns && nav1.nsmax == nav2.nsmax && nav1.ne == nav2.ne && nav1.nemax == nav2.nemax && - nav1.nc == nav2.nc && nav1.ncmax == nav2.ncmax && nav1.na == nav2.na && nav1.namax == nav2.namax && - nav1.nt == nav2.nt && nav1.ntmax == nav2.ntmax && nav1.nf == nav2.nf && nav1.nfmax == nav2.nfmax && - *nav1.eph == *nav2.eph && *nav1.geph == *nav2.geph && *nav1.seph == *nav2.seph && *nav1.peph == *nav2.peph && - *nav1.pclk == *nav2.pclk && *nav1.alm == *nav2.alm && *nav1.tec == *nav2.tec && *nav1.fcb == *nav2.fcb && + if (nav1.n != nav2.n) + return false; + for (int i = 0; i < nav1.n; ++i) + { + if (nav1.eph[i] != nav2.eph[i]) + return false; + } + + if (nav1.ng != nav2.ng) + return false; + for (int i = 0; i < nav1.ng; ++i) + { + if (nav1.geph[i] != nav2.geph[i]) + return false; + } + + if (nav1.ns != nav2.ns) + return false; + for (int i = 0; i < nav1.ns; ++i) + { + if (nav1.seph[i] != nav2.seph[i]) + return false; + } + + if (nav1.ne != nav2.ne) + return false; + for (int i = 0; i < nav1.ne; ++i) + { + if (nav1.peph[i] != nav2.peph[i]) + return false; + } + + if (nav1.nc != nav2.nc) + return false; + for (int i = 0; i < nav1.nc; ++i) + { + if (nav1.pclk[i] != nav2.pclk[i]) + return false; + } + + if (nav1.na != nav2.na) + return false; + for (int i = 0; i < nav1.na; ++i) + { + if (nav1.alm[i] != nav2.alm[i]) + return false; + } + + if (nav1.nt != nav2.nt) + return false; + for (int i = 0; i < nav1.nt; ++i) + { + if (nav1.tec[i] != nav2.tec[i]) + return false; + } + + if (nav1.nf != nav2.nf) + return false; + for (int i = 0; i < nav1.nf; ++i) + { + if (nav1.fcb[i] != nav2.fcb[i]) + return false; + } + + // erp to do + + return nav1.nmax == nav2.nmax && nav1.ngmax == nav2.ngmax && nav1.nsmax == nav2.nsmax && nav1.nemax == nav2.nemax && + nav1.ncmax == nav2.ncmax && nav1.namax == nav2.namax && nav1.ntmax == nav2.ntmax && nav1.nfmax == nav2.nfmax && nav1.erp == nav2.erp && GnssUtils::equalArray<double>( nav1.utc_gps, nav2.utc_gps, ARRAY_SIZE(nav1.utc_gps), ARRAY_SIZE(nav2.utc_gps)) && diff --git a/test/gtest_navigation.cpp b/test/gtest_navigation.cpp index 6982d3a..d9cfd4c 100644 --- a/test/gtest_navigation.cpp +++ b/test/gtest_navigation.cpp @@ -8,7 +8,7 @@ nav_t nav; const gtime_t t_start{ 0, 0 }; // no limit const gtime_t t_end{ 0, 0 }; // no limit const double dt = 0.0; // no limit -const char* opt = ""; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" +const char* opt = ""; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" void loadRinex() { @@ -18,96 +18,6 @@ void loadRinex() uniqnav(&nav); } -TEST(NavigationTests, Ephemeris) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().eph) == *(nav.eph)); -} - -TEST(NavigationTests, GlonassEphemeris) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().geph) == *(nav.geph)); -} - -TEST(NavigationTests, SBASEphemeris) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().seph) == *(nav.seph)); -} - -TEST(NavigationTests, PreciseEphemeris) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().peph) == *(nav.peph)); -} - -TEST(NavigationTests, PreciseClock) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().pclk) == *(nav.pclk)); -} - -TEST(NavigationTests, Almanac) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().alm) == *(nav.alm)); -} - -TEST(NavigationTests, TecGrid) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().tec) == *(nav.tec)); -} - -TEST(NavigationTests, FCBData) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().fcb) == *(nav.fcb)); -} - -TEST(NavigationTests, EarthRotationParams) -{ - loadRinex(); - - Navigation navigation; - - navigation.setNavigation(nav); - ASSERT_TRUE(navigation.getNavigation().erp == nav.erp); -} - TEST(NavigationTests, setgetNavigation) { loadRinex(); @@ -115,7 +25,7 @@ TEST(NavigationTests, setgetNavigation) Navigation navigation; navigation.setNavigation(nav); - ASSERT_TRUE(*(navigation.getNavigation().eph) == *(nav.eph)); + ASSERT_TRUE(navigation.getNavigation() == nav); } int main(int argc, char** argv) diff --git a/test/gtest_observations.cpp b/test/gtest_observations.cpp index 5d2de7a..e4f0b2c 100644 --- a/test/gtest_observations.cpp +++ b/test/gtest_observations.cpp @@ -3,13 +3,12 @@ using namespace GnssUtils; std::string rnx_file = std::string(_GNSS_UTILS_ROOT_DIR) + "/test/data/sample_data.obs"; -obs_t obs; const gtime_t t_start{ 0, 0 }; // no limit const gtime_t t_end{ 0, 0 }; // no limit const double dt = 0.0; // no limit -const char* opt = "-SYS=G"; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" +const char* opt = ""; // only GPS | GPS+GAL: "-SYS=G,L" | ALL: "" -void loadRinex() +void loadRinex(obs_t& obs) { // RTKLIB utilities obs.data = (obsd_t*)malloc(sizeof(obsd_t) * MAXSAT); @@ -24,7 +23,8 @@ void loadRinex() TEST(ObservationsTest, AddClearObservation) { - loadRinex(); + obs_t obs; + loadRinex(obs); Observations observations; @@ -44,19 +44,20 @@ TEST(ObservationsTest, AddClearObservation) // Add duplicated observation (has to crash) observations.addObservation(obs.data[0]); - ASSERT_DEATH(observations.addObservation(obs.data[0]),""); + ASSERT_DEATH(observations.addObservation(obs.data[0]), ""); } TEST(ObservationsTest, LoadFromRinex) { + // RTKLIB utilities + obs_t obs; + loadRinex(obs); + // GnssUtils utilities Observations observations; observations.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); - observations.print(); - // RTKLIB utilities - loadRinex(); - ASSERT_EQ(obs.n, 6); + ASSERT_EQ(obs.n, 18); // Comparison ASSERT_TRUE(obs.n == observations.getObservations().size()); @@ -70,7 +71,8 @@ TEST(ObservationsTest, LoadFromRinex) TEST(ObservationsTest, GetObservationBySat) { - loadRinex(); + obs_t obs; + loadRinex(obs); Observations observations; observations.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); @@ -79,39 +81,44 @@ TEST(ObservationsTest, GetObservationBySat) { ASSERT_TRUE(obs.data[ii] == observations.getObservationBySat(obs.data[ii].sat)); } + free(obs.data); } TEST(ObservationsTest, GetObservationByIdx) { - loadRinex(); + obs_t obs; + loadRinex(obs); Observations observations; observations.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); for (int ii = 0; ii < obs.n; ++ii) { - // We do this check like this because both loading functions load the rinex file and then sort the observations - ASSERT_TRUE( obs.data[ii] == observations.getObservationByIdx(ii)); + Observations::print(obs.data[ii]); + ASSERT_TRUE(obs.data[ii] == observations.getObservationByIdx(ii)); } } TEST(ObservationsTest, data) { - loadRinex(); + obs_t obs; + loadRinex(obs); Observations observations; observations.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); for (int ii = 0; ii < obs.n; ++ii) { - // We do this check like this because both loading functions load the rinex file and then sort the observations - ASSERT_TRUE( obs.data[ii] == observations.data()[ii]); + Observations::print(obs.data[ii]); + Observations::print(observations.data()[ii]); + ASSERT_TRUE(obs.data[ii] == observations.data()[ii]); } } TEST(ObservationsTest, HasSatellite) { - loadRinex(); + obs_t obs; + loadRinex(obs); Observations observations; observations.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); @@ -140,7 +147,6 @@ TEST(ObservationsTest, FindCommonObservations) ASSERT_TRUE(observations2 == common2); } - TEST(ObservationsTest, FindCommonObservationsRemoved) { Observations observations1; @@ -158,7 +164,6 @@ TEST(ObservationsTest, FindCommonObservationsRemoved) ASSERT_TRUE(common1 == common2); ASSERT_FALSE(observations1 == common1); ASSERT_TRUE(observations2 == common2); - } TEST(ObservationsTest, FindCommonObservationsChangeTime) @@ -170,7 +175,7 @@ TEST(ObservationsTest, FindCommonObservationsChangeTime) // Change time for (auto&& obs : observations2.getObservations()) { - obs.time.sec +=10; + obs.time.sec += 10; } Observations common1; @@ -184,29 +189,32 @@ TEST(ObservationsTest, FindCommonObservationsChangeTime) for (auto obs = common1.getObservations().begin(); obs != common1.getObservations().end(); ++obs) { - const obsd_t& obs1 = common1.getObservationBySat(obs->sat); - const obsd_t& obs2 = common2.getObservationBySat(obs->sat); - - ASSERT_FALSE(obs1.time == obs2.time); - ASSERT_TRUE(obs1.eventime == obs2.eventime); - ASSERT_TRUE(obs1.timevalid == obs2.timevalid); - ASSERT_TRUE(obs1.sat == obs2.sat); - ASSERT_TRUE(obs1.rcv == obs2.rcv); - ASSERT_TRUE(memcmp(obs1.SNR, obs2.SNR, sizeof(obs1.SNR)) == 0); - ASSERT_TRUE(memcmp(obs1.LLI, obs2.LLI, sizeof(obs1.LLI)) == 0); - ASSERT_TRUE(memcmp(obs1.code, obs2.code, sizeof(obs1.code)) == 0); - ASSERT_TRUE(memcmp(obs1.qualL, obs2.qualL, sizeof(obs1.qualL)) == 0); - ASSERT_TRUE(memcmp(obs1.qualP, obs2.qualP, sizeof(obs1.qualP)) == 0); - ASSERT_TRUE(obs1.freq == obs2.freq); - ASSERT_TRUE(equalArray<double>(obs1.L, obs2.L, sizeof(obs1.L) / sizeof(obs1.L[0]), sizeof(obs2.L) / sizeof(obs2.L[0]))); - ASSERT_TRUE(equalArray<double>(obs1.P, obs2.P, sizeof(obs1.P) / sizeof(obs1.P[0]), sizeof(obs2.P) / sizeof(obs2.P[0]))); - ASSERT_TRUE(equalArray<float>(obs1.D, obs2.D, sizeof(obs1.D) / sizeof(obs1.D[0]), sizeof(obs2.D) / sizeof(obs2.D[0]))); + const obsd_t& obs1 = common1.getObservationBySat(obs->sat); + const obsd_t& obs2 = common2.getObservationBySat(obs->sat); + + ASSERT_FALSE(obs1.time == obs2.time); + ASSERT_TRUE(obs1.eventime == obs2.eventime); + ASSERT_TRUE(obs1.timevalid == obs2.timevalid); + ASSERT_TRUE(obs1.sat == obs2.sat); + ASSERT_TRUE(obs1.rcv == obs2.rcv); + ASSERT_TRUE(memcmp(obs1.SNR, obs2.SNR, sizeof(obs1.SNR)) == 0); + ASSERT_TRUE(memcmp(obs1.LLI, obs2.LLI, sizeof(obs1.LLI)) == 0); + ASSERT_TRUE(memcmp(obs1.code, obs2.code, sizeof(obs1.code)) == 0); + ASSERT_TRUE(memcmp(obs1.qualL, obs2.qualL, sizeof(obs1.qualL)) == 0); + ASSERT_TRUE(memcmp(obs1.qualP, obs2.qualP, sizeof(obs1.qualP)) == 0); + ASSERT_TRUE(obs1.freq == obs2.freq); + ASSERT_TRUE( + equalArray<double>(obs1.L, obs2.L, sizeof(obs1.L) / sizeof(obs1.L[0]), sizeof(obs2.L) / sizeof(obs2.L[0]))); + ASSERT_TRUE( + equalArray<double>(obs1.P, obs2.P, sizeof(obs1.P) / sizeof(obs1.P[0]), sizeof(obs2.P) / sizeof(obs2.P[0]))); + ASSERT_TRUE( + equalArray<float>(obs1.D, obs2.D, sizeof(obs1.D) / sizeof(obs1.D[0]), sizeof(obs2.D) / sizeof(obs2.D[0]))); } } int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); - //rnx_file = argv[1]; + // rnx_file = argv[1]; return RUN_ALL_TESTS(); } -- GitLab