void __testListen_Accept_After_Connect() { __init_pcap_record(CU_get_current_test()->pName); int err = 0; int ret = 0; my_context server_socket = __target->open(__target, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_PTR_NOT_NULL_FATAL(server_socket); struct sockaddr_in addr; socklen_t len = sizeof(addr); memset(&addr, 0, len); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(10000); ret = __target->bind(__target, server_socket, (struct sockaddr*)&addr, len, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_TRUE_FATAL(ret); ret = __target->listen(__target, server_socket, 3, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_TRUE_FATAL(ret); addr.sin_addr.s_addr = inet_addr("10.0.0.100"); my_context client = __reference->open(__reference, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_PTR_NOT_NULL_FATAL(client); // printf("aaaaaaaaaaaaaaaaaaaaa\n"); ret = __reference->connect(__reference, client, (struct sockaddr*)&addr, len, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_TRUE_FATAL(ret); // printf("aaaaaaaaaaaaaaa\n"); __flush_packets(100); ret = __target->accept(__target, server_socket, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_TRUE_FATAL(ret); // printf("bbbbbbbbbbbbbbbb\n"); application* clientApp = __find_app(__reference, client); CU_ASSERT_EQUAL(clientApp->active_open_calls, 1); application* serverApp = __find_app(__target, server_socket); CU_ASSERT_EQUAL(serverApp->active_open_calls, 0); CU_ASSERT_EQUAL(list_get_count(serverApp->passive_open_calls), 1); // printf("cccccccccccccc\n"); __pcap_close(); }
void testCheckDuplicates2(void) { bson b, b2; bson_iterator it, sit; bson_type bt; bson_init(&b); bson_append_start_array(&b, "array"); bson_append_int(&b, "0", 1); bson_append_finish_array(&b); bson_append_start_array(&b, "array"); bson_append_int(&b, "0", 3); bson_append_int(&b, "1", 4); bson_append_finish_array(&b); bson_finish(&b); CU_ASSERT_FALSE_FATAL(b.err); CU_ASSERT_TRUE_FATAL(bson_check_duplicate_keys(&b)); bson_init(&b2); bson_fix_duplicate_keys(&b, &b2); bson_finish(&b2); CU_ASSERT_FALSE_FATAL(b2.err); CU_ASSERT_FALSE_FATAL(bson_check_duplicate_keys(&b2)); BSON_ITERATOR_INIT(&it, &b2); bt = bson_iterator_next(&it); CU_ASSERT_EQUAL_FATAL(bt, BSON_ARRAY); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&it), "array"); BSON_ITERATOR_SUBITERATOR(&it, &sit); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "0"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 1); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "1"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 3); bt = bson_iterator_next(&sit); CU_ASSERT_STRING_EQUAL_FATAL(BSON_ITERATOR_KEY(&sit), "2"); CU_ASSERT_TRUE_FATAL(BSON_IS_NUM_TYPE(bt)); CU_ASSERT_EQUAL_FATAL(bson_iterator_int(&sit), 4); bt = bson_iterator_next(&sit); CU_ASSERT_EQUAL_FATAL(bt, BSON_EOO); bson_destroy(&b2); bson_destroy(&b); }
void test_addPattern(void) { HObs hObs = NULL; RU8 pattern[] = { 0x01, 0x02, 0x03, 0x04 }; RU32 context = 0; hObs = obsLib_new( 0, 0 ); CU_ASSERT_TRUE_FATAL( rpal_memory_isValid( hObs ) ); CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern, sizeof( pattern ), &context ) ); obsLib_free( hObs ); }
static void test_raw_expected(const char * uriStr, const char * testBuf, size_t testLen, const char * expectBuf, size_t expectLen, lwm2m_media_type_t format, const char * id) { lwm2m_data_t * tlvP; lwm2m_uri_t uri; int size; if (uriStr != NULL) { lwm2m_stringToUri(uriStr, strlen(uriStr), &uri); } size = lwm2m_data_parse((uriStr != NULL) ? &uri : NULL, (uint8_t *)testBuf, testLen, format, &tlvP); CU_ASSERT_TRUE_FATAL(size>0); // Serialize to the same format and compare to the input buffer test_data_and_compare(uriStr, format, tlvP, size, id, (uint8_t*)expectBuf, expectLen); // Serialize to the other format respectivly. if (format == LWM2M_CONTENT_TLV) test_data(uriStr, LWM2M_CONTENT_JSON, tlvP, size, id); else if (format == LWM2M_CONTENT_JSON) test_data(uriStr, LWM2M_CONTENT_TLV, tlvP, size, id); }
static LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; char filepath[256]={0}; char ringpath[256]={0}; char ringbackpath[256]={0}; char rootcapath[256]={0}; char dnsuserhostspath[256]={0}; char nowebcampath[256]={0}; if (path==NULL) path="."; if (file){ sprintf(filepath, "%s/%s", path, file); CU_ASSERT_TRUE_FATAL(ortp_file_exist(filepath)==0); } lc = linphone_core_new(v_table,NULL,*filepath!='\0' ? filepath : NULL, user_data); sal_enable_test_features(lc->sal,TRUE); snprintf(rootcapath, sizeof(rootcapath), "%s/certificates/cn/cafile.pem", path); linphone_core_set_root_ca(lc,rootcapath); sprintf(dnsuserhostspath, "%s/%s", path, userhostsfile); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); snprintf(ringpath,sizeof(ringpath), "%s/sounds/oldphone.wav",path); snprintf(ringbackpath,sizeof(ringbackpath), "%s/sounds/ringback.wav", path); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); snprintf(nowebcampath, sizeof(nowebcampath), "%s/images/nowebcamCIF.jpg", path); linphone_core_set_static_picture(lc,nowebcampath); return lc; }
/** * @brief Parses the testBuf to an array of lwm2m_data_t objects and serializes the result * to TLV and JSON and if applicable compares it to the original testBuf. * @param testBuf The input buffer. * @param testLen The length of the input buffer. * @param format The format of the testBuf. Maybe LWM2M_CONTENT_TLV or LWM2M_CONTENT_JSON at the moment. * @param id The test object id for debug out. */ static void test_raw(const char * uriStr, const char * testBuf, size_t testLen, lwm2m_media_type_t format, const char * id) { lwm2m_data_t * tlvP; lwm2m_uri_t uri; int size; if (uriStr != NULL) { lwm2m_stringToUri(uriStr, strlen(uriStr), &uri); } size = lwm2m_data_parse((uriStr != NULL) ? &uri : NULL, (uint8_t *)testBuf, testLen, format, &tlvP); CU_ASSERT_TRUE_FATAL(size>0); // Serialize to the same format and compare to the input buffer test_data_and_compare(uriStr, format, tlvP, size, id, (uint8_t*)testBuf, testLen); // Serialize to the TLV format // the reverse is not possible as TLV format loses the data type information if (format == LWM2M_CONTENT_JSON) { test_data(uriStr, LWM2M_CONTENT_TLV, tlvP, size, id); } }
void test_cancel() { T1 t1, t2; CU_ASSERT_TRUE_FATAL(t1.cancel()); t2.start(); CU_ASSERT_FALSE_FATAL(t2.cancel()); t2.stop(); }
void testTicket53(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_53", JBOWRITER | JBOCREAT)); ejdbclose(jb); ejdbdel(jb); jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_53", JBOWRITER)); EJCOLL *coll = ejdbcreatecoll(jb, "mycoll", NULL); if (!coll) { eprint(jb, __LINE__, "testTicket53"); } CU_ASSERT_TRUE(coll != NULL); ejdbclose(jb); ejdbdel(jb); }
LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { LinphoneCore* lc; LpConfig* config = NULL; char *filepath = NULL; char *ringpath = NULL; char *ringbackpath = NULL; char *rootcapath = NULL; char *dnsuserhostspath = NULL; char *nowebcampath = NULL; if (path==NULL) path="."; if (file){ filepath = ms_strdup_printf("%s/%s", path, file); CU_ASSERT_TRUE_FATAL(ortp_file_exist(filepath)==0); config = lp_config_new_with_factory(NULL,filepath); } // setup dynamic-path assets ringpath = ms_strdup_printf("%s/sounds/oldphone.wav",path); ringbackpath = ms_strdup_printf("%s/sounds/ringback.wav", path); nowebcampath = ms_strdup_printf("%s/images/nowebcamCIF.jpg", path); rootcapath = ms_strdup_printf("%s/certificates/cn/cafile.pem", path); dnsuserhostspath = ms_strdup_printf( "%s/%s", path, userhostsfile); if( config != NULL ) { lp_config_set_string(config, "sound", "remote_ring", ringbackpath); lp_config_set_string(config, "sound", "local_ring" , ringpath); lp_config_set_string(config, "sip", "root_ca" , rootcapath); lc = linphone_core_new_with_config(v_table, config, user_data); } else { lc = linphone_core_new(v_table,NULL,(filepath!=NULL&&filepath[0]!='\0') ? filepath : NULL, user_data); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); linphone_core_set_root_ca(lc,rootcapath); } sal_enable_test_features(lc->sal,TRUE); sal_set_dns_user_hosts_file(lc->sal, dnsuserhostspath); linphone_core_set_static_picture(lc,nowebcampath); linphone_core_enable_ipv6(lc, liblinphone_tester_ipv6_enabled); ms_free(ringpath); ms_free(ringbackpath); ms_free(nowebcampath); ms_free(rootcapath); ms_free(dnsuserhostspath); if( filepath ) ms_free(filepath); if( config ) lp_config_unref(config); return lc; }
static void sender_insertProducts(void) { pqueue* pq; int status = pq_open(UP7_PQ_PATHNAME, 0, &pq); CU_ASSERT_EQUAL_FATAL(status, 0); product prod; prod_info* info = &prod.info; char ident[80]; void* data = NULL; unsigned short xsubi[3] = {(unsigned short)1234567890, (unsigned short)9876543210, (unsigned short)1029384756 }; info->feedtype = EXP; info->ident = ident; info->origin = "localhost"; (void)memset(info->signature, 0, sizeof(info->signature)); for (int i = 0; i < NUM_PRODS; i++) { const unsigned size = MAX_PROD_SIZE*erand48(xsubi) + 0.5; const ssize_t nbytes = snprintf(ident, sizeof(ident), "%d", i); CU_ASSERT_TRUE_FATAL(nbytes >= 0 && nbytes < sizeof(ident)); status = set_timestamp(&info->arrival); CU_ASSERT_EQUAL_FATAL(status, 0); info->seqno = i; uint32_t signet = htonl(i); (void)memcpy(info->signature+sizeof(signaturet)-sizeof(signet), &signet, sizeof(signet)); info->sz = size; data = realloc(data, size); CU_ASSERT_PTR_NOT_NULL(data); prod.data = data; status = pq_insert(pq, &prod); CU_ASSERT_EQUAL_FATAL(status, 0); char buf[LDM_INFO_MAX]; LOG_ADD1("Inserted: prodInfo=\"%s\"", s_prod_info(buf, sizeof(buf), info, 1)); log_log(LOG_INFO); struct timespec duration; duration.tv_sec = 0; duration.tv_nsec = 5000000; // 5 ms status = nanosleep(&duration, NULL); CU_ASSERT_EQUAL_FATAL(status, 0); } free(data); status = pq_close(pq); CU_ASSERT_EQUAL_FATAL(status, 0); }
static void test_open_on_dev_null_if_closed( void) { int status = close(STDERR_FILENO); CU_ASSERT_EQUAL_FATAL(status, 0); status = open_on_dev_null_if_closed(STDERR_FILENO, O_RDWR); CU_ASSERT_EQUAL_FATAL(status, 0); CU_ASSERT_FALSE_FATAL(log_is_stderr_useful()); CU_ASSERT_TRUE_FATAL(fcntl(STDERR_FILENO, F_GETFD) >= 0); }
void test_CreateAndDestroy(void) { HObs hObs = NULL; hObs = obsLib_new( 0, 0 ); CU_ASSERT_TRUE_FATAL( rpal_memory_isValid( hObs ) ); obsLib_free( hObs ); }
void test_local_no_start() { T2 t2(false); t2.start(); USLEEP(100); USLEEP(100); CU_ASSERT_TRUE_FATAL( RThreadState::state_is(t2, T2::terminatedState)); t2.stop(); }
static void test_1(void) { const char buffer[] = {0x03, 0x0A, 0xC1, 0x01, 0x14, 0x03, 0x0B, 0xC1, 0x01, 0x15, 0x03, 0x0C, 0xC1, 0x01, 0x16}; int testLen = sizeof(buffer); lwm2m_media_type_t format = LWM2M_CONTENT_TLV; lwm2m_data_t * tlvP; int size = lwm2m_data_parse(NULL, (uint8_t *)buffer, testLen, format, &tlvP); CU_ASSERT_TRUE_FATAL(size>0); // Serialize to the same format and compare to the input buffer test_data_and_compare(NULL, format, tlvP, size, "1", (uint8_t*)buffer, testLen); }
void test_current() { StdThreadRepository& tr = StdThreadRepository::instance(); // this thread is not registered; CU_ASSERT_PTR_NULL_FATAL(RT::current()); CU_ASSERT_EQUAL_FATAL(tr.size(), 0); T1* thread1 = T1::create<T1>("thread1"); T1* thread2 = T1::create<T1>("thread2"); thread1->start(); thread2->start(); thread1->is_terminal_state().wait(); thread2->is_terminal_state().wait(); CU_ASSERT_TRUE_FATAL(thread1->is_check_passed().signalled()); CU_ASSERT_FALSE_FATAL(thread1->is_check_failed().signalled()); CU_ASSERT_TRUE_FATAL(thread2->is_check_passed().signalled()); CU_ASSERT_FALSE_FATAL(thread2->is_check_failed().signalled()); thread1->remove(); // implies stop() thread2->remove(); }
static int numLines( const char* const pathname) { FILE* stream = fopen(pathname, "r"); CU_ASSERT_PTR_NOT_NULL_FATAL(stream); int n = 0; char line[_POSIX_MAX_INPUT]; for (; fgets(line, sizeof(line), stream) != NULL; ++n) ; CU_ASSERT_TRUE_FATAL(feof(stream)); CU_ASSERT_FALSE_FATAL(ferror(stream)); CU_ASSERT_EQUAL_FATAL(fclose(stream), 0); return n; }
/** * @retval 0 Success. * @retval LDM7_INVAL No multicast sender child process exists. */ static int terminateMcastSender(void) { int status; /* * Terminate the multicast sender process by sending a SIGTERM to the * process group. */ { struct sigaction oldSigact; struct sigaction newSigact; status = sigemptyset(&newSigact.sa_mask); CU_ASSERT_EQUAL_FATAL(status, 0); udebug("Setting SIGTERM action to ignore"); newSigact.sa_flags = 0; newSigact.sa_handler = SIG_IGN; status = sigaction(SIGTERM, &newSigact, &oldSigact); CU_ASSERT_EQUAL_FATAL(status, 0); udebug("Sending SIGTERM to process group"); status = kill(0, SIGTERM); CU_ASSERT_EQUAL_FATAL(status, 0); udebug("Restoring SIGTERM action"); status = sigaction(SIGTERM, &oldSigact, NULL); CU_ASSERT_EQUAL(status, 0); } /* Reap the terminated multicast sender. */ { udebug("Reaping multicast sender child process"); const pid_t wpid = wait(&status); if (wpid == (pid_t)-1) { CU_ASSERT_EQUAL(errno, ECHILD); status = LDM7_INVAL; } else { CU_ASSERT_TRUE_FATAL(wpid > 0); CU_ASSERT_TRUE(WIFEXITED(status)); CU_ASSERT_EQUAL(WEXITSTATUS(status), 0); status = mlsm_terminated(wpid); CU_ASSERT_EQUAL(status, 0); } } return status; }
void test_local_block() { { T1 t1; t1.start(); } { T2 t2(true); t2.start(); USLEEP(100); USLEEP(100); CU_ASSERT_TRUE_FATAL( RThreadState::state_is(t2, T2::terminatedState)); } }
void test_ssm_src_sess_create(void) { rtp_config_t config; rtp_init_config(&config, RTPAPP_VAMRTP); config.senders_cached = 1; config.rtcp_bw_cfg.media_as_bw = RTCP_DFLT_AS_BW; /* Use the fatal form; no use proceeding if we can't create a session. */ CU_ASSERT_TRUE_FATAL(rtp_create_session_ssm_rsi_source(&config, &p_rtp_ssm_src, TRUE)); /* KK!! Should beat on the session creation some more! */ }
void test_ptp_sess_create(void) { rtp_config_t config; rtp_init_config(&config, RTPAPP_DEFAULT); config.senders_cached = 1; /* assume only one sender and one receiver */ config.rtcp_bw_cfg.media_rr_bw = RTCP_DFLT_PER_RCVR_BW; config.rtcp_bw_cfg.media_rs_bw = RTCP_DFLT_PER_SNDR_BW; /* Use the fatal form; no use proceeding if we can't create a session. */ CU_ASSERT_TRUE_FATAL(rtp_create_session_ptp(&config, &p_rtp_ptp, TRUE)); /* KK!! Should beat on the session creation some more! */ }
static int setup_timerfd(uint32_t delay, uint32_t period) { int res = 0; int tfd = -1; struct itimerspec newval, oldval; tfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); CU_ASSERT_TRUE_FATAL(tfd >= 0); /* Setup timeout */ newval.it_interval.tv_sec = (time_t)(period / 1000); newval.it_interval.tv_nsec = (long int)((period % 1000) * 1000 * 1000); newval.it_value.tv_sec = (time_t)(delay / 1000); newval.it_value.tv_nsec = (long int)((delay % 1000) * 1000 * 1000); res = timerfd_settime(tfd, 0, &newval, &oldval); CU_ASSERT_EQUAL_FATAL(res, 0); return tfd; }
void test_singlePattern(void) { HObs hObs = NULL; RU8 pattern[] = { 0x01, 0x02, 0x03, 0x04 }; RU8 buffer1[] = { 0x02, 0x04, 0xFF, 0xEF, 0x01, 0x02, 0x03, 0x04 }; RU8 buffer2[] = { 0x02, 0x04, 0xFF, 0xEF, 0x01, 0x02, 0x03, 0x04, 0xEE, 0x6F }; RU8 buffer3[] = { 0x02, 0x04, 0xFF, 0xEF, 0x01, 0x02, 0x01, 0x04, 0xEE, 0x6F }; RU8 buffer4[] = { 0x02, 0x04, 0xFF, 0xEF, 0x01, 0x02, 0x03, 0x04, 0xEE, 0x6F, 0x01, 0x02, 0x03, 0x04 }; RU32 context = 0; PVOID hitCtx = NULL; RU8* hitLoc = NULL; hObs = obsLib_new( 0, 0 ); CU_ASSERT_TRUE_FATAL( rpal_memory_isValid( hObs ) ); CU_ASSERT_TRUE_FATAL( obsLib_addPattern( hObs, (RPU8)&pattern, sizeof( pattern ), &context ) ); // 1 pattern found end of buffer CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer1, sizeof( buffer1 ) ) ); CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); CU_ASSERT_EQUAL( hitCtx, &context ); CU_ASSERT_EQUAL( hitLoc, buffer1 + sizeof( buffer1 ) - 4 ); CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); // 1 pattern found middle of buffer CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer2, sizeof( buffer2 ) ) ); CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); CU_ASSERT_EQUAL( hitCtx, &context ); CU_ASSERT_EQUAL( hitLoc, buffer2 + sizeof( buffer2 ) - 6 ); CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); // 0 pattern found CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer3, sizeof( buffer3 ) ) ); CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); // 2 pattern found end and middle of buffer CU_ASSERT_TRUE_FATAL( obsLib_setTargetBuffer( hObs, buffer4, sizeof( buffer4 ) ) ); CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); CU_ASSERT_EQUAL( hitCtx, &context ); CU_ASSERT_EQUAL( hitLoc, buffer4 + sizeof( buffer4 ) - 10 ); CU_ASSERT_TRUE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); CU_ASSERT_EQUAL( hitCtx, &context ); CU_ASSERT_EQUAL( hitLoc, buffer4 + sizeof( buffer4 ) - 4 ); CU_ASSERT_FALSE( obsLib_nextHit( hObs, &hitCtx, &hitLoc ) ); obsLib_free( hObs ); }
static void process_response_event(void *user_ctx, const belle_sip_response_event_t *event){ int status; belle_sip_request_t* request; BELLESIP_UNUSED(user_ctx); CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_response(event)); belle_sip_message("process_response_event [%i] [%s]" ,status=belle_sip_response_get_status_code(belle_sip_response_event_get_response(event)) ,belle_sip_response_get_reason_phrase(belle_sip_response_event_get_response(event))); if (status==401){ belle_sip_header_cseq_t* cseq; belle_sip_client_transaction_t *t; belle_sip_uri_t *dest; // CU_ASSERT_NOT_EQUAL_FATAL(number_of_challenge,2); CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_client_transaction(event)); /*require transaction mode*/ dest=belle_sip_client_transaction_get_route(belle_sip_response_event_get_client_transaction(event)); request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event))); cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ); belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1); belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_AUTHORIZATION); belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_PROXY_AUTHORIZATION); CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL,NULL,auth_domain)); t=belle_sip_provider_create_client_transaction(prov,request); belle_sip_client_transaction_send_request_to(t,dest); number_of_challenge++; authorized_request=request; belle_sip_object_ref(authorized_request); } else { CU_ASSERT_EQUAL(status,200); is_register_ok=1; using_transaction=belle_sip_response_event_get_client_transaction(event)!=NULL; belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack)); } }
/** * Closes the socket on failure. * * @param[in] up7 The upstream LDM-7 to be initialized. * @param[in] sock The socket for the upstream LDM-7. * @param[in] termFd Termination file-descriptor. * @retval 0 Success. */ static int up7_init( Up7* const up7, const int sock) { /* * 0 => use default read/write buffer sizes. * `sock` will be closed by `svc_destroy()`. */ SVCXPRT* const xprt = svcfd_create(sock, 0, 0); CU_ASSERT_PTR_NOT_EQUAL_FATAL(xprt, NULL); /* * Set the remote address of the RPC server-side transport because * `svcfd_create()` doesn't. */ { struct sockaddr_in addr; socklen_t addrLen = sizeof(addr); int status = getpeername(sock, &addr, &addrLen); CU_ASSERT_EQUAL_FATAL(status, 0); CU_ASSERT_EQUAL_FATAL(addrLen, sizeof(addr)); CU_ASSERT_EQUAL_FATAL(addr.sin_family, AF_INET); xprt->xp_raddr = addr; xprt->xp_addrlen = addrLen; } // Last argument == 0 => don't register with portmapper bool success = svc_register(xprt, LDMPROG, SEVEN, ldmprog_7, 0); CU_ASSERT_TRUE_FATAL(success); up7->xprt = xprt; return 0; }
void testBSONExportImport(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); EJCOLL *coll = ejdbcreatecoll(jb, "col1", NULL); if (!coll) { eprint(jb, __LINE__, "testBSONExportImport"); } CU_ASSERT_TRUE(coll != NULL); bson_oid_t oid; bson bv1; bson_init(&bv1); bson_append_int(&bv1, "a", 1); bson_append_string(&bv1, "c", "d"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); EJCOLLOPTS copts = {0}; copts.large = true; copts.records = 200000; coll = ejdbcreatecoll(jb, "col2", &copts); if (!coll) { eprint(jb, __LINE__, "testBSONExportImport"); } CU_ASSERT_TRUE(coll != NULL); CU_ASSERT_TRUE(ejdbsetindex(coll, "f", JBIDXSTR | JBIDXNUM)); bson_init(&bv1); bson_append_int(&bv1, "e", 1); bson_append_string(&bv1, "f", "g"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_append_string(&bv1, "f", "g2"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); TCXSTR *log = tcxstrnew(); TCLIST *cnames = tclistnew(); tclistpush2(cnames, "col1"); tclistpush2(cnames, "col2"); bool rv = ejdbexport(jb, "testBSONExportImport", NULL, 0, log); if (!rv) { eprint(jb, __LINE__, "testBSONExportImport"); } CU_ASSERT_TRUE(rv); bson *ometa = ejdbmeta(jb); CU_ASSERT_TRUE_FATAL(ometa != NULL); ejdbclose(jb); ejdbdel(jb); //Restore data: jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT)); coll = ejdbgetcoll(jb, "col1"); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_finish(&bv1); CU_ASSERT_TRUE(ejdbsavebson(coll, &bv1, &oid)); bson_destroy(&bv1); rv = ejdbimport(jb, "testBSONExportImport", cnames, JBIMPORTREPLACE, log); CU_ASSERT_TRUE(rv); //fprintf(stderr, "\n\n%s", TCXSTRPTR(log)); CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "Replacing all data in 'col1'")); CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "1 objects imported into 'col1'")); CU_ASSERT_PTR_NOT_NULL(strstr(TCXSTRPTR(log), "2 objects imported into 'col2'")); bson *nmeta = ejdbmeta(jb); CU_ASSERT_TRUE_FATAL(nmeta != NULL); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.name", strlen("collections.0.name")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.records", strlen("collections.0.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.name", strlen("collections.1.name")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.records", strlen("collections.1.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.buckets", strlen("collections.1.options.buckets")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.large", strlen("collections.1.options.large")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.field", strlen("collections.1.indexes.0.field")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.type", strlen("collections.1.indexes.0.type")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.records", strlen("collections.1.indexes.0.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.field", strlen("collections.1.indexes.1.field")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.type", strlen("collections.1.indexes.1.type")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.records", strlen("collections.1.indexes.1.records")) == 0); ejdbclose(jb); ejdbdel(jb); jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); coll = ejdbcreatecoll(jb, "col1", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_finish(&bv1); CU_ASSERT_TRUE(ejdbsavebson(coll, &bv1, &oid)); EJQ *q = ejdbcreatequery(jb, &bv1, NULL, 0, NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(q); uint32_t count = 0; ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); CU_ASSERT_EQUAL(count, 1); rv = ejdbimport(jb, "testBSONExportImport", NULL, JBIMPORTUPDATE, NULL); CU_ASSERT_TRUE(rv); coll = ejdbcreatecoll(jb, "col1", NULL); ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); CU_ASSERT_EQUAL(count, 1); ejdbquerydel(q); bson_destroy(&bv1); ejdbclose(jb); ejdbdel(jb); bson_del(ometa); bson_del(nmeta); tcxstrdel(log); tclistdel(cnames); }
void testBSONExportImport2(void) { EJDB *jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); EJCOLL *coll = ejdbcreatecoll(jb, "col1", NULL); if (!coll) { eprint(jb, __LINE__, "testBSONExportImport2"); } CU_ASSERT_TRUE(coll != NULL); bson_oid_t oid; const char *log = NULL; bson bv1; bson_init(&bv1); bson_append_int(&bv1, "a", 1); bson_append_string(&bv1, "c", "d"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); EJCOLLOPTS copts = {0}; copts.large = true; copts.records = 200000; coll = ejdbcreatecoll(jb, "col2", &copts); if (!coll) { eprint(jb, __LINE__, "testBSONExportImport2"); } CU_ASSERT_TRUE(coll != NULL); CU_ASSERT_TRUE(ejdbsetindex(coll, "f", JBIDXSTR | JBIDXNUM)); bson_init(&bv1); bson_append_int(&bv1, "e", 1); bson_append_string(&bv1, "f", "g"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_append_string(&bv1, "f", "g2"); bson_finish(&bv1); ejdbsavebson(coll, &bv1, &oid); bson_destroy(&bv1); bson cmd; bson_init(&cmd); bson_append_start_object(&cmd, "export"); bson_append_string(&cmd, "path", "testBSONExportImport2"); bson_append_start_array(&cmd, "cnames"); bson_append_string(&cmd, "0", "col1"); bson_append_string(&cmd, "1", "col2"); bson_append_finish_array(&cmd); bson_append_finish_object(&cmd); bson_finish(&cmd); bson *bret = ejdbcommand(jb, &cmd); CU_ASSERT_PTR_NOT_NULL_FATAL(bret); bson_destroy(&cmd); bson_iterator it; bson_iterator_init(&it, bret); CU_ASSERT_TRUE(bson_find_fieldpath_value("error", &it) == BSON_EOO); bson_iterator_init(&it, bret); CU_ASSERT_TRUE(bson_compare_long(0, bson_data(bret), "errorCode") == 0); bson_iterator_init(&it, bret); CU_ASSERT_TRUE(bson_find_fieldpath_value("log", &it) == BSON_STRING); bson_del(bret); bson *ometa = ejdbmeta(jb); CU_ASSERT_TRUE_FATAL(ometa != NULL); ejdbclose(jb); ejdbdel(jb); //Restore data: jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT)); coll = ejdbgetcoll(jb, "col1"); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_finish(&bv1); CU_ASSERT_TRUE(ejdbsavebson(coll, &bv1, &oid)); bson_destroy(&bv1); bson_init(&cmd); bson_append_start_object(&cmd, "import"); bson_append_string(&cmd, "path", "testBSONExportImport2"); bson_append_int(&cmd, "mode", JBIMPORTREPLACE); bson_append_start_array(&cmd, "cnames"); bson_append_string(&cmd, "0", "col1"); bson_append_string(&cmd, "1", "col2"); bson_append_finish_array(&cmd); bson_append_finish_object(&cmd); bson_finish(&cmd); bret = ejdbcommand(jb, &cmd); CU_ASSERT_PTR_NOT_NULL_FATAL(bret); bson_destroy(&cmd); bson_iterator_init(&it, bret); CU_ASSERT_TRUE_FATAL(bson_find_fieldpath_value("log", &it) == BSON_STRING); log = bson_iterator_string(&it); CU_ASSERT_PTR_NOT_NULL(strstr(log, "Replacing all data in 'col1'")); CU_ASSERT_PTR_NOT_NULL(strstr(log, "1 objects imported into 'col1'")); CU_ASSERT_PTR_NOT_NULL(strstr(log, "2 objects imported into 'col2'")); bson_del(bret); log = NULL; bson *nmeta = ejdbmeta(jb); CU_ASSERT_TRUE_FATAL(nmeta != NULL); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.name", strlen("collections.0.name")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.0.records", strlen("collections.0.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.name", strlen("collections.1.name")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.records", strlen("collections.1.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.buckets", strlen("collections.1.options.buckets")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.options.large", strlen("collections.1.options.large")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.field", strlen("collections.1.indexes.0.field")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.type", strlen("collections.1.indexes.0.type")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.0.records", strlen("collections.1.indexes.0.records")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.field", strlen("collections.1.indexes.1.field")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.type", strlen("collections.1.indexes.1.type")) == 0); CU_ASSERT_TRUE(bson_compare(bson_data(ometa), bson_data(nmeta), "collections.1.indexes.1.records", strlen("collections.1.indexes.1.records")) == 0); ejdbclose(jb); ejdbdel(jb); jb = ejdbnew(); CU_ASSERT_TRUE_FATAL(ejdbopen(jb, "dbt4_export", JBOWRITER | JBOCREAT | JBOTRUNC)); coll = ejdbcreatecoll(jb, "col1", NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(coll); bson_init(&bv1); bson_append_int(&bv1, "e", 2); bson_finish(&bv1); CU_ASSERT_TRUE(ejdbsavebson(coll, &bv1, &oid)); EJQ *q = ejdbcreatequery(jb, &bv1, NULL, 0, NULL); CU_ASSERT_PTR_NOT_NULL_FATAL(q); uint32_t count = 0; ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); CU_ASSERT_EQUAL(count, 1); bson_init(&cmd); bson_append_start_object(&cmd, "import"); bson_append_string(&cmd, "path", "testBSONExportImport2"); bson_append_int(&cmd, "mode", JBIMPORTUPDATE); bson_append_finish_object(&cmd); bson_finish(&cmd); bret = ejdbcommand(jb, &cmd); CU_ASSERT_PTR_NOT_NULL_FATAL(bret); bson_destroy(&cmd); bson_del(bret); coll = ejdbcreatecoll(jb, "col1", NULL); ejdbqryexecute(coll, q, &count, JBQRYCOUNT, NULL); CU_ASSERT_EQUAL(count, 1); ejdbquerydel(q); bson_destroy(&bv1); ejdbclose(jb); ejdbdel(jb); bson_del(ometa); bson_del(nmeta); }
void __testConnect_Simple_Second_IP() { __init_pcap_record(CU_get_current_test()->pName); int err = 0; int ret = 0; my_context server_socket = __reference->open(__reference, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_PTR_NOT_NULL_FATAL(server_socket); my_context client_socket = __target->open(__target, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_PTR_NOT_NULL_FATAL(client_socket); struct sockaddr_in server_addr; memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(10000); ret = __reference->bind(__reference, server_socket, (struct sockaddr*)&server_addr, sizeof(server_addr), &err); CU_ASSERT_TRUE_FATAL(ret); CU_ASSERT_EQUAL_FATAL(err, 0); ret = __reference->listen(__reference, server_socket, 5, &err); CU_ASSERT_TRUE_FATAL(ret); CU_ASSERT_EQUAL_FATAL(err, 0); ret = __reference->accept(__reference, server_socket, &err); CU_ASSERT_TRUE_FATAL(ret); CU_ASSERT_EQUAL_FATAL(err, 0); struct sockaddr_in client_addr; memset(&client_addr, 0, sizeof(client_addr)); client_addr.sin_family = AF_INET; client_addr.sin_addr.s_addr = inet_addr("192.168.0.200"); client_addr.sin_port = htons(10000); socklen_t len = sizeof(client_addr); ret = __target->connect(__target, client_socket, (struct sockaddr*)&client_addr, len, &err); CU_ASSERT_TRUE_FATAL(ret); CU_ASSERT_EQUAL_FATAL(err, 0); __flush_packets(100); CU_ASSERT_EQUAL_FATAL(list_get_count(__find_app(__reference, server_socket)->passive_open_calls), 1); CU_ASSERT_EQUAL_FATAL(__find_app(__target, client_socket)->active_open_calls, 1); server_addr.sin_addr.s_addr = inet_addr("192.168.0.200"); struct sockaddr_in temp_addr; memset(&temp_addr, 0, sizeof(temp_addr)); len = sizeof(temp_addr); __target->getpeername(__target, client_socket, (struct sockaddr*)&temp_addr, &len, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_EQUAL(len, sizeof(temp_addr)); CU_ASSERT_EQUAL(memcmp(&temp_addr, (struct sockaddr*)&server_addr, sizeof(temp_addr)), 0); memset(&temp_addr, 0, sizeof(temp_addr)); len = sizeof(temp_addr); __target->getsockname(__target, client_socket, (struct sockaddr*)&temp_addr, &len, &err); CU_ASSERT_EQUAL_FATAL(err, 0); CU_ASSERT_EQUAL(len, sizeof(temp_addr)); CU_ASSERT_EQUAL(temp_addr.sin_addr.s_addr, inet_addr("192.168.0.100")); __pcap_close(); }
static void testInventoryWithTwoDiedAliensOnTheSameGridTile (void) { const char *mapName = "test_game"; if (FS_CheckFile("maps/%s.bsp", mapName) != -1) { edict_t *diedEnt; edict_t *diedEnt2; edict_t *ent; edict_t *floorItems; invList_t *invlist; int count; /* the other tests didn't call the server shutdown function to clean up */ OBJZERO(*sv); SV_Map(true, mapName, NULL); level.activeTeam = TEAM_ALIEN; /* first alien that should die and drop its inventory */ diedEnt = G_EdictsGetNextLivingActorOfTeam(NULL, TEAM_ALIEN); CU_ASSERT_PTR_NOT_NULL_FATAL(diedEnt); diedEnt->HP = 0; G_ActorDieOrStun(diedEnt, NULL); CU_ASSERT_TRUE_FATAL(G_IsDead(diedEnt)); /* second alien that should die and drop its inventory */ diedEnt2 = G_EdictsGetNextLivingActorOfTeam(NULL, TEAM_ALIEN); CU_ASSERT_PTR_NOT_NULL_FATAL(diedEnt2); /* move to the location of the first died alien to drop the inventory into the same floor container */ Player &player = diedEnt2->getPlayer(); CU_ASSERT_TRUE_FATAL(G_IsAIPlayer(&player)); G_ClientMove(player, 0, diedEnt2, diedEnt->pos); CU_ASSERT_TRUE_FATAL(VectorCompare(diedEnt2->pos, diedEnt->pos)); diedEnt2->HP = 0; G_ActorDieOrStun(diedEnt2, NULL); CU_ASSERT_TRUE_FATAL(G_IsDead(diedEnt2)); /* now try to collect the inventory with a third alien */ ent = G_EdictsGetNextLivingActorOfTeam(NULL, TEAM_ALIEN); CU_ASSERT_PTR_NOT_NULL_FATAL(ent); player = ent->getPlayer(); CU_ASSERT_TRUE_FATAL(G_IsAIPlayer(&player)); G_ClientMove(player, 0, ent, diedEnt->pos); CU_ASSERT_TRUE_FATAL(VectorCompare(ent->pos, diedEnt->pos)); floorItems = G_GetFloorItems(ent); CU_ASSERT_PTR_NOT_NULL_FATAL(floorItems); CU_ASSERT_PTR_EQUAL(floorItems->getFloor(), ent->getFloor()); /* drop everything to floor to make sure we have space in the backpack */ G_InventoryToFloor(ent); CU_ASSERT_EQUAL(GAMETEST_GetItemCount(ent, CID_BACKPACK), 0); invlist = ent->getContainer(CID_BACKPACK); CU_ASSERT_PTR_NULL_FATAL(invlist); count = GAMETEST_GetItemCount(ent, CID_FLOOR); if (count > 0) { invList_t *entryToMove = ent->getFloor(); int tx, ty; ent->chr.inv.findSpace(INVDEF(CID_BACKPACK), entryToMove, &tx, &ty, entryToMove); if (tx != NONE) { Com_Printf("trying to move item %s from floor into backpack to pos %i:%i\n", entryToMove->def()->name, tx, ty); CU_ASSERT_TRUE(G_ActorInvMove(ent, INVDEF(CID_FLOOR), entryToMove, INVDEF(CID_BACKPACK), tx, ty, false)); UFO_CU_ASSERT_EQUAL_INT_MSG_FATAL(GAMETEST_GetItemCount(ent, CID_FLOOR), count - 1, va("item %s could not get moved successfully from floor into backpack", entryToMove->def()->name)); Com_Printf("item %s was removed from floor\n", entryToMove->def()->name); UFO_CU_ASSERT_EQUAL_INT_MSG_FATAL(GAMETEST_GetItemCount(ent, CID_BACKPACK), 1, va("item %s could not get moved successfully from floor into backpack", entryToMove->def()->name)); Com_Printf("item %s was moved successfully into the backpack\n", entryToMove->def()->name); invlist = ent->getContainer(CID_BACKPACK); CU_ASSERT_PTR_NOT_NULL_FATAL(invlist); } } SV_ShutdownGameProgs(); } else { UFO_CU_FAIL_MSG(va("Map resource '%s.bsp' for test is missing.", mapName)); } }
static void refresher_base_with_body(endpoint_t* client ,endpoint_t *server , const char* method , belle_sip_header_content_type_t* content_type ,const char* body) { belle_sip_request_t* req; belle_sip_client_transaction_t* trans; belle_sip_header_route_t* destination_route; belle_sip_refresher_t* refresher; const char* identity = "sip:" USERNAME "@" SIPDOMAIN ; const char* domain="sip:" SIPDOMAIN ; belle_sip_header_contact_t* contact=belle_sip_header_contact_new(); belle_sip_uri_t *dest_uri; uint64_t begin; uint64_t end; if (client->expire_in_contact) belle_sip_header_contact_set_expires(contact,1); dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp)); if (client->connection_family==AF_INET6) belle_sip_uri_set_host(dest_uri,"::1"); else belle_sip_uri_set_host(dest_uri,"127.0.0.1"); destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,dest_uri)); req=belle_sip_request_create( belle_sip_uri_parse(domain), method, belle_sip_provider_create_call_id(client->provider), belle_sip_header_cseq_create(20,method), belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG), belle_sip_header_to_create2(identity,NULL), belle_sip_header_via_new(), 70); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact)); if (!client->expire_in_contact) belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(1))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(destination_route)); if (content_type && body) { size_t body_lenth=strlen(body); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(content_type)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_content_length_create(body_lenth))); belle_sip_message_set_body(BELLE_SIP_MESSAGE(req),body,body_lenth); } trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans);/*to avoid trans from being deleted before refresher can use it*/ belle_sip_client_transaction_send_request(trans); if (client->early_refresher) { client->refresher= refresher = belle_sip_client_transaction_create_refresher(trans); } else { if (server->auth == none) { CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000)); } else { CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.fourHundredOne,1,1000)); /*update cseq*/ req=belle_sip_client_transaction_create_authenticated_request(trans,NULL,NULL); belle_sip_object_unref(trans); trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans); belle_sip_client_transaction_send_request(trans); CU_ASSERT_TRUE_FATAL(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000)); } client->refresher= refresher = belle_sip_client_transaction_create_refresher(trans); } CU_ASSERT_TRUE_FATAL(refresher!=NULL); belle_sip_object_unref(trans); belle_sip_refresher_set_listener(refresher,belle_sip_refresher_listener,client); begin = belle_sip_time_ms(); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,client->register_count+(client->early_refresher?1:0),client->register_count*1000 + 1000)); end = belle_sip_time_ms(); CU_ASSERT_TRUE(end-begin>=client->register_count*1000*.9); /*because refresh is at 90% of expire*/ CU_ASSERT_TRUE(end-begin<(client->register_count*1000 + 2000)); /*unregister twice to make sure refresh operation can be safely cascaded*/ belle_sip_refresher_refresh(refresher,0); belle_sip_refresher_refresh(refresher,0); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,client->register_count+1,1000)); CU_ASSERT_EQUAL(client->stat.refreshOk,client->register_count+1); belle_sip_refresher_stop(refresher); belle_sip_object_unref(refresher); }
static void subscribe_test(void) { belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t server_callbacks; belle_sip_request_t* req; belle_sip_client_transaction_t* trans; belle_sip_header_route_t* destination_route; const char* identity = "sip:" USERNAME "@" SIPDOMAIN ; const char* domain="sip:" SIPDOMAIN ; endpoint_t* client,*server; belle_sip_uri_t *dest_uri; belle_sip_refresher_t* refresher; belle_sip_header_contact_t* contact=belle_sip_header_contact_new(); uint64_t begin; uint64_t end; memset(&client_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); memset(&server_callbacks,0,sizeof(belle_sip_listener_callbacks_t)); client_callbacks.process_response_event=client_process_response_event; client_callbacks.process_auth_requested=client_process_auth_requested; server_callbacks.process_request_event=server_process_request_event; client = create_udp_endpoint(3452,&client_callbacks); server = create_udp_endpoint(6788,&server_callbacks); server->expire_in_contact=0; server->auth=digest_auth; dest_uri=(belle_sip_uri_t*)belle_sip_object_clone((belle_sip_object_t*)belle_sip_listening_point_get_uri(server->lp)); belle_sip_uri_set_host(dest_uri,"127.0.0.1"); destination_route=belle_sip_header_route_create(belle_sip_header_address_create(NULL,dest_uri)); req=belle_sip_request_create( belle_sip_uri_parse(domain), "SUBSCRIBE", belle_sip_provider_create_call_id(client->provider), belle_sip_header_cseq_create(20,"SUBSCRIBE"), belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG), belle_sip_header_to_create2(identity,NULL), belle_sip_header_via_new(), 70); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(1))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_create("Event","Presence"))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(destination_route)); trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans);/*to avoid trans from being deleted before refresher can use it*/ belle_sip_client_transaction_send_request(trans); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.fourHundredOne,1,1000)); req=belle_sip_client_transaction_create_authenticated_request(trans,NULL,NULL); belle_sip_object_unref(trans); trans=belle_sip_provider_create_client_transaction(client->provider,req); belle_sip_object_ref(trans); belle_sip_client_transaction_send_request(trans); CU_ASSERT_TRUE_FATAL(wait_for(server->stack,client->stack,&client->stat.twoHundredOk,1,1000)); /*maybe dialog should be automatically created*/ CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(trans))) refresher = belle_sip_client_transaction_create_refresher(trans); belle_sip_object_unref(trans); belle_sip_refresher_set_listener(refresher,belle_sip_refresher_listener,client); begin = belle_sip_time_ms(); CU_ASSERT_TRUE(wait_for(server->stack,client->stack,&client->stat.refreshOk,3,4000)); end = belle_sip_time_ms(); CU_ASSERT_TRUE(end-begin>=3000); CU_ASSERT_TRUE(end-begin<5000); /*unsubscribe twice to make sure refresh operation can be safely cascaded*/ belle_sip_refresher_refresh(refresher,0); belle_sip_refresher_refresh(refresher,0); belle_sip_refresher_stop(refresher); belle_sip_object_unref(refresher); destroy_endpoint(client); destroy_endpoint(server); }