From ad2b116059e22d393b7e44ad54f345a3fb4e267b Mon Sep 17 00:00:00 2001 From: Alan Antonuk Date: Mon, 8 Apr 2013 14:52:53 -0700 Subject: Formatted source code with astyle utilty --- tests/test_parse_url.c | 214 ++++++++++++++++++++++++------------------------- tests/test_tables.c | 60 ++++++++------ 2 files changed, 143 insertions(+), 131 deletions(-) (limited to 'tests') diff --git a/tests/test_parse_url.c b/tests/test_parse_url.c index 2e7d1c7..585514d 100644 --- a/tests/test_parse_url.c +++ b/tests/test_parse_url.c @@ -43,127 +43,127 @@ static void match_string(const char *what, const char *expect, const char *got) { - if (strcmp(got, expect)) { - fprintf(stderr, "Expected %s '%s', got '%s'\n", - what, expect, got); - abort(); - } + if (strcmp(got, expect)) { + fprintf(stderr, "Expected %s '%s', got '%s'\n", + what, expect, got); + abort(); + } } static void match_int(const char *what, int expect, int got) { - if (got != expect) { - fprintf(stderr, "Expected %s '%d', got '%d'\n", - what, expect, got); - abort(); - } + if (got != expect) { + fprintf(stderr, "Expected %s '%d', got '%d'\n", + what, expect, got); + abort(); + } } static void parse_success(const char *url, - const char *user, - const char *password, - const char *host, - int port, - const char *vhost) + const char *user, + const char *password, + const char *host, + int port, + const char *vhost) { - char *s = strdup(url); - struct amqp_connection_info ci; - int res; - - amqp_default_connection_info(&ci); - res = amqp_parse_url(s, &ci); - if (res) { - fprintf(stderr, - "Expected to successfully parse URL, but didn't: %s (%s)\n", - url, amqp_error_string(-res)); - abort(); - } - - match_string("user", user, ci.user); - match_string("password", password, ci.password); - match_string("host", host, ci.host); - match_int("port", port, ci.port); - match_string("vhost", vhost, ci.vhost); - - free(s); + char *s = strdup(url); + struct amqp_connection_info ci; + int res; + + amqp_default_connection_info(&ci); + res = amqp_parse_url(s, &ci); + if (res) { + fprintf(stderr, + "Expected to successfully parse URL, but didn't: %s (%s)\n", + url, amqp_error_string(-res)); + abort(); + } + + match_string("user", user, ci.user); + match_string("password", password, ci.password); + match_string("host", host, ci.host); + match_int("port", port, ci.port); + match_string("vhost", vhost, ci.vhost); + + free(s); } static void parse_fail(const char *url) { - char *s = strdup(url); - struct amqp_connection_info ci; - - amqp_default_connection_info(&ci); - if (amqp_parse_url(s, &ci) >= 0) { - fprintf(stderr, - "Expected to fail parsing URL, but didn't: %s\n", - url); - abort(); - } - - free(s); + char *s = strdup(url); + struct amqp_connection_info ci; + + amqp_default_connection_info(&ci); + if (amqp_parse_url(s, &ci) >= 0) { + fprintf(stderr, + "Expected to fail parsing URL, but didn't: %s\n", + url); + abort(); + } + + free(s); } int main(void) { - /* From the spec */ - parse_success("amqp://user:pass@host:10000/vhost", "user", "pass", - "host", 10000, "vhost"); - parse_success("amqp://user%61:%61pass@ho%61st:10000/v%2fhost", - "usera", "apass", "hoast", 10000, "v/host"); - parse_success("amqp://", "guest", "guest", "localhost", 5672, "/"); - parse_success("amqp://:@/", "", "", "localhost", 5672, ""); - parse_success("amqp://user@", "user", "guest", "localhost", 5672, "/"); - parse_success("amqp://user:pass@", "user", "pass", - "localhost", 5672, "/"); - parse_success("amqp://host", "guest", "guest", "host", 5672, "/"); - parse_success("amqp://:10000", "guest", "guest", "localhost", 10000, - "/"); - parse_success("amqp:///vhost", "guest", "guest", "localhost", 5672, - "vhost"); - parse_success("amqp://host/", "guest", "guest", "host", 5672, ""); - parse_success("amqp://host/%2f", "guest", "guest", "host", 5672, "/"); - parse_success("amqp://[::1]", "guest", "guest", "::1", 5672, "/"); - - /* Various other success cases */ - parse_success("amqp://host:100", "guest", "guest", "host", 100, "/"); - parse_success("amqp://[::1]:100", "guest", "guest", "::1", 100, "/"); - - parse_success("amqp://host/blah", "guest", "guest", - "host", 5672, "blah"); - parse_success("amqp://host:100/blah", "guest", "guest", - "host", 100, "blah"); - parse_success("amqp://:100/blah", "guest", "guest", - "localhost", 100, "blah"); - parse_success("amqp://[::1]/blah", "guest", "guest", - "::1", 5672, "blah"); - parse_success("amqp://[::1]:100/blah", "guest", "guest", - "::1", 100, "blah"); - - parse_success("amqp://user:pass@host", "user", "pass", - "host", 5672, "/"); - parse_success("amqp://user:pass@host:100", "user", "pass", - "host", 100, "/"); - parse_success("amqp://user:pass@:100", "user", "pass", - "localhost", 100, "/"); - parse_success("amqp://user:pass@[::1]", "user", "pass", - "::1", 5672, "/"); - parse_success("amqp://user:pass@[::1]:100", "user", "pass", - "::1", 100, "/"); - - /* Various failure cases */ - parse_fail("http://www.rabbitmq.com"); - parse_fail("amqp://foo:bar:baz"); - parse_fail("amqp://foo[::1]"); - parse_fail("amqp://foo:[::1]"); - parse_fail("amqp://[::1]foo"); - parse_fail("amqp://foo:1000xyz"); - parse_fail("amqp://foo:1000000"); - parse_fail("amqp://foo/bar/baz"); - - parse_fail("amqp://foo%1"); - parse_fail("amqp://foo%1x"); - parse_fail("amqp://foo%xy"); - - return 0; + /* From the spec */ + parse_success("amqp://user:pass@host:10000/vhost", "user", "pass", + "host", 10000, "vhost"); + parse_success("amqp://user%61:%61pass@ho%61st:10000/v%2fhost", + "usera", "apass", "hoast", 10000, "v/host"); + parse_success("amqp://", "guest", "guest", "localhost", 5672, "/"); + parse_success("amqp://:@/", "", "", "localhost", 5672, ""); + parse_success("amqp://user@", "user", "guest", "localhost", 5672, "/"); + parse_success("amqp://user:pass@", "user", "pass", + "localhost", 5672, "/"); + parse_success("amqp://host", "guest", "guest", "host", 5672, "/"); + parse_success("amqp://:10000", "guest", "guest", "localhost", 10000, + "/"); + parse_success("amqp:///vhost", "guest", "guest", "localhost", 5672, + "vhost"); + parse_success("amqp://host/", "guest", "guest", "host", 5672, ""); + parse_success("amqp://host/%2f", "guest", "guest", "host", 5672, "/"); + parse_success("amqp://[::1]", "guest", "guest", "::1", 5672, "/"); + + /* Various other success cases */ + parse_success("amqp://host:100", "guest", "guest", "host", 100, "/"); + parse_success("amqp://[::1]:100", "guest", "guest", "::1", 100, "/"); + + parse_success("amqp://host/blah", "guest", "guest", + "host", 5672, "blah"); + parse_success("amqp://host:100/blah", "guest", "guest", + "host", 100, "blah"); + parse_success("amqp://:100/blah", "guest", "guest", + "localhost", 100, "blah"); + parse_success("amqp://[::1]/blah", "guest", "guest", + "::1", 5672, "blah"); + parse_success("amqp://[::1]:100/blah", "guest", "guest", + "::1", 100, "blah"); + + parse_success("amqp://user:pass@host", "user", "pass", + "host", 5672, "/"); + parse_success("amqp://user:pass@host:100", "user", "pass", + "host", 100, "/"); + parse_success("amqp://user:pass@:100", "user", "pass", + "localhost", 100, "/"); + parse_success("amqp://user:pass@[::1]", "user", "pass", + "::1", 5672, "/"); + parse_success("amqp://user:pass@[::1]:100", "user", "pass", + "::1", 100, "/"); + + /* Various failure cases */ + parse_fail("http://www.rabbitmq.com"); + parse_fail("amqp://foo:bar:baz"); + parse_fail("amqp://foo[::1]"); + parse_fail("amqp://foo:[::1]"); + parse_fail("amqp://[::1]foo"); + parse_fail("amqp://foo:1000xyz"); + parse_fail("amqp://foo:1000000"); + parse_fail("amqp://foo/bar/baz"); + + parse_fail("amqp://foo%1"); + parse_fail("amqp://foo%1x"); + parse_fail("amqp://foo%xy"); + + return 0; } diff --git a/tests/test_tables.c b/tests/test_tables.c index 404a6d8..21e1c01 100644 --- a/tests/test_tables.c +++ b/tests/test_tables.c @@ -48,20 +48,21 @@ void die(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - abort(); + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + abort(); } static void dump_indent(int indent, FILE *out) { int i; - for (i = 0; i < indent; i++) + for (i = 0; i < indent; i++) { fputc(' ', out); + } } static void dump_value(int indent, amqp_field_value_t v, FILE *out) @@ -114,26 +115,28 @@ static void dump_value(int indent, amqp_field_value_t v, FILE *out) case AMQP_FIELD_KIND_DECIMAL: fprintf(out, " %d:::%u\n", v.value.decimal.decimals, - v.value.decimal.value); + v.value.decimal.value); break; case AMQP_FIELD_KIND_UTF8: fprintf(out, " %.*s\n", (int)v.value.bytes.len, - (char *)v.value.bytes.bytes); + (char *)v.value.bytes.bytes); break; case AMQP_FIELD_KIND_BYTES: fputc(' ', out); - for (i = 0; i < (int)v.value.bytes.len; i++) + for (i = 0; i < (int)v.value.bytes.len; i++) { fprintf(out, "%02x", ((char *) v.value.bytes.bytes)[i]); + } fputc('\n', out); break; case AMQP_FIELD_KIND_ARRAY: fputc('\n', out); - for (i = 0; i < v.value.array.num_entries; i++) + for (i = 0; i < v.value.array.num_entries; i++) { dump_value(indent + 2, v.value.array.entries[i], out); + } break; @@ -146,8 +149,8 @@ static void dump_value(int indent, amqp_field_value_t v, FILE *out) for (i = 0; i < v.value.table.num_entries; i++) { dump_indent(indent + 2, out); fprintf(out, "%.*s ->\n", - (int)v.value.table.entries[i].key.len, - (char *)v.value.table.entries[i].key.bytes); + (int)v.value.table.entries[i].key.len, + (char *)v.value.table.entries[i].key.bytes); dump_value(indent + 4, v.value.table.entries[i].value, out); } @@ -361,9 +364,10 @@ static void test_table_codec(FILE *out) decoding_bytes.bytes = pre_encoded_table; result = amqp_decode_table(decoding_bytes, &pool, &decoded, - &decoding_offset); - if (result < 0) + &decoding_offset); + if (result < 0) { die("Table decoding failed: %s", amqp_error_string(-result)); + } fprintf(out, "BBBBBBBBBB\n"); @@ -386,16 +390,18 @@ static void test_table_codec(FILE *out) encoding_result.bytes = &encoding_buffer[0]; result = amqp_encode_table(encoding_result, &table, &offset); - if (result < 0) + if (result < 0) { die("Table encoding failed: %s", amqp_error_string(-result)); + } if (offset != sizeof(pre_encoded_table)) die("Offset should be %ld, was %ld", (long)sizeof(pre_encoded_table), - (long)offset); + (long)offset); result = memcmp(pre_encoded_table, encoding_buffer, offset); - if (result != 0) + if (result != 0) { die("Table encoding differed", result); + } } empty_amqp_pool(&pool); @@ -417,12 +423,14 @@ static int compare_files(FILE *f1_in, FILE *f2_in) size_t f2_got = fread(f2_buf, 1, CHUNK_SIZE, f2_in); res = memcmp(f1_buf, f2_buf, f1_got < f2_got ? f1_got : f2_got); - if (res) + if (res) { break; + } if (f1_got < CHUNK_SIZE || f2_got < CHUNK_SIZE) { - if (f1_got != f2_got) + if (f1_got != f2_got) { res = (f1_got < f2_got ? -1 : 1); + } break; } } @@ -439,24 +447,28 @@ int main(void) char *expected_path; out = tmpfile(); - if (out == NULL) + if (out == NULL) { die("failed to create temporary file: %s", strerror(errno)); + } test_table_codec(out); fprintf(out, "----------\n"); test_dump_value(out); - if (srcdir == NULL) + if (srcdir == NULL) { srcdir = "."; + } expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2); sprintf(expected_path, "%s/%s", srcdir, expected_file_name); expected = fopen(expected_path, "r"); - if (!expected) + if (!expected) { die("failed to open %s: %s", expected_path, strerror(errno)); + } - if (compare_files(expected, out)) + if (compare_files(expected, out)) { die("output file did not have expected contents"); + } fclose(out); fclose(expected); -- cgit v1.2.1