From dc04434f7398528ef69954f0f840ac9ce5847347 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 6 May 2009 21:36:45 +0100 Subject: Better support for tables --- tests/Makefile.am | 4 ++++ tests/test_tables.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/Makefile.am create mode 100644 tests/test_tables.c (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..dafdba4 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,4 @@ +noinst_PROGRAMS = test_tables + +AM_CFLAGS = -I../librabbitmq +AM_LDFLAGS = ../librabbitmq/librabbitmq.la diff --git a/tests/test_tables.c b/tests/test_tables.c new file mode 100644 index 0000000..9631f49 --- /dev/null +++ b/tests/test_tables.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +int main(int argc, char const * const *argv) { + amqp_table_entry_t entries[8] = { AMQP_TABLE_ENTRY_S("zebra", amqp_cstring_bytes("last")), + AMQP_TABLE_ENTRY_S("aardvark", amqp_cstring_bytes("first")), + AMQP_TABLE_ENTRY_S("middle", amqp_cstring_bytes("third")), + AMQP_TABLE_ENTRY_I("number", 1234), + AMQP_TABLE_ENTRY_D("decimal", AMQP_DECIMAL(2, 1234)), + AMQP_TABLE_ENTRY_T("time", (uint64_t) 1234123412341234LL), + AMQP_TABLE_ENTRY_S("beta", amqp_cstring_bytes("second")), + AMQP_TABLE_ENTRY_S("wombat", amqp_cstring_bytes("fourth")) }; + amqp_table_t table = { .num_entries = sizeof(entries) / sizeof(entries[0]), + .entries = &entries[0] }; + int i; + + qsort(table.entries, table.num_entries, sizeof(amqp_table_entry_t), &amqp_table_entry_cmp); + + for (i = 0; i < table.num_entries; i++) { + amqp_table_entry_t *e = &table.entries[i]; + printf("%.*s -> %c (", (int) e->key.len, (char *) e->key.bytes, e->kind); + switch (e->kind) { + case 'S': printf("%.*s", (int) e->value.bytes.len, (char *) e->value.bytes.bytes); break; + case 'I': printf("%d", e->value.i32); break; + case 'D': printf("%d:::%u", e->value.decimal.decimals, e->value.decimal.value); break; + case 'T': printf("%llu", e->value.u64); break; + case 'F': printf("..."); break; + default: printf("???"); break; + } + printf(")\n"); + } + + return 0; +} -- cgit v1.2.1