if (config == NULL)
return NULL;
+ config->scanner_url = NULL;
+ config->username = NULL;
+
config->scanner_url = malloc(sizeof(char));
+ if (config->scanner_url == NULL) {
+ kds_s2000w_config_free(config);
+ config = NULL;
+ return NULL;
+ }
+
config->username = malloc(sizeof(char));
+ if (config->username == NULL) {
+ kds_s2000w_config_free(config);
+ config = NULL;
+ return NULL;
+ }
*config->scanner_url = '\0';
*config->username = '\0';
config->log_level = 0;
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
+#include "kds_s2000w_client_mock.h"
#include "../src/kds_s2000w_config.h"
+void _kds_s2000w_config_no_mem(int16_t no_mem_counter)
+{
+ const char* input_stream = "profile = 1\n";
+
+ set_no_mem_counter(no_mem_counter);
+ program_config_t* config = kds_s2000w_config_load(input_stream);
+
+ assert_null(config);
+}
+
void kds_s2000w_config_null_test()
{
program_config_t* config = kds_s2000w_config_load(NULL);
config = NULL;
}
+void kds_s2000w_config_load_no_mem_test()
+{
+ for (int16_t i = 0; i < 3; i++) {
+ _kds_s2000w_config_no_mem(i);
+ }
+}
+
int main()
{
const struct CMUnitTest read_config[] = {
cmocka_unit_test(kds_s2000w_config_heartbeat_five_seconds_test),
cmocka_unit_test(kds_s2000w_config_default_heartbeat_zero_set_default_test),
cmocka_unit_test(kds_s2000w_config_ssl_verify_on_test),
- cmocka_unit_test(kds_s2000w_config_profile_test)
+ cmocka_unit_test(kds_s2000w_config_profile_test),
+ cmocka_unit_test(kds_s2000w_config_load_no_mem_test)
};
return cmocka_run_group_tests(read_config, NULL, NULL);