@@ -163,14 +163,11 @@ static int s_test_mqtt_append_sdk_metrics_empty(struct aws_allocator *allocator,
163163 (void )ctx ;
164164
165165 struct aws_mqtt_iot_sdk_metrics metrics = {{0 }};
166- struct aws_mqtt_iot_sdk_metrics_storage * metrics_storage =
167- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & metrics );
168166
169167 struct aws_byte_buf output_username ;
170168 AWS_ZERO_STRUCT (output_username );
171169
172- ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (allocator , NULL , metrics_storage , & output_username , NULL ));
173- aws_mqtt_iot_sdk_metrics_storage_destroy (metrics_storage );
170+ ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (allocator , NULL , & metrics , & output_username , NULL ));
174171
175172 struct aws_byte_cursor output_cursor = aws_byte_cursor_from_buf (& output_username );
176173
@@ -199,17 +196,14 @@ static int s_test_mqtt_append_sdk_metrics_basic(struct aws_allocator *allocator,
199196 // .metadata_entries = NULL,
200197 // .metadata_count = 0,
201198 };
202- struct aws_mqtt_iot_sdk_metrics_storage * metrics_storage =
203- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & metrics );
204199
205200 struct aws_byte_buf output_username ;
206201 AWS_ZERO_STRUCT (output_username );
207202
208203 struct aws_byte_cursor original_username = aws_byte_cursor_from_c_str ("TEST_USERNAME" );
209204
210- ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (
211- allocator , & original_username , metrics_storage , & output_username , NULL ));
212- aws_mqtt_iot_sdk_metrics_storage_destroy (metrics_storage );
205+ ASSERT_SUCCESS (
206+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & metrics , & output_username , NULL ));
213207
214208 struct aws_byte_cursor output_cursor = aws_byte_cursor_from_buf (& output_username );
215209
@@ -238,18 +232,15 @@ static int s_test_mqtt_append_sdk_metrics_existing_attributes(struct aws_allocat
238232 // .metadata_entries = NULL,
239233 // .metadata_count = 0,
240234 };
241- struct aws_mqtt_iot_sdk_metrics_storage * metrics_storage =
242- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & metrics );
243235
244236 struct aws_byte_buf output_username ;
245237 AWS_ZERO_STRUCT (output_username );
246238
247239 struct aws_byte_cursor original_username =
248240 aws_byte_cursor_from_c_str ("user?SDK=ExistingSDK&Platform=ExistingPlatform" );
249241
250- ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (
251- allocator , & original_username , metrics_storage , & output_username , NULL ));
252- aws_mqtt_iot_sdk_metrics_storage_destroy (metrics_storage );
242+ ASSERT_SUCCESS (
243+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & metrics , & output_username , NULL ));
253244
254245 struct aws_byte_cursor output_cursor = aws_byte_cursor_from_buf (& output_username );
255246
@@ -266,17 +257,14 @@ static int s_test_mqtt_append_sdk_metrics_special_chars(struct aws_allocator *al
266257 (void )ctx ;
267258
268259 struct aws_mqtt_iot_sdk_metrics metrics = {.library_name = aws_byte_cursor_from_c_str ("SDK/Test-1.0" )};
269- struct aws_mqtt_iot_sdk_metrics_storage * metrics_storage =
270- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & metrics );
271260
272261 struct aws_byte_buf output_username ;
273262 AWS_ZERO_STRUCT (output_username );
274263
275264 struct aws_byte_cursor original_username = aws_byte_cursor_from_c_str ("user@domain.com" );
276265
277- ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (
278- allocator , & original_username , metrics_storage , & output_username , NULL ));
279- aws_mqtt_iot_sdk_metrics_storage_destroy (metrics_storage );
266+ ASSERT_SUCCESS (
267+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & metrics , & output_username , NULL ));
280268
281269 struct aws_byte_cursor output_cursor = aws_byte_cursor_from_buf (& output_username );
282270
@@ -309,27 +297,20 @@ static int s_test_mqtt_append_sdk_metrics_long_strings(struct aws_allocator *all
309297 long_sdk_name [sizeof (long_sdk_name ) - 1 ] = '\0' ;
310298
311299 struct aws_mqtt_iot_sdk_metrics metrics = {.library_name = aws_byte_cursor_from_c_str (long_sdk_name )};
312- struct aws_mqtt_iot_sdk_metrics_storage * metrics_storage =
313- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & metrics );
314300
315301 struct aws_mqtt_iot_sdk_metrics short_metrics = {.library_name = aws_byte_cursor_from_c_str ("SHORT_SDK_NAME" )};
316- struct aws_mqtt_iot_sdk_metrics_storage * short_metrics_storage =
317- aws_mqtt_iot_sdk_metrics_storage_new (allocator , & short_metrics );
318302
319303 struct aws_byte_buf output_username ;
320304 AWS_ZERO_STRUCT (output_username );
321305
322306 struct aws_byte_cursor original_username = aws_byte_cursor_from_c_str (long_username );
323307
324308 // aws_mqtt_append_sdk_metrics_to_username does not valid original username length
325- ASSERT_SUCCESS (aws_mqtt_append_sdk_metrics_to_username (
326- allocator , & original_username , short_metrics_storage , & output_username , NULL ));
327- aws_mqtt_iot_sdk_metrics_storage_destroy (short_metrics_storage );
328-
309+ ASSERT_SUCCESS (
310+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & short_metrics , & output_username , NULL ));
329311 // aws_mqtt_append_sdk_metrics_to_username fails when the extra metrics string exceeds buffer limit
330- ASSERT_FAILS (aws_mqtt_append_sdk_metrics_to_username (
331- allocator , & original_username , metrics_storage , & output_username , NULL ));
332- aws_mqtt_iot_sdk_metrics_storage_destroy (metrics_storage );
312+ ASSERT_FAILS (
313+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & metrics , & output_username , NULL ));
333314
334315 aws_byte_buf_clean_up (& output_username );
335316
@@ -347,8 +328,17 @@ static int s_test_mqtt_append_sdk_metrics_invalid_utf8(struct aws_allocator *all
347328
348329 struct aws_mqtt_iot_sdk_metrics metrics = {.library_name = invalid_utf8_library };
349330
331+ struct aws_byte_buf output_username ;
332+ AWS_ZERO_STRUCT (output_username );
333+
334+ struct aws_byte_cursor original_username = aws_byte_cursor_from_c_str ("testuser" );
335+
350336 /* Should fail due to invalid UTF-8 */
351- ASSERT_FAILS (aws_mqtt_validate_iot_sdk_metrics (& metrics ));
337+ ASSERT_FAILS (
338+ aws_mqtt_append_sdk_metrics_to_username (allocator , & original_username , & metrics , & output_username , NULL ));
339+ ASSERT_INT_EQUALS (aws_last_error (), AWS_ERROR_INVALID_UTF8 );
340+
341+ aws_byte_buf_clean_up (& output_username );
352342
353343 return AWS_OP_SUCCESS ;
354344}
0 commit comments