| 1 | // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors.cxx . . $ `<file>/tests/test_merge_capabilities.c`/ |
| 2 | // SPDX-License-Identifier: mit |
| 3 | |
| 4 | #include "amqp_socket.h"cxx . . $ `<file>/librabbitmq/amqp_socket.h`/ |
| 5 | #include "amqp_table.h"cxx . . $ `<file>/librabbitmq/amqp_table.h`/ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | static int compare_bytescxx . . $ compare_bytes(d566a8a24e15fd18).(amqp_bytes_tcxx . . $ amqp_bytes_t# l, amqp_bytes_tcxx . . $ amqp_bytes_t# r); |
| 11 | static int compare_amqp_table_entrycxx . . $ compare_amqp_table_entry(f5cc0d428b6b7a65).(amqp_table_entry_tcxx . . $ amqp_table_entry_t# result, |
| 12 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# expect); |
| 13 | static int compare_field_valuecxx . . $ compare_field_value(32b5e98fa145e1f8).(amqp_field_value_tcxx . . $ amqp_field_value_t# result, |
| 14 | amqp_field_value_tcxx . . $ amqp_field_value_t# expect); |
| 15 | static int compare_amqp_tablecxx . . $ compare_amqp_table(b73ef48618dc86b).(amqp_table_tcxx . . $ amqp_table_t#* result, amqp_table_tcxx . . $ amqp_table_t#* expect); |
| 16 | |
| 17 | static int compare_bytescxx . . $ compare_bytes(d566a8a24e15fd18).(amqp_bytes_tcxx . . $ amqp_bytes_t# l, amqp_bytes_tcxx . . $ amqp_bytes_t# r) { |
| 18 | if (l.lencxx . . $ amqp_bytes_t_#len. == r.lencxx . . $ amqp_bytes_t_#len. && |
| 19 | (l.bytescxx . . $ amqp_bytes_t_#bytes. == r.bytescxx . . $ amqp_bytes_t_#bytes. || 0 == memcmpcxx . . $ memcmp(36f949851efa3055).(l.bytescxx . . $ amqp_bytes_t_#bytes., r.bytescxx . . $ amqp_bytes_t_#bytes., l.lencxx . . $ amqp_bytes_t_#len.))) { |
| 20 | return 1; |
| 21 | } |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static int compare_amqp_table_entrycxx . . $ compare_amqp_table_entry(f5cc0d428b6b7a65).(amqp_table_entry_tcxx . . $ amqp_table_entry_t# result, |
| 26 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# expect) { |
| 27 | if (!compare_bytescxx . . $ compare_bytes(d566a8a24e15fd18).(result.keycxx . . $ amqp_table_entry_t_#key., expect.keycxx . . $ amqp_table_entry_t_#key.)) { |
| 28 | return 0; |
| 29 | } |
| 30 | return compare_field_valuecxx . . $ compare_field_value(32b5e98fa145e1f8).(result.valuecxx . . $ amqp_table_entry_t_#value., expect.valuecxx . . $ amqp_table_entry_t_#value.); |
| 31 | } |
| 32 | |
| 33 | static int compare_field_valuecxx . . $ compare_field_value(32b5e98fa145e1f8).(amqp_field_value_tcxx . . $ amqp_field_value_t# result, |
| 34 | amqp_field_value_tcxx . . $ amqp_field_value_t# expect) { |
| 35 | if (result.kindcxx . . $ amqp_field_value_t_#kind. != expect.kindcxx . . $ amqp_field_value_t_#kind.) { |
| 36 | return 0; |
| 37 | } |
| 38 | switch (result.kindcxx . . $ amqp_field_value_t_#kind.) { |
| 39 | case AMQP_FIELD_KIND_BOOLEANcxx . . $ AMQP_FIELD_KIND_BOOLEAN.: |
| 40 | return result.valuecxx . . $ amqp_field_value_t_#value..booleancxx . . $ amqp_field_value_t_#$anonymous_type_0#boolean. == expect.valuecxx . . $ amqp_field_value_t_#value..booleancxx . . $ amqp_field_value_t_#$anonymous_type_0#boolean.; |
| 41 | case AMQP_FIELD_KIND_I8cxx . . $ AMQP_FIELD_KIND_I8.: |
| 42 | return result.valuecxx . . $ amqp_field_value_t_#value..i8cxx . . $ amqp_field_value_t_#$anonymous_type_0#i8. == expect.valuecxx . . $ amqp_field_value_t_#value..i8cxx . . $ amqp_field_value_t_#$anonymous_type_0#i8.; |
| 43 | case AMQP_FIELD_KIND_U8cxx . . $ AMQP_FIELD_KIND_U8.: |
| 44 | return result.valuecxx . . $ amqp_field_value_t_#value..u8cxx . . $ amqp_field_value_t_#$anonymous_type_0#u8. == expect.valuecxx . . $ amqp_field_value_t_#value..u8cxx . . $ amqp_field_value_t_#$anonymous_type_0#u8.; |
| 45 | case AMQP_FIELD_KIND_I16cxx . . $ AMQP_FIELD_KIND_I16.: |
| 46 | return result.valuecxx . . $ amqp_field_value_t_#value..i16cxx . . $ amqp_field_value_t_#$anonymous_type_0#i16. == expect.valuecxx . . $ amqp_field_value_t_#value..i16cxx . . $ amqp_field_value_t_#$anonymous_type_0#i16.; |
| 47 | case AMQP_FIELD_KIND_U16cxx . . $ AMQP_FIELD_KIND_U16.: |
| 48 | return result.valuecxx . . $ amqp_field_value_t_#value..u16cxx . . $ amqp_field_value_t_#$anonymous_type_0#u16. == expect.valuecxx . . $ amqp_field_value_t_#value..u16cxx . . $ amqp_field_value_t_#$anonymous_type_0#u16.; |
| 49 | case AMQP_FIELD_KIND_I32cxx . . $ AMQP_FIELD_KIND_I32.: |
| 50 | return result.valuecxx . . $ amqp_field_value_t_#value..i32cxx . . $ amqp_field_value_t_#$anonymous_type_0#i32. == expect.valuecxx . . $ amqp_field_value_t_#value..i32cxx . . $ amqp_field_value_t_#$anonymous_type_0#i32.; |
| 51 | case AMQP_FIELD_KIND_U32cxx . . $ AMQP_FIELD_KIND_U32.: |
| 52 | return result.valuecxx . . $ amqp_field_value_t_#value..u32cxx . . $ amqp_field_value_t_#$anonymous_type_0#u32. == expect.valuecxx . . $ amqp_field_value_t_#value..u32cxx . . $ amqp_field_value_t_#$anonymous_type_0#u32.; |
| 53 | case AMQP_FIELD_KIND_I64cxx . . $ AMQP_FIELD_KIND_I64.: |
| 54 | return result.valuecxx . . $ amqp_field_value_t_#value..i64cxx . . $ amqp_field_value_t_#$anonymous_type_0#i64. == expect.valuecxx . . $ amqp_field_value_t_#value..i64cxx . . $ amqp_field_value_t_#$anonymous_type_0#i64.; |
| 55 | case AMQP_FIELD_KIND_U64cxx . . $ AMQP_FIELD_KIND_U64.: |
| 56 | case AMQP_FIELD_KIND_TIMESTAMPcxx . . $ AMQP_FIELD_KIND_TIMESTAMP.: |
| 57 | return result.valuecxx . . $ amqp_field_value_t_#value..u64cxx . . $ amqp_field_value_t_#$anonymous_type_0#u64. == expect.valuecxx . . $ amqp_field_value_t_#value..u64cxx . . $ amqp_field_value_t_#$anonymous_type_0#u64.; |
| 58 | case AMQP_FIELD_KIND_F32cxx . . $ AMQP_FIELD_KIND_F32.: |
| 59 | return result.valuecxx . . $ amqp_field_value_t_#value..f32cxx . . $ amqp_field_value_t_#$anonymous_type_0#f32. == expect.valuecxx . . $ amqp_field_value_t_#value..f32cxx . . $ amqp_field_value_t_#$anonymous_type_0#f32.; |
| 60 | case AMQP_FIELD_KIND_F64cxx . . $ AMQP_FIELD_KIND_F64.: |
| 61 | return result.valuecxx . . $ amqp_field_value_t_#value..f64cxx . . $ amqp_field_value_t_#$anonymous_type_0#f64. == expect.valuecxx . . $ amqp_field_value_t_#value..f64cxx . . $ amqp_field_value_t_#$anonymous_type_0#f64.; |
| 62 | case AMQP_FIELD_KIND_DECIMALcxx . . $ AMQP_FIELD_KIND_DECIMAL.: |
| 63 | return !memcmpcxx . . $ memcmp(36f949851efa3055).(&result.valuecxx . . $ amqp_field_value_t_#value..decimalcxx . . $ amqp_field_value_t_#$anonymous_type_0#decimal., &expect.valuecxx . . $ amqp_field_value_t_#value..decimalcxx . . $ amqp_field_value_t_#$anonymous_type_0#decimal., |
| 64 | sizeof(expect.valuecxx . . $ amqp_field_value_t_#value..decimalcxx . . $ amqp_field_value_t_#$anonymous_type_0#decimal.)); |
| 65 | case AMQP_FIELD_KIND_UTF8cxx . . $ AMQP_FIELD_KIND_UTF8.: |
| 66 | case AMQP_FIELD_KIND_BYTEScxx . . $ AMQP_FIELD_KIND_BYTES.: |
| 67 | return compare_bytescxx . . $ compare_bytes(d566a8a24e15fd18).(result.valuecxx . . $ amqp_field_value_t_#value..bytescxx . . $ amqp_field_value_t_#$anonymous_type_0#bytes., expect.valuecxx . . $ amqp_field_value_t_#value..bytescxx . . $ amqp_field_value_t_#$anonymous_type_0#bytes.); |
| 68 | case AMQP_FIELD_KIND_ARRAYcxx . . $ AMQP_FIELD_KIND_ARRAY.: { |
| 69 | int i; |
| 70 | if (result.valuecxx . . $ amqp_field_value_t_#value..arraycxx . . $ amqp_field_value_t_#$anonymous_type_0#array..num_entriescxx . . $ amqp_array_t_#num_entries. != expect.valuecxx . . $ amqp_field_value_t_#value..arraycxx . . $ amqp_field_value_t_#$anonymous_type_0#array..num_entriescxx . . $ amqp_array_t_#num_entries.) { |
| 71 | return 0; |
| 72 | } |
| 73 | for (i = 0; i < result.valuecxx . . $ amqp_field_value_t_#value..arraycxx . . $ amqp_field_value_t_#$anonymous_type_0#array..num_entriescxx . . $ amqp_array_t_#num_entries.; ++i) { |
| 74 | if (!compare_field_valuecxx . . $ compare_field_value(32b5e98fa145e1f8).(result.valuecxx . . $ amqp_field_value_t_#value..arraycxx . . $ amqp_field_value_t_#$anonymous_type_0#array..entriescxx . . $ amqp_array_t_#entries.[i], |
| 75 | expect.valuecxx . . $ amqp_field_value_t_#value..arraycxx . . $ amqp_field_value_t_#$anonymous_type_0#array..entriescxx . . $ amqp_array_t_#entries.[i])) { |
| 76 | return 0; |
| 77 | } |
| 78 | } |
| 79 | return 1; |
| 80 | } |
| 81 | case AMQP_FIELD_KIND_TABLEcxx . . $ AMQP_FIELD_KIND_TABLE.: |
| 82 | return compare_amqp_tablecxx . . $ compare_amqp_table(b73ef48618dc86b).(&result.valuecxx . . $ amqp_field_value_t_#value..tablecxx . . $ amqp_field_value_t_#$anonymous_type_0#table., &expect.valuecxx . . $ amqp_field_value_t_#value..tablecxx . . $ amqp_field_value_t_#$anonymous_type_0#table.); |
| 83 | case AMQP_FIELD_KIND_VOIDcxx . . $ AMQP_FIELD_KIND_VOID.: |
| 84 | return 1; |
| 85 | } |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | static int compare_amqp_tablecxx . . $ compare_amqp_table(b73ef48618dc86b).(amqp_table_tcxx . . $ amqp_table_t#* result, amqp_table_tcxx . . $ amqp_table_t#* expect) { |
| 90 | int i; |
| 91 | |
| 92 | if (result->num_entriescxx . . $ amqp_table_t_#num_entries. != expect->num_entriescxx . . $ amqp_table_t_#num_entries.) { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | for (i = 0; i < expect->num_entriescxx . . $ amqp_table_t_#num_entries.; ++i) { |
| 97 | if (!compare_amqp_table_entrycxx . . $ compare_amqp_table_entry(f5cc0d428b6b7a65).(expect->entriescxx . . $ amqp_table_t_#entries.[i], result->entriescxx . . $ amqp_table_t_#entries.[i])) { |
| 98 | return 0; |
| 99 | } |
| 100 | } |
| 101 | return 1; |
| 102 | } |
| 103 | |
| 104 | static void test_merge_capabilitiescxx . . $ test_merge_capabilities(8a31c57a2e06b0d6).(amqp_table_tcxx . . $ amqp_table_t#* base, amqp_table_tcxx . . $ amqp_table_t#* add, |
| 105 | amqp_table_tcxx . . $ amqp_table_t#* expect) { |
| 106 | amqp_pool_tcxx . . $ amqp_pool_t# pool; |
| 107 | amqp_table_tcxx . . $ amqp_table_t# result; |
| 108 | int res; |
| 109 | init_amqp_poolcxx . . $ init_amqp_pool(77b3d1941c008140).(&pool, 4096); |
| 110 | |
| 111 | res = amqp_merge_capabilitiescxx . . $ amqp_merge_capabilities(7174850691ec52e).(base, add, &result, &pool); |
| 112 | if (AMQP_STATUS_OKcxx . . $ AMQP_STATUS_OK. != res) { |
| 113 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "amqp_merge_capabilities returned !ok: %d\n", res); |
| 114 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 115 | } |
| 116 | |
| 117 | if (!compare_amqp_tablecxx . . $ compare_amqp_table(b73ef48618dc86b).(&result, expect)) { |
| 118 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "amqp_merge_capabilities incorrect result.\n"); |
| 119 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 120 | } |
| 121 | empty_amqp_poolcxx . . $ empty_amqp_pool(5e0a27621b52c3e2).(&pool); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | int maincxx . . $ main(b126dc7c1de90089).(void) { |
| 126 | { |
| 127 | amqp_table_tcxx . . $ amqp_table_t# sub_base; |
| 128 | amqp_table_tcxx . . $ amqp_table_t# sub_add; |
| 129 | amqp_table_tcxx . . $ amqp_table_t# sub_expect; |
| 130 | amqp_table_tcxx . . $ amqp_table_t# base; |
| 131 | amqp_table_tcxx . . $ amqp_table_t# add; |
| 132 | amqp_table_tcxx . . $ amqp_table_t# expect; |
| 133 | |
| 134 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# sub_base_entries[1]; |
| 135 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# sub_add_entries[2]; |
| 136 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# sub_expect_entries[2]; |
| 137 | |
| 138 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# base_entries[3]; |
| 139 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# add_entries[3]; |
| 140 | amqp_table_entry_tcxx . . $ amqp_table_entry_t# expect_entries[4]; |
| 141 | |
| 142 | sub_base_entries[0] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("foo", "bar"); |
| 143 | sub_base.num_entriescxx . . $ amqp_table_t_#num_entries. = |
| 144 | sizeof(sub_base_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 145 | sub_base.entriescxx . . $ amqp_table_t_#entries. = sub_base_entries; |
| 146 | |
| 147 | sub_add_entries[0] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("something", "else"); |
| 148 | sub_add_entries[1] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("foo", "baz"); |
| 149 | sub_add.num_entriescxx . . $ amqp_table_t_#num_entries. = sizeof(sub_add_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 150 | sub_add.entriescxx . . $ amqp_table_t_#entries. = sub_add_entries; |
| 151 | |
| 152 | sub_expect_entries[0] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("foo", "baz"); |
| 153 | sub_expect_entries[1] = |
| 154 | amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("something", "else"); |
| 155 | sub_expect.num_entriescxx . . $ amqp_table_t_#num_entries. = |
| 156 | sizeof(sub_expect_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 157 | sub_expect.entriescxx . . $ amqp_table_t_#entries. = sub_expect_entries; |
| 158 | |
| 159 | base_entries[0] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("product", "1.0"); |
| 160 | base_entries[1] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("nooverride", "yeah"); |
| 161 | base_entries[2] = amqp_table_construct_table_entrycxx . . $ amqp_table_construct_table_entry(4df46d2c81b2d967).("props", &sub_base); |
| 162 | base.num_entriescxx . . $ amqp_table_t_#num_entries. = sizeof(base_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 163 | base.entriescxx . . $ amqp_table_t_#entries. = base_entries; |
| 164 | |
| 165 | add_entries[0] = amqp_table_construct_bool_entrycxx . . $ amqp_table_construct_bool_entry(b53dd7528db866c9).("bool_entry", 1); |
| 166 | add_entries[1] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("product", "2.0"); |
| 167 | add_entries[2] = amqp_table_construct_table_entrycxx . . $ amqp_table_construct_table_entry(4df46d2c81b2d967).("props", &sub_add); |
| 168 | add.num_entriescxx . . $ amqp_table_t_#num_entries. = sizeof(add_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 169 | add.entriescxx . . $ amqp_table_t_#entries. = add_entries; |
| 170 | |
| 171 | expect_entries[0] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("product", "2.0"), |
| 172 | expect_entries[1] = amqp_table_construct_utf8_entrycxx . . $ amqp_table_construct_utf8_entry(d273add1d84c2a1d).("nooverride", "yeah"), |
| 173 | expect_entries[2] = amqp_table_construct_table_entrycxx . . $ amqp_table_construct_table_entry(4df46d2c81b2d967).("props", &sub_expect); |
| 174 | expect_entries[3] = amqp_table_construct_bool_entrycxx . . $ amqp_table_construct_bool_entry(b53dd7528db866c9).("bool_entry", 1); |
| 175 | expect.num_entriescxx . . $ amqp_table_t_#num_entries. = sizeof(expect_entries) / sizeof(amqp_table_entry_tcxx . . $ amqp_table_entry_t#); |
| 176 | expect.entriescxx . . $ amqp_table_t_#entries. = expect_entries; |
| 177 | |
| 178 | test_merge_capabilitiescxx . . $ test_merge_capabilities(8a31c57a2e06b0d6).(&base, &add, &expect); |
| 179 | } |
| 180 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ok\n"); |
| 181 | return 0; |
| 182 | } |