int main(int argc, char *argv[])
{
	int rc;
	struct test_struct data;
	struct test_struct2 data2;
	const char *lines =
		"u8: 5\n"
		"u16: 10\n"
		"u32: 15\n"
		"u64: 20\n"
		"i8: 45\n"
		"i16: 410\n"
		"xyz: 1.2345\n"
		"abc[0]: 7.8910\n"
		"abc[1]: 2.222\n"
		"blah: blah blah blah\n"
		"blah2:\n"
		"i32: 415\n"
		"i64: 420\n"
		"some_data: this is a test\n"
		"doubledata: 3.1415927\n"
		"floatdata: 6.66666";

	void *base_address[] = { &data, &data2 };

	memset(&data, 0, sizeof(data));
	rc = key_value_parse_lines(test_kvs, lines, base_address);
	CHECK(data.u8 == 5);
	CHECK(data.u16 == 10);
	CHECK(data.u32 == 15);
	CHECK(data.u64 == 20);
	CHECK(data.i8 == 45);
	CHECK(data.i16 == 410);
	CHECK(data.i32 == 415);
	CHECK(data.i64 == 420);
	CHECK(fabs(data.floatdata - 6.66666) < 0.0001);
	CHECK(abs(data.doubledata - 3.1415927) < 0.0001);
	CHECK(abs(data2.xyz - 1.2345) < 0.0001);
	CHECK(fabs(data2.abc[0] - 7.8910) < 0.0001);
	CHECK(fabs(data2.abc[1] - 2.222) < 0.0001);
	CHECK(strcmp("this is a test", data.some_data) == 0);
	CHECK(strcmp("blah blah blah", data2.blah) == 0);
	CHECK(strcmp("", data2.blah2) == 0);
	CHECK(rc == 0);

	printf("---- Begin testing key_value_write_lines\n");
	key_value_write_lines(stdout, test_kvs, base_address);
	printf("---- End testing key_value_write_lines\n");

	printf("test_key_value_parser: all tests pass.\n");
	return 0;
}
Exemple #2
0
static int write_bridge_info(FILE *f, struct bridge_info *b)
{
	void *base_address[] = { &b->entity, b };

	return key_value_write_lines(f, snis_entity_kvs, base_address);
}