Sven Roederer | 4f5bfd8 | 2024-07-17 15:27:24 +0200 | [diff] [blame^] | 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 <boost/test/unit_test.hpp> |
| 21 | #include <iostream> |
| 22 | #include <sstream> |
| 23 | #include "gen-cpp/Thrift5272_types.h" |
| 24 | |
| 25 | BOOST_AUTO_TEST_SUITE(Thrift5272Test) |
| 26 | |
| 27 | namespace utf = boost::unit_test; |
| 28 | |
| 29 | // Define this env var to enable some logging (in case you need to debug) |
| 30 | #undef ENABLE_STDERR_LOGGING |
| 31 | |
| 32 | using namespace thrift5272; |
| 33 | |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE( printTo ) |
| 36 | { |
| 37 | std::stringstream ss; |
| 38 | std::string text; |
| 39 | Meta a = Meta(); |
| 40 | |
| 41 | a.printTo(ss); |
| 42 | text = ss.str(); |
| 43 | BOOST_TEST(text == "Meta(byte_type=0, i8_type=0, i16_type=0, i32_type=0, i64_type=0)"); |
| 44 | |
| 45 | ss.clear(); |
| 46 | ss.str(""); |
| 47 | a.byte_type = 50; |
| 48 | a.i8_type = 50; |
| 49 | a.i16_type = 50; |
| 50 | a.i32_type = 50; |
| 51 | a.i64_type = 50; |
| 52 | a.printTo(ss); |
| 53 | text = ss.str(); |
| 54 | BOOST_TEST(text == "Meta(byte_type=50, i8_type=50, i16_type=50, i32_type=50, i64_type=50)"); |
| 55 | |
| 56 | ss.clear(); |
| 57 | ss.str(""); |
| 58 | a.byte_type = 127; |
| 59 | a.i8_type = 127; |
| 60 | a.i16_type = 127; |
| 61 | a.i32_type = 127; |
| 62 | a.i64_type = 127; |
| 63 | a.printTo(ss); |
| 64 | text = ss.str(); |
| 65 | BOOST_TEST(text == "Meta(byte_type=127, i8_type=127, i16_type=127, i32_type=127, i64_type=127)"); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_CASE( ostream_handle_int8_to_str ) |
| 69 | { |
| 70 | int8_t t = 65; |
| 71 | std::ostringstream o; |
| 72 | o << t; |
| 73 | BOOST_TEST(o.str() != "65", "ostingstream handles int8 correctly. let's drop specialization for Thrift5272 from TToString.h."); |
| 74 | } |
| 75 | |
| 76 | BOOST_AUTO_TEST_SUITE_END() |