format_test_wstring.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // ------------------------------------------------------------------------------
  2. // format_test_wstring.cpp : test wchar_t format use (if supported)
  3. // ------------------------------------------------------------------------------
  4. // Copyright Samuel Krempp 2003. Use, modification, and distribution are
  5. // subject to the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // See http://www.boost.org/libs/format for library home page
  8. // ------------------------------------------------------------------------------
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/format.hpp>
  11. int main(int, char* [])
  12. {
  13. using boost::format;
  14. using boost::str;
  15. #if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF)
  16. using boost::wformat;
  17. wformat wfmter(L"%%##%%##%%1 %1%00");
  18. if(str( wfmter % L"Escaped OK" ) != L"%##%##%1 Escaped OK00")
  19. BOOST_ERROR("Basic w-parsing Failed");
  20. if(str( wformat(L"%%##%#x ##%%1 %s00") % 20 % L"Escaped OK" ) != L"%##0x14 ##%1 Escaped OK00")
  21. BOOST_ERROR("Basic wp-parsing Failed") ;
  22. // testcase for https://svn.boost.org/trac10/ticket/7379 (for valgrind)
  23. wformat wfmt(L"%1$.1f");
  24. std::wstring ws = str(wfmt % 123.45f);
  25. BOOST_TEST_EQ(ws.compare(L"123.4"), 0);
  26. wformat wfmt2(L"%1$.0f %%");
  27. std::wstring ws2 = (wfmt2 % 123.45f).str();
  28. BOOST_TEST_EQ(ws2.compare(L"123 %"), 0);
  29. #endif // wformat tests
  30. return boost::report_errors();
  31. }