END_TEST START_TEST(test_cjose_jws_import_get_plain_after_verify) { cjose_err err; // import the common key cjose_jwk_t *jwk = cjose_jwk_import(JWK_COMMON, strlen(JWK_COMMON), &err); ck_assert_msg(NULL != jwk, "cjose_jwk_import failed: " "%s, file: %s, function: %s, line: %ld", err.message, err.file, err.function, err.line); // import the jws created with the common key cjose_jws_t *jws = cjose_jws_import(JWS_COMMON, strlen(JWS_COMMON), &err); ck_assert_msg(NULL != jws, "cjose_jws_import failed: " "%s, file: %s, function: %s, line: %ld", err.message, err.file, err.function, err.line); // verify the imported jws ck_assert_msg(cjose_jws_verify(jws, jwk, &err), "cjose_jws_verify failed: " "%s, file: %s, function: %s, line: %ld", err.message, err.file, err.function, err.line); // get plaintext from imported and verified jws uint8_t *plaintext = NULL; size_t plaintext_len = 0; ck_assert_msg(cjose_jws_get_plaintext(jws, &plaintext, &plaintext_len, &err), "cjose_jws_get_plaintext failed: " "%s, file: %s, function: %s, line: %ld", err.message, err.file, err.function, err.line); // compare the verified plaintext to the expected value ck_assert_msg(strncmp(PLAIN_COMMON, plaintext, strlen(PLAIN_COMMON)) == 0, "verified plaintext from JWS doesn't match the original"); cjose_jws_release(jws); cjose_jwk_release(jwk); }
END_TEST /******************************************************************************* * test for chunk_map and friends */ START_TEST(test_chunk_map) { chunk_t *map, contents = chunk_from_chars(0x01,0x02,0x03,0x04,0x05); char *path = "/tmp/strongswan-chunk-map-test"; ck_assert(chunk_write(contents, path, 022, TRUE)); /* read */ map = chunk_map(path, FALSE); ck_assert(map != NULL); ck_assert_msg(chunk_equals(*map, contents), "%B", map); /* altering mapped chunk should not hurt */ *map = chunk_empty; ck_assert(chunk_unmap(map)); /* write */ map = chunk_map(path, TRUE); ck_assert(map != NULL); ck_assert_msg(chunk_equals(*map, contents), "%B", map); map->ptr[0] = 0x06; ck_assert(chunk_unmap(map)); /* verify write */ contents.ptr[0] = 0x06; map = chunk_map(path, FALSE); ck_assert(map != NULL); ck_assert_msg(chunk_equals(*map, contents), "%B", map); ck_assert(chunk_unmap(map)); unlink(path); }
END_TEST START_TEST(test_bits_io_write_bit) { BitsIOFile *bfile = bits_io_open("test/test.hf", "r"); unsigned char bit; bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, 1); bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, 1); bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, 0); bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, 1); bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, 0); int nbytes = bits_io_num_bytes(bfile); ck_assert_int_eq(nbytes, 0); int result = bits_io_close(bfile); ck_assert_msg(result != EOF, "closing the file should not be EOF."); bfile = bits_io_open("test/test-stress.hf", "r"); for (int i = 0; i < BIT_ITERATIONS; i++) { bit = bits_io_read_bit(bfile); ck_assert_int_eq(bit, i%2); } ck_assert_int_eq(bits_io_num_bytes(bfile), BIT_ITERATIONS/7); result = bits_io_close(bfile); ck_assert_msg(result != EOF, "closing the file should not be EOF."); // Delete the files: remove("test/test.hf"); remove("test/test-stress.hf"); }
END_TEST START_TEST(check_parser_header) { dmime_common_headers_t *header1, *header2; int res = 0; size_t outsize; unsigned char *formatted; header1 = dime_prsr_headers_create(); header1->headers[HEADER_TYPE_DATE] = st_import("11:34:12 AM March 12, 2004", 26); header1->headers[HEADER_TYPE_TO] = st_import("*****@*****.**", 13); header1->headers[HEADER_TYPE_CC] = st_import("*****@*****.**", 16); header1->headers[HEADER_TYPE_FROM] = st_import("*****@*****.**", 22); header1->headers[HEADER_TYPE_ORGANIZATION] = st_import("Cool people organization", 24); header1->headers[HEADER_TYPE_SUBJECT] = st_import("here's stuff", 12); formatted = dime_prsr_headers_format(header1, &outsize); ck_assert_msg(formatted != NULL, "Failed to format common headers.\n"); header2 = dime_prsr_headers_parse(formatted, outsize); ck_assert_msg(header2 != NULL, "Failed to parse common headers.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_DATE], header2->headers[HEADER_TYPE_DATE]); ck_assert_msg(res == 0, "Date header was corrupted.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_TO], header2->headers[HEADER_TYPE_TO]); ck_assert_msg(res == 0, "To header was corrupted.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_CC], header2->headers[HEADER_TYPE_CC]); ck_assert_msg(res == 0, "CC header was corrupted.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_FROM], header2->headers[HEADER_TYPE_FROM]); ck_assert_msg(res == 0, "From header was corrupted.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_ORGANIZATION], header2->headers[HEADER_TYPE_ORGANIZATION]); ck_assert_msg(res == 0, "Organization header was corrupted.\n"); res = st_cmp_cs_eq(header1->headers[HEADER_TYPE_SUBJECT], header2->headers[HEADER_TYPE_SUBJECT]); ck_assert_msg(res == 0, "Subject header was corrupted.\n"); dime_prsr_headers_destroy(header1); dime_prsr_headers_destroy(header2); free(formatted); fprintf(stderr, "DMIME common header parsing complete.\n"); }
END_TEST START_TEST(test_large_data) { unsigned char k[CRYPTO_SHARED_KEY_SIZE]; unsigned char n[CRYPTO_NONCE_SIZE]; unsigned char m1[MAX_CRYPTO_PACKET_SIZE - CRYPTO_MAC_SIZE]; unsigned char c1[sizeof(m1) + CRYPTO_MAC_SIZE]; unsigned char m1prime[sizeof(m1)]; unsigned char m2[MAX_CRYPTO_PACKET_SIZE]; unsigned char c2[sizeof(m2) + CRYPTO_MAC_SIZE]; int c1len, c2len; int m1plen; //Generate random messages rand_bytes(m1, sizeof(m1)); rand_bytes(m2, sizeof(m2)); rand_bytes(n, CRYPTO_NONCE_SIZE); //Generate key rand_bytes(k, CRYPTO_SHARED_KEY_SIZE); c1len = encrypt_data_symmetric(k, n, m1, sizeof(m1), c1); c2len = encrypt_data_symmetric(k, n, m2, sizeof(m2), c2); ck_assert_msg(c1len == sizeof(m1) + CRYPTO_MAC_SIZE, "could not encrypt"); ck_assert_msg(c2len == sizeof(m2) + CRYPTO_MAC_SIZE, "could not encrypt"); m1plen = decrypt_data_symmetric(k, n, c1, c1len, m1prime); ck_assert_msg(m1plen == sizeof(m1), "decrypted text lengths differ"); ck_assert_msg(memcmp(m1prime, m1, sizeof(m1)) == 0, "decrypted texts differ"); }
/** * Run an echo server */ static job_requeue_t serve_echo(echo_server_config_t *config) { tls_socket_t *tls; int sfd, cfd; identification_t *server, *client = NULL; ssize_t len, total, done; char buf[128]; server = identification_create_from_string(config->addr); if (config->cauth) { client = server; } sfd = config->fd; while (TRUE) { cfd = accept(sfd, NULL, NULL); if (cfd < 0) { break; } tls = tls_socket_create(TRUE, server, client, cfd, NULL, config->version, TRUE); ck_assert(tls != NULL); while (TRUE) { len = tls->read(tls, buf, sizeof(buf), TRUE); if (len <= 0) { break; } total = 0; while (total < len) { done = tls->write(tls, buf + total, len - total); ck_assert_msg(done > 0, "%s", strerror(errno)); total += done; } } tls->destroy(tls); close(cfd); } server->destroy(server); return JOB_REQUEUE_NONE; }
END_TEST #define NUM_VALORES 9 START_TEST( test_cola_prioridad_pop) { const tipo_dato VALORES[NUM_VALORES] = { 9, 5, 10, 1, 6, 11, 0, 2, 3 }; const tipo_dato VALORES_FINALES_INORDER[NUM_VALORES - 2] = { 2, 3, 4, 5, 6, 9, 10 }; int resultado = 0; int num_datos_colectados = 0; cola_prioridad_contexto ctx; tipo_dato valores_inorder_resultado[NUM_VALORES] = { 0 }; nodo_cola_prioridad **referencias_directas = NULL; nodo_cola_prioridad *nodo_pop_1 = NULL; nodo_cola_prioridad *nodo_pop_2 = NULL; caca_log_debug("empezando el año"); cola_prioridad_init(&ctx, NULL, (tipo_dato *) VALORES, NULL, NUM_VALORES, NULL, NULL); referencias_directas = ctx.referencias_directas_por_indice; for (int i = 0; i < NUM_VALORES + 1; i++) { caca_log_debug("referencias directas indice %d valor %ld", i, ARBOL_AVL_GET_VALOR(*(referencias_directas + i))); } nodo_pop_1 = cola_prioridad_pop(&ctx); nodo_pop_2 = cola_prioridad_pop(&ctx); cola_prioridad_get_valores(&ctx, valores_inorder_resultado, &num_datos_colectados); for (int i = 0; i < NUM_VALORES; i++) { caca_log_debug("eien pressure %d %ld", i, *(valores_inorder_resultado + i)); } resultado = num_datos_colectados == (NUM_VALORES - 2) && !memcmp(VALORES_FINALES_INORDER, valores_inorder_resultado, 9) && nodo_pop_1->valor == 0 && nodo_pop_2->valor == 1; zlog_fini(); ck_assert_msg(resultado, "los datos colectados %d", num_datos_colectados); }
END_TEST START_TEST (test_reject_p1_n1_c2) { int i; s_array * paths; c_array * line_buffer; i_array * stat_indices; d_array * obs_stats; d_array * means; d_array * std_devs; s_array * header; sample_array * samples; int num_to_retain; num_to_retain = 1; paths = init_s_array(1); line_buffer = init_c_array(1023); stat_indices = init_i_array(4); means = init_d_array(1); std_devs = init_d_array(1); obs_stats = init_d_array(1); header = init_s_array(1); append_s_array(paths, "data/test_parameter_stat_samples.txt"); parse_header(get_s_array(paths, 0), line_buffer, header); for (i = 3; i < header->length; i += 2) { append_i_array(stat_indices, i); } append_d_array(obs_stats, 0.21); append_d_array(obs_stats, 2.0); append_d_array(means, 0.2225); append_d_array(means, 3.0); append_d_array(std_devs, 0.009574271); append_d_array(std_devs, 1.154701); standardize_vector(obs_stats, means, std_devs); samples = reject(paths, line_buffer, stat_indices, obs_stats, means, std_devs, num_to_retain, header); ck_assert_int_eq(samples->length, num_to_retain); ck_assert_int_eq(samples->capacity, num_to_retain); ck_assert_msg((almost_equal(samples->a[0]->distance, 0.0, 0.000001)), "euclidean distance was %lf, expected %lf", samples->a[0]->distance, 0.0); free_s_array(paths); free_c_array(line_buffer); free_i_array(stat_indices); free_d_array(obs_stats); free_sample_array(samples); free_d_array(means); free_d_array(std_devs); free_s_array(header); }
}END_TEST START_TEST(check_Fs_LoadFile) { void *buffer; int64_t len = Fs_Load("quetoo.cfg", &buffer); ck_assert_msg(len > 0, "Failed to load quetoo.cfg"); const char *prefix = "// generated by Quetoo, do not modify\n"; ck_assert(g_str_has_prefix((const char *) buffer, prefix)); Fs_Free(buffer); }END_TEST
END_TEST START_TEST(test_modu) { double a[]= {10.0, 0.0, 0.0}; double m; modu(a,&m); // fail_unless( m == 10.0); ck_assert_msg( fabs(m - 10.0) < EPS, "Was expecting m to be 10.0 but found %f \n", m); }
END_TEST START_TEST(test_pack_loc_limit) { LocMsg lmsg; LocMsg *lmsgp = NULL; char *buf; enum ck_msg_type type; lmsg.file = (char *) ""; lmsg.line = 0; pack (CK_MSG_LOC, &buf, (CheckMsg *) &lmsg); lmsg.file = NULL; upack (buf, (CheckMsg *) &lmsg, &type); ck_assert_msg (lmsg.file != NULL, "Empty string not handled properly"); ck_assert_msg (strcmp (lmsg.file, "") == 0, "Empty string not handled properly"); free (lmsg.file); lmsg.file = NULL; pack (CK_MSG_LOC, &buf, (CheckMsg *) &lmsg); pack (CK_MSG_LOC, &buf, (CheckMsg *) lmsgp); }
void test_expire_basic(uint32_t policy, bool cas) { #define KEY "key" #define VAL "value" #define NOW 12345678 struct bstring key; struct val val; rstatus_i status; struct item *it; test_reset(policy, cas); key.data = KEY; key.len = sizeof(KEY) - 1; val.type = VAL_TYPE_STR; val.vstr.data = VAL; val.vstr.len = sizeof(VAL) - 1; now = NOW; status = cuckoo_insert(&key, &val, NOW + 1); ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d", status); it = cuckoo_get(&key); ck_assert_msg(it != NULL, "cuckoo_get returned NULL"); now += 2; it = cuckoo_get(&key); ck_assert_msg(it == NULL, "cuckoo_get returned not NULL after expiration"); #undef NOW #undef KEY #undef VAL }
END_TEST START_TEST (test_send_disconnect) { int err; memif_connection_t conn; conn.fd = -1; /* only possible fail if memif_msg_send fails... */ /* obsolete without socket */ if ((err = memif_msg_send_disconnect (conn.fd, (uint8_t *)"unit_test_dc", 0)) != MEMIF_ERR_SUCCESS) ck_assert_msg (err == MEMIF_ERR_BAD_FD, "err code: %u, err msg: %s", err, memif_strerror (err)); }
END_TEST START_TEST(test_fork1c_pass) { pid_t pid; if((pid = check_fork()) < 0) { ck_abort_msg("Failed to fork new process"); } else if (pid > 0) { check_waitpid_and_exit(pid); } else { ck_assert_msg(1, NULL); check_waitpid_and_exit(0); } }
END_TEST START_TEST(test_getself_name) { char *nickname = "testGallop"; int len = strlen(nickname); char nick_check[len]; setname(m, (uint8_t *)nickname, len); getself_name(m, (uint8_t *)nick_check); ck_assert_msg((memcmp(nickname, nick_check, len) == 0), "getself_name failed to return the known name!\n" "known name: %s\nreturned: %s\n", nickname, nick_check); }
END_TEST /* Parse PDBML - Write PDB */ START_TEST(test_read_pdbml) { /* set filename */ char filename_in[] = "test_alanine_in_01.xml"; /* set gPDBXML flag */ gPDBXML = FALSE; /* read test file */ strcat(test_input_filename,filename_in); fp = fopen(test_input_filename,"r"); wpdb = blReadWholePDB(fp); fclose(fp); /* tests */ ck_assert_msg(wpdb != NULL, "Failed to read PDB file."); ck_assert_msg(wpdb->pdb != NULL, "No atom data read from file."); ck_assert_msg(wpdb->natoms > 0, "Atom count not set."); ck_assert_msg(gPDBXML == TRUE, "PDB read flag not set."); }
END_TEST /** * Inserts enough items to exceed the heap's capacity and cause it to expand. */ START_TEST(expand_test) { pb_heap_insert(heap, (void*)1, 1.f); pb_heap_insert(heap, (void*)3, 3.f); pb_heap_insert(heap, (void*)7, 7.f); pb_heap_insert(heap, (void*)8, 8.f); pb_heap_insert(heap, (void*)10, 10.f); pb_heap_insert(heap, (void*)113, 113.f); ck_assert_msg(heap->items.size == 10, "Heap's size was %u, should have been 10.", heap->items.size); }
END_TEST START_TEST(check_ec_sha_signatures) { EC_KEY *key; unsigned char *rdata, *sigdata; size_t dlens[] = { 16, 128, 1024, 65535 }; size_t rsize, siglen, last_min = 1; unsigned int shabits; int res; res = crypto_init(); ck_assert_msg(!res, "Crypto initialization routine failed.\n"); key = generate_ec_keypair(0); ck_assert_msg((key != NULL), "EC SHA signature/verification check failed: could not generate key pair.\n"); for (size_t i = 0; i < (sizeof(dlens) / sizeof(dlens[0])); i++) { for (size_t j = 0; j < N_SIGNATURE_TIER_TESTS; j++) { for (size_t k = 0; k < 3; k++) { if (!k) { shabits = 160; } else if (k == 1) { shabits = 256; } else { shabits = 512; } rdata = gen_random_data(last_min, dlens[i], &rsize); ck_assert_msg((rdata != NULL), "EC SHA signature/verification check failed: could not generate random data.\n"); sigdata = ec_sign_sha_data(rdata, rsize, shabits, key, &siglen); ck_assert_msg((sigdata != NULL), "EC SHA signature/verification check failed: could not sign data.\n"); ck_assert_msg((siglen > 0), "EC SHA signature/verification check failed: signature result had bad length.\n"); res = verify_ec_sha_signature(rdata, rsize, shabits, sigdata, siglen, key); ck_assert_msg((res == 1), "EC SHA signature/verification check failed: signature verification failed (%d).\n", res); free(sigdata); free(rdata); } last_min = dlens[i]; } } free_ec_key(key); fprintf(stderr, "EC SHA signature/verification check completed.\n"); }
static void validate_bitmap(struct tw_bitmap *bitmap, uint32_t nbits) { ck_assert_msg(tw_bitmap_empty(bitmap), "A new bitmap should be empty"); for (uint32_t pos = 0; pos < nbits; ++pos) { ck_assert(!tw_bitmap_test(bitmap, pos)); tw_bitmap_set(bitmap, pos); } for (uint32_t pos = 0; pos < nbits; ++pos) { ck_assert(tw_bitmap_test(bitmap, (nbits - 1) - pos)); } ck_assert(tw_bitmap_full(bitmap)); for (uint32_t pos = 0; pos < nbits; ++pos) { ck_assert_msg(tw_bitmap_test(bitmap, pos)); tw_bitmap_clear(bitmap, pos); ck_assert_msg(!tw_bitmap_test(bitmap, pos)); } ck_assert(tw_bitmap_empty(bitmap)); }
END_TEST ////////////////////////////////////////////////////////////////////// ///////////// table unit tests ////////////////////////////////////////////////////////////////////// START_TEST(test_table_build) { TreeNode *t = huffman_build_tree("books/holmes.txt");// holmes ck_assert_int_eq(tree_size(t), 161); EncodeTable *etab = table_build(t); ck_assert_msg(etab != NULL, "Encode table should not be NULL."); free(t); }
END_TEST START_TEST (test_frequency_of_int_partitions_by_k_n2) { double e, ep; e = 0.000001; int n, tp, i; d_array * probs; probs = init_d_array(1); n = 2; tp = frequency_of_int_partitions_by_k(n, probs); ep = 1.0; ck_assert_msg((almost_equal(tp, ep, e) != 0), "total probability is %lf, not %lf", tp, ep); ck_assert_int_eq(probs->length, n); i = 0; ep = 0.5; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 1; ep = 0.5; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); free_d_array(probs); }
static UA_StatusCode makeThumbprint_testing(const UA_SecurityPolicy *securityPolicy, const UA_ByteString *certificate, UA_ByteString *thumbprint) { SET_CALLED(makeCertificateThumbprint); ck_assert(securityPolicy != NULL); ck_assert(certificate != NULL); ck_assert(thumbprint != NULL); ck_assert_msg(thumbprint->length == 20, "Thumbprints have to be 20 bytes long (current specification)"); memset(thumbprint->data, 42, 20); return UA_STATUSCODE_GOOD; }
END_TEST START_TEST(test_pack_len) { CtxMsg cmsg; char *buf; int n = 0; enum ck_msg_type type; cmsg.ctx = CK_CTX_TEST; n = pack (CK_MSG_CTX, &buf, (CheckMsg *) &cmsg); ck_assert_msg (n > 0, "Return val from pack not set correctly"); /* Value below may change with different implementations of pack */ ck_assert_msg (n == 8, "Return val from pack not correct"); n = upack (buf, (CheckMsg *) &cmsg, &type); if (n != 8) { snprintf (errm, sizeof (errm), "%d bytes read from upack, should be 8", n); fail (errm); } free (buf); }
/* Media change */ CALL_AND_START_LOOP(TypeAudio, TypeAudio) { /* Both send */ payload_size = toxav_prepare_audio_frame(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, 1000, sample_payload, frame_size); if ( payload_size < 0 ) { ck_assert_msg ( 0, "Failed to encode payload" ); } toxav_send_audio(status_control.Alice.av, status_control.Alice.call_index, prepared_payload, payload_size); payload_size = toxav_prepare_audio_frame(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, 1000, sample_payload, frame_size); if ( payload_size < 0 ) { ck_assert_msg ( 0, "Failed to encode payload" ); } toxav_send_audio(status_control.Bob.av, status_control.Bob.call_index, prepared_payload, payload_size); /* Wait 2 seconds and change transmission type */ if (time(NULL) - times_they_are_a_changin > 2) { times_they_are_a_changin = time(NULL); muhcaps.audio_bitrate ++; toxav_change_settings(status_control.Alice.av, status_control.Alice.call_index, &muhcaps); } if (time(NULL) - cur_time > 10) { /* Transmit for 10 seconds */ step++; /* This terminates the loop */ toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index); toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index); /* Call over Alice hangs up */ toxav_hangup(status_control.Alice.av, status_control.Alice.call_index); } }
END_TEST START_TEST( test_imprime_array) { const tipo_dato VALORES[3][3] = { { 10, 20, 30 }, { 100, 200, 300 }, { 1000, 2000, 3000 } }; void *ptr = NULL; ptr = (void *) VALORES; zlog_fini(); ck_assert_msg(!caca_imprime_matrix(ptr, 3, NULL, 3), "El valor %p no es apuntador valido", ptr); }
/* * assert_address_records_in_answer asserts that ancount in the header * is >= 1, ancount is equal to the length of "answer", and that all of * the records in the answer section are A and/or AAAA resource records * based on the value of the a/aaaa arguments. */ void assert_address_in_answer(struct extracted_response *ex_response, int a, int aaaa) { uint32_t ancount; size_t length; struct getdns_dict *rr_dict; uint32_t type; uint32_t address_records = 0; size_t i; ASSERT_RC(getdns_dict_get_int(ex_response->header, "ancount", &ancount), GETDNS_RETURN_GOOD, "Failed to extract \"ancount\""); ck_assert_msg(ancount >= 1, "Expected ancount >= 1, got %d", ancount); ASSERT_RC(getdns_list_get_length(ex_response->answer, &length), GETDNS_RETURN_GOOD, "Failed to extract \"answer\" length"); ck_assert_msg(length == ancount, "Expected \"answer\" length == ancount: %d, got %d", ancount, length); for(i = 0; i < length; i++) { ASSERT_RC(getdns_list_get_dict(ex_response->answer, i, &rr_dict), GETDNS_RETURN_GOOD, "Failed to extract \"answer\" record"); ASSERT_RC(getdns_dict_get_int(rr_dict, "type", &type), GETDNS_RETURN_GOOD, "Failed to extract \"type\" from answer record"); switch (type) { case GETDNS_RRTYPE_A: if(a && type == GETDNS_RRTYPE_A) address_records++; case GETDNS_RRTYPE_AAAA: if(aaaa && type == GETDNS_RRTYPE_AAAA) address_records++; } } ck_assert_msg(ancount == address_records, "ancount: %d address records mismatch: %d", ancount, address_records); }
END_TEST START_TEST (test_cumulative_frequency_of_int_partitions_by_k_n7) { double e, ep; e = 0.000001; int n, tp, i, ip; d_array * probs; probs = init_d_array(1); n = 7; tp = cumulative_frequency_of_int_partitions_by_k(n, probs); ep = 1.0; ip = 15; ck_assert_msg((almost_equal(tp, ep, e) != 0), "total probability is %lf, not %lf", tp, ep); ck_assert_int_eq(probs->length, n); i = 0; ep = 1/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 1; ep = 4/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 2; ep = 8/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 3; ep = 11/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 4; ep = 13/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 5; ep = 14/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); i = 6; ep = 15/(double)ip; ck_assert_msg((almost_equal(get_d_array(probs, i), ep, e) != 0), "cat %d has probability is %lf, not %lf", i+1, get_d_array(probs, i), ep); free_d_array(probs); }
END_TEST START_TEST (test_recv_disconnect) { int err; memif_connection_t conn; memif_msg_t msg; msg.type = MEMIF_MSG_TYPE_DISCONNECT; memset (msg.disconnect.string, 0, sizeof (msg.disconnect.string)); strncpy ((char *) msg.disconnect.string, "unit_test_dc", 12); if ((err = memif_msg_receive_disconnect (&conn, &msg)) != MEMIF_ERR_SUCCESS) ck_assert_msg (err == MEMIF_ERR_DISCONNECT, "err code: %u, err msg: %s", err, memif_strerror (err)); ck_assert_str_eq ((char *)conn.remote_disconnect_string, "unit_test_dc"); }
END_TEST START_TEST (test_send_hello) { int err; memif_connection_t conn; conn.fd = -1; if ((err = memif_init (control_fd_update, TEST_APP_NAME, NULL, NULL, NULL)) != MEMIF_ERR_SUCCESS) ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err)); if ((err = memif_msg_send_hello (conn.fd)) != MEMIF_ERR_SUCCESS) ck_assert_msg (err == MEMIF_ERR_BAD_FD, "err code: %u, err msg: %s", err, memif_strerror (err)); }
END_TEST START_TEST (test_generate_int_partitions_n1) { int n; n = 1; i_array * expected = init_i_array(1); i_array_2d * partitions = init_i_array_2d(1,1); partitions = generate_int_partitions(n); ck_assert_int_eq(partitions->length, 1); append_i_array(expected, 1); ck_assert_msg((i_arrays_equal(get_i_array_2d(partitions, 0), expected) != 0), "unexpected partition"); free_i_array(expected); free_i_array_2d(partitions); }