/* * Add a duplicate block record */ static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t cluster, struct ext2_inode *inode) { dnode_t *n; struct dup_cluster *db; struct dup_inode *di; struct cluster_el *cluster_el; struct inode_el *ino_el; n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(cluster)); if (n) db = (struct dup_cluster *) dnode_get(n); else { db = (struct dup_cluster *) e2fsck_allocate_memory(ctx, sizeof(struct dup_cluster), "duplicate cluster header"); db->num_bad = 0; db->inode_list = 0; dict_alloc_insert(&clstr_dict, INT_TO_VOIDPTR(cluster), db); } ino_el = (struct inode_el *) e2fsck_allocate_memory(ctx, sizeof(struct inode_el), "inode element"); ino_el->inode = ino; ino_el->next = db->inode_list; db->inode_list = ino_el; db->num_bad++; n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino)); if (n) di = (struct dup_inode *) dnode_get(n); else { di = (struct dup_inode *) e2fsck_allocate_memory(ctx, sizeof(struct dup_inode), "duplicate inode header"); if (ino == EXT2_ROOT_INO) { di->dir = EXT2_ROOT_INO; dup_inode_founddir++; } else di->dir = 0; di->num_dupblocks = 0; di->cluster_list = 0; di->inode = *inode; dict_alloc_insert(&ino_dict, INT_TO_VOIDPTR(ino), di); } cluster_el = (struct cluster_el *) e2fsck_allocate_memory(ctx, sizeof(struct cluster_el), "cluster element"); cluster_el->cluster = cluster; cluster_el->next = di->cluster_list; di->cluster_list = cluster_el; di->num_dupblocks++; }
static void test_object_data(void) { belle_sip_object_t* obj = belle_sip_object_new(belle_sip_object_t); belle_sip_object_t* cloned = belle_sip_object_new(belle_sip_object_t); int i = 123; const char* str = "toto", *str2 = "titi"; /* normal insertion with no destroy callback */ // should return 0 BC_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_i", INT_TO_VOIDPTR(i), NULL), 0, int, "%d"); // should return the value we put in it BC_ASSERT_EQUAL( VOIDPTR_TO_INT(belle_sip_object_data_get(obj, "test_i")), i, int, "%d"); /* * Overwriting insertion */ // overwrite data: should return 1 when set() i = 124; BC_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_i", INT_TO_VOIDPTR(i), NULL), 1 , int, "%d"); // should return the new value we put in it BC_ASSERT_EQUAL( VOIDPTR_TO_INT(belle_sip_object_data_get(obj, "test_i")), i, int, "%d"); /* * normal insertion with destroy callback */ BC_ASSERT_EQUAL(belle_sip_object_data_set(obj, "test_str", (void*)belle_sip_strdup(str), test_object_data_string_destroy), 0, int, "%d"); // we should get back the same string BC_ASSERT_STRING_EQUAL( (const char*)belle_sip_object_data_get(obj, "test_str"), str ); BC_ASSERT_EQUAL(belle_sip_object_data_remove(obj, "test_str"),0, int, "%d"); // we expect the destroy() function to be called on removal BC_ASSERT_EQUAL(destroy_called, 1, int, "%d"); destroy_called = 0; /* * string insertion and replace */ belle_sip_object_data_set(obj, "test_str", (void*)belle_sip_strdup(str), test_object_data_string_destroy); belle_sip_object_data_set(obj, "test_str", (void*)belle_sip_strdup(str2), test_object_data_string_destroy); BC_ASSERT_EQUAL(destroy_called, 1, int, "%d"); // we expect the dtor to have been called to free the first string /* * Get non-existent key */ BC_ASSERT_PTR_NULL(belle_sip_object_data_get(obj, "non-exist")); /* * test cloning the dictionary */ belle_sip_object_data_clone(obj, cloned, test_object_data_string_clone); BC_ASSERT_EQUAL(clone_called,2,int,"%d"); // we expect the clone function to be called for "test_i" and "test_st, int, "%d"r" // the values should be equal BC_ASSERT_EQUAL( VOIDPTR_TO_INT(belle_sip_object_data_get(obj, "test_i")), VOIDPTR_TO_INT(belle_sip_object_data_get(cloned, "test_i")) , int, "%d"); BC_ASSERT_STRING_EQUAL( (const char*)belle_sip_object_data_get(obj, "test_str"), (const char*)belle_sip_object_data_get(cloned, "test_str")); // but the pointers should be different BC_ASSERT_PTR_NOT_EQUAL( belle_sip_object_data_get(obj, "test_str"), belle_sip_object_data_get(cloned, "test_str")); /* * Foreach test */ belle_sip_object_data_foreach(obj, test_object_data_foreach_cb, NULL); BC_ASSERT_EQUAL( foreach_called, 2 , int, "%d"); belle_sip_object_unref(obj); belle_sip_object_unref(cloned); }