/*
 * Test Check bootstrap channel sync call.
 * 1. Set access point, check connect and authorize sending CONNECT and receiving CONNACK
 * 2. Receive Bootstrap Kaa Sync message.
 * 3. Send disconnect, check sending.
 * 4. Check socket close.
 * 5. Call sync
 * 6. Check connect and authorize sending CONNECT and receiving CONNACK
 * 7. Receive Bootstrap Kaa Sync message.
 * 8. Send disconnect, check sending.
 * 9. Check socket close.
 */
void test_bootstrap_sync_success(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    //Set access point and imitate start of connection to destination
    test_set_access_point(channel);

    //Check standard bootstrap flow (connect, authenticate, sync receive and disconnect)
    test_check_bootstrap_sync(channel);


    //Imitate sync call
    channel->sync_handler(channel->context, bootstrap_services, 1);

    //Check standard bootstrap flow (connect, authenticate, sync receive and disconnect)
    test_check_bootstrap_sync(channel);

    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
예제 #2
0
void test_profile_update(void)
{
    KAA_TRACE_IN(logger);

    char* pattern = "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3";

    kaa_error_t err;
    char* body = "test";
    kaa_digest calculated_hash;

    err = ext_calculate_sha_hash(NULL, 50, calculated_hash);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);
    err = ext_calculate_sha_hash(body, 0, calculated_hash);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);
    err = ext_calculate_sha_hash(body, 4, NULL);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = ext_calculate_sha_hash(body, 4, calculated_hash);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    char buf[SHA_1_DIGEST_LENGTH * 2 + 1];
    for (int i = 0; i < SHA_1_DIGEST_LENGTH; ++i) {
        sprintf(&buf[i * 2], "%02x", calculated_hash[i]);
    }

    ASSERT_EQUAL(0, memcmp(buf, pattern, SHA_1_DIGEST_LENGTH * 2));
}
void test_noop_decision_on_failure(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;

    size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024;
    size_t DEFAULT_UPLOAD_COUNT_THRESHOLD  = 64;

    error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_set_threshold_volume(strategy, DEFAULT_UPLOAD_VOLUME_THRESHOLD);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = ext_log_upload_strategy_set_threshold_count(strategy, DEFAULT_UPLOAD_COUNT_THRESHOLD);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_on_failure(NULL, NO_APPENDERS_CONFIGURED);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_on_failure(strategy, NO_APPENDERS_CONFIGURED);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    test_log_storage_context_t log_storage_context;
    ext_log_upload_decision_t upload_decision = NOOP;

    log_storage_context.total_size = DEFAULT_UPLOAD_VOLUME_THRESHOLD;
    log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD;
    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, NOOP);

    KAA_TRACE_OUT(logger);
}
예제 #4
0
파일: test_kaa_list.c 프로젝트: nthevu/kaa
void test_list_for_each()
{
    KAA_TRACE_IN(logger);

    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    int32_t *number1_ptr;
    int node_number = 4;
    for (int i = 0; i < node_number; ++i) {
        number1_ptr = (int32_t *)KAA_MALLOC(sizeof(int32_t *));
        ASSERT_NOT_NULL(number1_ptr);
        *number1_ptr = rand();
        kaa_list_push_back(list, number1_ptr);
    }

    int number2 = rand();
    kaa_list_for_each(kaa_list_begin(list), kaa_list_back(list), (process_data)&test_process_data, &number2);

    kaa_list_node_t *it = kaa_list_begin(list);
    while (it) {
        ASSERT_EQUAL(*(int32_t *)kaa_list_get_data(kaa_list_begin(list)), number2);
        it = kaa_list_next(it);
    }

    kaa_list_destroy(list, NULL);

    KAA_TRACE_OUT(logger);
}
void test_upload_decision_by_timeout(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;

    size_t DEFAULT_UPLOAD_TIMEOUT_THRESHOLD  = 1;// in sec.

    error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_BY_TIMEOUT_STRATEGY);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_set_upload_timeout(strategy, DEFAULT_UPLOAD_TIMEOUT_THRESHOLD);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    test_log_storage_context_t log_storage_context;
    ext_log_upload_decision_t upload_decision = NOOP;

    log_storage_context.total_size = 0;
    log_storage_context.record_count = 0;
    log_storage_context.upload_timeout = DEFAULT_UPLOAD_TIMEOUT_THRESHOLD;
    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, NOOP);

    log_storage_context.upload_timeout = DEFAULT_UPLOAD_TIMEOUT_THRESHOLD + 1;

    usleep(1000 * 1000);

    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, UPLOAD);

    KAA_TRACE_OUT(logger);
}
예제 #6
0
void test_allocate_log_record_buffer(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_allocate_log_record_buffer(storage, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_log_record_t record1 = { NULL, 0 };
    error_code = ext_log_storage_allocate_log_record_buffer(storage, &record1);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_NULL(record1.data);

    kaa_log_record_t record2 = { NULL, 256 };
    error_code = ext_log_storage_allocate_log_record_buffer(storage, &record2);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_NOT_NULL(record2.data);

    ext_log_storage_deallocate_log_record_buffer(storage, &record2);
    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
예제 #7
0
void test_meta_extension_get_size_failed(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = kaa_meta_data_request_get_size(NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);
}
예제 #8
0
void test_topic_list_listeners_adding_and_removing(void)
{
    KAA_TRACE_IN(context->logger);
    err = kaa_get_topics(context->notification_manager, &topics);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_topic_list_listener(context->notification_manager, &topic_listener, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_topic_list_listener(context->notification_manager, &topic_listener, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_topic_list_listener(context->notification_manager, &topic_listener_2, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_topic_list_listener(context->notification_manager, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_topic_list_listener(context->notification_manager, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_topic_list_listener(context->notification_manager, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    KAA_TRACE_OUT(context->logger);
}
예제 #9
0
void test_reallocation()
{
    KAA_TRACE_IN(logger);

    kaa_buffer_t *buffer_ptr;
    kaa_error_t error_code;

    error_code = kaa_buffer_create_buffer(&buffer_ptr, BUFFER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_buffer_lock_space(buffer_ptr, BUFFER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_buffer_lock_space(buffer_ptr, BUFFER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_BUFFER_IS_NOT_ENOUGH);

    error_code = kaa_buffer_reallocate_space(buffer_ptr, BUFFER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_buffer_lock_space(buffer_ptr, BUFFER_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_buffer_destroy(buffer_ptr);

    KAA_TRACE_OUT(logger);
}
예제 #10
0
void test_subscriptions(void)
{
    KAA_TRACE_IN(context->logger);

    err = kaa_subscribe_to_topic(context->notification_manager, &topic_id, false);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_unsubscribe_from_topic(context->notification_manager, &topic_id, false);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    uint64_t fake_ids[2] = { 22, 11 };
    err = kaa_subscribe_to_topics(context->notification_manager, fake_ids, 2, false);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_unsubscribe_from_topics(context->notification_manager, fake_ids, 2, false);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    uint64_t existing_ids[1] = { 22 };
    err = kaa_subscribe_to_topics(context->notification_manager, existing_ids, 1, false);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_unsubscribe_from_topics(context->notification_manager, existing_ids, 1, false);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    KAA_TRACE_OUT(context->logger);
}
void test_upload_decision_by_count(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;

    size_t DEFAULT_UPLOAD_COUNT_THRESHOLD  = 64;

    error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_BY_RECORD_COUNT);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_set_threshold_count(strategy, DEFAULT_UPLOAD_COUNT_THRESHOLD);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    test_log_storage_context_t log_storage_context;
    ext_log_upload_decision_t upload_decision = NOOP;

    log_storage_context.total_size = 0;
    log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD - 1;
    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, NOOP);

    log_storage_context.total_size = 0;
    log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD;
    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, UPLOAD);

    log_storage_context.total_size = 0;
    log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD + 1;
    upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context);
    ASSERT_EQUAL(upload_decision, UPLOAD);

    KAA_TRACE_OUT(logger);
}
예제 #12
0
void test_create_request(void)
{
    KAA_TRACE_IN(logger);

    size_t expected_size = 0;
    ASSERT_EQUAL(kaa_configuration_manager_get_size(config_manager, &expected_size), KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, sizeof(uint32_t) + KAA_EXTENSION_HEADER_SIZE + SHA_1_DIGEST_LENGTH);

    char request_buffer[expected_size];
    kaa_platform_message_writer_t *writer = NULL;
    ASSERT_EQUAL(kaa_platform_message_writer_create(&writer, request_buffer, expected_size), KAA_ERR_NONE);
    ASSERT_EQUAL(kaa_configuration_manager_request_serialize(config_manager, writer), KAA_ERR_NONE);

    char *cursor = writer->begin;
    ASSERT_EQUAL(*cursor, KAA_CONFIGURATION_EXTENSION_TYPE);
    cursor += sizeof(uint32_t);

    ASSERT_EQUAL(KAA_NTOHL(*((uint32_t *) cursor)), sizeof(uint32_t) + SHA_1_DIGEST_LENGTH);    // checking payload size
    cursor += sizeof(uint32_t);

    ASSERT_EQUAL(KAA_NTOHL(*((uint32_t *) cursor)), CONFIG_START_SEQ_N);    // checking sequence number
    cursor += sizeof(uint32_t);

    kaa_digest check_hash;
    ext_calculate_sha_hash(KAA_CONFIGURATION_DATA, KAA_CONFIGURATION_DATA_LENGTH, check_hash);  // checking configuration hash
    ASSERT_EQUAL(memcmp(cursor, check_hash, SHA_1_DIGEST_LENGTH), 0);
    cursor += SHA_1_DIGEST_LENGTH;

    ASSERT_EQUAL(cursor, writer->end);

    kaa_platform_message_writer_destroy(writer);
}
예제 #13
0
void test_add_log_record(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_count = 0;
    const char *data = "DATA";
    size_t data_size = strlen("DATA");

    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count);

    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count);
    ASSERT_EQUAL(ext_log_storage_get_total_size(storage), record_count * data_size);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
예제 #14
0
void test_profile_handle_sync(void)
{
    KAA_TRACE_IN(logger);

    bool need_resync = false;
    kaa_error_t error_code = KAA_ERR_NONE;
    uint16_t extension_options = 0x1; /* Need resync */

    const size_t buffer_size = 6;
    char buffer[buffer_size];
    kaa_platform_message_reader_t *reader;
    error_code = kaa_platform_message_reader_create(&reader, buffer, buffer_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_profile_handle_server_sync(profile_manager, reader, extension_options, 0);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = kaa_profile_need_profile_resync(profile_manager, &need_resync);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_TRUE(need_resync);

    extension_options = 0x0; /* Need resync */
    error_code = kaa_profile_handle_server_sync(profile_manager, reader, extension_options, 0);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    error_code = kaa_profile_need_profile_resync(profile_manager, &need_resync);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_FALSE(need_resync);

    kaa_platform_message_reader_destroy(reader);

    KAA_TRACE_OUT(logger);
}
예제 #15
0
파일: test_kaa_list.c 프로젝트: nthevu/kaa
void test_list_push_front()
{
    KAA_TRACE_IN(logger);

    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    int32_t *number;
    int node_number = 2;
    for (int i = 0; i < node_number; ++i) {
        number = (int32_t *)KAA_MALLOC(sizeof(int32_t *));
        ASSERT_NOT_NULL(number);
        *number = rand();
        kaa_list_push_front(list, number);
    }

    ASSERT_EQUAL(kaa_list_get_size(list), node_number);

    ASSERT_NOT_NULL(kaa_list_begin(list));
    ASSERT_NULL(kaa_list_prev(kaa_list_begin(list)));

    ASSERT_EQUAL((*(int32_t *)kaa_list_get_data(kaa_list_begin(list))), *number);

    kaa_list_destroy(list, NULL);

    KAA_TRACE_OUT(logger);
}
/*
 * Test IO error during operation.
 * 1. Set access point, check connect and authorize sending CONNECT and receiving CONNACK
 * 2. Imitate IO error on read
 * 3. Close socket, check bootstrap manager access point failure notification
 */
void test_set_access_point_io_error(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    //Set access point and imitate start of connection to destination
    test_set_access_point(channel);


    //Imitate WR event, and wait socket connect call, channel should start authorization, prepare
    //CONNECT message
    error_code = kaa_tcp_channel_process_event(channel,FD_WRITE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.socket_connected, true);
    ASSERT_EQUAL(access_point_test_info.socket_connected_callback, true);
    ASSERT_EQUAL(access_point_test_info.fill_connect_message, true);
    ASSERT_EQUAL(access_point_test_info.request_connect, true);


    //Check correct RD,WR operation, in this point we waiting for RD,WR operations true
    CHECK_SOCKET_RW(channel,true,true);

    //Imitate socket ready for writing, and writing CONNECT message
    error_code = kaa_tcp_channel_process_event(channel,FD_WRITE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.auth_packet_written, true);

    //Check correct RD,WR operation, in this point we waiting for RD operations true
    //and WR false, no pending services and empty buffer.
    CHECK_SOCKET_RW(channel,true,false);

    //Imitate socket ready for reading, and got IO error during read
    access_point_test_info.socket_connecting_error_scenario = true;
    error_code = kaa_tcp_channel_process_event(channel,FD_READ);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(access_point_test_info.connack_read, false);
    ASSERT_EQUAL(access_point_test_info.socket_disconnected_callback, true);
    ASSERT_EQUAL(access_point_test_info.socket_disconnected_closed, true);
    ASSERT_EQUAL(access_point_test_info.bootstrap_manager_on_access_point_failed, true);


    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
예제 #17
0
void test_retrieving_topic_list(void)
{
    KAA_TRACE_IN(context->logger);
    err = kaa_get_topics(context->notification_manager, &topics);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    size_t topics_size = kaa_list_get_size(topics);
    ASSERT_EQUAL(topics_size, 1);

    KAA_TRACE_OUT(context->logger);
}
예제 #18
0
void test_profile_sync_get_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("dummy");

    size_t serialized_profile_size = profile->get_size(profile);
    char *serialized_profile = (char *) KAA_MALLOC(serialized_profile_size * sizeof(char));
    avro_writer_t writer = avro_writer_memory(serialized_profile, serialized_profile_size);
    profile->serialize(writer, profile);

    size_t expected_size = KAA_EXTENSION_HEADER_SIZE
                         + sizeof(uint32_t)  // profile size
                         + kaa_aligned_size_get(serialized_profile_size);

    size_t profile_sync_size = 0;

    error_code = kaa_profile_manager_update_profile(profile_manager, profile);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    status->is_registered = true;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    status->is_registered = false;

    expected_size += sizeof(uint32_t)
                   + TEST_PUB_KEY_SIZE;

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    const char *access_token = "access token";
    error_code = kaa_profile_manager_set_endpoint_access_token(profile_manager, access_token);

    expected_size += sizeof(uint32_t)
                   + strlen(access_token);

    error_code = kaa_profile_request_get_size(profile_manager, &profile_sync_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_size, profile_sync_size);

    avro_writer_free(writer);
    KAA_FREE(serialized_profile);
    profile->destroy(profile);

    KAA_TRACE_OUT(logger);
}
예제 #19
0
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);
}
예제 #20
0
파일: test_kaa_list.c 프로젝트: nthevu/kaa
void test_list_create()
{
    KAA_TRACE_IN(logger);

    kaa_list_t *list = kaa_list_create();
    ASSERT_NOT_NULL(list);

    ASSERT_EQUAL(kaa_list_get_size(list), 0);
    ASSERT_NULL(kaa_list_begin(list));
    ASSERT_NULL(kaa_list_back(list));

    kaa_list_destroy(list, NULL);

    KAA_TRACE_OUT(logger);
}
예제 #21
0
void test_meta_extension_get_size(void)
{
    KAA_TRACE_IN(logger);

    const size_t expected_meta_extension_size = KAA_EXTENSION_HEADER_SIZE
                                              + sizeof(uint32_t) /* request id */
                                              + sizeof(uint32_t) /* timeout */
                                              + SHA_1_DIGEST_LENGTH
                                              + SHA_1_DIGEST_LENGTH
                                              + KAA_SDK_TOKEN_LENGTH;

    size_t meta_extension_size;
    kaa_error_t error_code = kaa_meta_data_request_get_size(&meta_extension_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(expected_meta_extension_size, meta_extension_size);
}
예제 #22
0
void test_notification_listeners_adding_and_removing(void)
{
    KAA_TRACE_IN(context->logger);
    err = kaa_add_notification_listener(context->notification_manager, &listener, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_notification_listener(context->notification_manager, &listener, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_notification_listener(context->notification_manager, &listener_2, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_notification_listener(context->notification_manager, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_notification_listener(context->notification_manager, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_notification_listener(context->notification_manager, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_optional_notification_listener(context->notification_manager, &listener, &topic_id, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_optional_notification_listener(context->notification_manager, &listener, &topic_id, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_add_optional_notification_listener(context->notification_manager, &listener_2, &topic_id, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    *(uint32_t *)pointer_to_sqn = KAA_HTONL((uint32_t) 100); // Need to change sqn
    err = kaa_platform_protocol_process_server_sync(context->platform_protocol, buffer_pointer, size);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    ASSERT_EQUAL(listener_has_been_notified, true); // whether callback has been called

    err = kaa_remove_optional_notification_listener(context->notification_manager, &topic_id, &id);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_optional_notification_listener(context->notification_manager, &topic_id, &id);
    ASSERT_NOT_EQUAL(err, KAA_ERR_NONE);

    err = kaa_remove_optional_notification_listener(context->notification_manager, &topic_id, &id2);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    KAA_TRACE_OUT(context->logger);
}
void test_set_batch_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;

    size_t DEFAULT_BATCH_SIZE = 8 * 1024;

    error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_set_batch_size(strategy, DEFAULT_BATCH_SIZE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(ext_log_upload_strategy_get_bucket_size(strategy), DEFAULT_BATCH_SIZE);

    KAA_TRACE_OUT(logger);
}
void test_set_upload_timeout(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code = KAA_ERR_NONE;

    size_t DEFAULT_UPLOAD_TIMEOUT = 2 * 60;

    error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_upload_strategy_set_upload_timeout(strategy, DEFAULT_UPLOAD_TIMEOUT);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(ext_log_upload_strategy_get_timeout(strategy), DEFAULT_UPLOAD_TIMEOUT);

    KAA_TRACE_OUT(logger);
}
예제 #25
0
void test_profile_is_set(void)
{
    KAA_TRACE_IN(logger);

#if KAA_PROFILE_SCHEMA_VERSION > 0
    ASSERT_FALSE(kaa_profile_manager_is_profile_set(profile_manager));
    kaa_profile_t *profile = kaa_profile_basic_endpoint_profile_test_create();
    profile->profile_body = kaa_string_copy_create("test");
    kaa_error_t error = kaa_profile_manager_update_profile(profile_manager, profile);
    profile->destroy(profile);
    ASSERT_EQUAL(error, KAA_ERR_NONE);
    ASSERT_TRUE(kaa_profile_manager_is_profile_set(profile_manager));
#else
    ASSERT_TRUE(kaa_profile_manager_is_profile_set(profile_manager));
#endif

    KAA_TRACE_OUT(logger);
}
/*
 * Test create and destroy bootstrap channel
 */
void test_create_kaa_tcp_channel(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;

    kaa_transport_channel_interface_t *channel = NULL;
    channel = KAA_CALLOC(1,sizeof(kaa_transport_channel_interface_t));

    kaa_service_t bootstrap_services[] = {KAA_SERVICE_BOOTSTRAP};

    error_code = kaa_tcp_channel_create(channel,logger,bootstrap_services,1);

    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_NOT_NULL(channel->context);
    ASSERT_NOT_NULL(channel->get_protocol_id);
    ASSERT_NOT_NULL(channel->get_supported_services);
    ASSERT_NOT_NULL(channel->init);
    ASSERT_NOT_NULL(channel->destroy);
    ASSERT_NOT_NULL(channel->set_access_point);
    ASSERT_NOT_NULL(channel->sync_handler);

    kaa_transport_protocol_id_t protocol_info;
    error_code = channel->get_protocol_id(channel->context,&protocol_info);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(protocol_info.id, 0x56c8ff92);
    ASSERT_EQUAL(protocol_info.version, 1);

    kaa_service_t *r_supported_services;
    size_t r_supported_service_count = 0;
    error_code = channel->get_supported_services(channel->context,&r_supported_services,&r_supported_service_count);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(r_supported_service_count, 1);
    ASSERT_EQUAL(r_supported_services[0], KAA_SERVICE_BOOTSTRAP);

    channel->destroy(channel->context);

    KAA_TRACE_OUT(logger);

    KAA_FREE(channel);
}
예제 #27
0
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);
}
예제 #28
0
void test_serializing(void)
{
    KAA_TRACE_IN(context->logger);

    kaa_serialize_info_t *info = (kaa_serialize_info_t *) KAA_MALLOC(sizeof(kaa_serialize_info_t));

    kaa_service_t service[] = { KAA_SERVICE_NOTIFICATION };

    info->services = service;
    info->services_count = 1;
    info->allocator = &allocator;
    info->allocator_context = &allocator; //mock
    err = kaa_platform_protocol_serialize_client_sync(context->platform_protocol, info, &buffer, &buffer_size);
    ASSERT_EQUAL(err, KAA_ERR_NONE);

    KAA_FREE(buffer);
    KAA_FREE(info);

    KAA_TRACE_OUT(context->logger);
}
예제 #29
0
void test_meta_extension_serialize_failed(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    const size_t buffer_size = 6;
    char buffer[buffer_size];
    kaa_platform_message_writer_t *writer;

    error_code = kaa_platform_message_writer_create(&writer, buffer, buffer_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_meta_data_request_serialize(NULL, NULL, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = kaa_meta_data_request_serialize(NULL, (kaa_platform_message_writer_t *)!NULL, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_platform_message_writer_destroy(writer);
}
예제 #30
0
void test_shrink_to_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    const char *data = "DATA";
    size_t data_size = strlen("DATA");
    size_t TEST_RECORD_COUNT = 10;

    size_t STORAGE_SIZE = data_size * TEST_RECORD_COUNT;
    size_t PERCENT_TO_DELETE = 75;
    size_t NEW_STORAGE_SIZE = (STORAGE_SIZE * (100 - PERCENT_TO_DELETE) / 100);

    error_code = ext_limited_log_storage_create(&storage, logger, STORAGE_SIZE, PERCENT_TO_DELETE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_count = 0;

    while (record_count <= TEST_RECORD_COUNT) {
        error_code = add_log_record(storage, data, data_size);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
        ++record_count;
    }

    size_t occupied_size_after_removal = 0;
    size_t record_count_after_removal = 0;
    while (occupied_size_after_removal + data_size <= NEW_STORAGE_SIZE) {
        occupied_size_after_removal += data_size;
        ++record_count_after_removal;
    }

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count_after_removal + 1 /* new record added after removal */);
    ASSERT_EQUAL(ext_log_storage_get_total_size(storage), occupied_size_after_removal + data_size);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}