From 6e921fa3685ccda0e8df6d0414b0c28d8cffe5ac Mon Sep 17 00:00:00 2001 From: Christian Vetter Date: Thu, 20 Jun 2024 09:58:48 +0200 Subject: [PATCH] Do not print stats about each resource if the whole archive failed to open Signed-off-by: Christian Vetter --- flatdata-cpp/src/Archive.cpp | 12 ++-- flatdata-cpp/test/CMakeLists.txt | 2 + flatdata-cpp/test/GeneratedArchiveTest.cpp | 81 ++++++++++------------ 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/flatdata-cpp/src/Archive.cpp b/flatdata-cpp/src/Archive.cpp index 2c5c9fe3..4fb7a83c 100644 --- a/flatdata-cpp/src/Archive.cpp +++ b/flatdata-cpp/src/Archive.cpp @@ -243,15 +243,16 @@ Archive::describe( size_t nest_level ) const if ( is_root_node ) { result << hline << "FATAL: Resource storage not initialized. Please check archive path." - << newl; + << newl << hline; } else { - result << "Uninitialized Archive " << name( ); + result << "Uninitialized Archive " << name( ) << newl; } + return result.str( ); } - if ( m_storage && !m_signature ) + if ( !m_signature ) { result << ( is_root_node ? hline : empty ) << "FATAL: Archive signature does not match software expectations." @@ -259,9 +260,10 @@ Archive::describe( size_t nest_level ) const result << compute_diff( schema( ), m_storage->read_schema( internal::signature_name( name( ) ).c_str( ) ).char_ptr( ) ); + return result.str( ); } - if ( m_storage && !m_is_open ) + if ( !m_is_open ) { // Error propagated to root and storage is not initialized in respective child. No root // check needed. @@ -282,7 +284,7 @@ Archive::describe( size_t nest_level ) const { const std::string indent( ( nest_level - 1 ) * TAB_WIDTH, ' ' ); result << newl + indent + std::string( "|" ) + newl + indent + std::string( "|->" ) - << " Flatdata Archive: " << name( ) << std::endl; + << " Flatdata Archive: " << name( ) << newl; } describe_resources( result, nest_level ); diff --git a/flatdata-cpp/test/CMakeLists.txt b/flatdata-cpp/test/CMakeLists.txt index eb4c34d9..b04604be 100644 --- a/flatdata-cpp/test/CMakeLists.txt +++ b/flatdata-cpp/test/CMakeLists.txt @@ -21,6 +21,8 @@ target_include_directories(flatdata_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor ) +target_compile_definitions(flatdata_test PRIVATE CATCH_CONFIG_CONSOLE_WIDTH=120) + target_link_libraries(flatdata_test flatdata ${CMAKE_THREAD_LIBS_INIT} diff --git a/flatdata-cpp/test/GeneratedArchiveTest.cpp b/flatdata-cpp/test/GeneratedArchiveTest.cpp index 35d236e6..5230e203 100644 --- a/flatdata-cpp/test/GeneratedArchiveTest.cpp +++ b/flatdata-cpp/test/GeneratedArchiveTest.cpp @@ -361,9 +361,6 @@ Resource Optional Too Large Loaded Details outer1 NO NO YES Structure of size 1 outer2 NO NO YES Structure of size 1 inner NO NO NO Uninitialized Archive InnerArchive -| -|-> Flatdata Archive: InnerArchive - inner NO NO NO Uninitialized Structure AStruct ================================================================================ )data"; @@ -395,9 +392,44 @@ Resource Optional Too Large Loaded Details ================================================================================ outer NO NO YES Structure of size 1 archive_resource YES NO NO Uninitialized Archive InnerArchive +================================================================================ +)data"; + + REQUIRE( outer.describe( ) == expected ); +} + +TEMPLATE_TEST_CASE_METHOD( + Fixture, "Sub-archives are described", "[GeneratedArchive]", std::true_type, std::false_type ) +{ + { + auto outer_builder = OuterArchiveBuilder::open( Fixture< TestType >::storage ); + CHECK( outer_builder ); + + flatdata::Struct< AStruct > o; + outer_builder.set_outer1( *o ); + outer_builder.set_outer2( *o ); + + auto inner_builder = outer_builder.inner( ); + CHECK( inner_builder ); + inner_builder.set_inner( *o ); + } + + auto outer = OuterArchive::open( Fixture< TestType >::storage ); + REQUIRE( outer.is_open( ) ); + REQUIRE( outer.inner( ).is_open( ) ); + + const char* const expected + = R"data(================================================================================ +Flatdata Archive: OuterArchive +================================================================================ +Resource Optional Too Large Loaded Details +================================================================================ +outer1 NO NO YES Structure of size 1 +outer2 NO NO YES Structure of size 1 +inner NO NO YES | |-> Flatdata Archive: InnerArchive - inner NO NO NO Uninitialized Structure AStruct + inner NO NO YES Structure of size 1 ================================================================================ )data"; @@ -531,16 +563,6 @@ TEST_CASE( "Describe ouputs fatal errors", "[GeneratedArchive]" ) R"data(================================================================================ FATAL: Resource storage not initialized. Please check archive path. ================================================================================ -Flatdata Archive: SimpleResources -================================================================================ -Resource Optional Too Large Loaded Details -================================================================================ -object_resource NO NO NO Uninitialized Structure AStruct -vector_resource NO NO NO Uninitialized Array -multivector_resource NO NO NO Uninitialized MultiArray -raw_data_resource NO NO NO Uninitialized Raw data -optional_resource YES NO NO Uninitialized Raw data -================================================================================ )data"; REQUIRE( archive.describe( ) == expected ); @@ -604,24 +626,6 @@ FATAL: Archive signature does not match software expectations. "}" "}" ... -================================================================================ -FATAL: Archive initialization failed. Failed loading mandatory resources. -================================================================================ -Flatdata Archive: OutermostArchive -================================================================================ -Resource Optional Too Large Loaded Details -================================================================================ -outermost NO NO NO Uninitialized Structure AStruct -outer NO NO NO Uninitialized Archive OuterArchive -| -|-> Flatdata Archive: OuterArchive - outer1 NO NO NO Uninitialized Structure AStruct - outer2 NO NO NO Uninitialized Structure AStruct - inner NO NO NO Uninitialized Archive InnerArchive - | - |-> Flatdata Archive: InnerArchive - inner NO NO NO Uninitialized Structure AStruct -================================================================================ )"; REQUIRE( description == expectation ); } @@ -668,19 +672,6 @@ FATAL: Archive signature does not match software expectations. "}" "}" ... -================================================================================ -FATAL: Archive initialization failed. Failed loading mandatory resources. -================================================================================ -Flatdata Archive: OuterWithOptional -================================================================================ -Resource Optional Too Large Loaded Details -================================================================================ -outer NO NO NO Uninitialized Structure AStruct -archive_resource YES NO NO Uninitialized Archive InnerArchive -| -|-> Flatdata Archive: InnerArchive - inner NO NO NO Uninitialized Structure AStruct -================================================================================ )"; REQUIRE( description == expectation ); }