1// Copyright 2021 Peter Dimov.
2// Distributed under the Boost Software License, Version 1.0.
3// http://www.boost.org/LICENSE_1_0.txt
4
5#if defined(__GNUC__) && __GNUC__ >= 7
6# pragma GCC diagnostic ignored "-Wformat-truncation"
7#endif
8
9#include <boost/system/detail/snprintf.hpp>
10#include <boost/core/lightweight_test.hpp>
11
12int main()
13{
14 {
15 char buffer[ 64 ];
16 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
17
18 BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
19 }
20
21 {
22 char buffer[ 64 ];
23 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
24
25 BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
26 }
27
28 {
29 char buffer[ 15 ];
30 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
31
32 BOOST_TEST_CSTR_EQ( buffer, "...xy...151..." );
33 }
34
35 {
36 char buffer[ 14 ];
37 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
38
39 BOOST_TEST_CSTR_EQ( buffer, "...xy...151.." );
40 }
41
42 {
43 char buffer[ 5 ];
44 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
45
46 BOOST_TEST_CSTR_EQ( buffer, "...x" );
47 }
48
49 {
50 char buffer[ 1 ];
51 boost::system::detail::snprintf( s: buffer, maxlen: sizeof(buffer), format: "...%s...%d...", "xy", 151 );
52
53 BOOST_TEST_CSTR_EQ( buffer, "" );
54 }
55
56 {
57 char buffer[ 1 ] = { 'Q' };
58 boost::system::detail::snprintf( s: buffer, maxlen: 0, format: "...%s...%d...", "xy", 151 );
59
60 BOOST_TEST_EQ( buffer[0], 'Q' );
61 }
62
63 return boost::report_errors();
64}
65

source code of boost/libs/system/test/snprintf_test.cpp