/*
- * Copyright (c) [2019-2024] SUSE LLC
+ * Copyright (c) [2019-2026] SUSE LLC
*
* All Rights Reserved.
*
#include "Stomp.h"
+
namespace Stomp
{
{
has_content_length = true;
- if (value.empty())
- {
- throw runtime_error("stomp error: empty content-length value");
- }
-
try
{
size_t parsed_chars = 0;
}
catch (const invalid_argument&)
{
- throw runtime_error("stomp error: invalid content-length syntax");
+ throw runtime_error("stomp error: invalid content-length syntax '" + value + "'");
}
catch (const out_of_range&)
{
throw runtime_error("stomp error: expected a message, got a part of it");
}
+
void
write_message(ostream& os, const Message& msg)
{
BOOST_CHECK_EQUAL(msg.body, "WORLD");
}
+
+
+BOOST_AUTO_TEST_CASE(error1)
+{
+ // missing \0 at frame end
+
+ istringstream s1("HELLO\nkey:value\ncontent-length:5\n\nWORL" + null);
+ istream s2(s1.rdbuf());
+
+ BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
+ return strcmp(e.what(), "stomp error: missing \\0 at frame end") == 0;
+ });
+}
+
+
+BOOST_AUTO_TEST_CASE(error2)
+{
+ // empty content-lenght value
+
+ istringstream s1("HELLO\nkey:value\ncontent-length:\n\nWORLD" + null);
+ istream s2(s1.rdbuf());
+
+ BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
+ cout << e.what() << '\n';
+ return strcmp(e.what(), "stomp error: invalid content-length syntax ''") == 0;
+ });
+}
+
+
+BOOST_AUTO_TEST_CASE(error3)
+{
+ // invalid content-lenght value
+
+ istringstream s1("HELLO\nkey:value\ncontent-length:5a\n\nWORLD" + null);
+ istream s2(s1.rdbuf());
+
+ BOOST_CHECK_EXCEPTION(read_message(s2), exception, [](const exception& e) {
+ cout << e.what() << '\n';
+ return strcmp(e.what(), "stomp error: invalid content-length value '5a'") == 0;
+ });
+}