void test_create_request(void **state) { (void)state; kaa_user_log_record_t *test_log_record = kaa_test_log_record_create(); test_log_record->data = kaa_string_copy_create(TEST_LOG_BUFFER); size_t test_log_record_size = test_log_record->get_size(test_log_record); kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); strategy.decision = NOOP; strategy.max_parallel_uploads = UINT32_MAX; kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 2 * test_log_record_size, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, create_mock_storage(), &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); size_t expected_size = 0; error_code = kaa_logging_request_get_size(log_collector, &expected_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); uint8_t buffer[expected_size]; kaa_platform_message_writer_t *writer = NULL; error_code = kaa_platform_message_writer_create(&writer, buffer, expected_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_NOT_NULL(writer); error_code = kaa_logging_request_serialize(log_collector, writer); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_platform_message_writer_destroy(writer); uint8_t *buf_cursor = buffer; ASSERT_EQUAL(KAA_EXTENSION_LOGGING, KAA_HTONS(*(uint16_t *)buf_cursor)); buf_cursor += sizeof(uint16_t); uint8_t options[] = { 0x00, 0x01 }; ASSERT_EQUAL(memcmp(buf_cursor, options, 2), 0); buf_cursor += 2; ASSERT_EQUAL(*(uint32_t *) buf_cursor, KAA_HTONL(20)); buf_cursor += sizeof(uint32_t); uint8_t request_id_records_count[] = { 0x00, 0x01, 0x00, 0x01 }; ASSERT_EQUAL(memcmp(buf_cursor, request_id_records_count, 4), 0); buf_cursor += 4; uint8_t record_buf[test_log_record_size]; avro_writer_t avro_writer = avro_writer_memory((char *)record_buf, test_log_record_size); test_log_record->serialize(avro_writer, test_log_record); avro_writer_free(avro_writer); ASSERT_EQUAL(*(uint32_t *) buf_cursor, KAA_HTONL(test_log_record_size)); buf_cursor += sizeof(uint32_t); ASSERT_EQUAL(memcmp(buf_cursor, record_buf, test_log_record_size), 0); kaa_log_collector_destroy(log_collector); test_log_record->destroy(test_log_record); } void test_response(void **state) { (void)state; srand(time(NULL)); kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); mock_storage_context_t *storage = create_mock_storage(); kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 1024, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, storage, &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); uint32_t response_count = 2; size_t response_buffer_size = sizeof(uint32_t) + sizeof(uint32_t) * response_count; uint8_t response_buffer[response_buffer_size]; uint8_t *response = response_buffer; *((uint32_t *)response) = KAA_HTONL(response_count); response += sizeof(uint32_t); /* First response */ *((uint16_t *)response) = KAA_HTONS(rand()); response += sizeof(uint16_t); *((uint8_t *)response) = 0x0; // SUCCESS response += sizeof(uint8_t); *((uint8_t *)response) = 0; response += sizeof(uint8_t); /* Second response */ *((uint16_t *)response) = KAA_HTONS(rand()); response += sizeof(uint16_t); *((uint8_t *)response) = 0x1; // FAILURE response += sizeof(uint8_t); *((uint8_t *)response) = rand() % 4; response += sizeof(uint8_t); kaa_platform_message_reader_t *reader = NULL; error_code = kaa_platform_message_reader_create(&reader, response_buffer, response_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_NOT_NULL(reader); error_code = kaa_logging_handle_server_sync(log_collector, reader, 0, response_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_TRUE(strategy.on_failure_count); ASSERT_TRUE(storage->on_remove_by_id_count); ASSERT_TRUE(storage->on_unmark_by_id_count); kaa_platform_message_reader_destroy(reader); kaa_log_collector_destroy(log_collector); } void test_timeout(void **state) { (void)state; kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_user_log_record_t *test_log_record = kaa_test_log_record_create(); test_log_record->data = kaa_string_copy_create(TEST_LOG_BUFFER); size_t test_log_record_size = test_log_record->get_size(test_log_record); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); strategy.timeout = TEST_TIMEOUT; strategy.decision = NOOP; strategy.max_parallel_uploads = UINT32_MAX; kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 2 * test_log_record_size, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, create_mock_storage(), &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); size_t request_buffer_size = 256; uint8_t request_buffer[request_buffer_size]; kaa_platform_message_writer_t *writer = NULL; error_code = kaa_platform_message_writer_create(&writer, request_buffer, request_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_request_serialize(log_collector, writer); ASSERT_EQUAL(error_code, KAA_ERR_NONE); sleep(TEST_TIMEOUT + 1); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_TRUE(strategy.on_timeout_count); test_log_record->destroy(test_log_record); kaa_platform_message_writer_destroy(writer); kaa_log_collector_destroy(log_collector); } void test_decline_timeout(void **state) { (void)state; kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_user_log_record_t *test_log_record = kaa_test_log_record_create(); test_log_record->data = kaa_string_copy_create(TEST_LOG_BUFFER); size_t test_log_record_size = test_log_record->get_size(test_log_record); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); strategy.timeout = TEST_TIMEOUT; strategy.decision = NOOP; strategy.max_parallel_uploads = UINT32_MAX; mock_storage_context_t *storage = create_mock_storage(); ASSERT_NOT_NULL(storage); kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 2 * test_log_record_size, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, storage, &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); size_t request_buffer_size = 256; uint8_t request_buffer[request_buffer_size]; kaa_platform_message_writer_t *writer = NULL; error_code = kaa_platform_message_writer_create(&writer, request_buffer, request_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_request_serialize(log_collector, writer); ASSERT_EQUAL(error_code, KAA_ERR_NONE); sleep(TEST_TIMEOUT + 1); uint16_t bucket_id = *((uint16_t *)(request_buffer + KAA_EXTENSION_HEADER_SIZE)); bucket_id = KAA_NTOHS(bucket_id); uint32_t response_count = 1; size_t response_buffer_size = sizeof(uint32_t) + sizeof(uint32_t) * response_count; uint8_t response_buffer[response_buffer_size]; uint8_t *response = response_buffer; *((uint32_t *)response) = KAA_HTONL(response_count); response += sizeof(uint32_t); /* First response */ *((uint16_t *)response) = KAA_HTONS(bucket_id); response += sizeof(uint16_t); *((uint8_t *)response) = 0x0; // SUCCESS response += sizeof(uint8_t); *((uint8_t *)response) = 0; response += sizeof(uint8_t); kaa_platform_message_reader_t *reader = NULL; error_code = kaa_platform_message_reader_create(&reader, response_buffer, response_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_NOT_NULL(reader); error_code = kaa_logging_handle_server_sync(log_collector, reader, 0, response_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_TRUE(storage->on_remove_by_id_count); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_FALSE(strategy.on_timeout_count); test_log_record->destroy(test_log_record); kaa_platform_message_writer_destroy(writer); kaa_platform_message_reader_destroy(reader); kaa_log_collector_destroy(log_collector); } void test_max_parallel_uploads_with_log_sync(void **state) { (void)state; uint32_t channel_id = 0; kaa_transport_channel_interface_t transport_context; test_kaa_channel_create(&transport_context); kaa_channel_manager_add_transport_channel(channel_manager, &transport_context, &channel_id); kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_user_log_record_t *test_log_record = kaa_test_log_record_create(); test_log_record->data = kaa_string_copy_create(TEST_LOG_BUFFER); size_t test_log_size = test_log_record->get_size(test_log_record); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); strategy.timeout = INT16_MAX; strategy.decision = UPLOAD; mock_storage_context_t *storage = create_mock_storage(); ASSERT_NOT_NULL(storage); kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 2 * test_log_size, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, storage, &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); /* * Ensure the log delivery is forbidden at all. */ strategy.max_parallel_uploads = 0; error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(((mock_transport_channel_context_t *)transport_context.context)->on_sync_count, 0); /* * Ensure the first request is allowed. */ // cppcheck-suppress redundantAssignment strategy.max_parallel_uploads = 1; error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(((mock_transport_channel_context_t *)transport_context.context)->on_sync_count, 1); /* * Do the first request to remember the delivery timeout of the log batch. */ size_t request_buffer_size = 256; uint8_t request_buffer[request_buffer_size]; kaa_platform_message_writer_t *writer = NULL; error_code = kaa_platform_message_writer_create(&writer, request_buffer, request_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_request_serialize(log_collector, writer); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); /* * Ensure the second request is forbidden. */ ASSERT_EQUAL(((mock_transport_channel_context_t *)transport_context.context)->on_sync_count, 1); /* * Clean up. */ error_code = kaa_channel_manager_remove_transport_channel(channel_manager, channel_id); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_record->destroy(test_log_record); kaa_log_collector_destroy(log_collector); } void test_max_parallel_uploads_with_sync_all(void **state) { (void)state; uint32_t channel_id = 0; kaa_transport_channel_interface_t transport_context; test_kaa_channel_create(&transport_context); kaa_channel_manager_add_transport_channel(channel_manager, &transport_context, &channel_id); kaa_log_collector_t *log_collector = NULL; kaa_error_t error_code = kaa_log_collector_create(&log_collector, status, channel_manager, logger); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_user_log_record_t *test_log_record = kaa_test_log_record_create(); test_log_record->data = kaa_string_copy_create(TEST_LOG_BUFFER); size_t test_log_size = test_log_record->get_size(test_log_record); mock_strategy_context_t strategy; memset(&strategy, 0, sizeof(mock_strategy_context_t)); strategy.timeout = INT16_MAX; strategy.decision = UPLOAD; mock_storage_context_t *storage = create_mock_storage(); ASSERT_NOT_NULL(storage); kaa_log_bucket_constraints_t constraints = { .max_bucket_size = 2 * test_log_size, .max_bucket_log_count = UINT32_MAX, }; error_code = kaa_logging_init(log_collector, storage, &strategy, &constraints); ASSERT_EQUAL(error_code, KAA_ERR_NONE); /* * Ensure the log delivery is forbidden at all. */ strategy.max_parallel_uploads = 0; error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); size_t expected_size = 0; error_code = kaa_logging_request_get_size(log_collector, &expected_size); assert_int_equal(KAA_ERR_NONE, error_code); ASSERT_FALSE(expected_size); /* * Ensure the first request is allowed. */ // cppcheck-suppress redundantAssignment strategy.max_parallel_uploads = 1; error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); /* * Do the first request to remember the delivery timeout of the log batch. */ error_code = kaa_logging_request_get_size(log_collector, &expected_size); assert_int_equal(KAA_ERR_NONE, error_code); ASSERT_TRUE(expected_size); size_t request_buffer_size = 256; uint8_t request_buffer[request_buffer_size]; kaa_platform_message_writer_t *writer = NULL; error_code = kaa_platform_message_writer_create(&writer, request_buffer, request_buffer_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_request_serialize(log_collector, writer); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_logging_add_record(log_collector, test_log_record, NULL); ASSERT_EQUAL(error_code, KAA_ERR_NONE); /* * Ensure the second request is forbidden. */ error_code = kaa_logging_request_get_size(log_collector, &expected_size); assert_int_equal(KAA_ERR_NONE, error_code); ASSERT_FALSE(expected_size); /* * Clean up. */ error_code = kaa_channel_manager_remove_transport_channel(channel_manager, channel_id); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_record->destroy(test_log_record); kaa_log_collector_destroy(log_collector); } /* ---------------------------------------------------------------------------*/ /* Log delivery tests */ /* ---------------------------------------------------------------------------*/ /* Server chunk, managed by a corresponding reader object. * Perfectly packed. Packed attribute is intentionally avoided. */ struct response_chunk { uint8_t bucket_id[2]; /* 16 bits for bucket ID */ uint8_t resp_code; /* 8 bits for response code. 0 == SUCCESS, 1 == FAILURE */ uint8_t reserved; /* Should be 0 */ }; struct response_packet { uint8_t resp_cnt[4]; /* 32 bits for amount of responces in buffer */ struct response_chunk resps[]; /* Responses itself */ }; #define RESP_PACKETS 2 /* Amount of response packets */ #define RESP_SUCCESS_IDX 0 /* Index of successfull response */ #define RESP_FAILURE_IDX 1 /* Index of failed response */ #define TEST_BUFFER_SIZE 1024 #define TEST_EXT_OP 0 /* Simple stub */ static mock_strategy_context_t test_strategy1; static mock_strategy_context_t test_strategy2; static mock_storage_context_t *test_storage1; static mock_storage_context_t *test_storage2; static kaa_log_collector_t *log_collector; static size_t test_log_record_size = TEST_BUFFER_SIZE; /* Will contain response_packet. Thus required to be aligned. */ static uint32_t test_reader_buffer[TEST_BUFFER_SIZE / 4]; static uint32_t test_writer_buffer[TEST_BUFFER_SIZE / 4]; /* Portion of the test buffer filled with valid data */ static size_t test_filled_size; static kaa_platform_message_reader_t *test_reader; static kaa_platform_message_writer_t *test_writer; static kaa_user_log_record_t *test_log_record; /* Values to be checked inside mock event function */ static void *expected_ctx; static int check_bucket; static uint16_t expected_bucked_id; /* Required to trace generic mock function calls */ static int call_is_expected; static int call_completed; /* Required to trace on fail mock function calls */ static int failed_call_is_expected; static int failed_call_completed; /* Required to trace on success mock function calls */ static int success_call_is_expected; static int success_call_completed; /* Required to trace on timeout mock function calls */ static int timeout_call_is_expected; static int timeout_call_completed; /* Mock event functions */ static void mock_log_event_generic_fn(void *ctx, const kaa_log_bucket_info_t *bucket) { ASSERT_TRUE(call_is_expected); ASSERT_NOT_NULL(bucket); /* Shouldn't be NULL no matter what */ if (check_bucket) { ASSERT_EQUAL(expected_bucked_id, bucket->bucket_id); } ASSERT_EQUAL(expected_ctx, ctx); call_completed++; }
void testSetAtWithInt() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet.at(1); ASSERT_EQUAL(2, i); }
void testBracketOperatorBackWithInt() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet[3]; ASSERT_EQUAL(4, i); }
void testCaselessCompare() { IndexableSet<std::string, CaselessComparator> indexSet {"hallo","Hallo","Test","taste"}; ASSERT_EQUAL(3, indexSet.size()); }
void testIndexSetBackWithInt() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet.back(); ASSERT_EQUAL(4, i); }
void testDefaultConstructor() { IndexableSet<int> indexSet{}; indexSet.insert(1); ASSERT_EQUAL(1, indexSet[0] ); }
void testCopyConstructor() { IndexableSet<int> indexSet {1, 2, 3, 4, 5}; IndexableSet<int> copiedIndexSet(indexSet); ASSERT_EQUAL(3, indexSet[2]); }
void testSubtraction(){ Ring5 two{2}; ASSERT_EQUAL(Ring5{0}, two-two); ASSERT_EQUAL(Ring5{0}, Ring5{4}-Ring5{4}); }
void testMultiplication(){ Ring5 four{4}; Ring5 three{3}; Ring5 two = four * three; ASSERT_EQUAL(Ring5{2},two); }
void testAddition() { Ring5 two{2}; Ring5 four = two+two; ASSERT_EQUAL(4,four.value()); }
void testAdditionWrap(){ Ring5 four{4}; Ring5 three = four + four; ASSERT_EQUAL(3,three.value()); }
// define operator<< format void testOutputOperator(){ std::ostringstream out; out << Ring5{4}; ASSERT_EQUAL("Ring5{4}",out.str()); }
// operator==, operator<< for failures void testValueCtorWithLargeInput(){ Ring5 four{19}; ASSERT_EQUAL(Ring5{4},four); }
void test_meta_extension_serialize(void) { KAA_TRACE_IN(logger); size_t meta_extension_size; kaa_error_t error_code = kaa_meta_data_request_get_size(&meta_extension_size); char buffer[meta_extension_size]; kaa_platform_message_writer_t *writer; error_code = kaa_platform_message_writer_create(&writer, buffer, meta_extension_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); uint32_t expected_timeout = KAA_SYNC_TIMEOUT; kaa_digest expected_public_key_hash = {0x74, 0xc7, 0x51, 0x43, 0x00, 0xf7, 0xb8, 0x21, 0x2c, 0xc3, 0x6b, 0xa5, 0x9c, 0xb4, 0x03, 0xef, 0xc2, 0x5c, 0x65, 0x6c}; kaa_digest expected_profile_hash = {0xfa, 0x71, 0xb5, 0x02, 0xe7, 0xdf, 0x96, 0x86, 0x6c, 0xdc, 0xe1, 0x4a, 0x17, 0x35, 0x7f, 0xd9, 0xa8, 0xfb, 0x71, 0x09}; error_code = ext_copy_sha_hash(status->endpoint_public_key_hash, expected_public_key_hash); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_copy_sha_hash(status->profile_hash, expected_profile_hash); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_context_t *context = NULL; kaa_init(&context); kaa_platform_protocol_t *protocol = NULL; kaa_platform_protocol_create(&protocol, context, status); error_code = kaa_meta_data_request_serialize(protocol, writer, 1); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_deinit(context); kaa_platform_message_reader_t *reader; error_code = kaa_platform_message_reader_create(&reader, buffer, meta_extension_size); ASSERT_EQUAL(error_code, KAA_ERR_NONE); uint16_t extension_type; uint16_t extension_options; uint32_t extension_payload; error_code = kaa_platform_message_read_extension_header( reader, &extension_type, &extension_options, &extension_payload); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(extension_type, KAA_META_DATA_EXTENSION_TYPE); ASSERT_EQUAL(extension_options, (TIMEOUT_VALUE | PUBLIC_KEY_HASH_VALUE | PROFILE_HASH_VALUE | APP_TOKEN_VALUE)); ASSERT_EQUAL(extension_payload, meta_extension_size - KAA_EXTENSION_HEADER_SIZE); uint32_t request_id; uint32_t timeout; kaa_digest public_key_hash; kaa_digest profile_hash; char sdk_token[KAA_SDK_TOKEN_LENGTH]; error_code = kaa_platform_message_read(reader, &request_id, sizeof(uint32_t)); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(KAA_NTOHL(request_id), 1); error_code = kaa_platform_message_read(reader, &timeout, sizeof(uint32_t)); ASSERT_EQUAL(error_code, KAA_ERR_NONE); timeout = KAA_NTOHL(timeout); ASSERT_EQUAL(expected_timeout, timeout); error_code = kaa_platform_message_read_aligned(reader, public_key_hash, SHA_1_DIGEST_LENGTH); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = (memcmp(public_key_hash, expected_public_key_hash, SHA_1_DIGEST_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_platform_message_read_aligned(reader, profile_hash, SHA_1_DIGEST_LENGTH); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = (memcmp(profile_hash, expected_profile_hash, SHA_1_DIGEST_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = kaa_platform_message_read_aligned(reader, sdk_token, KAA_SDK_TOKEN_LENGTH); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = (memcmp(sdk_token, KAA_SDK_TOKEN, KAA_SDK_TOKEN_LENGTH) == 0 ? KAA_ERR_NONE : KAA_ERR_READ_FAILED); ASSERT_EQUAL(error_code, KAA_ERR_NONE); kaa_platform_message_reader_destroy(reader); kaa_platform_message_writer_destroy(writer); }
void testBracketOperatorBackWithString() { IndexableSet<std::string> indexSet{"Hallo","Hoi","Test","Tester"}; std::string compareString = indexSet[3]; ASSERT_EQUAL("Tester", compareString); }
void testDefaultCtor() { Ring5 v{}; ASSERT_EQUAL(0,v.value()); }
void testNegativeBracketToPositiveIndexString() { IndexableSet<std::string> indexSet{"Hallo","Hoi","Test","Tester"}; std::string compareString = indexSet[-1]; ASSERT_EQUAL("Tester", compareString); }
void testValueCtor(){ Ring5 four{4}; ASSERT_EQUAL(4,four.value()); }
void testRangeConstructor() { std::vector<int> myInts = {1, 2, 3, 4, 5}; IndexableSet<int> indexSet(myInts.begin() , myInts.end()); ASSERT_EQUAL(3, indexSet[2]); }
// Test _xl_get_row(). CTEST(utility, _xl_get_row) { ASSERT_EQUAL(0, lxw_get_row("A1")); ASSERT_EQUAL(1, lxw_get_row("B2")); ASSERT_EQUAL(2, lxw_get_row("C3")); ASSERT_EQUAL(9, lxw_get_row("J10")); ASSERT_EQUAL(24, lxw_get_row("Y25")); ASSERT_EQUAL(25, lxw_get_row("Z26")); ASSERT_EQUAL(26, lxw_get_row("AA27")); ASSERT_EQUAL(254, lxw_get_row("IU255")); ASSERT_EQUAL(255, lxw_get_row("IV256")); ASSERT_EQUAL(256, lxw_get_row("IW257")); ASSERT_EQUAL(16383, lxw_get_row("XFD16384")); ASSERT_EQUAL(16384, lxw_get_row("XFE16385")); ASSERT_EQUAL(1048576, lxw_get_row("XFE1048577")); }
void testMoveConstructor() { IndexableSet<int> indexSet {1, 2, 3, 4, 5}; IndexableSet<int> moveIndexSet(std::move(indexSet)); ASSERT_EQUAL(3, moveIndexSet[2]); }
void SequencerChannelsTest::testSequencerChannels(void) { // 1st test { const std::string TEST_FILE_IN = "TestData/sequences_3x2x1.xml"; SequencerChannels sg; state::PatternChannelMap in_chans; state::PatternChannelMap out_chans; sg.readSequences(TEST_FILE_IN, in_chans, out_chans); //std::cout<<"SequencerChannelsTest: "<<" "<<std::endl; //std::cout<<sg<<std::endl; // simple tests { int in_sz = in_chans.getSize(); int out_sz = out_chans.getSize(); ASSERT_EQUAL(1, in_sz); ASSERT_EQUAL(1, out_sz); } // check input channel and size { //for all in in_chans { std::map<boost::uuids::uuid, boost::shared_ptr<PatternChannel> >::const_iterator it_in_chans = in_chans.begin(); const std::map<boost::uuids::uuid, boost::shared_ptr<PatternChannel> >::const_iterator it_in_chans_end = in_chans.end(); while (it_in_chans != it_in_chans_end) { int width = it_in_chans->second->getWidth(); int length = it_in_chans->second->getLength(); ASSERT_EQUAL(3, width); ASSERT_EQUAL(2, length); ++it_in_chans; } } } //check output channel and size { //for all in out_chans { std::map<boost::uuids::uuid, boost::shared_ptr<PatternChannel> >::const_iterator it_out_chans = out_chans.begin(); const std::map<boost::uuids::uuid, boost::shared_ptr<PatternChannel> >::const_iterator it_out_chans_end = out_chans.end(); while (it_out_chans != it_out_chans_end) { int width = it_out_chans->second->getWidth(); int length = it_out_chans->second->getLength(); ASSERT_EQUAL(3, width); ASSERT_EQUAL(2, length); ++it_out_chans; } } } } // 1st test { const std::string TEST_FILE_IN = "TestData/sequences_3x2x3-2x3x1.xml"; SequencerChannels sg; state::PatternChannelMap in_chans; state::PatternChannelMap out_chans; sg.readSequences(TEST_FILE_IN, in_chans, out_chans); //std::cout<<"SequencerChannelsTest: "<<" "<<std::endl; //std::cout<<sg<<std::endl; // simple tests { int in_sz = in_chans.getSize(); int out_sz = out_chans.getSize(); ASSERT_EQUAL(3, in_sz); ASSERT_EQUAL(1, out_sz); } } }
void testIndexSetFrontWithInt() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet.front(); ASSERT_EQUAL(1, i); }
/* * 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() { 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); }
void testIndexSetSizeAfterCreation() { IndexableSet<std::string> indexSet{}; ASSERT_EQUAL(indexSet.size(), 0); }
void test_check_bootstrap_sync(kaa_transport_channel_interface_t *channel) { ASSERT_NOT_NULL(channel); //Reset test bools access_point_test_info.socket_connected = false; access_point_test_info.socket_connected_callback = false; access_point_test_info.fill_connect_message = false; access_point_test_info.request_connect = false; access_point_test_info.auth_packet_written = false; access_point_test_info.connack_read = false; access_point_test_info.kaasync_read = false; access_point_test_info.kaasync_processed = false; access_point_test_info.socket_disconnected_write = false; access_point_test_info.socket_disconnected_callback = false; access_point_test_info.socket_disconnected_closed = false; access_point_test_info.bootstrap_manager_on_access_point_failed = false; //Imitate WR event, and wait socket connect call, channel should start authorization, prepare //CONNECT message kaa_error_t 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 read CONNACK message 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, true); //Check correct RD,WR operation, in this point we waiting for RD operations true //and WR false, no pending services and empty buffer. //Checking receiving KAA_SYNC message CHECK_SOCKET_RW(channel,true,false); //Imitate socket ready for reading, and read KAA_SYNC Bootstrap message error_code = kaa_tcp_channel_process_event(channel,FD_READ); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(access_point_test_info.kaasync_read, true); ASSERT_EQUAL(access_point_test_info.kaasync_processed, true); //Check correct RD,WR operation, in this point we waiting for WR operations true //and RD true, no pending services and buffer with Disconnect message. //Checking receiving KAA_SYNC message CHECK_SOCKET_RW(channel,true,true); //Imitate socket ready for writing, and write Disconnect 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_disconnected_write, true); 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, false); }
void testBracketOperatorFrontWithInt() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet[0]; ASSERT_EQUAL(1, i); }
void test_hashes(redis::client & c) { test("hset"); { c.hset("hash1", "key1", "hval1"); c.hset("hash1", "key2", "hval2"); c.hset("hash1", "key3", "hval3"); ASSERT_EQUAL(c.exists("hash1"), true); ASSERT_EQUAL(c.type("hash1"), redis::client::datatype_hash); ASSERT_EQUAL(c.hlen("hash1"), 3L); } test("hget"); { ASSERT_EQUAL(c.hget("hash1", "key1"), string("hval1")); ASSERT_EQUAL(c.hget("hash1", "key2"), string("hval2")); ASSERT_EQUAL(c.hget("hash1", "key3"), string("hval3")); } test("hsetnx"); { ASSERT_EQUAL(c.hsetnx("hash1", "key1", "hvalINVALID"), false); ASSERT_EQUAL(c.hget("hash1", "key1"), string("hval1")); ASSERT_EQUAL(c.hsetnx("hash1", "key4", "hval4"), true); ASSERT_EQUAL(c.hget("hash1", "key4"), string("hval4")); } redis::client::string_pair_vector content; test("hmset"); { content.push_back( make_pair("key1", "hval1") ); content.push_back( make_pair("key2", "hval2") ); content.push_back( make_pair("key3", "hval3") ); c.hmset("hash2", content); } test("hmget"); { redis::client::string_vector fields; fields.push_back("key1"); fields.push_back("key2"); fields.push_back("key3"); fields.push_back("key4"); redis::client::string_vector content2; c.hmget("hash2", fields, content2); ASSERT_EQUAL(content2.size(), (size_t) 4); for(size_t i=0; i<content2.size(); i++) { if(content.size() > i) ASSERT_EQUAL( content2[i], content[i].second ); else ASSERT_EQUAL( content2[i], redis::client::missing_value() ); } } test("hincrby"); { c.hset("hash3", "key1", "1"); long l; l = c.hincrby("hash3", "key1", 1); ASSERT_EQUAL( l, 2L ); l = c.hincrby("hash3", "key2", 1); ASSERT_EQUAL( l, 1L ); l = c.hincrby("hash3", "key3", -3); ASSERT_EQUAL( l, -3L ); string s; s = c.hget("hash3", "key1"); ASSERT_EQUAL( s, string("2") ); s = c.hget("hash3", "key2" ); ASSERT_EQUAL( s, string("1") ); s = c.hget("hash3", "key3" ); ASSERT_EQUAL( s, string("-3") ); } test("hexists"); { ASSERT_EQUAL( c.hexists("hash3", "key1"), true ); ASSERT_EQUAL( c.hexists("hash3", "key4"), false ); } test("hdel"); { ASSERT_EQUAL( c.hdel("hash3", "key1"), true ); ASSERT_EQUAL( c.hexists("hash3", "key1"), false ); ASSERT_EQUAL( c.hdel("hash3", "key4"), false ); ASSERT_EQUAL( c.hexists("hash3", "key4"), false ); c.hset("hash3", "key1", "hval1"); } test("hlen"); { ASSERT_EQUAL( c.hlen("hash3"), 3L ); ASSERT_EQUAL( c.hlen("hash4"), 0L ); } test("hkeys"); { redis::client::string_vector fields; c.hkeys("hash3", fields); ASSERT_EQUAL( fields.size(), (size_t) 3 ); std::sort(fields.begin(), fields.end()); ASSERT_EQUAL( fields[0], string("key1") ); ASSERT_EQUAL( fields[1], string("key2") ); ASSERT_EQUAL( fields[2], string("key3") ); } test("hvals"); { redis::client::string_vector vals; c.hvals("hash1", vals); ASSERT_EQUAL( vals.size(), (size_t) 4 ); std::sort(vals.begin(), vals.end()); ASSERT_EQUAL( vals[0], string("hval1") ); ASSERT_EQUAL( vals[1], string("hval2") ); ASSERT_EQUAL( vals[2], string("hval3") ); ASSERT_EQUAL( vals[3], string("hval4") ); } test("hgetall"); { redis::client::string_pair_vector entries; c.hgetall("hash1", entries); ASSERT_EQUAL( entries.size(), (size_t) 4 ); std::sort(entries.begin(), entries.end()); ASSERT_EQUAL( entries[0].first, string("key1") ); ASSERT_EQUAL( entries[0].second, string("hval1") ); ASSERT_EQUAL( entries[1].first, string("key2") ); ASSERT_EQUAL( entries[1].second, string("hval2") ); ASSERT_EQUAL( entries[2].first, string("key3") ); ASSERT_EQUAL( entries[2].second, string("hval3") ); ASSERT_EQUAL( entries[3].first, string("key4") ); ASSERT_EQUAL( entries[3].second, string("hval4") ); } }
void testNegativeBracketToPositiveIndex() { IndexableSet<int> indexSet{1,2,3,4}; int i = indexSet[-1]; ASSERT_EQUAL(4, i); }
void test_unmark_by_bucket_id(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_len = 0; size_t TEST_RECORD_COUNT = 10; size_t record_count = 0; const char *data = "DATA"; size_t data_size = strlen("DATA"); 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 buffer_size = data_size; char buffer[buffer_size]; size_t bucket_id_1 = 1; size_t i; for (i = 0; i < record_count / 2; ++i) { error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_1, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NONE); } size_t bucket_id_2 = 2; for (i = 0; i < record_count / 2; ++i) { error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_2, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NONE); } size_t bucket_id_3 = 3; error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND); error_code = ext_log_storage_remove_by_bucket_id(storage, bucket_id_2); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND); error_code = ext_log_storage_unmark_by_bucket_id(storage, bucket_id_1); ASSERT_EQUAL(error_code, KAA_ERR_NONE); size_t bucket_id_4 = 4; for (i = 0; i < record_count / 2; ++i) { error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_4, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NONE); } error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len); ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND); error_code = ext_log_storage_remove_by_bucket_id(storage, bucket_id_4); ASSERT_EQUAL(error_code, KAA_ERR_NONE); ASSERT_EQUAL(ext_log_storage_get_records_count(storage), 0); ASSERT_EQUAL(ext_log_storage_get_total_size(storage), 0); ext_log_storage_destroy(storage); KAA_TRACE_OUT(logger); }