END_TEST START_TEST ( llist_05_list_for_each ) { int retval; llist listToTest = NULL; listToTest = llist_create ( NULL, NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE ); // Insert a 5 nodes 1..5 retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_REAR ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_REAR ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_REAR ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_REAR ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_REAR ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); retval = llist_for_each ( listToTest, trivial_node_func ); ck_assert_int_eq ( retval, LLIST_SUCCESS ); llist_destroy ( listToTest, false, NULL ); }
static int llist_len(struct llist_head *head) { struct llist_head *entry; int i = 0; llist_for_each(entry, head) i++; return i; }
int test_datastructure_link_list() { llist_t *llist; allocator_t *allocator; struct test t1={1,2}; struct test t2={2,2}; struct test t3={3,2}; struct test t4={4,2}; int ret = 0; /* *allocator = allocator_creator(ALLOCATOR_TYPE_CTR_MALLOC); *allocator_ctr_init(allocator, 0, 0, 1024); *dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator); */ allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC,0); //ct = container_creator(CONTAINER_TYPE_LIST,allocator); llist = llist_create(allocator,0); llist_init(llist,sizeof(struct test)); llist_push_front(llist,&t1); llist_push_front(llist,&t2); llist_push_front(llist,&t3); llist_push_front(llist,&t4); llist_push_back(llist,&t1); llist_push_back(llist,&t2); llist_push_back(llist,&t3); llist_push_back(llist,&t4); llist_for_each(llist,print_list_data); llist_destroy(llist); return ret; }
static void subscr_dump_full_vty(struct vty *vty, struct gsm_subscriber *subscr) { int rc; int reqs; struct gsm_auth_info ainfo; struct gsm_auth_tuple atuple; struct llist_head *entry; char expire_time[200]; vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id, subscr->authorized, VTY_NEWLINE); if (strlen(subscr->name)) vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); if (strlen(subscr->extension)) vty_out(vty, " Extension: %s%s", subscr->extension, VTY_NEWLINE); vty_out(vty, " LAC: %d/0x%x%s", subscr->lac, subscr->lac, VTY_NEWLINE); vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); if (subscr->tmsi != GSM_RESERVED_TMSI) vty_out(vty, " TMSI: %08X%s", subscr->tmsi, VTY_NEWLINE); rc = db_get_authinfo_for_subscr(&ainfo, subscr); if (!rc) { vty_out(vty, " A3A8 algorithm id: %d%s", ainfo.auth_algo, VTY_NEWLINE); vty_out(vty, " A3A8 Ki: %s%s", osmo_hexdump(ainfo.a3a8_ki, ainfo.a3a8_ki_len), VTY_NEWLINE); } rc = db_get_lastauthtuple_for_subscr(&atuple, subscr); if (!rc) { vty_out(vty, " A3A8 last tuple (used %d times):%s", atuple.use_count, VTY_NEWLINE); vty_out(vty, " seq # : %d%s", atuple.key_seq, VTY_NEWLINE); vty_out(vty, " RAND : %s%s", osmo_hexdump(atuple.vec.rand, sizeof(atuple.vec.rand)), VTY_NEWLINE); vty_out(vty, " SRES : %s%s", osmo_hexdump(atuple.vec.sres, sizeof(atuple.vec.sres)), VTY_NEWLINE); vty_out(vty, " Kc : %s%s", osmo_hexdump(atuple.vec.kc, sizeof(atuple.vec.kc)), VTY_NEWLINE); } /* print the expiration time of a subscriber */ strftime(expire_time, sizeof(expire_time), "%a, %d %b %Y %T %z", localtime(&subscr->expire_lu)); expire_time[sizeof(expire_time) - 1] = '\0'; vty_out(vty, " Expiration Time: %s%s", expire_time, VTY_NEWLINE); reqs = 0; llist_for_each(entry, &subscr->requests) reqs += 1; vty_out(vty, " Paging: %s paging Requests: %d%s", subscr->is_paging ? "is" : "not", reqs, VTY_NEWLINE); vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE); }
void print_llist ( llist list ) { llist_for_each ( list, trivial_print_node ); printf ( "\n" ); }