Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test Framework #103

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.8.0 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 17)

PROJECT ( libcitygml )

Expand Down Expand Up @@ -58,9 +60,9 @@ ENDIF(WIN32)
if(UNIX)
if(APPLE)
MESSAGE(STATUS "APPLE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
else(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

MESSAGE(STATUS "Setting UNIX compile flags: ${CMAKE_CXX_FLAGS}")
endif(APPLE)
Expand Down Expand Up @@ -152,6 +154,8 @@ OPTION(LIBCITYGML_TESTS "Set to ON to build libcitygml tests programs." ON)
IF (LIBCITYGML_TESTS)
enable_testing()
ADD_SUBDIRECTORY( test )

ADD_SUBDIRECTORY( systemTests )
ENDIF(LIBCITYGML_TESTS)


Expand Down
5 changes: 0 additions & 5 deletions CTestTestfile.cmake

This file was deleted.

4 changes: 2 additions & 2 deletions osgplugin/ReaderWriterCityGML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ class ReaderWriterCityGML : public osgDB::ReaderWriter

virtual ReadResult readNode( const std::string&, const osgDB::ReaderWriter::Options* ) const override;
virtual ReadResult readNode( std::istream&, const osgDB::ReaderWriter::Options* ) const override;
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
virtual ReadResult readObject(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const override
{
ReadResult result = readNode(fileName, options);
osg::Node* node = result.getNode();
if (node) return node;
else return result;
}

virtual ReadResult readObject(std::istream& fin, const Options* options) const
virtual ReadResult readObject(std::istream& fin, const Options* options) const override
{
ReadResult result = readNode(fin, options);
osg::Node* node = result.getNode();
Expand Down
24 changes: 24 additions & 0 deletions systemTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include(FetchContent)

if (NOT ${LIBCITYGML_STATIC_CRT})
set(gtest_force_shared_crt ON)
endif()

set(BUILD_GMOCK OFF)

FetchContent_Declare(
gtest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2)
FetchContent_MakeAvailable(gtest)

add_executable(citygmlSystemTests
systemTestsMain.cpp
FileReadTests.cpp
)

target_include_directories(citygmlSystemTests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../sources/include)

target_link_libraries(citygmlSystemTests PRIVATE citygml gtest)

install(TARGETS citygmlSystemTests RUNTIME DESTINATION ${BIN_INSTALL_DIR})
142 changes: 142 additions & 0 deletions systemTests/FileReadTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <citygml/citygml.h>
#include <citygml/citygml_api.h>
#include <citygml/citymodel.h>
#include <citygml/geometry.h>
#include <citygml/implictgeometry.h>
#ifdef LIBCITYGML_USE_OPENGL
#include <citygml/tesselator.h>
#endif

#include <gtest/gtest.h>

#include <fstream>
#include <memory>
#include <time.h>


namespace {
constexpr bool USE_STREAM = false;
constexpr bool LOG = false;

void printIndent(unsigned int indent) {
for ( unsigned int i = 0; i < indent; i++ ) std::cout << " ";
}

void printGeometry( const citygml::Geometry& geometry, unsigned int indent ) {
printIndent(indent);
std::cout << "Geometry for LOD" << geometry.getLOD() << ", type: " << geometry.getTypeAsString() << "\n";

if(geometry.getLineStringCount() > 0) {
printIndent(indent+1);
std::cout << "Linestrings:" << geometry.getLineStringCount() << "\n";
}

if(geometry.getPolygonsCount() > 0) {
printIndent(indent+1);
std::cout << "Polygons:" << geometry.getPolygonsCount() << "\n";
}

if(geometry.getGeometriesCount() > 0) {
printIndent(indent+1);
std::cout << "SubGeometries:" << "\n";
for( unsigned int i = 0; i < geometry.getGeometriesCount(); i++ ) {
printGeometry(geometry.getGeometry(i), indent+1);
}
}
}


void printImplicitGeometry( const citygml::ImplicitGeometry& implicitGeometry, unsigned int indent ) {
printIndent(indent);
std::cout << "Reference point " << implicitGeometry.getReferencePoint() << "\n";
for ( unsigned int i = 0; i < implicitGeometry.getGeometriesCount(); i++ ) {
printGeometry( implicitGeometry.getGeometry(i), indent+1 );
}
}

void analyzeObject( const citygml::CityObject& object, unsigned int indent ) {
printIndent(indent);
std::cout << "Object " << object.getTypeAsString() << ": " << object.getId() << "\n";

for ( unsigned int i = 0; i < object.getGeometriesCount(); i++ ) {
printGeometry( object.getGeometry(i), indent+1 );
}

for ( unsigned int i = 0; i < object.getImplicitGeometryCount(); i++ ) {
printImplicitGeometry( object.getImplicitGeometry(i), indent+1 );
}

for ( unsigned int i = 0; i < object.getChildCityObjectsCount(); i++ ) {
analyzeObject( object.getChildCityObject(i), indent+1 );
}
}

void readFile(char const* fileName) {
std::cout << "Parsing CityGML file " << fileName << " using libcitygml v." << LIBCITYGML_VERSIONSTR << "...\n";

time_t start;
time( &start );

std::unique_ptr<TesselatorBase> tesselator;
#ifdef LIBCITYGML_USE_OPENGL
tesselator.reset(new Tesselator(nullptr));
#endif

citygml::ParserParams params;
std::shared_ptr<const citygml::CityModel> city;
try{
if constexpr (USE_STREAM) {
std::ifstream file;
file.open( fileName, std::ifstream::in );
std::shared_ptr<const citygml::CityModel> city = citygml::load( file, params, std::move(tesselator) );
} else {
city = citygml::load( fileName, params, std::move(tesselator) );
}
} catch(const std::runtime_error&){
FAIL();
}

time_t end;
time( &end );

std::cout << "Done in " << difftime( end, start ) << " seconds.\n";

if (!city) {
FAIL();
}

if constexpr (LOG) {
std::cout << "Analyzing the city objects...\n";

for (auto const& cityObject : city->getRootCityObjects()) {
std::cout << " Found " << cityObject->getTypeAsString() << "...\n";
std::cout << " + found object id " << cityObject->getId() << "\n";
if (cityObject->getChildCityObjectsCount() > 0) {
std::cout << " + with " << cityObject->getChildCityObjectsCount() << " children\n";
}
std::cout << " + with " << cityObject->getGeometriesCount() << " geometr" << ( ( cityObject->getGeometriesCount() > 1 ) ? "ies\n" : "y\n" );
std::cout << " + with " << cityObject->getImplicitGeometryCount() << " implicit geometr" << ( ( cityObject->getImplicitGeometryCount() > 1 ) ? "ies\n" : "y\n" );
}
}

if constexpr (LOG) {
std::cout << std::endl << "Objects hierarchy:\n";
const citygml::ConstCityObjects& roots = city->getRootCityObjects();
for ( unsigned int i = 0; i < roots.size(); i++ ) analyzeObject( *(roots[ i ]), 2 );
}

std::cout << "Done.\n";
}
} // anonymous namespace

TEST(FileReadTests, berlin_open_data_sample_data) {
readFile("../../data/berlin_open_data_sample_data.citygml");
}

TEST(FileReadTests, b1_lod2_s) {
readFile("../../data/b1_lod2_s.gml");
}

TEST(FileRedTests, FZK_Haus_LoD0_KIT_IAI_KHH_B36_V1) {
readFile("../../data/FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml");
}
8 changes: 8 additions & 0 deletions systemTests/systemTestsMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#include "gtest/gtest.h"


int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ endif(NOT DEFINED BIN_INSTALL_DIR)
install(TARGETS citygmltest RUNTIME DESTINATION ${BIN_INSTALL_DIR})


add_test(NAME System_Tests COMMAND citygmlSystemTests)
add_test(NAME berlin_open_data_sample_data COMMAND citygmltest ../../data/berlin_open_data_sample_data.citygml)
add_test(NAME b1_lod2_s COMMAND citygmltest ../../data/b1_lod2_s.gml)
add_test(NAME FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1 COMMAND citygmltest ../../data/FZK-Haus-LoD0-KIT-IAI-KHH-B36-V1.gml)
Loading