@@ -27,7 +27,7 @@ struct DDimY
2727
2828extern " C" {
2929
30- void test_ddc_expose ()
30+ void test_ddc_expose_chunk ()
3131{
3232 // pdi_chunk_label_rank
3333 void * pdi_chunk_label_rank_ptr;
@@ -70,7 +70,7 @@ void test_ddc_expose()
7070
7171TEST (Pdi, ChunkAndChunkSpan)
7272{
73- std::string const pdi_cfg = R"PDI_CFG(
73+ char const * const pdi_cfg = R"PDI_CFG(
7474metadata:
7575 pdi_chunk_label_rank: size_t
7676 pdi_chunk_label_extents:
@@ -89,10 +89,10 @@ TEST(Pdi, ChunkAndChunkSpan)
8989 user_code:
9090 on_event:
9191 some_event:
92- test_ddc_expose : {}
92+ test_ddc_expose_chunk : {}
9393)PDI_CFG" ;
9494
95- PC_tree_t pdi_conf = PC_parse_string (pdi_cfg. c_str () );
95+ PC_tree_t pdi_conf = PC_parse_string (pdi_cfg);
9696 PDI_init (pdi_conf);
9797
9898 PDI_errhandler (PDI_NULL_HANDLER);
@@ -127,3 +127,70 @@ TEST(Pdi, ChunkAndChunkSpan)
127127 PDI_finalize ();
128128 PC_tree_destroy (&pdi_conf);
129129}
130+
131+ extern " C" {
132+
133+ void test_ddc_expose_c_string ()
134+ {
135+ // c_string_size
136+ void * c_string_size_ptr;
137+ ASSERT_EQ (PDI_access (" c_string_size" , &c_string_size_ptr, PDI_IN), PDI_OK);
138+ std::size_t const * const c_string_size = static_cast <std::size_t *>(c_string_size_ptr);
139+ ASSERT_EQ (*c_string_size, 3 );
140+
141+ // c_string
142+ void * c_string_ptr;
143+ ASSERT_EQ (PDI_access (" c_string" , &c_string_ptr, PDI_IN), PDI_OK);
144+ std::string_view const c_string (
145+ static_cast <char *>(c_string_ptr),
146+ static_cast <char *>(c_string_ptr) + *c_string_size);
147+ EXPECT_EQ (c_string, " foo" );
148+
149+ EXPECT_EQ (PDI_reclaim (" c_string_size" ), PDI_OK);
150+ EXPECT_EQ (PDI_reclaim (" c_string" ), PDI_OK);
151+
152+ // nb_event_called
153+ void * nb_event_called_ptr;
154+ ASSERT_EQ (PDI_access (" nb_event_called" , &nb_event_called_ptr, PDI_INOUT), PDI_OK);
155+ int * const nb_event_called = static_cast <int *>(nb_event_called_ptr);
156+ *nb_event_called += 1 ;
157+
158+ EXPECT_EQ (PDI_reclaim (" nb_event_called" ), PDI_OK);
159+ }
160+ }
161+
162+ TEST (Pdi, CString)
163+ {
164+ char const * const pdi_cfg = R"PDI_CFG(
165+ metadata:
166+ c_string_size: size_t
167+ c_string: {type: array, subtype: char, size: "$c_string_size"}
168+
169+ data:
170+ nb_event_called: int
171+
172+ plugins:
173+ user_code:
174+ on_event:
175+ some_event:
176+ test_ddc_expose_c_string: {}
177+ )PDI_CFG" ;
178+
179+ PC_tree_t pdi_conf = PC_parse_string (pdi_cfg);
180+ PDI_init (pdi_conf);
181+
182+ PDI_errhandler (PDI_NULL_HANDLER);
183+
184+ {
185+ int nb_event_called = 0 ;
186+
187+ ddc::PdiEvent (" some_event" )
188+ .with (" c_string" , " foo" )
189+ .with (" nb_event_called" , nb_event_called);
190+
191+ EXPECT_EQ (nb_event_called, 1 );
192+ }
193+
194+ PDI_finalize ();
195+ PC_tree_destroy (&pdi_conf);
196+ }
0 commit comments