Skip to content

Commit ad98ddf

Browse files
add initializer for device props (#2392)
1 parent 5c9f969 commit ad98ddf

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

sdk/inc/azure/iot/az_iot_adu_client.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ typedef struct
130130

131131
/**
132132
* @brief Holds the ADU agent device properties.
133+
*
134+
* az_iot_adu_client_device_properties_default() must be called to first initialize the
135+
* device properties.
136+
*
133137
* @remarks These properties are used by the ADU service for matching
134138
* update groups and verifying the current update deployed.
135139
* https://docs.microsoft.com/azure/iot-hub-device-update/device-update-plug-and-play
@@ -455,6 +459,15 @@ typedef struct
455459
*/
456460
AZ_NODISCARD az_iot_adu_client_options az_iot_adu_client_options_default();
457461

462+
/**
463+
* @brief Gets the default #az_iot_adu_client_device_properties.
464+
* @details Call this to obtain an initialized #az_iot_adu_client_device_properties structure that
465+
* can be afterwards modified and passed to necessary APIs.
466+
*
467+
* @return #az_iot_adu_client_device_properties.
468+
*/
469+
AZ_NODISCARD az_iot_adu_client_device_properties az_iot_adu_client_device_properties_default();
470+
458471
/**
459472
* @brief Initializes an Azure IoT ADU Client.
460473
*

sdk/src/azure/iot/az_iot_adu_client.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ AZ_NODISCARD az_iot_adu_client_options az_iot_adu_client_options_default()
101101
= default_compatibility_properties };
102102
}
103103

104+
AZ_NODISCARD az_iot_adu_client_device_properties az_iot_adu_client_device_properties_default()
105+
{
106+
return (az_iot_adu_client_device_properties){ .manufacturer = AZ_SPAN_LITERAL_EMPTY,
107+
.model = AZ_SPAN_LITERAL_EMPTY,
108+
.custom_properties = NULL,
109+
.adu_version = AZ_SPAN_LITERAL_EMPTY,
110+
.delivery_optimization_agent_version
111+
= AZ_SPAN_LITERAL_EMPTY,
112+
.update_id = AZ_SPAN_LITERAL_EMPTY };
113+
}
114+
104115
AZ_NODISCARD az_result
105116
az_iot_adu_client_init(az_iot_adu_client* client, az_iot_adu_client_options* options)
106117
{

sdk/tests/iot/adu/test_az_iot_adu.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ static uint8_t expected_agent_state_long_payload_with_retry[]
5656
"\"installedUpdateId\":\"{\\\"provider\\\":\\\"Contoso\\\",\\\"name\\\":\\\"Foobar\\\","
5757
"\\\"version\\\":\\\"1.0\\\"}\"}}}";
5858

59-
az_iot_adu_client_device_properties adu_device_properties
60-
= { .manufacturer = AZ_SPAN_LITERAL_FROM_STR(TEST_ADU_DEVICE_MANUFACTURER),
61-
.model = AZ_SPAN_LITERAL_FROM_STR(TEST_ADU_DEVICE_MODEL),
62-
.adu_version = AZ_SPAN_LITERAL_FROM_STR(TEST_AZ_IOT_ADU_CLIENT_AGENT_VERSION),
63-
.delivery_optimization_agent_version = AZ_SPAN_LITERAL_EMPTY,
64-
.update_id = AZ_SPAN_LITERAL_FROM_STR(TEST_ADU_DEVICE_UPDATE_ID) };
59+
// Initialized in setup() below.
60+
static az_iot_adu_client_device_properties adu_device_properties;
6561

6662
static uint8_t send_response_valid_payload[]
6763
= "{\"deviceUpdate\":{\"__t\":\"c\",\"service\":{\"ac\":200,\"av\":1,\"value\":{}}}}";
@@ -457,6 +453,20 @@ static uint8_t file_url_contoso[]
457453
"westus2/contoso-adu-instance--contoso-adu/9f9bdc01a5cd49c09e79e35505a913c5/"
458454
"contoso-v1.1.bin";
459455

456+
static int setup(void** state)
457+
{
458+
(void)state;
459+
460+
adu_device_properties = az_iot_adu_client_device_properties_default();
461+
adu_device_properties.manufacturer = AZ_SPAN_FROM_STR(TEST_ADU_DEVICE_MANUFACTURER);
462+
adu_device_properties.model = AZ_SPAN_FROM_STR(TEST_ADU_DEVICE_MODEL);
463+
adu_device_properties.adu_version = AZ_SPAN_FROM_STR(TEST_AZ_IOT_ADU_CLIENT_AGENT_VERSION);
464+
adu_device_properties.delivery_optimization_agent_version = AZ_SPAN_EMPTY;
465+
adu_device_properties.update_id = AZ_SPAN_FROM_STR(TEST_ADU_DEVICE_UPDATE_ID);
466+
467+
return 0;
468+
}
469+
460470
#ifndef AZ_NO_PRECONDITION_CHECKING
461471
ENABLE_PRECONDITION_CHECK_TESTS()
462472

@@ -1425,5 +1435,5 @@ int test_az_iot_adu()
14251435
cmocka_unit_test(test_az_iot_adu_client_parse_update_manifest_payload_too_many_file_ids_fail),
14261436
cmocka_unit_test(test_az_iot_adu_client_parse_update_manifest_payload_too_many_total_files_fail)
14271437
};
1428-
return cmocka_run_group_tests_name("az_iot_adu", tests, NULL, NULL);
1438+
return cmocka_run_group_tests_name("az_iot_adu", tests, setup, NULL);
14291439
}

0 commit comments

Comments
 (0)