Debian Codegraph @

c/tests/pn_test_test.cpp

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 // Tests for the test framework
21
22 #include "./pn_test.hpp"
23
24 #include <proton/condition.h>
25 #include <proton/error.h>
26 #include <proton/event.h>
27
28 #include <sstream>
29
30 using namespace pn_test;
31
32 TEST_CASE("test_stringify") {
33 std::ostringstream o;
34 SECTION("event_type") {
35 o << PN_CONNECTION_INIT;
36 CHECK(o.str() == "PN_CONNECTION_INIT");
37 CHECK(Catch::Detail::stringify(PN_CONNECTION_INIT) == "PN_CONNECTION_INIT");
38 }
39 SECTION("condition") {
40 pn_condition_t *c = pn_condition();
41 SECTION("empty") {
42 o << *c;
43 CHECK(o.str() == "pn_condition{}");
44 CHECK_THAT(*c, cond_empty());
45 }
46 SECTION("name-desc") {
47 pn_condition_set_name(c, "foo");
48 pn_condition_set_description(c, "bar");
49 o << *c;
50 CHECK(o.str() == "pn_condition{\"foo\", \"bar\"}");
51 CHECK_THAT(*c, cond_matches("foo", "bar"));
52 CHECK_THAT(*c, !cond_empty());
53 }
54 SECTION("desc-only") {
55 pn_condition_set_name(c, "foo");
56 o << *c;
57 CHECK(o.str() == "pn_condition{\"foo\", null}");
58 CHECK_THAT(*c, cond_matches("foo"));
59 }
60 pn_condition_free(c);
61 }
62 SECTION("error") {
63 pn_error_t *err = pn_error();
64 pn_error_format(err, PN_EOS, "foo");
65 o << *err;
66 pn_error_free(err);
67 CHECK(o.str() == "pn_error{PN_EOS, \"foo\"}");
68 }
69 }