@@ -429,6 +429,81 @@ static struct ctrace *generate_encoder_test_data()
429429 return context ;
430430}
431431
432+ static int generate_sample_resource_minimal_attributes (struct ctrace_resource * resource )
433+ {
434+ struct ctrace_attributes * attributes ;
435+ int result ;
436+
437+ attributes = ctr_attributes_create ();
438+
439+ if (attributes == NULL ) {
440+ return -1 ;
441+ }
442+
443+ result = ctr_attributes_set_string (attributes , "receiver.tool" , "ctraces" );
444+
445+ if (result != 0 ) {
446+ ctr_attributes_destroy (attributes );
447+
448+ return -2 ;
449+ }
450+
451+ result = ctr_resource_set_attributes (resource , attributes );
452+
453+ if (result != 0 ) {
454+ ctr_attributes_destroy (attributes );
455+
456+ return -3 ;
457+ }
458+
459+ return 0 ;
460+ }
461+
462+ static struct ctrace * generate_encoder_test_data_with_empty_spans ()
463+ {
464+ struct ctrace_resource_span * resource_span ;
465+ struct ctrace_scope_span * scope_span ;
466+ struct ctrace * context ;
467+ int result ;
468+
469+ context = ctr_create (NULL );
470+
471+ if (context == NULL ) {
472+ return NULL ;
473+ }
474+
475+ resource_span = ctr_resource_span_create (context );
476+
477+ if (resource_span == NULL ) {
478+ ctr_destroy (context );
479+
480+ return NULL ;
481+ }
482+
483+ ctr_resource_span_set_schema_url (resource_span , "" );
484+ ctr_resource_set_dropped_attr_count (resource_span -> resource , 0 );
485+
486+ result = generate_sample_resource_minimal_attributes (resource_span -> resource );
487+
488+ if (result != 0 ) {
489+ ctr_destroy (context );
490+
491+ return NULL ;
492+ }
493+
494+ scope_span = ctr_scope_span_create (resource_span );
495+
496+ if (scope_span == NULL ) {
497+ ctr_destroy (context );
498+
499+ return NULL ;
500+ }
501+
502+ ctr_scope_span_set_schema_url (scope_span , "" );
503+
504+ return context ;
505+ }
506+
432507/*
433508 * perform the following and then compare text buffers
434509 *
@@ -483,6 +558,24 @@ void test_msgpack_to_cmt()
483558 ctr_destroy (context );
484559}
485560
561+ void test_msgpack_to_ctr_with_empty_spans ()
562+ {
563+ struct ctrace * context ;
564+ char * referece_text_buffer ;
565+
566+ context = generate_encoder_test_data_with_empty_spans ();
567+ TEST_ASSERT (context != NULL );
568+
569+ referece_text_buffer = ctr_encode_text_create (context );
570+ TEST_ASSERT (referece_text_buffer != NULL );
571+
572+ printf ("%s\n" , referece_text_buffer );
573+ msgpack_encode_decode_and_compare (context );
574+
575+ ctr_encode_text_destroy (referece_text_buffer );
576+ ctr_destroy (context );
577+ }
578+
486579void test_simple_to_msgpack_and_back ()
487580{
488581 struct ctrace * ctx ;
@@ -640,5 +733,6 @@ void test_simple_to_msgpack_and_back()
640733TEST_LIST = {
641734 {"cmt_simple_to_msgpack_and_back" , test_simple_to_msgpack_and_back },
642735 {"cmt_msgpack" , test_msgpack_to_cmt },
736+ {"empty_spans" , test_msgpack_to_ctr_with_empty_spans },
643737 { 0 }
644738};
0 commit comments