summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/format/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/format/test')
-rw-r--r--src/boost/libs/format/test/Jamfile.v220
-rw-r--r--src/boost/libs/format/test/format_test1.cpp42
-rw-r--r--src/boost/libs/format/test/format_test2.cpp212
-rw-r--r--src/boost/libs/format/test/format_test3.cpp130
-rw-r--r--src/boost/libs/format/test/format_test_enum.cpp43
-rw-r--r--src/boost/libs/format/test/format_test_exceptions.cpp105
-rw-r--r--src/boost/libs/format/test/format_test_wstring.cpp40
7 files changed, 592 insertions, 0 deletions
diff --git a/src/boost/libs/format/test/Jamfile.v2 b/src/boost/libs/format/test/Jamfile.v2
new file mode 100644
index 000000000..f77f97c85
--- /dev/null
+++ b/src/boost/libs/format/test/Jamfile.v2
@@ -0,0 +1,20 @@
+# Boost.Format Library test Jamfile
+#
+# Copyright (c) 2003 Samuel Krempp
+#
+# Distributed under the Boost Software License, Version 1.0. (See accompany-
+# ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+import testing ;
+
+test-suite "format"
+ : [ run format_test1.cpp ]
+ [ run format_test1.cpp : : : <toolset>msvc:<cxxflags>"/FIWindows.h" : format_test1_windows_h ]
+ [ run format_test2.cpp ]
+ [ run format_test2.cpp : : : <toolset>msvc:<cxxflags>"/FIWindows.h" : format_test2_windows_h ]
+ [ run format_test3.cpp ]
+ [ run format_test3.cpp : : : <toolset>msvc:<cxxflags>"/FIWindows.h" : format_test3_windows_h ]
+ [ run format_test_enum.cpp : : : <toolset>clang:<cxxflags>-Wno-unnamed-type-template-args ]
+ [ run format_test_exceptions.cpp ]
+ [ run format_test_wstring.cpp ]
+ ; \ No newline at end of file
diff --git a/src/boost/libs/format/test/format_test1.cpp b/src/boost/libs/format/test/format_test1.cpp
new file mode 100644
index 000000000..d259d2332
--- /dev/null
+++ b/src/boost/libs/format/test/format_test1.cpp
@@ -0,0 +1,42 @@
+// ------------------------------------------------------------------------------
+// libs/format/test/format_test1.cpp : test constructing objects and basic parsing
+// ------------------------------------------------------------------------------
+
+// Copyright Samuel Krempp 2003. Use, modification, and distribution are
+// subject to the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+
+int main(int, char* [])
+{
+ using boost::format;
+ using boost::str;
+
+ if(str( format(" %% ") ) != " % ")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format("nothing") ) != "nothing")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format("%% ") ) != "% ")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format(" %%") ) != " %")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format(" %n ") ) != " ")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format("%n ") ) != " ")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+ if(str( format(" %n") ) != " ")
+ BOOST_ERROR("Basic parsing without arguments Failed");
+
+ if(str( format("%%##%%##%%1 %1%00") % "Escaped OK" ) != "%##%##%1 Escaped OK00")
+ BOOST_ERROR("Basic parsing Failed");
+ if(str( format("%%##%#x ##%%1 %s00") % 20 % "Escaped OK" ) != "%##0x14 ##%1 Escaped OK00")
+ BOOST_ERROR("Basic p-parsing Failed") ;
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/format/test/format_test2.cpp b/src/boost/libs/format/test/format_test2.cpp
new file mode 100644
index 000000000..9fb061011
--- /dev/null
+++ b/src/boost/libs/format/test/format_test2.cpp
@@ -0,0 +1,212 @@
+// ------------------------------------------------------------------------------
+// format_test2.cpp : a few real, simple tests.
+// ------------------------------------------------------------------------------
+
+// Copyright Samuel Krempp 2003. Use, modification, and distribution are
+// subject to the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// see http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/algorithm/string.hpp>
+#include <boost/config.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+#include <boost/predef.h>
+
+#include <iostream>
+#include <iomanip>
+
+#if !defined(BOOST_NO_STD_LOCALE)
+#include <locale>
+#endif
+
+struct Rational {
+ int n,d;
+ Rational (int an, int ad) : n(an), d(ad) {}
+};
+
+std::ostream& operator<<( std::ostream& os, const Rational& r) {
+ os << r.n << "/" << r.d;
+ return os;
+}
+
+#if !defined(BOOST_NO_STD_LOCALE)
+// in C++03 this has to be globally defined or gcc complains
+struct custom_tf : std::numpunct<char> {
+ std::string do_truename() const { return "POSITIVE"; }
+ std::string do_falsename() const { return "NEGATIVE"; }
+};
+#endif
+
+int main(int, char* [])
+{
+ using namespace std;
+ using boost::format;
+ using boost::io::group;
+ using boost::str;
+
+ Rational r(16,9);
+ const Rational cr(9,16);
+
+ string s;
+ s = str(format("%5%. %5$=6s . %1% format %5%, c'%3% %1% %2%.\n")
+ % "le" % "bonheur" % "est" % "trop" % group(setfill('_'), "bref") );
+
+ if(s != "bref. _bref_ . le format bref, c'est le bonheur.\n") {
+ cerr << s;
+ BOOST_ERROR("centered alignement : formatting result incorrect");
+ }
+
+
+ s = str(format("%+8d %-8d\n") % r % cr );
+ if(s != " +16/+9 9/16 \n") {
+ cerr << s;
+ BOOST_ERROR("(user-type) formatting result incorrect");
+ }
+
+ s = str(format("[%0+4d %0+8d %-08d]\n") % 8 % r % r);
+ if(s != "[+008 +0016/+9 16/9 ]\n") {
+ cerr << s;
+ BOOST_ERROR("(zero-padded user-type) formatting result incorrect");
+ }
+
+
+ s = str( format("%1%, %20T_ (%|2$5|,%|3$5|)\n") % "98765" % 1326 % 88 ) ;
+ if( s != "98765, _____________ ( 1326, 88)\n" )
+ BOOST_ERROR("(tabulation) formatting result incorrect");
+ s = str( format("%s, %|20t|=") % 88 ) ;
+ if( s != "88, =" ) {
+ cout << s << endl;
+ BOOST_ERROR("(tabulation) formatting result incorrect");
+ }
+
+
+ s = str(format("%.2s %8c.\n") % "root" % "user" );
+ if(s != "ro u.\n") {
+ cerr << s;
+ BOOST_ERROR("(truncation) formatting result incorrect");
+ }
+
+ // width in format-string is overridden by setw manipulator :
+ s = str( format("%|1$4| %|1$|") % group(setfill('0'), setw(6), 1) );
+ if( s!= "000001 000001")
+ BOOST_ERROR("width in format VS in argument misbehaved");
+
+ s = str( format("%|=s|") % group(setfill('_'), setw(6), r) );
+ if( s!= "_16/9_") {
+ cerr << s << endl;
+ BOOST_ERROR("width in group context is not handled correctly");
+ }
+
+
+ // options that uses internal alignment : + 0 #
+ s = str( format("%+6d %0#6x %s\n") % 342 % 33 % "ok" );
+ if( s !=" +342 0x0021 ok\n")
+ BOOST_ERROR("(flags +, 0, or #) formatting result incorrect");
+
+ // flags in the format string are not sticky
+ // and hex in argument overrrides type-char d (->decimal) :
+ s = str( format("%2$#4d %|1$4| %|2$#4| %|3$|")
+ % 101
+ % group(setfill('_'), hex, 2)
+ % 103 );
+ if(s != "_0x2 101 _0x2 103")
+ BOOST_ERROR("formatting error. (not-restoring state ?)");
+
+
+
+ // flag '0' is tricky .
+ // left-align cancels '0':
+ s = str( format("%2$0#12X %2$0#-12d %1$0#10d \n") % -20 % 10 );
+ if( s != "0X000000000A 10 -000000020 \n"){
+ cerr << s;
+ BOOST_ERROR("formatting error. (flag 0)");
+ }
+
+ // actually testing floating point output is implementation
+ // specific so we're just going to do minimal checking...
+ double dbl = 1234567.890123f;
+
+#if (__cplusplus >= 201103L) || (BOOST_VERSION_NUMBER_MAJOR(BOOST_COMP_MSVC) >= 12)
+ // msvc-12.0 and later have support for hexfloat but do not set __cplusplus to a C++11 value
+ BOOST_TEST(boost::starts_with((boost::format("%A") % dbl).str(), "0X"));
+ BOOST_TEST(boost::starts_with((boost::format("%a") % dbl).str(), "0x"));
+#endif
+
+ BOOST_TEST(boost::contains((boost::format("%E") % dbl).str(), "E"));
+ BOOST_TEST(boost::contains((boost::format("%e") % dbl).str(), "e"));
+ BOOST_TEST(boost::contains((boost::format("%F") % dbl).str(), "."));
+ BOOST_TEST(boost::contains((boost::format("%f") % dbl).str(), "."));
+ BOOST_TEST(!(boost::format("%G") % dbl).str().empty());
+ BOOST_TEST(!(boost::format("%g") % dbl).str().empty());
+
+ // testing argument type parsing - remember argument types are ignored
+ // because operator % presents the argument type.
+ unsigned int value = 456;
+ BOOST_TEST_EQ((boost::format("%hhu") % value).str(), "456");
+ BOOST_TEST_EQ((boost::format("%hu") % value).str(), "456");
+ BOOST_TEST_EQ((boost::format("%lu") % value).str(), "456");
+ BOOST_TEST_EQ((boost::format("%llu") % value).str(), "456");
+ BOOST_TEST_EQ((boost::format("%ju") % value).str(), "456");
+ BOOST_TEST_EQ((boost::format("%zu") % value).str(), "456");
+ BOOST_TEST(boost::starts_with((boost::format("%Lf") % value).str(), "456"));
+
+#if !defined(BOOST_NO_STD_LOCALE)
+ // boolalpha support
+ std::locale loc;
+ const std::numpunct<char>& punk(std::use_facet<std::numpunct<char> >(loc));
+
+ // Demonstrates how to modify the default string to something else
+ std::locale custom(std::locale(), new custom_tf);
+ boost::ignore_unused(locale::global(custom));
+ BOOST_TEST_EQ((boost::format("%b") % false).str(), "NEGATIVE");
+ BOOST_TEST_EQ((boost::format("%b") % true).str(), "POSITIVE");
+
+ // restore system default
+ locale::global(loc);
+ BOOST_TEST_EQ((boost::format("%b") % false).str(), punk.falsename());
+ BOOST_TEST_EQ((boost::format("%b") % true).str(), punk.truename());
+#endif
+
+ // Support for microsoft argument type specifiers: 'w' (same as 'l'), I, I32, I64
+ BOOST_TEST_EQ((boost::format("%wc") % '5').str(), "5");
+ BOOST_TEST_EQ((boost::format("%Id") % 123).str(), "123");
+ BOOST_TEST_EQ((boost::format("%I32d") % 456).str(), "456");
+ BOOST_TEST_EQ((boost::format("%I64d") % 789).str(), "789");
+
+ // issue-36 volatile (and const) keyword
+ volatile int vint = 1234567;
+ BOOST_TEST_EQ((boost::format("%1%") % vint).str(), "1234567");
+ volatile const int vcint = 7654321;
+ BOOST_TEST_EQ((boost::format("%1%") % vcint).str(), "7654321");
+
+ // skip width if '*'
+ BOOST_TEST_EQ((boost::format("%*d") % vint).str(), "1234567");
+
+ // internal ios flag
+ BOOST_TEST_EQ((boost::format("%_6d") % -77).str(), "- 77");
+
+ // combining some flags
+ BOOST_TEST_EQ((boost::format("%+05.5d" ) % 77).str(), "+0077");
+ BOOST_TEST_EQ((boost::format("%+ 5.5d" ) % 77).str(), " +77");
+ BOOST_TEST_EQ((boost::format("%+_ 5.5d" ) % 77).str(), "+ 77");
+ BOOST_TEST_EQ((boost::format("%+- 5.5d" ) % 77).str(), "+77 ");
+ BOOST_TEST_EQ((boost::format("%+05.5d" ) % -77).str(), "-0077");
+ BOOST_TEST_EQ((boost::format("%+ 5.5d" ) % -77).str(), " -77");
+ BOOST_TEST_EQ((boost::format("%+_ 5.5d" ) % -77).str(), "- 77");
+ BOOST_TEST_EQ((boost::format("%+- 5.5d" ) % -77).str(), "-77 ");
+
+ // reuse state and reset format flags
+ std::string mystr("abcdefghijklmnop");
+ BOOST_TEST_EQ((boost::format("%2.2s %-4.4s % 8.8s")
+ % mystr % mystr % mystr).str(), "ab abcd abcdefg");
+
+ // coverage, operator =
+ format fmt("%1%%2%%3%");
+ fmt = fmt;
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/format/test/format_test3.cpp b/src/boost/libs/format/test/format_test3.cpp
new file mode 100644
index 000000000..fa8c17e21
--- /dev/null
+++ b/src/boost/libs/format/test/format_test3.cpp
@@ -0,0 +1,130 @@
+// ------------------------------------------------------------------------------
+// format_test3.cpp : complicated format strings and / or advanced uses
+// ------------------------------------------------------------------------------
+
+// Copyright Samuel Krempp 2003. Use, modification, and distribution are
+// subject to the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// see http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+#include <iostream>
+#include <iomanip>
+
+struct Rational {
+ int n,d;
+ Rational (int an, int ad) : n(an), d(ad) {}
+};
+
+std::ostream& operator<<( std::ostream& os, const Rational& r) {
+ os << r.n << "/" << r.d;
+ return os;
+}
+
+int main(int, char* [])
+{
+ using namespace std;
+ using boost::format;
+ using boost::io::group;
+ using boost::str;
+
+ string s, s2;
+ // special paddings
+ s = str( format("[%=6s] [%+6s] [%+6s] [% 6s] [%+6s]\n")
+ % 123
+ % group(internal, setfill('W'), 234)
+ % group(internal, setfill('X'), -345)
+ % group(setfill('Y'), 456)
+ % group(setfill('Z'), -10 ) );
+
+ if(s != "[ 123 ] [+WW234] [-XX345] [YY 456] [ZZZ-10]\n" ) {
+ cerr << s ;
+ BOOST_ERROR("formatting error. (with special paddings)");
+ }
+
+ s = str( format("[% 6.8s] [% 8.6s] [% 7.7s]\n")
+ % group(internal, setfill('x'), Rational(12345,54321))
+ % group(internal, setfill('x'), Rational(123,45))
+ % group(internal, setfill('x'), Rational(123,321))
+ );
+ if(s != (s2="[ 12345/5] [ xx123/4] [ 123/32]\n" )) {
+ cerr << s << s2;
+ BOOST_ERROR("formatting error. (with special paddings)");
+ }
+
+ s = str( format("[% 6.8s] [% 6.8s] [% 6.8s] [% 6.8s] [%6.8s]\n")
+ % 1234567897
+ % group(setfill('x'), 12)
+ % group(internal, setfill('x'), 12)
+ % group(internal, setfill('x'), 1234567890)
+ % group(internal, setfill('x'), 123456)
+ );
+ if(s != (s2="[ 1234567] [xxx 12] [ xxx12] [ 1234567] [123456]\n") ) {
+ cerr << s << s2;
+ BOOST_ERROR("formatting error. (with special paddings)");
+ }
+
+ s = str( format("[% 8.6s] [% 6.4s] [% 6.4s] [% 8.6s] [% 8.6s]\n")
+ % 1234567897
+ % group(setfill('x'), 12)
+ % group(internal, setfill('x'), 12)
+ % group(internal, setfill('x'), 1234567890)
+ % group(internal, setfill('x'), 12345)
+ );
+ if(s != (s2="[ 12345] [xxx 12] [ xxx12] [ xx12345] [ xx12345]\n") ) {
+ cerr << s << s2;
+ BOOST_ERROR("formatting error. (with special paddings)");
+ }
+
+ // nesting formats :
+ s = str( format("%2$014x [%1%] %|2$05|\n") % (format("%05s / %s") % -18 % 7)
+ %group(showbase, -100)
+ );
+ if( s != "0x0000ffffff9c [-0018 / 7] -0100\n" ){
+ cerr << s ;
+ BOOST_ERROR("nesting did not work");
+ }
+
+ // bind args, and various arguments counts :
+ {
+ boost::format bf("%1% %4% %1%");
+ bf.bind_arg(1, "one") % 2 % "three" ;
+ BOOST_TEST_EQ(bf.expected_args(), 4);
+ BOOST_TEST_EQ(bf.fed_args(), 2);
+ BOOST_TEST_EQ(bf.bound_args(), 1);
+ BOOST_TEST_EQ(bf.remaining_args(), 1);
+ BOOST_TEST_EQ(bf.cur_arg(), 4);
+ bf.clear_binds();
+ bf % "one" % 2 % "three" ;
+ BOOST_TEST_EQ(bf.expected_args(), 4);
+ BOOST_TEST_EQ(bf.fed_args(), 3);
+ BOOST_TEST_EQ(bf.bound_args(), 0);
+ BOOST_TEST_EQ(bf.remaining_args(), 1);
+ BOOST_TEST_EQ(bf.cur_arg(), 4);
+ }
+ // testcase for bug reported at
+ // http://lists.boost.org/boost-users/2006/05/19723.php
+ {
+ format f("%40t%1%");
+ int x = 0;
+ f.bind_arg(1, x);
+ f.clear();
+ }
+
+ // testcase for bug reported at
+ // http://lists.boost.org/boost-users/2005/11/15454.php
+ std::string l_param;
+ std::string l_str = (boost::format("here is an empty string: %1%") % l_param).str();
+ BOOST_TEST_EQ(std::string("here is an empty string: "), l_str);
+
+ // testcase for SourceForge bug #1506914
+ std::string arg; // empty string
+ s = str(format("%=8s") % arg);
+ BOOST_TEST_EQ(std::string(" "), s);
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/format/test/format_test_enum.cpp b/src/boost/libs/format/test/format_test_enum.cpp
new file mode 100644
index 000000000..ac4a4e8ed
--- /dev/null
+++ b/src/boost/libs/format/test/format_test_enum.cpp
@@ -0,0 +1,43 @@
+// ------------------------------------------------------------------------------
+// format_test_enum.cpp : test format use with enums
+// ------------------------------------------------------------------------------
+
+// Copyright Steven Watanabe 2009.
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+
+enum enum_plain { PLAIN };
+enum { ANONYMOUS };
+enum enum_overloaded { OVERLOADED };
+typedef enum { OVERLOADED_TYPEDEF } enum_overloaded_typedef;
+
+std::ostream& operator<<(std::ostream& os, enum_overloaded) {
+ os << "overloaded";
+ return(os);
+}
+
+std::ostream& operator<<(std::ostream& os, enum_overloaded_typedef) {
+ os << "overloaded";
+ return(os);
+}
+
+int main(int, char*[]) {
+ // in this case, we should implicitly convert to int
+ BOOST_TEST_EQ((boost::format("%d") % PLAIN).str(), "0");
+ BOOST_TEST_EQ((boost::format("%d") % ANONYMOUS).str(), "0");
+
+ // but here we need to use the overloaded operator
+ BOOST_TEST_EQ((boost::format("%s") % OVERLOADED).str(), "overloaded");
+ BOOST_TEST_EQ((boost::format("%s") % OVERLOADED_TYPEDEF).str(), "overloaded");
+
+ return boost::report_errors();
+}
diff --git a/src/boost/libs/format/test/format_test_exceptions.cpp b/src/boost/libs/format/test/format_test_exceptions.cpp
new file mode 100644
index 000000000..4ef579ab6
--- /dev/null
+++ b/src/boost/libs/format/test/format_test_exceptions.cpp
@@ -0,0 +1,105 @@
+// ------------------------------------------------------------------------------
+// format_test_exceptions.cpp : exception handling
+// ------------------------------------------------------------------------------
+
+// Copyright 2017 James E. King, III - Use, modification, and distribution are
+// subject to the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// see http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/algorithm/string.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+#include <iomanip>
+#include <iostream>
+
+#define CHECK_INVALID_0(FMT, EX) { BOOST_TEST_THROWS((boost::format(FMT)).str(), EX); \
+ boost::format safe; safe.exceptions(boost::io::no_error_bits); safe.parse(FMT); (safe).str(); }
+#define CHECK_INVALID_1(FMT, _1, EX) { BOOST_TEST_THROWS((boost::format(FMT) % _1).str(), EX); \
+ boost::format safe; safe.exceptions(boost::io::no_error_bits); safe.parse(FMT); (safe % _1).str(); }
+#define CHECK_INVALID_2(FMT, _1, _2, EX) { BOOST_TEST_THROWS((boost::format(FMT) % _1 % _2).str(), EX); \
+ boost::format safe; safe.exceptions(boost::io::no_error_bits); safe.parse(FMT); (safe % _1 % _2).str(); }
+
+int main(int, char* [])
+{
+ using namespace boost::io;
+
+ // https://svn.boost.org/trac10/ticket/8735
+
+ CHECK_INVALID_0("%", bad_format_string); // no conversion specifier
+ CHECK_INVALID_0("%|", bad_format_string); // truncated
+ CHECK_INVALID_0("%|%", bad_format_string); // mismatched bars
+ CHECK_INVALID_0("%|2%", bad_format_string); // mismatched bars
+ CHECK_INVALID_0("%'", bad_format_string); // flag ' is ignored, no conversion specifier
+ CHECK_INVALID_0("%2", bad_format_string); // no terminating percent
+ CHECK_INVALID_0("%*", bad_format_string); // truncated
+ CHECK_INVALID_1("%$2", 1, bad_format_string); // no conversion specifier
+ CHECK_INVALID_1("%$2.*", 1, bad_format_string); // no conversion specifier
+ CHECK_INVALID_0("%0%", bad_format_string); // positional arguments start at 1
+ CHECK_INVALID_2("%1%", 1, 2, too_many_args);
+ CHECK_INVALID_1("%1% %2%", 1, too_few_args);
+
+ CHECK_INVALID_0("%I", bad_format_string);
+ CHECK_INVALID_0("%I2", bad_format_string);
+ CHECK_INVALID_0("%I2d", bad_format_string);
+ CHECK_INVALID_0("%I3", bad_format_string);
+ CHECK_INVALID_0("%I3d", bad_format_string);
+ CHECK_INVALID_0("%I32", bad_format_string);
+ CHECK_INVALID_0("%I33", bad_format_string);
+ CHECK_INVALID_0("%I6", bad_format_string);
+ CHECK_INVALID_0("%I62", bad_format_string);
+ CHECK_INVALID_0("%I63", bad_format_string);
+ CHECK_INVALID_0("%I63d", bad_format_string);
+ CHECK_INVALID_0("%I64", bad_format_string);
+ CHECK_INVALID_0("%I128d", bad_format_string);
+ CHECK_INVALID_0("%3.*4d", bad_format_string);
+
+ // mixing positional and non-positional
+ CHECK_INVALID_2("%1% %2d", 1, 2, bad_format_string);
+ CHECK_INVALID_2("%2d %2%", 1, 2, bad_format_string);
+
+ // found while improving coverage - a number following the * for width
+ // or precision was being eaten instead of being treated as an error
+ CHECK_INVALID_0("%1$*4d", bad_format_string);
+ CHECK_INVALID_0("%1$05.*32d", bad_format_string);
+ CHECK_INVALID_0("%1$05.*6", bad_format_string);
+
+ // found while improving coverage, this caused an unhandled exception
+ // the "T" conversion specifier didn't handle the exception flags properly
+ CHECK_INVALID_0("%1$T", bad_format_string); // missing fill character
+
+ // test what() on exceptions
+ format_error base_err;
+ BOOST_TEST_GT(strlen(base_err.what()), 0u);
+
+ bad_format_string bfs(2, 3);
+ BOOST_TEST(boost::contains(bfs.what(), "bad_format_string"));
+
+ too_few_args tfa(5, 4);
+ BOOST_TEST(boost::contains(tfa.what(), "format-string"));
+
+ too_many_args tma(4, 5);
+ BOOST_TEST(boost::contains(tma.what(), "format-string"));
+
+ boost::io::out_of_range oor(1, 2, 3);
+ BOOST_TEST(boost::contains(oor.what(), "out_of_range"));
+
+ // bind and unbind
+ boost::format two("%1%, %2%");
+ two.bind_arg(1, 1);
+ two.bind_arg(2, 2);
+ BOOST_TEST_EQ(two.str(), "1, 2");
+
+ two.clear_bind(1);
+ BOOST_TEST_THROWS(two.str(), too_few_args);
+ BOOST_TEST_THROWS(two.clear_bind(1), boost::io::out_of_range);
+ two.exceptions(no_error_bits);
+ two.clear_bind(1);
+ two.str();
+
+ return boost::report_errors();
+}
+
diff --git a/src/boost/libs/format/test/format_test_wstring.cpp b/src/boost/libs/format/test/format_test_wstring.cpp
new file mode 100644
index 000000000..2d224724f
--- /dev/null
+++ b/src/boost/libs/format/test/format_test_wstring.cpp
@@ -0,0 +1,40 @@
+// ------------------------------------------------------------------------------
+// format_test_wstring.cpp : test wchar_t format use (if supported)
+// ------------------------------------------------------------------------------
+
+// Copyright Samuel Krempp 2003. Use, modification, and distribution are
+// subject to the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/format for library home page
+
+// ------------------------------------------------------------------------------
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/format.hpp>
+
+int main(int, char* [])
+{
+ using boost::format;
+ using boost::str;
+
+#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF)
+ using boost::wformat;
+ wformat wfmter(L"%%##%%##%%1 %1%00");
+ if(str( wfmter % L"Escaped OK" ) != L"%##%##%1 Escaped OK00")
+ BOOST_ERROR("Basic w-parsing Failed");
+ if(str( wformat(L"%%##%#x ##%%1 %s00") % 20 % L"Escaped OK" ) != L"%##0x14 ##%1 Escaped OK00")
+ BOOST_ERROR("Basic wp-parsing Failed") ;
+
+ // testcase for https://svn.boost.org/trac10/ticket/7379 (for valgrind)
+ wformat wfmt(L"%1$.1f");
+ std::wstring ws = str(wfmt % 123.45f);
+ BOOST_TEST_EQ(ws.compare(L"123.4"), 0);
+ wformat wfmt2(L"%1$.0f %%");
+ std::wstring ws2 = (wfmt2 % 123.45f).str();
+ BOOST_TEST_EQ(ws2.compare(L"123 %"), 0);
+
+#endif // wformat tests
+
+ return boost::report_errors();
+}