| 1 | // Copyright 2007 - 2021, Alan Antonuk and the rabbitmq-c contributors. |
| 2 | // SPDX-License-Identifier: mit |
| 3 | |
| 4 | #include "amqp_private.h" |
| 5 | #include <rabbitmq-c/amqp.h> |
| 6 | #include <rabbitmq-c/framing.h> |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | static void expect_frame_max(int requested, int expected) { |
| 12 | int res; |
| 13 | amqp_connection_state_t state = amqp_new_connection(); |
| 14 | |
| 15 | if (state == NULL) { |
| 16 | fprintf(stderr, "amqp_new_connection failed\n"); |
| 17 | abort(); |
| 18 | } |
| 19 | |
| 20 | state->state = CONNECTION_STATE_IDLE; |
| 21 | |
| 22 | res = amqp_tune_connection(state, 0, requested, 0); |
| 23 | if (res != AMQP_STATUS_OK) { |
| 24 | fprintf(stderr, "amqp_tune_connection returned %d\n", res); |
| 25 | abort(); |
| 26 | } |
| 27 | |
| 28 | if (amqp_get_frame_max(state) != expected) { |
| 29 | fprintf(stderr, "expected frame_max %d, got %d\n", expected, |
| 30 | amqp_get_frame_max(state)); |
| 31 | abort(); |
| 32 | } |
| 33 | |
| 34 | if (state->outbound_buffer.len != (size_t)expected) { |
| 35 | fprintf(stderr, "expected outbound buffer length %d, got %zu\n", expected, |
| 36 | state->outbound_buffer.len); |
| 37 | abort(); |
| 38 | } |
| 39 | |
| 40 | amqp_destroy_connection(state); |
| 41 | } |
| 42 | |
| 43 | int main(void) { |
| 44 | expect_frame_max(0, AMQP_FRAME_MIN_SIZE); |
| 45 | expect_frame_max(1, AMQP_FRAME_MIN_SIZE); |
| 46 | expect_frame_max(AMQP_FRAME_MIN_SIZE - 1, AMQP_FRAME_MIN_SIZE); |
| 47 | expect_frame_max(AMQP_FRAME_MIN_SIZE, AMQP_FRAME_MIN_SIZE); |
| 48 | expect_frame_max(AMQP_DEFAULT_FRAME_SIZE, AMQP_DEFAULT_FRAME_SIZE); |
| 49 | |
| 50 | return 0; |
| 51 | } |