| 1 |
/* |
| 2 |
* |
| 3 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 4 |
* or more contributor license agreements. See the NOTICE file |
| 5 |
* distributed with this work for additional information |
| 6 |
* regarding copyright ownership. The ASF licenses this file |
| 7 |
* to you under the Apache License, Version 2.0 (the |
| 8 |
* "License"); you may not use this file except in compliance |
| 9 |
* with the License. You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, |
| 14 |
* software distributed under the License is distributed on an |
| 15 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 |
* KIND, either express or implied. See the License for the |
| 17 |
* specific language governing permissions and limitations |
| 18 |
* under the License. |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "./pn_test.hpp" |
| 23 |
|
| 24 |
#include <proton/error.h> |
| 25 |
#include <proton/message.h> |
| 26 |
#include <stdarg.h> |
| 27 |
|
| 28 |
using namespace pn_test; |
| 29 |
|
| 30 |
TEST_CASE("message_overflow_error") { |
| 31 |
pn_message_t *message = pn_message(); |
| 32 |
char buf[6]; |
| 33 |
size_t size = 6; |
| 34 |
|
| 35 |
int err = pn_message_encode(message, buf, &size); |
| 36 |
CHECK(PN_OVERFLOW == err); |
| 37 |
CHECK(0 == pn_message_errno(message)); |
| 38 |
pn_message_free(message); |
| 39 |
} |
| 40 |
|
| 41 |
static void recode(pn_message_t *dst, pn_message_t *src) { |
| 42 |
pn_rwbytes_t buf = {0}; |
| 43 |
int size = pn_message_encode2(src, &buf); |
| 44 |
REQUIRE(size > 0); |
| 45 |
pn_message_decode(dst, buf.start, size); |
| 46 |
free(buf.start); |
| 47 |
} |
| 48 |
|
| 49 |
TEST_CASE("message_inferred") { |
| 50 |
pn_message_t *src = pn_message(); |
| 51 |
pn_message_t *dst = pn_message(); |
| 52 |
|
| 53 |
CHECK(!pn_message_is_inferred(src)); |
| 54 |
pn_data_put_binary(pn_message_body(src), pn_bytes("hello")); |
| 55 |
recode(dst, src); |
| 56 |
CHECK(!pn_message_is_inferred(dst)); |
| 57 |
pn_message_set_inferred(src, true); |
| 58 |
recode(dst, src); |
| 59 |
CHECK(pn_message_is_inferred(dst)); |
| 60 |
|
| 61 |
pn_message_clear(src); |
| 62 |
CHECK(!pn_message_is_inferred(src)); |
| 63 |
pn_data_put_list(pn_message_body(src)); |
| 64 |
pn_data_enter(pn_message_body(src)); |
| 65 |
pn_data_put_binary(pn_message_body(src), pn_bytes("hello")); |
| 66 |
recode(dst, src); |
| 67 |
CHECK(!pn_message_is_inferred(dst)); |
| 68 |
pn_message_set_inferred(src, true); |
| 69 |
recode(dst, src); |
| 70 |
CHECK(pn_message_is_inferred(dst)); |
| 71 |
|
| 72 |
pn_message_clear(src); |
| 73 |
CHECK(!pn_message_is_inferred(src)); |
| 74 |
pn_data_put_string(pn_message_body(src), pn_bytes("hello")); |
| 75 |
recode(dst, src); |
| 76 |
CHECK(!pn_message_is_inferred(dst)); |
| 77 |
pn_message_set_inferred(src, true); |
| 78 |
recode(dst, src); |
| 79 |
/* A value section is never considered to be inferred */ |
| 80 |
CHECK(!pn_message_is_inferred(dst)); |
| 81 |
|
| 82 |
pn_message_free(src); |
| 83 |
pn_message_free(dst); |
| 84 |
} |