Skip to content
Snippets Groups Projects
Commit 6e23cc07 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

added some tests and configured config.h.in for ROOT_DIR

parent 98d8f446
No related branches found
No related tags found
2 merge requests!20new tag,!19new tag
...@@ -39,9 +39,37 @@ endif() ...@@ -39,9 +39,37 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
# Testing
IF(NOT BUILD_TESTS) IF(NOT BUILD_TESTS)
OPTION(BUILD_TESTS "Build Unit tests" ON) OPTION(BUILD_TESTS "Build Unit tests" ON)
ENDIF(NOT BUILD_TESTS) ENDIF(NOT BUILD_TESTS)
if(BUILD_TESTS)
# Enables testing for this directory and below.
# Note that ctest expects to find a test file in the build directory root.
# Therefore, this command should be in the source directory root.
#include(CTest) # according to http://public.kitware.com/pipermail/cmake/2012-June/050853.html
MESSAGE("Building tests.")
enable_testing()
set(_GNSS_UTILS_ROOT_DIR ${CMAKE_SOURCE_DIR})
endif()
# Define the directory where will be the configured config.h
SET(GNSS_UTILS_CONFIG_DIR ${PROJECT_BINARY_DIR}/conf/gnss_utils/internal)
# Create the specified output directory if it does not exist.
IF(NOT EXISTS "${GNSS_UTILS_CONFIG_DIR}")
message(STATUS "Creating config output directory: ${GNSS_UTILS_CONFIG_DIR}")
file(MAKE_DIRECTORY "${GNSS_UTILS_CONFIG_DIR}")
ENDIF()
IF(EXISTS "${GNSS_UTILS_CONFIG_DIR}" AND NOT IS_DIRECTORY "${GNSS_UTILS_CONFIG_DIR}")
message(FATAL_ERROR "Bug: Specified CONFIG_DIR: "
"${GNSS_UTILS_CONFIG_DIR} exists, but is not a directory.")
ENDIF()
# Configure config.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/internal/config.h.in "${GNSS_UTILS_CONFIG_DIR}/config.h")
message("GNSS_UTILS CONFIG ${GNSS_UTILS_CONFIG_DIR}/config.h")
message("CONFIG DIRECTORY ${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_BINARY_DIR}/conf")
# rtklib path # rtklib path
SET(RTKLIB_DIR deps/RTKLIB) SET(RTKLIB_DIR deps/RTKLIB)
...@@ -87,7 +115,6 @@ SET(RTKLIB_SRC ...@@ -87,7 +115,6 @@ SET(RTKLIB_SRC
${RTKLIB_SRC_DIR}/rcv/tersus.c ${RTKLIB_SRC_DIR}/rcv/tersus.c
${RTKLIB_SRC_DIR}/rcv/ublox.c) ${RTKLIB_SRC_DIR}/rcv/ublox.c)
# application header files # application header files
SET(HEADERS SET(HEADERS
include/gnss_utils/utils/utils.h include/gnss_utils/utils/utils.h
...@@ -119,6 +146,13 @@ INCLUDE_DIRECTORIES(include/ ${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${RTKLI ...@@ -119,6 +146,13 @@ INCLUDE_DIRECTORIES(include/ ${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${RTKLI
ADD_LIBRARY(gnss_utils SHARED ${SOURCES} ${RTKLIB_SRC}) ADD_LIBRARY(gnss_utils SHARED ${SOURCES} ${RTKLIB_SRC})
TARGET_LINK_LIBRARIES(gnss_utils ${Boost_LIBRARIES}) TARGET_LINK_LIBRARIES(gnss_utils ${Boost_LIBRARIES})
# Examples
ADD_SUBDIRECTORY(src/examples)
# Testing
if(BUILD_TESTS)
add_subdirectory(test)
endif()
# Installing # Installing
INSTALL(TARGETS ${PROJECT_NAME} INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
...@@ -126,23 +160,8 @@ INSTALL(TARGETS ${PROJECT_NAME} ...@@ -126,23 +160,8 @@ INSTALL(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib/iri-algorithms) ARCHIVE DESTINATION lib/iri-algorithms)
INSTALL(FILES ${HEADERS} DESTINATION include/iri-algorithms/gnss_utils) INSTALL(FILES ${HEADERS} DESTINATION include/iri-algorithms/gnss_utils)
INSTALL(FILES Findgnss_utils.cmake DESTINATION ${CMAKE_ROOT}/Modules/) INSTALL(FILES Findgnss_utils.cmake DESTINATION ${CMAKE_ROOT}/Modules/)
INSTALL(FILES "${WOLF_CONFIG_DIR}/config.h"
DESTINATION include/iri-algorithms/gnss_utils/internal)
# Examples
ADD_SUBDIRECTORY(src/examples)
if(BUILD_TESTS)
# Enables testing for this directory and below.
# Note that ctest expects to find a test file in the build directory root.
# Therefore, this command should be in the source directory root.
#include(CTest) # according to http://public.kitware.com/pipermail/cmake/2012-June/050853.html
MESSAGE("Building tests.")
enable_testing()
endif()
# Testing
if(BUILD_TESTS)
add_subdirectory(test)
endif()
FIND_PACKAGE(Doxygen) FIND_PACKAGE(Doxygen)
......
...@@ -68,6 +68,8 @@ public: ...@@ -68,6 +68,8 @@ public:
Observations& common_obs_1, Observations& common_obs_1,
Observations& common_obs_2); Observations& common_obs_2);
bool operator==(const Observations& other_obs) const;
private: private:
// Private objects // Private objects
std::map<unsigned char, int> sat_2_idx_; //< key: corresponding sat number, value: idx in obs_ vector std::map<unsigned char, int> sat_2_idx_; //< key: corresponding sat number, value: idx in obs_ vector
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <string> #include <string>
#include "gnss_utils/internal/config.h"
#define ARRAY_SIZE(arr) sizeof(arr) / sizeof(arr[0]) #define ARRAY_SIZE(arr) sizeof(arr) / sizeof(arr[0])
#define GNSSUTILS_MSG "--GnssUtils--" #define GNSSUTILS_MSG "--GnssUtils--"
...@@ -42,4 +43,4 @@ bool equalObservations(const obs_t& obs1, const obs_t& obs2); ...@@ -42,4 +43,4 @@ bool equalObservations(const obs_t& obs1, const obs_t& obs2);
} // namespace GnssUtils } // namespace GnssUtils
#endif // INCLUDE_GNSS_UTILS_UTILS_UTILS_H_ #endif // INCLUDE_GNSS_UTILS_UTILS_UTILS_H_
\ No newline at end of file
#ifndef GNSS_UTILS_INTERNAL_CONFIG_H_
#define GNSS_UTILS_INTERNAL_CONFIG_H_
#cmakedefine _GNSS_UTILS_DEBUG
#cmakedefine _GNSS_UTILS_TRACE
#define _GNSS_UTILS_ROOT_DIR "${_GNSS_UTILS_ROOT_DIR}"
#endif /* GNSS_UTILS_INTERNAL_CONFIG_H_ */
...@@ -218,3 +218,18 @@ void Observations::findCommonObservations(const Observations& obs_1, ...@@ -218,3 +218,18 @@ void Observations::findCommonObservations(const Observations& obs_1,
// std::cout << (int)obs_2_ref.sat << " "; // std::cout << (int)obs_2_ref.sat << " ";
// std::cout << std::endl; // std::cout << std::endl;
} }
bool Observations::operator ==(const Observations &other_obs) const
{
if (sat_2_idx_ != other_obs.sat_2_idx_)
return false;
if (idx_2_sat_ != other_obs.idx_2_sat_)
return false;
for (auto i = 0; i < obs_.size(); i++)
if (!equalObservations(obs_.at(i), other_obs.obs_.at(i)))
return false;
return true;
}
...@@ -17,7 +17,5 @@ gnss_utils_add_gtest(gtest_transformations gtest_transformations.cpp) ...@@ -17,7 +17,5 @@ gnss_utils_add_gtest(gtest_transformations gtest_transformations.cpp)
target_link_libraries(gtest_transformations ${PROJECT_NAME}) target_link_libraries(gtest_transformations ${PROJECT_NAME})
# Observations test # Observations test
add_executable(gtest_observations gtest_observations.cpp) gnss_utils_add_gtest(gtest_observations gtest_observations.cpp)
add_dependencies(gtest_observations libgtest) target_link_libraries(gtest_observations libgtest ${PROJECT_NAME})
target_link_libraries(gtest_observations libgtest ${PROJECT_NAME}) \ No newline at end of file
add_test(NAME gtest_observations COMMAND gtest_observations "${CMAKE_CURRENT_LIST_DIR}/../src/examples/sample_data.obs")
This diff is collapsed.
3.04 OBSERVATION DATA M RINEX VERSION / TYPE
sbf2rin-13.4.3 20200205 113408 UTC PGM / RUN BY / DATE
SEPT MARKER NAME
Unknown MARKER NUMBER
Unknown Unknown OBSERVER / AGENCY
3021420 SEPT ASTERX-M2 4.4.0 REC # / TYPE / VERS
Unknown Unknown ANT # / TYPE
4789398.3686 176958.8129 4194502.0999 APPROX POSITION XYZ
0.0000 0.0000 0.0000 ANTENNA: DELTA H/E/N
G 7 X1 C1C L1C C2W L2W C2L L2L SYS / # / OBS TYPES
E 7 X1 C1C L1C C5Q L5Q C7Q L7Q SYS / # / OBS TYPES
S 3 X1 C1C L1C SYS / # / OBS TYPES
R 5 X1 C1C L1C C2C L2C SYS / # / OBS TYPES
C 5 X1 C2I L2I C7I L7I SYS / # / OBS TYPES
SEPTENTRIO RECEIVERS OUTPUT ALIGNED CARRIER PHASES. COMMENT
NO FURTHER PHASE SHIFT APPLIED IN THE RINEX ENCODER. COMMENT
G L1C SYS / PHASE SHIFT
G L2W SYS / PHASE SHIFT
G L2L 0.00000 SYS / PHASE SHIFT
E L1C 0.00000 SYS / PHASE SHIFT
E L5Q 0.00000 SYS / PHASE SHIFT
E L7Q 0.00000 SYS / PHASE SHIFT
S L1C SYS / PHASE SHIFT
R L1C SYS / PHASE SHIFT
R L2C SYS / PHASE SHIFT
C L2I SYS / PHASE SHIFT
C L7I SYS / PHASE SHIFT
0.050 INTERVAL
2019 12 12 11 37 42.0000000 GPS TIME OF FIRST OBS
2019 12 12 11 45 12.9000000 GPS TIME OF LAST OBS
36 # OF SATELLITES
C1C 0.000 C2C 0.000 GLONASS COD/PHS/BIS
8 R03 5 R05 1 R13 -2 R14 -7 R15 0 R19 3 R20 2 R21 4 GLONASS SLOT / FRQ #
END OF HEADER
> 2019 12 12 11 37 42.0000000 0 23
C05 16.000 40138840.659 6 209013478.40606 40138832.256 6 161622441.87406
C10 17.000 39633104.355 5 206379985.90205 39633100.852 6 159586077.69206
C23 18.000 22865676.301 8 119067585.90908
C32 19.000 22153454.599 8 115358921.19508
C37 20.000 23690566.611 7 123363010.77907
E01 11.000 26311074.676 7 138265636.53007 26311074.470 5 103250320.19005 26311070.977 7 105943790.57907
E09 12.000 25723493.482 5
E12 13.000 24803095.627 5 130341141.55605 24803092.768 4 97332661.71504 24803092.407 6 99871767.93506
E19 14.000 24540665.652 6 128962068.93606 24540664.837 5 96302837.53105 24540661.694 6 98815075.63606
E21 15.000 25609802.251 7 134580416.73507 25609802.381 7 100498367.38007 25609799.519 7 103120055.01507
G02 1.000 22032430.127 5
G06 2.000 22147435.410 6 116385570.45206 22147437.095 4 90690045.24704 22147437.422 7 90690046.16907
G07 3.000 20902411.481 8 109842911.60108 20902406.002 6 85591857.15006 20902406.930 7 85591857.16507
G09 4.000 21908403.525 6 115129430.37406 21908399.544 1 89711233.32401 21908399.320 5
G23 5.000 24104714.314 6 126671129.49306 24104706.816 2 98704739.67602
G30 6.000 21404145.095 8 112479542.93308 21404142.953 6 87646388.26706 21404143.916 7 87646383.27307
R03 7.000 21945110.617 7 117474090.63807 21945109.720 6 91368580.68606
R14 8.000 20214975.526 8 107757316.39008 20214976.579 7 83811176.41707
R15 9.000 22699008.378 5 121296675.96005 22699009.712 5 94341922.34705
R19 10.000 22853592.745 4 22853590.888 4
S23 21.000 38309228.895 7 201316353.13407
S25 22.000 37834172.957 6 198818604.39206
S36 23.000 37630702.258 7 197750698.01307
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#include "gnss_utils/observations.h" #include "gnss_utils/observations.h"
using namespace GnssUtils; using namespace GnssUtils;
std::string rnx_file = std::string(_GNSS_UTILS_ROOT_DIR) + "/test/data/sample_data.obs";
std::string rnx_file;
obs_t obs; obs_t obs;
const gtime_t t_start{ 0, 0 }; // no limit const gtime_t t_start{ 0, 0 }; // no limit
const gtime_t t_end{ 0, 0 }; // no limit const gtime_t t_end{ 0, 0 }; // no limit
...@@ -42,6 +41,10 @@ TEST(ObservationsTest, AddClearObservation) ...@@ -42,6 +41,10 @@ TEST(ObservationsTest, AddClearObservation)
// Testing clear // Testing clear
observations.clearObservations(); observations.clearObservations();
ASSERT_TRUE(0 == observations.getObservations().size()); ASSERT_TRUE(0 == observations.getObservations().size());
// Add duplicated observation (has to crash)
observations.addObservation(obs.data[0]);
//ASSERT_DEATH(observations.addObservation(obs.data[0]),"");
} }
TEST(ObservationsTest, LoadFromRinex) TEST(ObservationsTest, LoadFromRinex)
...@@ -57,7 +60,6 @@ TEST(ObservationsTest, LoadFromRinex) ...@@ -57,7 +60,6 @@ TEST(ObservationsTest, LoadFromRinex)
// Comparison // Comparison
ASSERT_TRUE(obs.n == observations.getObservations().size()); ASSERT_TRUE(obs.n == observations.getObservations().size());
for (int ii = 0; ii < obs.n; ++ii) for (int ii = 0; ii < obs.n; ++ii)
{ {
ASSERT_TRUE(equalObservations(obs.data[ii], observations.getObservations()[ii])); ASSERT_TRUE(equalObservations(obs.data[ii], observations.getObservations()[ii]));
...@@ -122,28 +124,89 @@ TEST(ObservationsTest, HasSatellite) ...@@ -122,28 +124,89 @@ TEST(ObservationsTest, HasSatellite)
TEST(ObservationsTest, FindCommonObservations) TEST(ObservationsTest, FindCommonObservations)
{ {
loadRinex(); Observations observations1;
observations1.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt);
Observations observations2(observations1);
ASSERT_TRUE(observations1 == observations2);
Observations common1;
Observations common2;
Observations::findCommonObservations(observations1, observations2, common1, common2);
ASSERT_TRUE(common1 == common2);
ASSERT_TRUE(observations1 == common1);
ASSERT_TRUE(observations2 == common2);
}
TEST(ObservationsTest, FindCommonObservationsRemoved)
{
Observations observations1; Observations observations1;
observations1.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt); observations1.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt);
Observations observations2(observations1); Observations observations2(observations1);
// Remove first observation of observations2
observations2.removeObservationByIdx(0);
Observations common1; Observations common1;
Observations common2; Observations common2;
Observations::findCommonObservations(observations1, observations2, common1, common2); Observations::findCommonObservations(observations1, observations2, common1, common2);
ASSERT_TRUE(common1 == common2);
ASSERT_FALSE(observations1 == common1);
ASSERT_TRUE(observations2 == common2);
}
TEST(ObservationsTest, FindCommonObservationsChangeTime)
{
Observations observations1;
observations1.loadFromRinex(rnx_file.c_str(), t_start, t_end, dt, opt);
Observations observations2(observations1);
// Change time
for (auto&& obs : observations2.getObservations())
{
obs.time.sec +=10;
}
Observations common1;
Observations common2;
Observations::findCommonObservations(observations1, observations2, common1, common2);
ASSERT_FALSE(common1 == common2);
ASSERT_TRUE(observations1 == common1);
ASSERT_TRUE(observations2 == common2);
for (auto obs = common1.getObservations().begin(); obs != common1.getObservations().end(); ++obs) for (auto obs = common1.getObservations().begin(); obs != common1.getObservations().end(); ++obs)
{ {
ASSERT_TRUE(equalObservations(common1.getObservationBySat(obs->sat), common2.getObservationBySat(obs->sat))); const obsd_t& obs1 = common1.getObservationBySat(obs->sat);
ASSERT_TRUE(equalObservations(observations1.getObservationBySat(obs->sat), common1.getObservationBySat(obs->sat))); const obsd_t& obs2 = common2.getObservationBySat(obs->sat);
ASSERT_TRUE(equalObservations(observations2.getObservationBySat(obs->sat), common2.getObservationBySat(obs->sat)));
ASSERT_FALSE(equalTime(obs1.time, obs2.time));
ASSERT_TRUE(equalTime(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) int main(int argc, char** argv)
{ {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
rnx_file = argv[1]; //rnx_file = argv[1];
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment