Skip to content

Commit 4558bb4

Browse files
authored
Added unit tests for column_type (#503)
close #165
1 parent 5d9ff8f commit 4558bb4

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

test/unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ add_executable(
105105
test/resultset_view.cpp
106106
test/resultset.cpp
107107
test/client_errc.cpp
108+
test/column_type.cpp
108109
test/common_server_errc.cpp
109110
test/mysql_server_errc.cpp
110111
test/mariadb_server_errc.cpp

test/unit/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ run
114114
test/resultset_view.cpp
115115
test/resultset.cpp
116116
test/client_errc.cpp
117+
test/column_type.cpp
117118
test/common_server_errc.cpp
118119
test/mysql_server_errc.cpp
119120
test/mariadb_server_errc.cpp

test/unit/test/column_type.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

Comments
 (0)