1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
* Copyright (c) 2013 Balabit
* Copyright (c) 2013 Viktor Tusa <tusa@balabit.hu>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#include <criterion/criterion.h>
#include "stomp.h"
static void
assert_stomp_header(stomp_frame *frame, char *key, char *value)
{
char *myvalue = g_hash_table_lookup(frame->headers, key);
cr_assert_str_eq(myvalue, value, "Stomp header assertion failed!");
}
static void
assert_stomp_command(stomp_frame *frame, char *command)
{
cr_assert_str_eq(frame->command, command, "Stomp command assertion failed");
}
static void
assert_stomp_body(stomp_frame *frame, char *body)
{
cr_assert_str_eq(frame->body, body, "Stomp body assertion failed");
}
Test(stomp_proto, test_only_command)
{
stomp_frame frame;
stomp_parse_frame(g_string_new("CONNECTED\n\n"), &frame);
assert_stomp_command(&frame, "CONNECTED");
stomp_frame_deinit(&frame);
}
Test(stomp_proto, test_command_and_data)
{
stomp_frame frame;
stomp_parse_frame(g_string_new("CONNECTED\n\nalmafa"), &frame);
assert_stomp_command(&frame, "CONNECTED");
assert_stomp_body(&frame, "almafa");
stomp_frame_deinit(&frame);
};
Test(stomp_proto, test_command_and_header_and_data)
{
stomp_frame frame;
stomp_parse_frame(g_string_new("CONNECTED\nheader_name:header_value\n\nbelafa"), &frame);
assert_stomp_command(&frame, "CONNECTED");
assert_stomp_header(&frame, "header_name", "header_value");
assert_stomp_body(&frame, "belafa");
stomp_frame_deinit(&frame);
};
Test(stomp_proto, test_command_and_header)
{
stomp_frame frame;
stomp_parse_frame(g_string_new("CONNECTED\nsession:ID:tusa-38077-1378214843533-2:1\n"), &frame);
assert_stomp_command(&frame, "CONNECTED");
assert_stomp_header(&frame, "session", "ID:tusa-38077-1378214843533-2:1");
stomp_frame_deinit(&frame);
};
Test(stomp_proto, test_generate_gstring_from_frame)
{
stomp_frame frame;
GString *actual;
stomp_frame_init(&frame, "SEND", sizeof("SEND"));
stomp_frame_add_header(&frame, "header_name", "header_value");
stomp_frame_set_body(&frame, "body", sizeof("body"));
actual = create_gstring_from_frame(&frame);
cr_assert_str_eq(actual->str, "SEND\nheader_name:header_value\n\nbody", "Generated stomp frame does not match");
stomp_frame_deinit(&frame);
};
Test(stomp_proto, test_invalid_command)
{
stomp_frame frame;
cr_assert_not(stomp_parse_frame(g_string_new("CONNECTED\n no-colon\n"), &frame));
stomp_frame_deinit(&frame);
};
|