|
| 1 | +// |
| 2 | +// Copyright (c) 2026 Vladislav Soulgard (vsoulgard at gmail dot com) |
| 3 | +// |
| 4 | +// Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | +// |
| 7 | + |
| 8 | +#include <boost/mysql/column_type.hpp> |
| 9 | + |
| 10 | +#include <boost/test/unit_test.hpp> |
| 11 | + |
| 12 | +#include <string> |
| 13 | +#include <sstream> |
| 14 | +#include <iostream> |
| 15 | + |
| 16 | +using namespace boost::mysql; |
| 17 | + |
| 18 | +BOOST_AUTO_TEST_SUITE(test_column_type) |
| 19 | + |
| 20 | +std::string to_string(column_type t) |
| 21 | +{ |
| 22 | + std::ostringstream oss; |
| 23 | + auto& result = oss << t; |
| 24 | + BOOST_TEST(!oss.fail()); |
| 25 | + // Check if operator<< return same stream object |
| 26 | + BOOST_TEST(&result == &oss); |
| 27 | + return oss.str(); |
| 28 | +} |
| 29 | + |
| 30 | +BOOST_AUTO_TEST_CASE(stream_operator_basic) |
| 31 | +{ |
| 32 | + // Numeric types |
| 33 | + BOOST_TEST(to_string(column_type::tinyint) == "tinyint"); |
| 34 | + BOOST_TEST(to_string(column_type::smallint) == "smallint"); |
| 35 | + BOOST_TEST(to_string(column_type::mediumint) == "mediumint"); |
| 36 | + BOOST_TEST(to_string(column_type::int_) == "int_"); |
| 37 | + BOOST_TEST(to_string(column_type::bigint) == "bigint"); |
| 38 | + |
| 39 | + // Floating-point types |
| 40 | + BOOST_TEST(to_string(column_type::float_) == "float_"); |
| 41 | + BOOST_TEST(to_string(column_type::double_) == "double_"); |
| 42 | + BOOST_TEST(to_string(column_type::decimal) == "decimal"); |
| 43 | + |
| 44 | + // Special types |
| 45 | + BOOST_TEST(to_string(column_type::bit) == "bit"); |
| 46 | + BOOST_TEST(to_string(column_type::year) == "year"); |
| 47 | + |
| 48 | + // Date/time types |
| 49 | + BOOST_TEST(to_string(column_type::time) == "time"); |
| 50 | + BOOST_TEST(to_string(column_type::date) == "date"); |
| 51 | + BOOST_TEST(to_string(column_type::datetime) == "datetime"); |
| 52 | + BOOST_TEST(to_string(column_type::timestamp) == "timestamp"); |
| 53 | + |
| 54 | + // String types |
| 55 | + BOOST_TEST(to_string(column_type::char_) == "char_"); |
| 56 | + BOOST_TEST(to_string(column_type::varchar) == "varchar"); |
| 57 | + BOOST_TEST(to_string(column_type::binary) == "binary"); |
| 58 | + BOOST_TEST(to_string(column_type::varbinary) == "varbinary"); |
| 59 | + |
| 60 | + // Large object types |
| 61 | + BOOST_TEST(to_string(column_type::text) == "text"); |
| 62 | + BOOST_TEST(to_string(column_type::blob) == "blob"); |
| 63 | + |
| 64 | + // Special MySQL types |
| 65 | + BOOST_TEST(to_string(column_type::enum_) == "enum_"); |
| 66 | + BOOST_TEST(to_string(column_type::set) == "set"); |
| 67 | + BOOST_TEST(to_string(column_type::json) == "json"); |
| 68 | + BOOST_TEST(to_string(column_type::geometry) == "geometry"); |
| 69 | +} |
| 70 | + |
| 71 | +BOOST_AUTO_TEST_CASE(stream_operator_unknown) |
| 72 | +{ |
| 73 | + // Unknown type |
| 74 | + BOOST_TEST(to_string(column_type::unknown) == "<unknown column type>"); |
| 75 | + |
| 76 | + // Incorrect value |
| 77 | + BOOST_TEST(to_string(static_cast<column_type>(999)) == "<unknown column type>"); |
| 78 | +} |
| 79 | + |
| 80 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments