mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 05:43:59 -07:00
Beginning CMake configuration for ZT
Only tested on Windows so far
This commit is contained in:
parent
af5d3a7f0b
commit
0b3b5f6174
111 changed files with 19586 additions and 36 deletions
47
ext/librabbitmq/tests/CMakeLists.txt
Normal file
47
ext/librabbitmq/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,47 @@
|
|||
include_directories(${LIBRABBITMQ_INCLUDE_DIRS})
|
||||
|
||||
if (MSVC)
|
||||
# No version of MSVC has inttypes.h, this uses the msinttypes
|
||||
# Note this includes stdint.h which is either in
|
||||
# ../librabbitmq/win32/msinttypes or in a standard location
|
||||
include_directories(win32/msinttypes)
|
||||
endif (MSVC)
|
||||
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
add_definitions(-DAMQP_STATIC)
|
||||
|
||||
add_executable(test_parse_url test_parse_url.c)
|
||||
target_link_libraries(test_parse_url rabbitmq-static)
|
||||
add_test(parse_url test_parse_url)
|
||||
|
||||
add_executable(test_tables test_tables.c)
|
||||
target_link_libraries(test_tables rabbitmq-static)
|
||||
add_test(tables test_tables)
|
||||
configure_file(test_tables.expected ${CMAKE_CURRENT_BINARY_DIR}/tests/test_tables.expected COPYONLY)
|
||||
|
||||
add_executable(test_hostcheck
|
||||
test_hostcheck.c
|
||||
../librabbitmq/amqp_hostcheck.c)
|
||||
add_test(hostcheck test_hostcheck)
|
||||
|
||||
add_executable(test_status_enum
|
||||
test_status_enum.c)
|
||||
target_link_libraries(test_status_enum rabbitmq-static)
|
||||
add_test(status_enum test_status_enum)
|
||||
|
||||
add_executable(test_basic
|
||||
test_basic.c)
|
||||
target_link_libraries(test_basic rabbitmq-static)
|
||||
|
||||
if (NOT APPLE)
|
||||
add_test(basic test_basic)
|
||||
endif()
|
||||
|
||||
add_executable(test_sasl_mechanism test_sasl_mechanism.c)
|
||||
target_link_libraries(test_sasl_mechanism rabbitmq-static)
|
||||
add_test(sasl_mechanism test_sasl_mechanism)
|
||||
|
||||
add_executable(test_merge_capabilities test_merge_capabilities.c)
|
||||
target_link_libraries(test_merge_capabilities rabbitmq-static)
|
||||
add_test(merge_capabilities test_merge_capabilities)
|
||||
|
207
ext/librabbitmq/tests/test_basic.c
Normal file
207
ext/librabbitmq/tests/test_basic.c
Normal file
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* Copyright 2017 Simon Giesecke
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "amqp.h"
|
||||
#include "amqp_tcp_socket.h"
|
||||
#include "amqp_time.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
static const int fixed_channel_id = 1;
|
||||
static const char test_queue_name[] = "test_queue";
|
||||
|
||||
amqp_connection_state_t setup_connection_and_channel(void) {
|
||||
amqp_connection_state_t connection_state_ = amqp_new_connection();
|
||||
|
||||
amqp_socket_t *socket = amqp_tcp_socket_new(connection_state_);
|
||||
assert(socket);
|
||||
|
||||
int rc = amqp_socket_open(socket, "localhost", AMQP_PROTOCOL_PORT);
|
||||
assert(rc == AMQP_STATUS_OK);
|
||||
|
||||
amqp_rpc_reply_t rpc_reply = amqp_login(
|
||||
connection_state_, "/", 1, AMQP_DEFAULT_FRAME_SIZE,
|
||||
AMQP_DEFAULT_HEARTBEAT, AMQP_SASL_METHOD_PLAIN, "guest", "guest");
|
||||
assert(rpc_reply.reply_type == AMQP_RESPONSE_NORMAL);
|
||||
|
||||
amqp_channel_open_ok_t *res =
|
||||
amqp_channel_open(connection_state_, fixed_channel_id);
|
||||
assert(res != NULL);
|
||||
|
||||
return connection_state_;
|
||||
}
|
||||
|
||||
void close_and_destroy_connection(amqp_connection_state_t connection_state_) {
|
||||
amqp_rpc_reply_t rpc_reply =
|
||||
amqp_connection_close(connection_state_, AMQP_REPLY_SUCCESS);
|
||||
assert(rpc_reply.reply_type == AMQP_RESPONSE_NORMAL);
|
||||
|
||||
int rc = amqp_destroy_connection(connection_state_);
|
||||
assert(rc == AMQP_STATUS_OK);
|
||||
}
|
||||
|
||||
void basic_publish(amqp_connection_state_t connectionState_,
|
||||
const char *message_) {
|
||||
amqp_bytes_t message_bytes = amqp_cstring_bytes(message_);
|
||||
|
||||
amqp_basic_properties_t properties;
|
||||
properties._flags = 0;
|
||||
|
||||
properties._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG;
|
||||
properties.delivery_mode = AMQP_DELIVERY_NONPERSISTENT;
|
||||
|
||||
int retval = amqp_basic_publish(
|
||||
connectionState_, fixed_channel_id, amqp_cstring_bytes(""),
|
||||
amqp_cstring_bytes(test_queue_name),
|
||||
/* mandatory=*/1,
|
||||
/* immediate=*/0, /* RabbitMQ 3.x does not support the "immediate" flag
|
||||
according to
|
||||
https://www.rabbitmq.com/specification.html */
|
||||
&properties, message_bytes);
|
||||
|
||||
assert(retval == 0);
|
||||
}
|
||||
|
||||
void queue_declare(amqp_connection_state_t connection_state_,
|
||||
const char *queue_name_) {
|
||||
amqp_queue_declare_ok_t *res = amqp_queue_declare(
|
||||
connection_state_, fixed_channel_id, amqp_cstring_bytes(queue_name_),
|
||||
/*passive*/ 0,
|
||||
/*durable*/ 0,
|
||||
/*exclusive*/ 0,
|
||||
/*auto_delete*/ 1, amqp_empty_table);
|
||||
assert(res != NULL);
|
||||
}
|
||||
|
||||
char *basic_get(amqp_connection_state_t connection_state_,
|
||||
const char *queue_name_, uint64_t *out_body_size_) {
|
||||
amqp_rpc_reply_t rpc_reply;
|
||||
amqp_time_t deadline;
|
||||
struct timeval timeout = {5, 0};
|
||||
int time_rc = amqp_time_from_now(&deadline, &timeout);
|
||||
assert(time_rc == AMQP_STATUS_OK);
|
||||
|
||||
do {
|
||||
rpc_reply = amqp_basic_get(connection_state_, fixed_channel_id,
|
||||
amqp_cstring_bytes(queue_name_), /*no_ack*/ 1);
|
||||
} while (rpc_reply.reply_type == AMQP_RESPONSE_NORMAL &&
|
||||
rpc_reply.reply.id == AMQP_BASIC_GET_EMPTY_METHOD &&
|
||||
amqp_time_has_past(deadline) == AMQP_STATUS_OK);
|
||||
|
||||
assert(rpc_reply.reply_type == AMQP_RESPONSE_NORMAL);
|
||||
assert(rpc_reply.reply.id == AMQP_BASIC_GET_OK_METHOD);
|
||||
|
||||
amqp_message_t message;
|
||||
rpc_reply =
|
||||
amqp_read_message(connection_state_, fixed_channel_id, &message, 0);
|
||||
assert(rpc_reply.reply_type == AMQP_RESPONSE_NORMAL);
|
||||
|
||||
char *body = malloc(message.body.len);
|
||||
memcpy(body, message.body.bytes, message.body.len);
|
||||
*out_body_size_ = message.body.len;
|
||||
amqp_destroy_message(&message);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
void publish_and_basic_get_message(const char *msg_to_publish) {
|
||||
amqp_connection_state_t connection_state = setup_connection_and_channel();
|
||||
|
||||
queue_declare(connection_state, test_queue_name);
|
||||
basic_publish(connection_state, msg_to_publish);
|
||||
|
||||
uint64_t body_size;
|
||||
char *msg = basic_get(connection_state, test_queue_name, &body_size);
|
||||
|
||||
assert(body_size == strlen(msg_to_publish));
|
||||
assert(strncmp(msg_to_publish, msg, body_size) == 0);
|
||||
free(msg);
|
||||
|
||||
close_and_destroy_connection(connection_state);
|
||||
}
|
||||
|
||||
char *consume_message(amqp_connection_state_t connection_state_,
|
||||
const char *queue_name_, uint64_t *out_body_size_) {
|
||||
amqp_basic_consume_ok_t *result =
|
||||
amqp_basic_consume(connection_state_, fixed_channel_id,
|
||||
amqp_cstring_bytes(queue_name_), amqp_empty_bytes,
|
||||
/*no_local*/ 0,
|
||||
/*no_ack*/ 1,
|
||||
/*exclusive*/ 0, amqp_empty_table);
|
||||
assert(result != NULL);
|
||||
|
||||
amqp_envelope_t envelope;
|
||||
struct timeval timeout = {5, 0};
|
||||
amqp_rpc_reply_t rpc_reply =
|
||||
amqp_consume_message(connection_state_, &envelope, &timeout, 0);
|
||||
assert(rpc_reply.reply_type == AMQP_RESPONSE_NORMAL);
|
||||
|
||||
*out_body_size_ = envelope.message.body.len;
|
||||
char *body = malloc(*out_body_size_);
|
||||
if (*out_body_size_) {
|
||||
memcpy(body, envelope.message.body.bytes, *out_body_size_);
|
||||
}
|
||||
|
||||
amqp_destroy_envelope(&envelope);
|
||||
return body;
|
||||
}
|
||||
|
||||
void publish_and_consume_message(const char *msg_to_publish) {
|
||||
amqp_connection_state_t connection_state = setup_connection_and_channel();
|
||||
|
||||
queue_declare(connection_state, test_queue_name);
|
||||
basic_publish(connection_state, msg_to_publish);
|
||||
|
||||
uint64_t body_size;
|
||||
char *msg = consume_message(connection_state, test_queue_name, &body_size);
|
||||
|
||||
assert(body_size == strlen(msg_to_publish));
|
||||
assert(strncmp(msg_to_publish, msg, body_size) == 0);
|
||||
free(msg);
|
||||
|
||||
close_and_destroy_connection(connection_state);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
publish_and_basic_get_message("");
|
||||
publish_and_basic_get_message("TEST");
|
||||
|
||||
publish_and_consume_message("");
|
||||
publish_and_consume_message("TEST");
|
||||
|
||||
return 0;
|
||||
}
|
71
ext/librabbitmq/tests/test_hostcheck.c
Normal file
71
ext/librabbitmq/tests/test_hostcheck.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2014 Michael Steinert
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "amqp_hostcheck.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void hostcheck_success(const char *match_pattern, const char *url) {
|
||||
int ok;
|
||||
|
||||
ok = amqp_hostcheck(match_pattern, url);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Expected hostname check to pass, but didn't: %s (%s)\n",
|
||||
url, match_pattern);
|
||||
abort();
|
||||
}
|
||||
|
||||
fprintf(stdout, "ok: [success] %s, %s\n", url, match_pattern);
|
||||
}
|
||||
|
||||
static void hostcheck_fail(const char *match_pattern, const char *url) {
|
||||
int ok;
|
||||
|
||||
ok = amqp_hostcheck(match_pattern, url);
|
||||
if (ok) {
|
||||
fprintf(stderr, "Expected hostname check to fail, but didn't: %s (%s)\n",
|
||||
url, match_pattern);
|
||||
abort();
|
||||
}
|
||||
|
||||
fprintf(stdout, "ok: [fail] %s, %s\n", url, match_pattern);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
hostcheck_success("www.rabbitmq.com", "www.rabbitmq.com");
|
||||
hostcheck_success("www.rabbitmq.com", "wWw.RaBbItMq.CoM");
|
||||
hostcheck_success("*.rabbitmq.com", "wWw.RaBbItMq.CoM");
|
||||
hostcheck_fail("rabbitmq.com", "www.rabbitmq.com");
|
||||
hostcheck_success("*.rabbitmq.com", "www.rabbitmq.com");
|
||||
hostcheck_fail("*.com", "www.rabbitmq.com");
|
||||
hostcheck_fail("*.rabbitmq.com", "long.url.rabbitmq.com");
|
||||
hostcheck_success("*.url.rabbitmq.com", "long.url.rabbitmq.com");
|
||||
|
||||
return 0;
|
||||
}
|
203
ext/librabbitmq/tests/test_merge_capabilities.c
Normal file
203
ext/librabbitmq/tests/test_merge_capabilities.c
Normal file
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* Copyright 2015 Alan Antonuk. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "amqp_socket.h"
|
||||
#include "amqp_table.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int compare_bytes(amqp_bytes_t l, amqp_bytes_t r);
|
||||
static int compare_amqp_table_entry(amqp_table_entry_t result,
|
||||
amqp_table_entry_t expect);
|
||||
static int compare_field_value(amqp_field_value_t result,
|
||||
amqp_field_value_t expect);
|
||||
static int compare_amqp_table(amqp_table_t* result, amqp_table_t* expect);
|
||||
|
||||
static int compare_bytes(amqp_bytes_t l, amqp_bytes_t r) {
|
||||
if (l.len == r.len &&
|
||||
(l.bytes == r.bytes || 0 == memcmp(l.bytes, r.bytes, l.len))) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compare_amqp_table_entry(amqp_table_entry_t result,
|
||||
amqp_table_entry_t expect) {
|
||||
if (!compare_bytes(result.key, expect.key)) {
|
||||
return 0;
|
||||
}
|
||||
return compare_field_value(result.value, expect.value);
|
||||
}
|
||||
|
||||
static int compare_field_value(amqp_field_value_t result,
|
||||
amqp_field_value_t expect) {
|
||||
if (result.kind != expect.kind) {
|
||||
return 0;
|
||||
}
|
||||
switch (result.kind) {
|
||||
case AMQP_FIELD_KIND_BOOLEAN:
|
||||
return result.value.boolean == expect.value.boolean;
|
||||
case AMQP_FIELD_KIND_I8:
|
||||
return result.value.i8 == expect.value.i8;
|
||||
case AMQP_FIELD_KIND_U8:
|
||||
return result.value.u8 == expect.value.u8;
|
||||
case AMQP_FIELD_KIND_I16:
|
||||
return result.value.i16 == expect.value.i16;
|
||||
case AMQP_FIELD_KIND_U16:
|
||||
return result.value.u16 == expect.value.u16;
|
||||
case AMQP_FIELD_KIND_I32:
|
||||
return result.value.i32 == expect.value.i32;
|
||||
case AMQP_FIELD_KIND_U32:
|
||||
return result.value.u32 == expect.value.u32;
|
||||
case AMQP_FIELD_KIND_I64:
|
||||
return result.value.i64 == expect.value.i64;
|
||||
case AMQP_FIELD_KIND_U64:
|
||||
case AMQP_FIELD_KIND_TIMESTAMP:
|
||||
return result.value.u64 == expect.value.u64;
|
||||
case AMQP_FIELD_KIND_F32:
|
||||
return result.value.f32 == expect.value.f32;
|
||||
case AMQP_FIELD_KIND_F64:
|
||||
return result.value.f64 == expect.value.f64;
|
||||
case AMQP_FIELD_KIND_DECIMAL:
|
||||
return !memcmp(&result.value.decimal, &expect.value.decimal,
|
||||
sizeof(expect.value.decimal));
|
||||
case AMQP_FIELD_KIND_UTF8:
|
||||
case AMQP_FIELD_KIND_BYTES:
|
||||
return compare_bytes(result.value.bytes, expect.value.bytes);
|
||||
case AMQP_FIELD_KIND_ARRAY: {
|
||||
int i;
|
||||
if (result.value.array.num_entries != expect.value.array.num_entries) {
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < result.value.array.num_entries; ++i) {
|
||||
if (!compare_field_value(result.value.array.entries[i],
|
||||
expect.value.array.entries[i])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
case AMQP_FIELD_KIND_TABLE:
|
||||
return compare_amqp_table(&result.value.table, &expect.value.table);
|
||||
case AMQP_FIELD_KIND_VOID:
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int compare_amqp_table(amqp_table_t* result, amqp_table_t* expect) {
|
||||
int i;
|
||||
|
||||
if (result->num_entries != expect->num_entries) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < expect->num_entries; ++i) {
|
||||
if (!compare_amqp_table_entry(expect->entries[i], result->entries[i])) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void test_merge_capabilities(amqp_table_t* base, amqp_table_t* add,
|
||||
amqp_table_t* expect) {
|
||||
amqp_pool_t pool;
|
||||
amqp_table_t result;
|
||||
int res;
|
||||
init_amqp_pool(&pool, 4096);
|
||||
|
||||
res = amqp_merge_capabilities(base, add, &result, &pool);
|
||||
if (AMQP_STATUS_OK != res) {
|
||||
fprintf(stderr, "amqp_merge_capabilities returned !ok: %d\n", res);
|
||||
abort();
|
||||
}
|
||||
|
||||
if (!compare_amqp_table(&result, expect)) {
|
||||
fprintf(stderr, "amqp_merge_capabilities incorrect result.\n");
|
||||
abort();
|
||||
}
|
||||
empty_amqp_pool(&pool);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
{
|
||||
amqp_table_t sub_base;
|
||||
amqp_table_t sub_add;
|
||||
amqp_table_t sub_expect;
|
||||
amqp_table_t base;
|
||||
amqp_table_t add;
|
||||
amqp_table_t expect;
|
||||
|
||||
amqp_table_entry_t sub_base_entries[1];
|
||||
amqp_table_entry_t sub_add_entries[2];
|
||||
amqp_table_entry_t sub_expect_entries[2];
|
||||
|
||||
amqp_table_entry_t base_entries[3];
|
||||
amqp_table_entry_t add_entries[3];
|
||||
amqp_table_entry_t expect_entries[4];
|
||||
|
||||
sub_base_entries[0] = amqp_table_construct_utf8_entry("foo", "bar");
|
||||
sub_base.num_entries =
|
||||
sizeof(sub_base_entries) / sizeof(amqp_table_entry_t);
|
||||
sub_base.entries = sub_base_entries;
|
||||
|
||||
sub_add_entries[0] = amqp_table_construct_utf8_entry("something", "else");
|
||||
sub_add_entries[1] = amqp_table_construct_utf8_entry("foo", "baz");
|
||||
sub_add.num_entries = sizeof(sub_add_entries) / sizeof(amqp_table_entry_t);
|
||||
sub_add.entries = sub_add_entries;
|
||||
|
||||
sub_expect_entries[0] = amqp_table_construct_utf8_entry("foo", "baz");
|
||||
sub_expect_entries[1] =
|
||||
amqp_table_construct_utf8_entry("something", "else");
|
||||
sub_expect.num_entries =
|
||||
sizeof(sub_expect_entries) / sizeof(amqp_table_entry_t);
|
||||
sub_expect.entries = sub_expect_entries;
|
||||
|
||||
base_entries[0] = amqp_table_construct_utf8_entry("product", "1.0");
|
||||
base_entries[1] = amqp_table_construct_utf8_entry("nooverride", "yeah");
|
||||
base_entries[2] = amqp_table_construct_table_entry("props", &sub_base);
|
||||
base.num_entries = sizeof(base_entries) / sizeof(amqp_table_entry_t);
|
||||
base.entries = base_entries;
|
||||
|
||||
add_entries[0] = amqp_table_construct_bool_entry("bool_entry", 1);
|
||||
add_entries[1] = amqp_table_construct_utf8_entry("product", "2.0");
|
||||
add_entries[2] = amqp_table_construct_table_entry("props", &sub_add);
|
||||
add.num_entries = sizeof(add_entries) / sizeof(amqp_table_entry_t);
|
||||
add.entries = add_entries;
|
||||
|
||||
expect_entries[0] = amqp_table_construct_utf8_entry("product", "2.0"),
|
||||
expect_entries[1] = amqp_table_construct_utf8_entry("nooverride", "yeah"),
|
||||
expect_entries[2] = amqp_table_construct_table_entry("props", &sub_expect);
|
||||
expect_entries[3] = amqp_table_construct_bool_entry("bool_entry", 1);
|
||||
expect.num_entries = sizeof(expect_entries) / sizeof(amqp_table_entry_t);
|
||||
expect.entries = expect_entries;
|
||||
|
||||
test_merge_capabilities(&base, &add, &expect);
|
||||
}
|
||||
fprintf(stderr, "ok\n");
|
||||
return 0;
|
||||
}
|
220
ext/librabbitmq/tests/test_parse_url.c
Normal file
220
ext/librabbitmq/tests/test_parse_url.c
Normal file
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MIT
|
||||
*
|
||||
* Portions created by Alan Antonuk are Copyright (c) 2012-2013
|
||||
* Alan Antonuk. All Rights Reserved.
|
||||
*
|
||||
* Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
|
||||
* VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* MSVC complains about strdup being deprecated in favor of _strdup */
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <amqp.h>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_success(const char *url, 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;
|
||||
|
||||
res = amqp_parse_url(s, &ci);
|
||||
if (res) {
|
||||
fprintf(stderr, "Expected to successfully parse URL, but didn't: %s (%s)\n",
|
||||
url, amqp_error_string2(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);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* From the spec */
|
||||
parse_success("amqp://user:pass@host:10000/vhost", "user", "pass", "host",
|
||||
10000, "vhost");
|
||||
parse_success("amqps://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("amqps://user%61:%61pass@ho%61st:10000/v%2fhost", "usera",
|
||||
"apass", "hoast", 10000, "v/host");
|
||||
|
||||
parse_success("amqp://", "guest", "guest", "localhost", 5672, "/");
|
||||
parse_success("amqps://", "guest", "guest", "localhost", 5671, "/");
|
||||
|
||||
parse_success("amqp://:@/", "", "", "localhost", 5672, "");
|
||||
parse_success("amqps://:@/", "", "", "localhost", 5671, "");
|
||||
|
||||
parse_success("amqp://user@", "user", "guest", "localhost", 5672, "/");
|
||||
parse_success("amqps://user@", "user", "guest", "localhost", 5671, "/");
|
||||
|
||||
parse_success("amqp://user:pass@", "user", "pass", "localhost", 5672, "/");
|
||||
parse_success("amqps://user:pass@", "user", "pass", "localhost", 5671, "/");
|
||||
|
||||
parse_success("amqp://host", "guest", "guest", "host", 5672, "/");
|
||||
parse_success("amqps://host", "guest", "guest", "host", 5671, "/");
|
||||
|
||||
parse_success("amqp://:10000", "guest", "guest", "localhost", 10000, "/");
|
||||
parse_success("amqps://:10000", "guest", "guest", "localhost", 10000, "/");
|
||||
|
||||
parse_success("amqp:///vhost", "guest", "guest", "localhost", 5672, "vhost");
|
||||
parse_success("amqps:///vhost", "guest", "guest", "localhost", 5671, "vhost");
|
||||
|
||||
parse_success("amqp://host/", "guest", "guest", "host", 5672, "");
|
||||
parse_success("amqps://host/", "guest", "guest", "host", 5671, "");
|
||||
|
||||
parse_success("amqp://host/%2f", "guest", "guest", "host", 5672, "/");
|
||||
parse_success("amqps://host/%2f", "guest", "guest", "host", 5671, "/");
|
||||
|
||||
parse_success("amqp://[::1]", "guest", "guest", "::1", 5672, "/");
|
||||
parse_success("amqps://[::1]", "guest", "guest", "::1", 5671, "/");
|
||||
|
||||
/* Various other success cases */
|
||||
parse_success("amqp://host:100", "guest", "guest", "host", 100, "/");
|
||||
parse_success("amqps://host:100", "guest", "guest", "host", 100, "/");
|
||||
|
||||
parse_success("amqp://[::1]:100", "guest", "guest", "::1", 100, "/");
|
||||
parse_success("amqps://[::1]:100", "guest", "guest", "::1", 100, "/");
|
||||
|
||||
parse_success("amqp://host/blah", "guest", "guest", "host", 5672, "blah");
|
||||
parse_success("amqps://host/blah", "guest", "guest", "host", 5671, "blah");
|
||||
|
||||
parse_success("amqp://host:100/blah", "guest", "guest", "host", 100, "blah");
|
||||
parse_success("amqps://host:100/blah", "guest", "guest", "host", 100, "blah");
|
||||
|
||||
parse_success("amqp://:100/blah", "guest", "guest", "localhost", 100, "blah");
|
||||
parse_success("amqps://:100/blah", "guest", "guest", "localhost", 100,
|
||||
"blah");
|
||||
|
||||
parse_success("amqp://[::1]/blah", "guest", "guest", "::1", 5672, "blah");
|
||||
parse_success("amqps://[::1]/blah", "guest", "guest", "::1", 5671, "blah");
|
||||
|
||||
parse_success("amqp://[::1]:100/blah", "guest", "guest", "::1", 100, "blah");
|
||||
parse_success("amqps://[::1]:100/blah", "guest", "guest", "::1", 100, "blah");
|
||||
|
||||
parse_success("amqp://user:pass@host", "user", "pass", "host", 5672, "/");
|
||||
parse_success("amqps://user:pass@host", "user", "pass", "host", 5671, "/");
|
||||
|
||||
parse_success("amqp://user:pass@host:100", "user", "pass", "host", 100, "/");
|
||||
parse_success("amqps://user:pass@host:100", "user", "pass", "host", 100, "/");
|
||||
|
||||
parse_success("amqp://user:pass@:100", "user", "pass", "localhost", 100, "/");
|
||||
parse_success("amqps://user:pass@:100", "user", "pass", "localhost", 100,
|
||||
"/");
|
||||
|
||||
parse_success("amqp://user:pass@[::1]", "user", "pass", "::1", 5672, "/");
|
||||
parse_success("amqps://user:pass@[::1]", "user", "pass", "::1", 5671, "/");
|
||||
|
||||
parse_success("amqp://user:pass@[::1]:100", "user", "pass", "::1", 100, "/");
|
||||
parse_success("amqps://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("amqps://foo:bar:baz");
|
||||
|
||||
parse_fail("amqp://foo[::1]");
|
||||
parse_fail("amqps://foo[::1]");
|
||||
|
||||
parse_fail("amqp://foo[::1]");
|
||||
parse_fail("amqps://foo[::1]");
|
||||
|
||||
parse_fail("amqp://foo:[::1]");
|
||||
parse_fail("amqps://foo:[::1]");
|
||||
|
||||
parse_fail("amqp://[::1]foo");
|
||||
parse_fail("amqps://[::1]foo");
|
||||
|
||||
parse_fail("amqp://foo:1000xyz");
|
||||
parse_fail("amqps://foo:1000xyz");
|
||||
|
||||
parse_fail("amqp://foo:1000000");
|
||||
parse_fail("amqps://foo:1000000");
|
||||
|
||||
parse_fail("amqp://foo/bar/baz");
|
||||
parse_fail("amqps://foo/bar/baz");
|
||||
|
||||
parse_fail("amqp://foo%1");
|
||||
parse_fail("amqps://foo%1");
|
||||
|
||||
parse_fail("amqp://foo%1x");
|
||||
parse_fail("amqps://foo%1x");
|
||||
|
||||
parse_fail("amqp://foo%xy");
|
||||
parse_fail("amqps://foo%xy");
|
||||
|
||||
return 0;
|
||||
}
|
70
ext/librabbitmq/tests/test_sasl_mechanism.c
Normal file
70
ext/librabbitmq/tests/test_sasl_mechanism.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MIT
|
||||
*
|
||||
* Portions created by Alan Antonuk are Copyright (c) 2012-2013
|
||||
* Alan Antonuk. All Rights Reserved.
|
||||
*
|
||||
* Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
|
||||
* VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <amqp_socket.h>
|
||||
|
||||
static void parse_success(amqp_bytes_t mechanisms,
|
||||
amqp_sasl_method_enum method) {
|
||||
if (!sasl_mechanism_in_list(mechanisms, method)) {
|
||||
fprintf(stderr, "Expected to find mechanism in list, but didn't: %s\n",
|
||||
(char *)mechanisms.bytes);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_fail(amqp_bytes_t mechanisms, amqp_sasl_method_enum method) {
|
||||
if (sasl_mechanism_in_list(mechanisms, method)) {
|
||||
fprintf(stderr,
|
||||
"Expected the mechanism not on the list, but it was present: %s\n",
|
||||
(char *)mechanisms.bytes);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
parse_success(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"),
|
||||
AMQP_SASL_METHOD_PLAIN);
|
||||
parse_fail(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 LOGIN PLAIN"),
|
||||
AMQP_SASL_METHOD_EXTERNAL);
|
||||
parse_success(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 EXTERNAL"),
|
||||
AMQP_SASL_METHOD_EXTERNAL);
|
||||
parse_fail(amqp_cstring_bytes("DIGEST-MD5 CRAM-MD5 EXTERNAL"),
|
||||
AMQP_SASL_METHOD_PLAIN);
|
||||
return 0;
|
||||
}
|
52
ext/librabbitmq/tests/test_status_enum.c
Normal file
52
ext/librabbitmq/tests/test_status_enum.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2015 Alan Antonuk
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "amqp.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static void check_errorstrings(amqp_status_enum start, amqp_status_enum end) {
|
||||
int i;
|
||||
for (i = start; i > end; --i) {
|
||||
const char* err = amqp_error_string2(i);
|
||||
if (0 == strcmp(err, "(unknown error)")) {
|
||||
printf("amqp_status_enum value %s%X", i < 0 ? "-" : "", (unsigned)i);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
check_errorstrings(AMQP_STATUS_OK, _AMQP_STATUS_NEXT_VALUE);
|
||||
check_errorstrings(AMQP_STATUS_TCP_ERROR, _AMQP_STATUS_TCP_NEXT_VALUE);
|
||||
check_errorstrings(AMQP_STATUS_SSL_ERROR, _AMQP_STATUS_SSL_NEXT_VALUE);
|
||||
|
||||
return 0;
|
||||
}
|
466
ext/librabbitmq/tests/test_tables.c
Normal file
466
ext/librabbitmq/tests/test_tables.c
Normal file
|
@ -0,0 +1,466 @@
|
|||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MIT
|
||||
*
|
||||
* Portions created by Alan Antonuk are Copyright (c) 2012-2013
|
||||
* Alan Antonuk. All Rights Reserved.
|
||||
*
|
||||
* Portions created by VMware are Copyright (c) 2007-2012 VMware, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Portions created by Tony Garnock-Jones are Copyright (c) 2009-2010
|
||||
* VMware, Inc. and Tony Garnock-Jones. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _USE_MATH_DEFINES
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <amqp.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
void die(const char *fmt, ...) {
|
||||
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++) {
|
||||
fputc(' ', out);
|
||||
}
|
||||
}
|
||||
|
||||
static void dump_value(int indent, amqp_field_value_t v, FILE *out) {
|
||||
int i;
|
||||
|
||||
dump_indent(indent, out);
|
||||
fputc(v.kind, out);
|
||||
|
||||
switch (v.kind) {
|
||||
case AMQP_FIELD_KIND_BOOLEAN:
|
||||
fputs(v.value.boolean ? " true\n" : " false\n", out);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_I8:
|
||||
fprintf(out, " %" PRId8 "\n", v.value.i8);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_U8:
|
||||
fprintf(out, " %" PRIu8 "\n", v.value.u8);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_I16:
|
||||
fprintf(out, " %" PRId16 "\n", v.value.i16);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_U16:
|
||||
fprintf(out, " %" PRIu16 "\n", v.value.u16);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_I32:
|
||||
fprintf(out, " %" PRId32 "\n", v.value.i32);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_U32:
|
||||
fprintf(out, " %" PRIu32 "\n", v.value.u32);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_I64:
|
||||
fprintf(out, " %" PRId64 "\n", v.value.i64);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_F32:
|
||||
fprintf(out, " %g\n", (double)v.value.f32);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_F64:
|
||||
fprintf(out, " %g\n", v.value.f64);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_DECIMAL:
|
||||
fprintf(out, " %u:::%u\n", v.value.decimal.decimals,
|
||||
v.value.decimal.value);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_UTF8:
|
||||
fprintf(out, " %.*s\n", (int)v.value.bytes.len,
|
||||
(char *)v.value.bytes.bytes);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_BYTES:
|
||||
fputc(' ', out);
|
||||
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++) {
|
||||
dump_value(indent + 2, v.value.array.entries[i], out);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_TIMESTAMP:
|
||||
fprintf(out, " %" PRIu64 "\n", v.value.u64);
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_TABLE:
|
||||
fputc('\n', 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);
|
||||
dump_value(indent + 4, v.value.table.entries[i].value, out);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case AMQP_FIELD_KIND_VOID:
|
||||
fputc('\n', out);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(out, "???\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_dump_value(FILE *out) {
|
||||
amqp_table_entry_t entries[8];
|
||||
amqp_table_t table;
|
||||
amqp_field_value_t val;
|
||||
|
||||
entries[0].key = amqp_cstring_bytes("zebra");
|
||||
entries[0].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[0].value.value.bytes = amqp_cstring_bytes("last");
|
||||
|
||||
entries[1].key = amqp_cstring_bytes("aardvark");
|
||||
entries[1].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[1].value.value.bytes = amqp_cstring_bytes("first");
|
||||
|
||||
entries[2].key = amqp_cstring_bytes("middle");
|
||||
entries[2].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[2].value.value.bytes = amqp_cstring_bytes("third");
|
||||
|
||||
entries[3].key = amqp_cstring_bytes("number");
|
||||
entries[3].value.kind = AMQP_FIELD_KIND_I32;
|
||||
entries[3].value.value.i32 = 1234;
|
||||
|
||||
entries[4].key = amqp_cstring_bytes("decimal");
|
||||
entries[4].value.kind = AMQP_FIELD_KIND_DECIMAL;
|
||||
entries[4].value.value.decimal.decimals = 2;
|
||||
entries[4].value.value.decimal.value = 1234;
|
||||
|
||||
entries[5].key = amqp_cstring_bytes("time");
|
||||
entries[5].value.kind = AMQP_FIELD_KIND_TIMESTAMP;
|
||||
entries[5].value.value.u64 = 1234123412341234;
|
||||
|
||||
entries[6].key = amqp_cstring_bytes("beta");
|
||||
entries[6].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[6].value.value.bytes = amqp_cstring_bytes("second");
|
||||
|
||||
entries[7].key = amqp_cstring_bytes("wombat");
|
||||
entries[7].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[7].value.value.bytes = amqp_cstring_bytes("fourth");
|
||||
|
||||
table.num_entries = 8;
|
||||
table.entries = entries;
|
||||
|
||||
qsort(table.entries, table.num_entries, sizeof(amqp_table_entry_t),
|
||||
&amqp_table_entry_cmp);
|
||||
|
||||
val.kind = AMQP_FIELD_KIND_TABLE;
|
||||
val.value.table = table;
|
||||
|
||||
dump_value(0, val, out);
|
||||
}
|
||||
|
||||
static uint8_t pre_encoded_table[] = {
|
||||
0x00, 0x00, 0x00, 0xff, 0x07, 0x6c, 0x6f, 0x6e, 0x67, 0x73, 0x74, 0x72,
|
||||
0x53, 0x00, 0x00, 0x00, 0x15, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73,
|
||||
0x20, 0x61, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x73, 0x74, 0x72, 0x69,
|
||||
0x6e, 0x67, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x69, 0x6e, 0x74,
|
||||
0x49, 0x00, 0x00, 0x30, 0x39, 0x07, 0x64, 0x65, 0x63, 0x69, 0x6d, 0x61,
|
||||
0x6c, 0x44, 0x03, 0x00, 0x01, 0xe2, 0x40, 0x09, 0x74, 0x69, 0x6d, 0x65,
|
||||
0x73, 0x74, 0x61, 0x6d, 0x70, 0x54, 0x00, 0x00, 0x63, 0xee, 0xa0, 0x53,
|
||||
0xc1, 0x94, 0x05, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x00, 0x00, 0x00,
|
||||
0x1f, 0x03, 0x6f, 0x6e, 0x65, 0x49, 0x00, 0x00, 0xd4, 0x31, 0x03, 0x74,
|
||||
0x77, 0x6f, 0x53, 0x00, 0x00, 0x00, 0x0d, 0x41, 0x20, 0x6c, 0x6f, 0x6e,
|
||||
0x67, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x04, 0x62, 0x79, 0x74,
|
||||
0x65, 0x62, 0xff, 0x04, 0x6c, 0x6f, 0x6e, 0x67, 0x6c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x49, 0x96, 0x02, 0xd2, 0x05, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x73,
|
||||
0x02, 0x8f, 0x04, 0x62, 0x6f, 0x6f, 0x6c, 0x74, 0x01, 0x06, 0x62, 0x69,
|
||||
0x6e, 0x61, 0x72, 0x79, 0x78, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x20, 0x62,
|
||||
0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,
|
||||
0x04, 0x76, 0x6f, 0x69, 0x64, 0x56, 0x05, 0x61, 0x72, 0x72, 0x61, 0x79,
|
||||
0x41, 0x00, 0x00, 0x00, 0x17, 0x49, 0x00, 0x00, 0xd4, 0x31, 0x53, 0x00,
|
||||
0x00, 0x00, 0x0d, 0x41, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x73, 0x74,
|
||||
0x72, 0x69, 0x6e, 0x67, 0x05, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x66, 0x40,
|
||||
0x49, 0x0f, 0xdb, 0x06, 0x64, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x64, 0x40,
|
||||
0x09, 0x21, 0xfb, 0x54, 0x44, 0x2d, 0x18};
|
||||
|
||||
static void test_table_codec(FILE *out) {
|
||||
amqp_pool_t pool;
|
||||
int result;
|
||||
|
||||
amqp_table_entry_t inner_entries[2];
|
||||
amqp_table_t inner_table;
|
||||
|
||||
amqp_field_value_t inner_values[2];
|
||||
amqp_array_t inner_array;
|
||||
|
||||
amqp_table_entry_t entries[14];
|
||||
amqp_table_t table;
|
||||
|
||||
inner_entries[0].key = amqp_cstring_bytes("one");
|
||||
inner_entries[0].value.kind = AMQP_FIELD_KIND_I32;
|
||||
inner_entries[0].value.value.i32 = 54321;
|
||||
|
||||
inner_entries[1].key = amqp_cstring_bytes("two");
|
||||
inner_entries[1].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
inner_entries[1].value.value.bytes = amqp_cstring_bytes("A long string");
|
||||
|
||||
inner_table.num_entries = 2;
|
||||
inner_table.entries = inner_entries;
|
||||
|
||||
inner_values[0].kind = AMQP_FIELD_KIND_I32;
|
||||
inner_values[0].value.i32 = 54321;
|
||||
|
||||
inner_values[1].kind = AMQP_FIELD_KIND_UTF8;
|
||||
inner_values[1].value.bytes = amqp_cstring_bytes("A long string");
|
||||
|
||||
inner_array.num_entries = 2;
|
||||
inner_array.entries = inner_values;
|
||||
|
||||
entries[0].key = amqp_cstring_bytes("longstr");
|
||||
entries[0].value.kind = AMQP_FIELD_KIND_UTF8;
|
||||
entries[0].value.value.bytes = amqp_cstring_bytes("Here is a long string");
|
||||
|
||||
entries[1].key = amqp_cstring_bytes("signedint");
|
||||
entries[1].value.kind = AMQP_FIELD_KIND_I32;
|
||||
entries[1].value.value.i32 = 12345;
|
||||
|
||||
entries[2].key = amqp_cstring_bytes("decimal");
|
||||
entries[2].value.kind = AMQP_FIELD_KIND_DECIMAL;
|
||||
entries[2].value.value.decimal.decimals = 3;
|
||||
entries[2].value.value.decimal.value = 123456;
|
||||
|
||||
entries[3].key = amqp_cstring_bytes("timestamp");
|
||||
entries[3].value.kind = AMQP_FIELD_KIND_TIMESTAMP;
|
||||
entries[3].value.value.u64 = 109876543209876;
|
||||
|
||||
entries[4].key = amqp_cstring_bytes("table");
|
||||
entries[4].value.kind = AMQP_FIELD_KIND_TABLE;
|
||||
entries[4].value.value.table = inner_table;
|
||||
|
||||
entries[5].key = amqp_cstring_bytes("byte");
|
||||
entries[5].value.kind = AMQP_FIELD_KIND_I8;
|
||||
entries[5].value.value.i8 = (int8_t)-1;
|
||||
|
||||
entries[6].key = amqp_cstring_bytes("long");
|
||||
entries[6].value.kind = AMQP_FIELD_KIND_I64;
|
||||
entries[6].value.value.i64 = 1234567890;
|
||||
|
||||
entries[7].key = amqp_cstring_bytes("short");
|
||||
entries[7].value.kind = AMQP_FIELD_KIND_I16;
|
||||
entries[7].value.value.i16 = 655;
|
||||
|
||||
entries[8].key = amqp_cstring_bytes("bool");
|
||||
entries[8].value.kind = AMQP_FIELD_KIND_BOOLEAN;
|
||||
entries[8].value.value.boolean = 1;
|
||||
|
||||
entries[9].key = amqp_cstring_bytes("binary");
|
||||
entries[9].value.kind = AMQP_FIELD_KIND_BYTES;
|
||||
entries[9].value.value.bytes = amqp_cstring_bytes("a binary string");
|
||||
|
||||
entries[10].key = amqp_cstring_bytes("void");
|
||||
entries[10].value.kind = AMQP_FIELD_KIND_VOID;
|
||||
|
||||
entries[11].key = amqp_cstring_bytes("array");
|
||||
entries[11].value.kind = AMQP_FIELD_KIND_ARRAY;
|
||||
entries[11].value.value.array = inner_array;
|
||||
|
||||
entries[12].key = amqp_cstring_bytes("float");
|
||||
entries[12].value.kind = AMQP_FIELD_KIND_F32;
|
||||
entries[12].value.value.f32 = (float)M_PI;
|
||||
|
||||
entries[13].key = amqp_cstring_bytes("double");
|
||||
entries[13].value.kind = AMQP_FIELD_KIND_F64;
|
||||
entries[13].value.value.f64 = M_PI;
|
||||
|
||||
table.num_entries = 14;
|
||||
table.entries = entries;
|
||||
|
||||
fprintf(out, "AAAAAAAAAA\n");
|
||||
|
||||
{
|
||||
amqp_field_value_t val;
|
||||
val.kind = AMQP_FIELD_KIND_TABLE;
|
||||
val.value.table = table;
|
||||
dump_value(0, val, out);
|
||||
}
|
||||
|
||||
init_amqp_pool(&pool, 4096);
|
||||
|
||||
{
|
||||
amqp_table_t decoded;
|
||||
size_t decoding_offset = 0;
|
||||
amqp_bytes_t decoding_bytes;
|
||||
decoding_bytes.len = sizeof(pre_encoded_table);
|
||||
decoding_bytes.bytes = pre_encoded_table;
|
||||
|
||||
result =
|
||||
amqp_decode_table(decoding_bytes, &pool, &decoded, &decoding_offset);
|
||||
if (result < 0) {
|
||||
die("Table decoding failed: %s", amqp_error_string2(result));
|
||||
}
|
||||
|
||||
fprintf(out, "BBBBBBBBBB\n");
|
||||
|
||||
{
|
||||
amqp_field_value_t val;
|
||||
val.kind = AMQP_FIELD_KIND_TABLE;
|
||||
val.value.table = decoded;
|
||||
|
||||
dump_value(0, val, out);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t encoding_buffer[4096];
|
||||
amqp_bytes_t encoding_result;
|
||||
size_t offset = 0;
|
||||
|
||||
memset(&encoding_buffer[0], 0, sizeof(encoding_buffer));
|
||||
encoding_result.len = sizeof(encoding_buffer);
|
||||
encoding_result.bytes = &encoding_buffer[0];
|
||||
|
||||
result = amqp_encode_table(encoding_result, &table, &offset);
|
||||
if (result < 0) {
|
||||
die("Table encoding failed: %s", amqp_error_string2(result));
|
||||
}
|
||||
|
||||
if (offset != sizeof(pre_encoded_table))
|
||||
die("Offset should be %ld, was %ld", (long)sizeof(pre_encoded_table),
|
||||
(long)offset);
|
||||
|
||||
result = memcmp(pre_encoded_table, encoding_buffer, offset);
|
||||
if (result != 0) {
|
||||
die("Table encoding differed", result);
|
||||
}
|
||||
}
|
||||
|
||||
empty_amqp_pool(&pool);
|
||||
}
|
||||
|
||||
#define CHUNK_SIZE 4096
|
||||
|
||||
static int compare_files(FILE *f1_in, FILE *f2_in) {
|
||||
char f1_buf[CHUNK_SIZE];
|
||||
char f2_buf[CHUNK_SIZE];
|
||||
int res;
|
||||
|
||||
rewind(f1_in);
|
||||
rewind(f2_in);
|
||||
|
||||
for (;;) {
|
||||
size_t f1_got = fread(f1_buf, 1, CHUNK_SIZE, f1_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) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (f1_got < CHUNK_SIZE || f2_got < CHUNK_SIZE) {
|
||||
if (f1_got != f2_got) {
|
||||
res = (f1_got < f2_got ? -1 : 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const char *expected_file_name = "tests/test_tables.expected";
|
||||
|
||||
int main(void) {
|
||||
char *srcdir = getenv("srcdir");
|
||||
FILE *out, *expected = NULL;
|
||||
char *expected_path;
|
||||
|
||||
out = tmpfile();
|
||||
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) {
|
||||
srcdir = ".";
|
||||
}
|
||||
|
||||
expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2);
|
||||
if (!expected_path) {
|
||||
die("out of memory");
|
||||
}
|
||||
sprintf(expected_path, "%s/%s", srcdir, expected_file_name);
|
||||
expected = fopen(expected_path, "r");
|
||||
if (!expected) {
|
||||
die("failed to open %s: %s", expected_path, strerror(errno));
|
||||
}
|
||||
|
||||
if (compare_files(expected, out)) {
|
||||
die("output file did not have expected contents");
|
||||
}
|
||||
|
||||
fclose(expected);
|
||||
free(expected_path);
|
||||
fclose(out);
|
||||
|
||||
return 0;
|
||||
}
|
90
ext/librabbitmq/tests/test_tables.expected
Normal file
90
ext/librabbitmq/tests/test_tables.expected
Normal file
|
@ -0,0 +1,90 @@
|
|||
AAAAAAAAAA
|
||||
F
|
||||
longstr ->
|
||||
S Here is a long string
|
||||
signedint ->
|
||||
I 12345
|
||||
decimal ->
|
||||
D 3:::123456
|
||||
timestamp ->
|
||||
T 109876543209876
|
||||
table ->
|
||||
F
|
||||
one ->
|
||||
I 54321
|
||||
two ->
|
||||
S A long string
|
||||
byte ->
|
||||
b -1
|
||||
long ->
|
||||
l 1234567890
|
||||
short ->
|
||||
s 655
|
||||
bool ->
|
||||
t true
|
||||
binary ->
|
||||
x 612062696e61727920737472696e67
|
||||
void ->
|
||||
V
|
||||
array ->
|
||||
A
|
||||
I 54321
|
||||
S A long string
|
||||
float ->
|
||||
f 3.14159
|
||||
double ->
|
||||
d 3.14159
|
||||
BBBBBBBBBB
|
||||
F
|
||||
longstr ->
|
||||
S Here is a long string
|
||||
signedint ->
|
||||
I 12345
|
||||
decimal ->
|
||||
D 3:::123456
|
||||
timestamp ->
|
||||
T 109876543209876
|
||||
table ->
|
||||
F
|
||||
one ->
|
||||
I 54321
|
||||
two ->
|
||||
S A long string
|
||||
byte ->
|
||||
b -1
|
||||
long ->
|
||||
l 1234567890
|
||||
short ->
|
||||
s 655
|
||||
bool ->
|
||||
t true
|
||||
binary ->
|
||||
x 612062696e61727920737472696e67
|
||||
void ->
|
||||
V
|
||||
array ->
|
||||
A
|
||||
I 54321
|
||||
S A long string
|
||||
float ->
|
||||
f 3.14159
|
||||
double ->
|
||||
d 3.14159
|
||||
----------
|
||||
F
|
||||
aardvark ->
|
||||
S first
|
||||
beta ->
|
||||
S second
|
||||
decimal ->
|
||||
D 2:::1234
|
||||
middle ->
|
||||
S third
|
||||
number ->
|
||||
I 1234
|
||||
time ->
|
||||
T 1234123412341234
|
||||
wombat ->
|
||||
S fourth
|
||||
zebra ->
|
||||
S last
|
304
ext/librabbitmq/tests/win32/msinttypes/inttypes.h
Normal file
304
ext/librabbitmq/tests/win32/msinttypes/inttypes.h
Normal file
|
@ -0,0 +1,304 @@
|
|||
// ISO C9x compliant inttypes.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The name of the author may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_INTTYPES_H_ // [
|
||||
#define _MSC_INTTYPES_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
// 7.8 Format conversion of integer types
|
||||
|
||||
typedef struct {
|
||||
intmax_t quot;
|
||||
intmax_t rem;
|
||||
} imaxdiv_t;
|
||||
|
||||
// 7.8.1 Macros for format specifiers
|
||||
|
||||
#if !defined(__cplusplus) || \
|
||||
defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198
|
||||
|
||||
// The fprintf macros for signed integers are:
|
||||
#define PRId8 "d"
|
||||
#define PRIi8 "i"
|
||||
#define PRIdLEAST8 "d"
|
||||
#define PRIiLEAST8 "i"
|
||||
#define PRIdFAST8 "d"
|
||||
#define PRIiFAST8 "i"
|
||||
|
||||
#define PRId16 "hd"
|
||||
#define PRIi16 "hi"
|
||||
#define PRIdLEAST16 "hd"
|
||||
#define PRIiLEAST16 "hi"
|
||||
#define PRIdFAST16 "hd"
|
||||
#define PRIiFAST16 "hi"
|
||||
|
||||
#define PRId32 "I32d"
|
||||
#define PRIi32 "I32i"
|
||||
#define PRIdLEAST32 "I32d"
|
||||
#define PRIiLEAST32 "I32i"
|
||||
#define PRIdFAST32 "I32d"
|
||||
#define PRIiFAST32 "I32i"
|
||||
|
||||
#define PRId64 "I64d"
|
||||
#define PRIi64 "I64i"
|
||||
#define PRIdLEAST64 "I64d"
|
||||
#define PRIiLEAST64 "I64i"
|
||||
#define PRIdFAST64 "I64d"
|
||||
#define PRIiFAST64 "I64i"
|
||||
|
||||
#define PRIdMAX "I64d"
|
||||
#define PRIiMAX "I64i"
|
||||
|
||||
#define PRIdPTR "Id"
|
||||
#define PRIiPTR "Ii"
|
||||
|
||||
// The fprintf macros for unsigned integers are:
|
||||
#define PRIo8 "o"
|
||||
#define PRIu8 "u"
|
||||
#define PRIx8 "x"
|
||||
#define PRIX8 "X"
|
||||
#define PRIoLEAST8 "o"
|
||||
#define PRIuLEAST8 "u"
|
||||
#define PRIxLEAST8 "x"
|
||||
#define PRIXLEAST8 "X"
|
||||
#define PRIoFAST8 "o"
|
||||
#define PRIuFAST8 "u"
|
||||
#define PRIxFAST8 "x"
|
||||
#define PRIXFAST8 "X"
|
||||
|
||||
#define PRIo16 "ho"
|
||||
#define PRIu16 "hu"
|
||||
#define PRIx16 "hx"
|
||||
#define PRIX16 "hX"
|
||||
#define PRIoLEAST16 "ho"
|
||||
#define PRIuLEAST16 "hu"
|
||||
#define PRIxLEAST16 "hx"
|
||||
#define PRIXLEAST16 "hX"
|
||||
#define PRIoFAST16 "ho"
|
||||
#define PRIuFAST16 "hu"
|
||||
#define PRIxFAST16 "hx"
|
||||
#define PRIXFAST16 "hX"
|
||||
|
||||
#define PRIo32 "I32o"
|
||||
#define PRIu32 "I32u"
|
||||
#define PRIx32 "I32x"
|
||||
#define PRIX32 "I32X"
|
||||
#define PRIoLEAST32 "I32o"
|
||||
#define PRIuLEAST32 "I32u"
|
||||
#define PRIxLEAST32 "I32x"
|
||||
#define PRIXLEAST32 "I32X"
|
||||
#define PRIoFAST32 "I32o"
|
||||
#define PRIuFAST32 "I32u"
|
||||
#define PRIxFAST32 "I32x"
|
||||
#define PRIXFAST32 "I32X"
|
||||
|
||||
#define PRIo64 "I64o"
|
||||
#define PRIu64 "I64u"
|
||||
#define PRIx64 "I64x"
|
||||
#define PRIX64 "I64X"
|
||||
#define PRIoLEAST64 "I64o"
|
||||
#define PRIuLEAST64 "I64u"
|
||||
#define PRIxLEAST64 "I64x"
|
||||
#define PRIXLEAST64 "I64X"
|
||||
#define PRIoFAST64 "I64o"
|
||||
#define PRIuFAST64 "I64u"
|
||||
#define PRIxFAST64 "I64x"
|
||||
#define PRIXFAST64 "I64X"
|
||||
|
||||
#define PRIoMAX "I64o"
|
||||
#define PRIuMAX "I64u"
|
||||
#define PRIxMAX "I64x"
|
||||
#define PRIXMAX "I64X"
|
||||
|
||||
#define PRIoPTR "Io"
|
||||
#define PRIuPTR "Iu"
|
||||
#define PRIxPTR "Ix"
|
||||
#define PRIXPTR "IX"
|
||||
|
||||
// The fscanf macros for signed integers are:
|
||||
#define SCNd8 "d"
|
||||
#define SCNi8 "i"
|
||||
#define SCNdLEAST8 "d"
|
||||
#define SCNiLEAST8 "i"
|
||||
#define SCNdFAST8 "d"
|
||||
#define SCNiFAST8 "i"
|
||||
|
||||
#define SCNd16 "hd"
|
||||
#define SCNi16 "hi"
|
||||
#define SCNdLEAST16 "hd"
|
||||
#define SCNiLEAST16 "hi"
|
||||
#define SCNdFAST16 "hd"
|
||||
#define SCNiFAST16 "hi"
|
||||
|
||||
#define SCNd32 "ld"
|
||||
#define SCNi32 "li"
|
||||
#define SCNdLEAST32 "ld"
|
||||
#define SCNiLEAST32 "li"
|
||||
#define SCNdFAST32 "ld"
|
||||
#define SCNiFAST32 "li"
|
||||
|
||||
#define SCNd64 "I64d"
|
||||
#define SCNi64 "I64i"
|
||||
#define SCNdLEAST64 "I64d"
|
||||
#define SCNiLEAST64 "I64i"
|
||||
#define SCNdFAST64 "I64d"
|
||||
#define SCNiFAST64 "I64i"
|
||||
|
||||
#define SCNdMAX "I64d"
|
||||
#define SCNiMAX "I64i"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
#define SCNdPTR "I64d"
|
||||
#define SCNiPTR "I64i"
|
||||
#else // _WIN64 ][
|
||||
#define SCNdPTR "ld"
|
||||
#define SCNiPTR "li"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// The fscanf macros for unsigned integers are:
|
||||
#define SCNo8 "o"
|
||||
#define SCNu8 "u"
|
||||
#define SCNx8 "x"
|
||||
#define SCNX8 "X"
|
||||
#define SCNoLEAST8 "o"
|
||||
#define SCNuLEAST8 "u"
|
||||
#define SCNxLEAST8 "x"
|
||||
#define SCNXLEAST8 "X"
|
||||
#define SCNoFAST8 "o"
|
||||
#define SCNuFAST8 "u"
|
||||
#define SCNxFAST8 "x"
|
||||
#define SCNXFAST8 "X"
|
||||
|
||||
#define SCNo16 "ho"
|
||||
#define SCNu16 "hu"
|
||||
#define SCNx16 "hx"
|
||||
#define SCNX16 "hX"
|
||||
#define SCNoLEAST16 "ho"
|
||||
#define SCNuLEAST16 "hu"
|
||||
#define SCNxLEAST16 "hx"
|
||||
#define SCNXLEAST16 "hX"
|
||||
#define SCNoFAST16 "ho"
|
||||
#define SCNuFAST16 "hu"
|
||||
#define SCNxFAST16 "hx"
|
||||
#define SCNXFAST16 "hX"
|
||||
|
||||
#define SCNo32 "lo"
|
||||
#define SCNu32 "lu"
|
||||
#define SCNx32 "lx"
|
||||
#define SCNX32 "lX"
|
||||
#define SCNoLEAST32 "lo"
|
||||
#define SCNuLEAST32 "lu"
|
||||
#define SCNxLEAST32 "lx"
|
||||
#define SCNXLEAST32 "lX"
|
||||
#define SCNoFAST32 "lo"
|
||||
#define SCNuFAST32 "lu"
|
||||
#define SCNxFAST32 "lx"
|
||||
#define SCNXFAST32 "lX"
|
||||
|
||||
#define SCNo64 "I64o"
|
||||
#define SCNu64 "I64u"
|
||||
#define SCNx64 "I64x"
|
||||
#define SCNX64 "I64X"
|
||||
#define SCNoLEAST64 "I64o"
|
||||
#define SCNuLEAST64 "I64u"
|
||||
#define SCNxLEAST64 "I64x"
|
||||
#define SCNXLEAST64 "I64X"
|
||||
#define SCNoFAST64 "I64o"
|
||||
#define SCNuFAST64 "I64u"
|
||||
#define SCNxFAST64 "I64x"
|
||||
#define SCNXFAST64 "I64X"
|
||||
|
||||
#define SCNoMAX "I64o"
|
||||
#define SCNuMAX "I64u"
|
||||
#define SCNxMAX "I64x"
|
||||
#define SCNXMAX "I64X"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
#define SCNoPTR "I64o"
|
||||
#define SCNuPTR "I64u"
|
||||
#define SCNxPTR "I64x"
|
||||
#define SCNXPTR "I64X"
|
||||
#else // _WIN64 ][
|
||||
#define SCNoPTR "lo"
|
||||
#define SCNuPTR "lu"
|
||||
#define SCNxPTR "lx"
|
||||
#define SCNXPTR "lX"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#endif // __STDC_FORMAT_MACROS ]
|
||||
|
||||
// 7.8.2 Functions for greatest-width integer types
|
||||
|
||||
// 7.8.2.1 The imaxabs function
|
||||
#define imaxabs _abs64
|
||||
|
||||
// 7.8.2.2 The imaxdiv function
|
||||
|
||||
// This is modified version of div() function from Microsoft's div.c found
|
||||
// in %MSVC.NET%\crt\src\div.c
|
||||
#ifdef STATIC_IMAXDIV // [
|
||||
static
|
||||
#else // STATIC_IMAXDIV ][
|
||||
_inline
|
||||
#endif // STATIC_IMAXDIV ]
|
||||
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) {
|
||||
imaxdiv_t result;
|
||||
|
||||
result.quot = numer / denom;
|
||||
result.rem = numer % denom;
|
||||
|
||||
if (numer < 0 && result.rem > 0) {
|
||||
// did division wrong; must fix up
|
||||
++result.quot;
|
||||
result.rem -= denom;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 7.8.2.3 The strtoimax and strtoumax functions
|
||||
#define strtoimax _strtoi64
|
||||
#define strtoumax _strtoui64
|
||||
|
||||
// 7.8.2.4 The wcstoimax and wcstoumax functions
|
||||
#define wcstoimax _wcstoi64
|
||||
#define wcstoumax _wcstoui64
|
||||
|
||||
#endif // _MSC_INTTYPES_H_ ]
|
Loading…
Add table
Add a link
Reference in a new issue