Skip to content

Commit 83943b1

Browse files
authored
Do not print stats about each resource if the whole archive failed to open (#244)
Signed-off-by: Christian Vetter <christian.vetter@here.com>
1 parent 2df1b1e commit 83943b1

3 files changed

Lines changed: 45 additions & 50 deletions

File tree

‎flatdata-cpp/src/Archive.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,25 +243,27 @@ Archive::describe( size_t nest_level ) const
243243
if ( is_root_node )
244244
{
245245
result << hline << "FATAL: Resource storage not initialized. Please check archive path."
246-
<< newl;
246+
<< newl << hline;
247247
}
248248
else
249249
{
250-
result << "Uninitialized Archive " << name( );
250+
result << "Uninitialized Archive " << name( ) << newl;
251251
}
252+
return result.str( );
252253
}
253254

254-
if ( m_storage && !m_signature )
255+
if ( !m_signature )
255256
{
256257
result << ( is_root_node ? hline : empty )
257258
<< "FATAL: Archive signature does not match software expectations."
258259
<< ( is_root_node ? newl : empty ) << hline;
259260
result << compute_diff(
260261
schema( ),
261262
m_storage->read_schema( internal::signature_name( name( ) ).c_str( ) ).char_ptr( ) );
263+
return result.str( );
262264
}
263265

264-
if ( m_storage && !m_is_open )
266+
if ( !m_is_open )
265267
{
266268
// Error propagated to root and storage is not initialized in respective child. No root
267269
// check needed.
@@ -282,7 +284,7 @@ Archive::describe( size_t nest_level ) const
282284
{
283285
const std::string indent( ( nest_level - 1 ) * TAB_WIDTH, ' ' );
284286
result << newl + indent + std::string( "|" ) + newl + indent + std::string( "|->" )
285-
<< " Flatdata Archive: " << name( ) << std::endl;
287+
<< " Flatdata Archive: " << name( ) << newl;
286288
}
287289

288290
describe_resources( result, nest_level );

‎flatdata-cpp/test/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ target_include_directories(flatdata_test
2121
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../vendor
2222
)
2323

24+
target_compile_definitions(flatdata_test PRIVATE CATCH_CONFIG_CONSOLE_WIDTH=120)
25+
2426
target_link_libraries(flatdata_test
2527
flatdata
2628
${CMAKE_THREAD_LIBS_INIT}

‎flatdata-cpp/test/GeneratedArchiveTest.cpp‎

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,6 @@ Resource Optional Too Large Loaded Details
361361
outer1 NO NO YES Structure of size 1
362362
outer2 NO NO YES Structure of size 1
363363
inner NO NO NO Uninitialized Archive InnerArchive
364-
|
365-
|-> Flatdata Archive: InnerArchive
366-
inner NO NO NO Uninitialized Structure AStruct
367364
================================================================================
368365
)data";
369366

@@ -395,9 +392,44 @@ Resource Optional Too Large Loaded Details
395392
================================================================================
396393
outer NO NO YES Structure of size 1
397394
archive_resource YES NO NO Uninitialized Archive InnerArchive
395+
================================================================================
396+
)data";
397+
398+
REQUIRE( outer.describe( ) == expected );
399+
}
400+
401+
TEMPLATE_TEST_CASE_METHOD(
402+
Fixture, "Sub-archives are described", "[GeneratedArchive]", std::true_type, std::false_type )
403+
{
404+
{
405+
auto outer_builder = OuterArchiveBuilder::open( Fixture< TestType >::storage );
406+
CHECK( outer_builder );
407+
408+
flatdata::Struct< AStruct > o;
409+
outer_builder.set_outer1( *o );
410+
outer_builder.set_outer2( *o );
411+
412+
auto inner_builder = outer_builder.inner( );
413+
CHECK( inner_builder );
414+
inner_builder.set_inner( *o );
415+
}
416+
417+
auto outer = OuterArchive::open( Fixture< TestType >::storage );
418+
REQUIRE( outer.is_open( ) );
419+
REQUIRE( outer.inner( ).is_open( ) );
420+
421+
const char* const expected
422+
= R"data(================================================================================
423+
Flatdata Archive: OuterArchive
424+
================================================================================
425+
Resource Optional Too Large Loaded Details
426+
================================================================================
427+
outer1 NO NO YES Structure of size 1
428+
outer2 NO NO YES Structure of size 1
429+
inner NO NO YES
398430
|
399431
|-> Flatdata Archive: InnerArchive
400-
inner NO NO NO Uninitialized Structure AStruct
432+
inner NO NO YES Structure of size 1
401433
================================================================================
402434
)data";
403435

@@ -531,16 +563,6 @@ TEST_CASE( "Describe ouputs fatal errors", "[GeneratedArchive]" )
531563
R"data(================================================================================
532564
FATAL: Resource storage not initialized. Please check archive path.
533565
================================================================================
534-
Flatdata Archive: SimpleResources
535-
================================================================================
536-
Resource Optional Too Large Loaded Details
537-
================================================================================
538-
object_resource NO NO NO Uninitialized Structure AStruct
539-
vector_resource NO NO NO Uninitialized Array
540-
multivector_resource NO NO NO Uninitialized MultiArray
541-
raw_data_resource NO NO NO Uninitialized Raw data
542-
optional_resource YES NO NO Uninitialized Raw data
543-
================================================================================
544566
)data";
545567

546568
REQUIRE( archive.describe( ) == expected );
@@ -604,24 +626,6 @@ FATAL: Archive signature does not match software expectations.
604626
"}"
605627
"}"
606628
...
607-
================================================================================
608-
FATAL: Archive initialization failed. Failed loading mandatory resources.
609-
================================================================================
610-
Flatdata Archive: OutermostArchive
611-
================================================================================
612-
Resource Optional Too Large Loaded Details
613-
================================================================================
614-
outermost NO NO NO Uninitialized Structure AStruct
615-
outer NO NO NO Uninitialized Archive OuterArchive
616-
|
617-
|-> Flatdata Archive: OuterArchive
618-
outer1 NO NO NO Uninitialized Structure AStruct
619-
outer2 NO NO NO Uninitialized Structure AStruct
620-
inner NO NO NO Uninitialized Archive InnerArchive
621-
|
622-
|-> Flatdata Archive: InnerArchive
623-
inner NO NO NO Uninitialized Structure AStruct
624-
================================================================================
625629
)";
626630
REQUIRE( description == expectation );
627631
}
@@ -668,19 +672,6 @@ FATAL: Archive signature does not match software expectations.
668672
"}"
669673
"}"
670674
...
671-
================================================================================
672-
FATAL: Archive initialization failed. Failed loading mandatory resources.
673-
================================================================================
674-
Flatdata Archive: OuterWithOptional
675-
================================================================================
676-
Resource Optional Too Large Loaded Details
677-
================================================================================
678-
outer NO NO NO Uninitialized Structure AStruct
679-
archive_resource YES NO NO Uninitialized Archive InnerArchive
680-
|
681-
|-> Flatdata Archive: InnerArchive
682-
inner NO NO NO Uninitialized Structure AStruct
683-
================================================================================
684675
)";
685676
REQUIRE( description == expectation );
686677
}

0 commit comments

Comments
 (0)