void TestBencodeDictInnerList(
    CuTest * tc
)
{
    bencode_t ben;

    bencode_t ben2;

    char *str = strdup("d3:keyl4:test3:fooe3:foo3:bare");

    const char *ren;

    int len;

    bencode_init(&ben, str, strlen(str));

    bencode_dict_get_next(&ben, &ben2, &ren, &len);
    CuAssertTrue(tc, !strncmp(ren, "key", len));

    bencode_dict_get_next(&ben, &ben2, &ren, &len);
    CuAssertTrue(tc, !strncmp(ren, "foo", len));

    CuAssertTrue(tc, !bencode_dict_has_next(&ben));
//    printf("%s\n", str);
//    CuAssertTrue(tc, !strcmp("l4:test3:fooe", str));
    free(str);
}
void TestBencodeDictGetNextInnerList(
    CuTest * tc
)
{
    bencode_t ben, ben2, ben3;
    char *str;
    const char *ren;
    int len;

    str = strdup("d3:keyl4:test3:fooee");
    bencode_init(&ben, str, strlen(str));

    bencode_dict_get_next(&ben, &ben2, &ren, &len);
    CuAssertTrue(tc, !strncmp(ren, "key", len));

    bencode_list_get_next(&ben2, &ben3);
    bencode_string_value(&ben3, &ren, &len);
    CuAssertTrue(tc, !strncmp("test", ren, len));

    bencode_list_get_next(&ben2, &ben3);
    bencode_string_value(&ben3, &ren, &len);
    CuAssertTrue(tc, !strncmp("foo", ren, len));

    CuAssertTrue(tc, !bencode_dict_has_next(&ben));
    free(str);
}
void TestBencodeDictHasNext(
    CuTest * tc
)
{
    bencode_t ben;

    char *str = strdup("d4:test3:fooe");

    bencode_init(&ben, str, strlen(str));

    CuAssertTrue(tc, 1 == bencode_dict_has_next(&ben));
    free(str);
}
int BencodeParser::bencode_dict_get_start_and_len(
		bencode_t * be,
		const char **start,
		int *len
)
{
	bencode_t ben, ben2;
	const char *ren;
	int tmplen;

	bencode_clone(be, &ben);
	*start = ben.str;
	while (bencode_dict_has_next(&ben))
		bencode_dict_get_next(&ben, &ben2, &ren, &tmplen);

	*len = ben.str - *start + 1;
	return 0;
}