Debian Codegraph @

cpp/src/scalar_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 #include "scalar_test.hpp"
21
22 namespace {
23
24 using namespace std;
25 using namespace proton;
26
27 using test::scalar_test_group;
28
29 // NOTE: proton::coerce<> and bad proton::get() are tested in value_test to avoid redundant test code.
30
31 void encode_decode_test() {
32 value v;
33 scalar a("foo");
34 v = a; // Assignment to value does encode, get<> does decode.
35 ASSERT_EQUAL(v, a);
36 ASSERT_EQUAL(std::string("foo"), get<std::string>(v));
37 scalar a2 = get<scalar>(v);
38 ASSERT_EQUAL(std::string("foo"), get<std::string>(a2));
39 }
40
41 void message_id_test() {
42 ASSERT_EQUAL(23, coerce<int64_t>(message_id(23)));
43 ASSERT_EQUAL(23u, get<uint64_t>(message_id(23)));
44 ASSERT(message_id("foo") != message_id(binary("foo")));
45 ASSERT_EQUAL(scalar("foo"), message_id("foo"));
46 ASSERT_EQUAL("foo", coerce<std::string>(message_id("foo")));
47 ASSERT(message_id("a") < message_id("z"));
48 uuid r = uuid::random();
49 ASSERT_EQUAL(r, get<uuid>(message_id(r)));
50 }
51
52 void annotation_key_test() {
53 ASSERT_EQUAL(23, coerce<int64_t>(annotation_key(23)));
54 ASSERT_EQUAL(23u, get<uint64_t>(annotation_key(23)));
55 ASSERT_EQUAL("foo", coerce<std::string>(annotation_key("foo")));
56 ASSERT_EQUAL(scalar(symbol("foo")), annotation_key("foo"));
57 }
58
59 template <class T> T make(const char c) { T x; std::fill(x.begin(), x.end(), c); return x; }
60
61 }
62
63 int main(int, char**) {
64 int failed = 0;
65 scalar_test_group<scalar>(failed);
66
67 RUN_TEST(failed, encode_decode_test());
68 RUN_TEST(failed, message_id_test());
69 RUN_TEST(failed, annotation_key_test());
70 return failed;
71 }