示例#1
0
void t15_hard_dup_dict_in_dict(){
	INIT_LOCAL();

	onion_dict *orig=onion_dict_new();

	char tmp[9];
	int i;
	for (i=0;i<256;i++){
		sprintf(tmp,"%08X",rand());
		onion_dict_add(orig, tmp, tmp, OD_DUP_ALL);
	}
	onion_dict_add(orig, "0", "no frees", 0);

	onion_dict *subdict=onion_dict_new();
	onion_dict_add(subdict,"subdict","test",0);
	onion_dict_add(orig, "subdict", subdict, OD_DICT|OD_FREE_VALUE);

	onion_dict *dest=onion_dict_hard_dup(orig);

	FAIL_IF(orig==dest);
	/// Check they have exactly the same keys.
	onion_dict_preorder(orig, cmpdict, dest);
	onion_dict_preorder(dest, cmpdict, orig);

	onion_dict_free(orig);
	onion_dict_free(dest);

	END_LOCAL();
}
示例#2
0
文件: 01-hash.c 项目: 511860050/onion
void t12_dict_in_dict(){
	INIT_LOCAL();
	
	onion_dict *A=onion_dict_new();
	onion_dict *B=onion_dict_new();
	onion_dict *C=onion_dict_new();
	onion_dict *D=onion_dict_new();
	
	int i;
	for (i=0;i<16;i++){
		char tmp[9];
		sprintf(tmp,"%08X",rand());
		onion_dict_add(A, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(B, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(C, tmp, tmp, OD_DUP_ALL);
		sprintf(tmp,"%08X",rand());
		onion_dict_add(D, tmp, tmp, OD_DUP_ALL);
	}

	onion_dict_add(A, "B", B, OD_DICT|OD_FREE_VALUE);
	onion_dict_add(A, "C", C, OD_DICT|OD_FREE_VALUE);
	onion_dict_add(A, "D", D, OD_DICT|OD_FREE_VALUE);

	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "B"), NULL);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "C"), NULL);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get(A, "D"), NULL);

	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "B"), B);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "C"), C);
	FAIL_IF_NOT_EQUAL((onion_dict*)onion_dict_get_dict(A, "D"), D);
	
	{
		onion_block *tmpA=onion_dict_to_json(A);
		onion_block *tmpB=onion_dict_to_json(B);
		onion_block *tmpC=onion_dict_to_json(C);
		onion_block *tmpD=onion_dict_to_json(D);
		/*
		ONION_DEBUG("Json is: %s",tmpA);
		ONION_DEBUG("Json is: %s",tmpB);
		ONION_DEBUG("Json is: %s",tmpC);
		ONION_DEBUG("Json is: %s",tmpD);
		*/
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpB)), NULL);
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpC)), NULL);
		FAIL_IF_EQUAL( strstr(onion_block_data(tmpA), onion_block_data(tmpD)), NULL);
		onion_block_free(tmpA);
		onion_block_free(tmpB);
		onion_block_free(tmpC);
		onion_block_free(tmpD);
	}
	B=onion_dict_hard_dup(A);
	
	onion_dict_free(A);
	onion_dict_free(B);
	
	END_LOCAL();
}
示例#3
0
文件: dict.c 项目: Sts0mrg0/onion
/// Sets the data on the node, on the right way.
static void onion_dict_set_node_data(onion_dict_node_data *data, const char *key, const void *value, int flags){
	//ONION_DEBUG("Set data %02X",flags);
	if ((flags&OD_DUP_KEY)==OD_DUP_KEY) // not enought with flag, as its a multiple bit flag, with FREE included
		data->key=onion_low_strdup(key);
	else
		data->key=key;
	if ((flags&OD_DUP_VALUE)==OD_DUP_VALUE){
		if (flags&OD_DICT)
			data->value=onion_dict_hard_dup((onion_dict*)value);
		else
			data->value=onion_low_strdup(value);
	}
	else
		data->value=value;
	data->flags=flags;
}
示例#4
0
文件: 01-hash.c 项目: 511860050/onion
void t11_hard_dup(){
	INIT_LOCAL();
	
	onion_dict *orig=onion_dict_new();
	
	char tmp[9];
	int i;
	for (i=0;i<256;i++){
		sprintf(tmp,"%08X",rand());
		onion_dict_add(orig, tmp, tmp, OD_DUP_ALL);
	}
	onion_dict_add(orig, "0", "no frees", 0);
	
	onion_dict *dest=onion_dict_hard_dup(orig);
	
	/// Check they have exactly the same keys.
	onion_dict_preorder(orig, cmpdict, dest);
	onion_dict_preorder(dest, cmpdict, orig);
	
	onion_dict_free(orig);
	onion_dict_free(dest);
	
	END_LOCAL();
}
示例#5
0
		/**
		 * @short Creates a real copy of all the elements on the dictionary.
		 */
		Dict hard_dup() const{
			return Dict(onion_dict_hard_dup(ptr), true);
		}