예제 #1
0
static void test_string_move_create(void **state)
{
    (void)state;

    ASSERT_NULL(kaa_string_move_create(NULL, NULL));

    const char *plain_test_str1 = "test";

    kaa_string_t *kaa_str1 = kaa_string_move_create(plain_test_str1, NULL);

    ASSERT_NOT_NULL(kaa_str1);
    ASSERT_NOT_NULL(kaa_str1->data);
    ASSERT_NULL(kaa_str1->destroy);
    ASSERT_EQUAL(strcmp(kaa_str1->data, plain_test_str1), 0);

    kaa_string_destroy(kaa_str1);
    kaa_str1 = NULL;

    char *plain_test_str2 = (char *)KAA_MALLOC(strlen(plain_test_str1) + 1);
    ASSERT_NOT_NULL(plain_test_str2);
    strcpy(plain_test_str2, plain_test_str1);

    kaa_string_t *kaa_str2 = kaa_string_move_create(plain_test_str2, &kaa_data_destroy);

    ASSERT_NOT_NULL(kaa_str2);
    ASSERT_NOT_NULL(kaa_str2->data);
    ASSERT_EQUAL(kaa_str2->destroy, &kaa_data_destroy);
    ASSERT_EQUAL(strcmp(kaa_str2->data, plain_test_str1), 0);

    kaa_string_destroy(kaa_str2);
}
예제 #2
0
static void test_string_deserialize(void **state)
{
    (void)state;

    const char *plain_test_str1 = "test";
    kaa_string_t *kaa_str1 = kaa_string_copy_create(plain_test_str1);
    ASSERT_NOT_NULL(kaa_str1);

    size_t expected_size = kaa_string_get_size(kaa_str1);
    char buffer[expected_size];
    avro_writer_t avro_writer = avro_writer_memory(buffer, expected_size);

    kaa_string_serialize(avro_writer, kaa_str1);

    avro_reader_t avro_reader = avro_reader_memory(buffer, expected_size);

    kaa_string_t *kaa_str2 = kaa_string_deserialize(avro_reader);
    ASSERT_NOT_NULL(kaa_str2);

    ASSERT_EQUAL(strcmp(kaa_str2->data, plain_test_str1), 0);
    ASSERT_EQUAL(strcmp(kaa_str2->data, kaa_str1->data), 0);

    kaa_string_destroy(kaa_str2);
    avro_reader_free(avro_reader);
    avro_writer_free(avro_writer);
    kaa_string_destroy(kaa_str1);
}
예제 #3
0
static void test_array_get_size(void **state)
{
    (void)state;

    srand(time(NULL));
    ASSERT_EQUAL(kaa_array_get_size(NULL, NULL), 0);
    ASSERT_EQUAL(kaa_array_get_size(NULL, (get_size_fn)kaa_null_get_size), avro_long_get_size(0));

    const char *plain_str = "data";
    kaa_string_t *reference_kaa_str = kaa_string_copy_create(plain_str);
    size_t element_size = kaa_string_get_size(reference_kaa_str);
    kaa_string_destroy(reference_kaa_str);

    size_t array_size = 1 + rand() % 10;

    kaa_list_t *avro_array = kaa_list_create();
    size_t i = 0;
    for (i = 0; i < array_size; ++i) {
        kaa_list_push_back(avro_array, kaa_string_copy_create(plain_str));
    }

    size_t expected_size = avro_long_get_size(array_size)
                         + array_size * element_size
                         + avro_long_get_size(0);

    ASSERT_EQUAL(kaa_array_get_size(avro_array, &kaa_string_get_size), expected_size);

    kaa_list_destroy(avro_array, kaa_string_destroy);
}
예제 #4
0
static void kaa_profile_basic_endpoint_profile_test_destroy(void *data)
{
    if (data) {
        kaa_profile_basic_endpoint_profile_test_t *record = (kaa_profile_basic_endpoint_profile_test_t *)data;

        kaa_string_destroy(record->profile_body);
        kaa_data_destroy(record);
    }
}
예제 #5
0
static void kaa_configuration_root_record_destroy(void *data)
{
    if (data) {
        kaa_configuration_root_record_t *record = (kaa_configuration_root_record_t *)data;

        kaa_string_destroy(record->data);
        if (record->__uuid && record->__uuid->destroy) {
            record->__uuid->destroy(record->__uuid);
        }
        kaa_data_destroy(record);
    }
}
예제 #6
0
static void test_string_get_size(void **state)
{
    (void)state;

    ASSERT_EQUAL(kaa_string_get_size(NULL), 0);

    const char *plain_test_str1 = "test";
    kaa_string_t *kaa_str1 = kaa_string_copy_create(plain_test_str1);
    ASSERT_NOT_NULL(kaa_str1);

    size_t plain_test_str1_len = strlen(plain_test_str1);
    ASSERT_EQUAL(kaa_string_get_size(kaa_str1), avro_long_get_size(plain_test_str1_len) + plain_test_str1_len);

    kaa_string_destroy(kaa_str1);
}
예제 #7
0
static void test_string_copy_create(void **state)
{
    (void)state;

    const char *plain_test_str1 = "test";

    ASSERT_NULL(kaa_string_copy_create(NULL));

    kaa_string_t *kaa_str1 = kaa_string_copy_create(plain_test_str1);
    ASSERT_NOT_NULL(kaa_str1);
    ASSERT_NOT_NULL(kaa_str1->data);
    ASSERT_EQUAL(kaa_str1->destroy, &kaa_data_destroy);
    ASSERT_EQUAL(strcmp(kaa_str1->data, plain_test_str1), 0);

    kaa_string_destroy(kaa_str1);
}
예제 #8
0
static void test_string_serialize(void **state)
{
    (void)state;

    const char *plain_test_str1 = "test";
    kaa_string_t *kaa_str1 = kaa_string_copy_create(plain_test_str1);
    ASSERT_NOT_NULL(kaa_str1);

    size_t expected_size = kaa_string_get_size(kaa_str1);
    char auto_buffer[expected_size];
    avro_writer_t auto_avro_writer = avro_writer_memory(auto_buffer, expected_size);
    char manual_buffer[expected_size];
    avro_writer_t manual_avro_writer = avro_writer_memory(manual_buffer, expected_size);

    ASSERT_EQUAL(auto_avro_writer->buf, auto_buffer);
    ASSERT_EQUAL(auto_avro_writer->written, 0);
    ASSERT_EQUAL((size_t)auto_avro_writer->len, expected_size);

    kaa_string_serialize(auto_avro_writer, NULL);

    ASSERT_EQUAL(auto_avro_writer->buf, auto_buffer);
    ASSERT_EQUAL(auto_avro_writer->written, 0);
    ASSERT_EQUAL((size_t)auto_avro_writer->len, expected_size);

    kaa_string_t fake_kaa_str = { NULL, NULL};

    kaa_string_serialize(auto_avro_writer, &fake_kaa_str);

    ASSERT_EQUAL(auto_avro_writer->buf, auto_buffer);
    ASSERT_EQUAL(auto_avro_writer->written, 0);
    ASSERT_EQUAL((size_t)auto_avro_writer->len, expected_size);

    /*
     * REAL DATA
     */
    kaa_string_serialize(auto_avro_writer, kaa_str1);

    avro_binary_encoding.write_string(manual_avro_writer, plain_test_str1);

    ASSERT_EQUAL(memcmp(auto_buffer, manual_buffer, expected_size), 0);

    kaa_string_destroy(kaa_str1);
    avro_writer_free(manual_avro_writer);
    avro_writer_free(auto_avro_writer);
}
예제 #9
0
static void test_array_serialize(void **state)
{
    (void)state;

    const char *plain_str = "data";
    kaa_string_t *reference_kaa_str = kaa_string_copy_create(plain_str);
    size_t element_size = kaa_string_get_size(reference_kaa_str);
    kaa_string_destroy(reference_kaa_str);

    size_t array_size = 1 + rand() % 10;
    size_t expected_size = avro_long_get_size(array_size)
                         + array_size * element_size
                         + avro_long_get_size(0);
    char manual_buffer[expected_size];
    avro_writer_t manual_avro_writer = avro_writer_memory(manual_buffer, expected_size);
    avro_binary_encoding.write_long(manual_avro_writer, array_size);

    kaa_list_t *avro_array = kaa_list_create();
    size_t i = 0;
    for (i = 0; i < array_size; ++i) {
        kaa_string_t *array_data = kaa_string_copy_create(plain_str);
        kaa_list_push_back(avro_array, array_data);
        avro_binary_encoding.write_string(manual_avro_writer, array_data->data);
    }

    avro_binary_encoding.write_long(manual_avro_writer, 0);

    size_t actual_size = kaa_array_get_size(avro_array, kaa_string_get_size);

    ASSERT_EQUAL(actual_size, expected_size);

    char auto_buffer[actual_size];
    avro_writer_t auto_avro_writer = avro_writer_memory(auto_buffer, actual_size);

    kaa_array_serialize(auto_avro_writer, avro_array, kaa_string_serialize);

    ASSERT_EQUAL(memcmp(auto_buffer, manual_buffer, expected_size), 0);

    kaa_list_destroy(avro_array, kaa_string_destroy);
    avro_writer_free(manual_avro_writer);
    avro_writer_free(auto_avro_writer);
}