| 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 "test_bits.hpp" |
| 21 |
|
| 22 |
#include "proton/internal/data.hpp" |
| 23 |
#include "proton/types.hpp" |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
using namespace proton; |
| 28 |
|
| 29 |
template <class T> void simple_type_test(const T& x) { |
| 30 |
ASSERT(codec::is_encodable<T>::value); |
| 31 |
value v; |
| 32 |
codec::encoder e(v); |
| 33 |
e << x; |
| 34 |
T y; |
| 35 |
codec::decoder d(v); |
| 36 |
d >> y; |
| 37 |
ASSERT_EQUAL(x, y); |
| 38 |
} |
| 39 |
|
| 40 |
template <class T> T make_fill(const char c) { |
| 41 |
T x; std::fill(x.begin(), x.end(), c); |
| 42 |
return x; |
| 43 |
} |
| 44 |
|
| 45 |
template <class T> void uncodable_type_test() { |
| 46 |
ASSERT(!codec::is_encodable<T>::value); |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
int main(int, char**) { |
| 52 |
int failed = 0; |
| 53 |
|
| 54 |
// Basic AMQP types |
| 55 |
RUN_TEST(failed, simple_type_test(null())); |
| 56 |
RUN_TEST(failed, simple_type_test(false)); |
| 57 |
RUN_TEST(failed, simple_type_test(uint8_t(42))); |
| 58 |
RUN_TEST(failed, simple_type_test(int8_t(-42))); |
| 59 |
RUN_TEST(failed, simple_type_test(uint16_t(4242))); |
| 60 |
RUN_TEST(failed, simple_type_test(int16_t(-4242))); |
| 61 |
RUN_TEST(failed, simple_type_test(uint32_t(4242))); |
| 62 |
RUN_TEST(failed, simple_type_test(int32_t(-4242))); |
| 63 |
RUN_TEST(failed, simple_type_test(uint64_t(4242))); |
| 64 |
RUN_TEST(failed, simple_type_test(int64_t(-4242))); |
| 65 |
RUN_TEST(failed, simple_type_test(wchar_t('X'))); |
| 66 |
RUN_TEST(failed, simple_type_test(float(1.234))); |
| 67 |
RUN_TEST(failed, simple_type_test(double(11.2233))); |
| 68 |
RUN_TEST(failed, simple_type_test(timestamp(1234))); |
| 69 |
RUN_TEST(failed, simple_type_test(make_fill<decimal32>(0))); |
| 70 |
RUN_TEST(failed, simple_type_test(make_fill<decimal64>(0))); |
| 71 |
RUN_TEST(failed, simple_type_test(make_fill<decimal128>(0))); |
| 72 |
RUN_TEST(failed, simple_type_test(uuid::copy("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"))); |
| 73 |
RUN_TEST(failed, simple_type_test(std::string("xxx"))); |
| 74 |
RUN_TEST(failed, simple_type_test(symbol("aaa"))); |
| 75 |
RUN_TEST(failed, simple_type_test(binary("aaa"))); |
| 76 |
|
| 77 |
// Native int type that may map differently per platform to uint types. |
| 78 |
RUN_TEST(failed, simple_type_test(char(42))); |
| 79 |
RUN_TEST(failed, simple_type_test(short(42))); |
| 80 |
RUN_TEST(failed, simple_type_test(int(42))); |
| 81 |
RUN_TEST(failed, simple_type_test(long(42))); |
| 82 |
|
| 83 |
RUN_TEST(failed, simple_type_test(static_cast<signed char>(42))); |
| 84 |
RUN_TEST(failed, simple_type_test(static_cast<signed short>(42))); |
| 85 |
RUN_TEST(failed, simple_type_test(static_cast<signed int>(42))); |
| 86 |
RUN_TEST(failed, simple_type_test(static_cast<signed long>(42))); |
| 87 |
|
| 88 |
RUN_TEST(failed, simple_type_test(static_cast<unsigned char>(42))); |
| 89 |
RUN_TEST(failed, simple_type_test(static_cast<unsigned short>(42))); |
| 90 |
RUN_TEST(failed, simple_type_test(static_cast<unsigned int>(42))); |
| 91 |
RUN_TEST(failed, simple_type_test(static_cast<unsigned long>(42))); |
| 92 |
|
| 93 |
RUN_TEST(failed, simple_type_test(static_cast<long long>(42))); |
| 94 |
RUN_TEST(failed, simple_type_test(static_cast<signed long long>(42))); |
| 95 |
RUN_TEST(failed, simple_type_test(static_cast<unsigned long long>(42))); |
| 96 |
|
| 97 |
// value and scalar types, more tests in value_test and scalar_test. |
| 98 |
RUN_TEST(failed, simple_type_test(value("foo"))); |
| 99 |
RUN_TEST(failed, value v(23); simple_type_test(v)); |
| 100 |
RUN_TEST(failed, simple_type_test(scalar(23))); |
| 101 |
RUN_TEST(failed, simple_type_test(annotation_key(42))); |
| 102 |
RUN_TEST(failed, simple_type_test(message_id(42))); |
| 103 |
|
| 104 |
// Make sure we reject uncodable types |
| 105 |
RUN_TEST(failed, (uncodable_type_test<std::pair<int, float> >())); |
| 106 |
RUN_TEST(failed, (uncodable_type_test<std::pair<scalar, value> >())); |
| 107 |
RUN_TEST(failed, (uncodable_type_test<std::basic_string<wchar_t> >())); |
| 108 |
RUN_TEST(failed, (uncodable_type_test<internal::data>())); |
| 109 |
RUN_TEST(failed, (uncodable_type_test<pn_data_t*>())); |
| 110 |
|
| 111 |
return failed; |
| 112 |
} |
| 113 |
|