int test_init(void) { kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); if (error || !logger) { return error; } kaa_context.logger = logger; error = kaa_status_create(&status); if (error || !status) { return error; } error = kaa_channel_manager_create(&channel_manager, &kaa_context); if (error || !channel_manager) { return error; } error = kaa_user_manager_create(&user_manager, status, channel_manager, logger); if (error || !user_manager) { return error; } kaa_attachment_status_listeners_t listeners = { NULL, &on_attached, &on_detached, &on_attach_success, &on_attach_failed }; error = kaa_user_manager_set_attachment_listeners(user_manager, &listeners); if (error) { return error; } return 0; }
int test_init(void) { kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); if (error || !logger) { return error; } kaa_context.logger = logger; error = kaa_status_create(&status); if (error || !status) { return error; } error = kaa_channel_manager_create(&channel_manager, &kaa_context); if (error || !channel_manager) { return error; } /* Add channel will fail due to absent access point, but it is expected */ kaa_channel_manager_add_transport_channel(channel_manager, &channel, NULL); error = kaa_profile_manager_create(&profile_manager, status, channel_manager, logger); if (error || !profile_manager) { return error; } return 0; }
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger) { // TODO(KAA-982): use asserts if (!context_p || !logger) { return KAA_ERR_BADPARAM; } kaa_context_t *context = KAA_CALLOC(1, sizeof(*context)); if (!context) { return KAA_ERR_NOMEM; } context->logger = logger; kaa_error_t error = KAA_ERR_NONE; context->status = KAA_CALLOC(1, sizeof(*context->status)); if (!context->status) { error = KAA_ERR_NOMEM; goto exit; } error = kaa_status_create(&context->status->status_instance); if (error) { goto exit; } error = kaa_platform_protocol_create(&context->platform_protocol, context->logger, context->status->status_instance); if (error) { goto exit; } error = kaa_channel_manager_create(&context->channel_manager, context); if (error) { goto exit; } error = kaa_extension_init_all(context); if (error) { goto exit; } error = kaa_failover_strategy_create(&context->failover_strategy, logger); if (error) { goto extensions_deinit; } *context_p = context; return KAA_ERR_NONE; extensions_deinit: kaa_extension_deinit_all(); exit: kaa_context_destroy(context); return error; }
void test_status_persistense(void) { KAA_TRACE_IN(logger); kaa_status_t *status; kaa_error_t err_code = kaa_status_create(&status); ASSERT_NULL(status->endpoint_access_token); ASSERT_EQUAL(status->event_seq_n, 0); ASSERT_FALSE(status->is_attached); ASSERT_FALSE(status->is_registered); ASSERT_FALSE(status->is_updated); ASSERT_EQUAL(kaa_status_set_endpoint_access_token(status, "my_token"), KAA_ERR_NONE); ASSERT_EQUAL(ext_copy_sha_hash(status->endpoint_public_key_hash, test_ep_key_hash), KAA_ERR_NONE); ASSERT_EQUAL(ext_copy_sha_hash(status->profile_hash, test_profile_hash), KAA_ERR_NONE); status->is_attached = true; status->is_registered = true; status->is_updated = true; status->event_seq_n = 10; err_code = kaa_status_save(status); ASSERT_EQUAL(err_code, KAA_ERR_NONE); kaa_status_destroy(status); status = NULL; err_code = kaa_status_create(&status); ASSERT_NOT_NULL(status->endpoint_access_token); ASSERT_EQUAL(strcmp("my_token", status->endpoint_access_token), 0); ASSERT_EQUAL(status->event_seq_n, 10); ASSERT_TRUE(status->is_attached); ASSERT_TRUE(status->is_registered); ASSERT_TRUE(status->is_updated); ASSERT_EQUAL(memcmp(test_ep_key_hash, status->endpoint_public_key_hash, SHA_1_DIGEST_LENGTH), 0); ASSERT_EQUAL(memcmp(test_profile_hash, status->profile_hash, SHA_1_DIGEST_LENGTH), 0); kaa_status_destroy(status); }
void test_create_status(void) { KAA_TRACE_IN(logger); kaa_status_t *status; kaa_error_t err_code = kaa_status_create(&status); ASSERT_EQUAL(err_code, KAA_ERR_NONE); ASSERT_NOT_NULL(status); kaa_status_destroy(status); }
int test_init(void) { kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); if (error || !logger) { return error; } error = kaa_status_create(&status); if (error || !status) { return error; } return 0; }
int test_init(void) { kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); if (error || !logger) return error; #ifndef KAA_DISABLE_FEATURE_CONFIGURATION error = kaa_status_create(&status); if (error || !status) return error; error = kaa_configuration_manager_create(&config_manager, NULL, status, logger); if (error || config_manager) return error; #endif return 0; }
int test_init(void) { kaa_error_t error = kaa_log_create(&logger, KAA_MAX_LOG_MESSAGE_LENGTH, KAA_MAX_LOG_LEVEL, NULL); if (error || !logger) { return error; } kaa_context.logger = logger; error = kaa_status_create(&status); if (error || !status) { return error; } error = kaa_channel_manager_create(&channel_manager, &kaa_context); if (error || !channel_manager) { return error; } return 0; }
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger) { KAA_RETURN_IF_NIL2(context_p, logger, KAA_ERR_BADPARAM); *context_p = (kaa_context_t *) KAA_MALLOC(sizeof(kaa_context_t)); KAA_RETURN_IF_NIL(*context_p, KAA_ERR_NOMEM); (*context_p)->logger = logger; kaa_error_t error = KAA_ERR_NONE; (*context_p)->status = (kaa_status_holder_t *) KAA_MALLOC(sizeof(kaa_status_holder_t)); if (!(*context_p)->status) error = KAA_ERR_NOMEM; if (!error) error = kaa_status_create(&((*context_p)->status->status_instance)); if (!error) error = kaa_platform_protocol_create(&((*context_p)->platfrom_protocol), *context_p, (*context_p)->status->status_instance); if (!error) error = kaa_channel_manager_create(&((*context_p)->channel_manager), (*context_p)); if (!error) error = kaa_bootstrap_manager_create(&((*context_p)->bootstrap_manager), (*context_p)->channel_manager, (*context_p)->logger); if (!error) error = kaa_profile_manager_create(&((*context_p)->profile_manager), (*context_p)->status->status_instance, (*context_p)->channel_manager, (*context_p)->logger); #ifndef KAA_DISABLE_FEATURE_EVENTS if (!error) error = kaa_event_manager_create(&((*context_p)->event_manager), (*context_p)->status->status_instance, (*context_p)->channel_manager, (*context_p)->logger); #else (*context_p)->event_manager = NULL; #endif #ifndef KAA_DISABLE_FEATURE_LOGGING if (!error) error = kaa_log_collector_create(&((*context_p)->log_collector), (*context_p)->status->status_instance, (*context_p)->channel_manager, (*context_p)->logger); #else (*context_p)->log_collector = NULL; #endif #ifndef KAA_DISABLE_FEATURE_CONFIGURATION if (!error) error = kaa_configuration_manager_create(&((*context_p)->configuration_manager), (*context_p)->channel_manager, (*context_p)->status->status_instance, (*context_p)->logger); #else (*context_p)->configuration_manager = NULL; #endif if (!error) error = kaa_user_manager_create(&((*context_p)->user_manager), (*context_p)->status->status_instance, (*context_p)->channel_manager, (*context_p)->logger); if (error) { kaa_context_destroy(*context_p); *context_p = NULL; } return error; }
static kaa_error_t kaa_context_create(kaa_context_t **context_p, kaa_logger_t *logger) { KAA_RETURN_IF_NIL2(context_p, logger, KAA_ERR_BADPARAM); kaa_context_t *context = KAA_MALLOC(sizeof(*context)); KAA_RETURN_IF_NIL(context, KAA_ERR_NOMEM); context->logger = logger; kaa_error_t error = KAA_ERR_NONE; context->status = KAA_MALLOC(sizeof(*context->status)); if (!context->status) error = KAA_ERR_NOMEM; if (!error) error = kaa_status_create(&context->status->status_instance); if (!error) error = kaa_platform_protocol_create(&context->platform_protocol, context, context->status->status_instance); if (!error) error = kaa_channel_manager_create(&context->channel_manager, context); if (!error) error = kaa_bootstrap_manager_create(&context->bootstrap_manager, context); if (!error) error = kaa_profile_manager_create(&context->profile_manager, context->status->status_instance, context->channel_manager, context->logger); if (!error) error = kaa_failover_strategy_create(&context->failover_strategy, logger); #ifndef KAA_DISABLE_FEATURE_EVENTS if (!error) error = kaa_event_manager_create(&context->event_manager, context->status->status_instance, context->channel_manager, context->logger); #else context->event_manager = NULL; #endif #ifndef KAA_DISABLE_FEATURE_LOGGING if (!error) error = kaa_log_collector_create(&context->log_collector, context->status->status_instance, context->channel_manager, context->logger); #else context->log_collector = NULL; #endif #ifndef KAA_DISABLE_FEATURE_CONFIGURATION if (!error) error = kaa_configuration_manager_create(&context->configuration_manager, context->channel_manager, context->status->status_instance, context->logger); #else context->configuration_manager = NULL; #endif #ifndef KAA_DISABLE_FEATURE_NOTIFICATION if (!error) error = kaa_notification_manager_create(&context->notification_manager, context->status->status_instance, context->channel_manager, context->logger); #else context->notification_manager = NULL; #endif if (!error) error = kaa_user_manager_create(&context->user_manager, context->status->status_instance, context->channel_manager, context->logger); if (error) { kaa_context_destroy(context); *context_p = NULL; } else { *context_p = context; } return error; }