diff options
Diffstat (limited to 'libcxx/test/std/input.output/iostream.format/ext.manip')
4 files changed, 323 insertions, 0 deletions
diff --git a/libcxx/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp b/libcxx/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp new file mode 100644 index 00000000000..1ea1d780c50 --- /dev/null +++ b/libcxx/test/std/input.output/iostream.format/ext.manip/get_money.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class moneyT> T7 get_money(moneyT& mon, bool intl = false); + +// REQUIRES: locale.en_US.UTF-8 + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } +}; + +int main() +{ + { + testbuf<char> sb(" -$1,234,567.89"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, false); + assert(x == -123456789); + } + { + testbuf<char> sb(" -USD 1,234,567.89"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, true); + assert(x == -123456789); + } + { + testbuf<wchar_t> sb(L" -$1,234,567.89"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, false); + assert(x == -123456789); + } + { + testbuf<wchar_t> sb(L" -USD 1,234,567.89"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + long double x = 0; + is >> std::get_money(x, true); + assert(x == -123456789); + } +} diff --git a/libcxx/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp b/libcxx/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp new file mode 100644 index 00000000000..17ff642dc46 --- /dev/null +++ b/libcxx/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt); + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +struct testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_string<CharT> string_type; + typedef std::basic_streambuf<CharT> base; +private: + string_type str_; +public: + + testbuf() {} + testbuf(const string_type& str) + : str_(str) + { + base::setg(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data()) + str_.size()); + } +}; + +int main() +{ + { + testbuf<char> sb(" Sat Dec 31 23:55:59 2061"); + std::istream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + is >> std::get_time(&t, "%a %b %d %H:%M:%S %Y"); + assert(t.tm_sec == 59); + assert(t.tm_min == 55); + assert(t.tm_hour == 23); + assert(t.tm_mday == 31); + assert(t.tm_mon == 11); + assert(t.tm_year == 161); + assert(t.tm_wday == 6); + assert(is.eof()); + assert(!is.fail()); + } + { + testbuf<wchar_t> sb(L" Sat Dec 31 23:55:59 2061"); + std::wistream is(&sb); + is.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + is >> std::get_time(&t, L"%a %b %d %H:%M:%S %Y"); + assert(t.tm_sec == 59); + assert(t.tm_min == 55); + assert(t.tm_hour == 23); + assert(t.tm_mday == 31); + assert(t.tm_mon == 11); + assert(t.tm_year == 161); + assert(t.tm_wday == 6); + assert(is.eof()); + assert(!is.fail()); + } +} diff --git a/libcxx/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp b/libcxx/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp new file mode 100644 index 00000000000..a00cf139be9 --- /dev/null +++ b/libcxx/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false); + +// REQUIRES: locale.en_US.UTF-8 + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, false); + assert(sb.str() == "-$1,234,567.89"); + } + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, true); + assert(sb.str() == "-USD 1,234,567.89"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, false); + assert(sb.str() == L"-$1,234,567.89"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + showbase(os); + long double x = -123456789; + os << std::put_money(x, true); + assert(sb.str() == L"-USD 1,234,567.89"); + } +} diff --git a/libcxx/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp b/libcxx/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp new file mode 100644 index 00000000000..52a98a1b568 --- /dev/null +++ b/libcxx/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <iomanip> + +// template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt); + +#include <iomanip> +#include <cassert> + +#include "platform_support.h" // locale name macros + +template <class CharT> +class testbuf + : public std::basic_streambuf<CharT> +{ + typedef std::basic_streambuf<CharT> base; + std::basic_string<CharT> str_; +public: + testbuf() + { + } + + std::basic_string<CharT> str() const + {return std::basic_string<CharT>(base::pbase(), base::pptr());} + +protected: + + virtual typename base::int_type + overflow(typename base::int_type __c = base::traits_type::eof()) + { + if (__c != base::traits_type::eof()) + { + int n = str_.size(); + str_.push_back(__c); + str_.resize(str_.capacity()); + base::setp(const_cast<CharT*>(str_.data()), + const_cast<CharT*>(str_.data() + str_.size())); + base::pbump(n+1); + } + return __c; + } +}; + +int main() +{ + { + testbuf<char> sb; + std::ostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + t.tm_sec = 59; + t.tm_min = 55; + t.tm_hour = 23; + t.tm_mday = 31; + t.tm_mon = 11; + t.tm_year = 161; + t.tm_wday = 6; + t.tm_isdst = 0; + os << std::put_time(&t, "%a %b %d %H:%M:%S %Y"); + assert(sb.str() == "Sat Dec 31 23:55:59 2061"); + } + { + testbuf<wchar_t> sb; + std::wostream os(&sb); + os.imbue(std::locale(LOCALE_en_US_UTF_8)); + std::tm t = {0}; + t.tm_sec = 59; + t.tm_min = 55; + t.tm_hour = 23; + t.tm_mday = 31; + t.tm_mon = 11; + t.tm_year = 161; + t.tm_wday = 6; + os << std::put_time(&t, L"%a %b %d %H:%M:%S %Y"); + assert(sb.str() == L"Sat Dec 31 23:55:59 2061"); + } +} |