summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/localization/locales/locale.convenience/conversions
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/localization/locales/locale.convenience/conversions')
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp73
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/overflow.pass.cpp100
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp59
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/rdbuf.pass.cpp31
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/seekoff.pass.cpp58
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/state.pass.cpp28
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/test.pass.cpp36
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.dat1
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp84
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow_utf8.dat1
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/tolower.pass.cpp31
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/toupper.pass.cpp31
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp32
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt.pass.cpp38
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt_state.pass.cpp28
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp68
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp39
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/state.pass.cpp25
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp39
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/types.pass.cpp35
-rw-r--r--libcxx/test/std/localization/locales/locale.convenience/conversions/nothing_to_do.pass.cpp12
21 files changed, 849 insertions, 0 deletions
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.pass.cpp
new file mode 100644
index 00000000000..3649f157d04
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/ctor.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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// wbuffer_convert(streambuf *bytebuf = 0, Codecvt *pcvt = new Codecvt,
+// state_type state = state_type());
+
+// UNSUPPORTED: asan, msan
+
+#include <locale>
+#include <codecvt>
+#include <sstream>
+#include <cassert>
+#include <new>
+
+int new_called = 0;
+
+void* operator new(std::size_t s) throw(std::bad_alloc)
+{
+ ++new_called;
+ return std::malloc(s);
+}
+
+void operator delete(void* p) throw()
+{
+ --new_called;
+ std::free(p);
+}
+
+int main()
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
+#if _LIBCPP_STD_VER > 11
+ static_assert(!std::is_convertible<std::streambuf*, B>::value, "");
+ static_assert( std::is_constructible<B, std::streambuf*>::value, "");
+#endif
+ {
+ B b;
+ assert(b.rdbuf() == nullptr);
+ assert(new_called != 0);
+ }
+ assert(new_called == 0);
+ {
+ std::stringstream s;
+ B b(s.rdbuf());
+ assert(b.rdbuf() == s.rdbuf());
+ assert(new_called != 0);
+ }
+ assert(new_called == 0);
+ {
+ std::stringstream s;
+ B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>);
+ assert(b.rdbuf() == s.rdbuf());
+ assert(new_called != 0);
+ }
+ assert(new_called == 0);
+ {
+ std::stringstream s;
+ B b(s.rdbuf(), new std::codecvt_utf8<wchar_t>, std::mbstate_t());
+ assert(b.rdbuf() == s.rdbuf());
+ assert(new_called != 0);
+ }
+ assert(new_called == 0);
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/overflow.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/overflow.pass.cpp
new file mode 100644
index 00000000000..24706b5a8e0
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/overflow.pass.cpp
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// int_type overflow(int_type c = traits::eof());
+
+// This test is not entirely portable
+
+#include <locale>
+#include <codecvt>
+#include <fstream>
+#include <cassert>
+
+struct test_buf
+ : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
+ typedef base::char_type char_type;
+ typedef base::int_type int_type;
+ typedef base::traits_type traits_type;
+
+ explicit test_buf(std::streambuf* sb) : base(sb) {}
+
+ char_type* pbase() const {return base::pbase();}
+ char_type* pptr() const {return base::pptr();}
+ char_type* epptr() const {return base::epptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type overflow(int_type c = traits_type::eof()) {return base::overflow(c);}
+};
+
+int main()
+{
+ {
+ std::ofstream bs("overflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow(L'a') == L'a');
+ assert(f.pbase() != 0);
+ assert(f.pptr() == f.pbase());
+ assert(f.epptr() - f.pbase() == 4095);
+ }
+ {
+ std::ifstream bs("overflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sgetc() == L'a');
+ }
+ std::remove("overflow.dat");
+ {
+ std::ofstream bs("overflow.dat");
+ test_buf f(bs.rdbuf());
+ f.pubsetbuf(0, 0);
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ assert(f.overflow('a') == 'a');
+ assert(f.pbase() == 0);
+ assert(f.pptr() == 0);
+ assert(f.epptr() == 0);
+ }
+ {
+ std::ifstream bs("overflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sgetc() == L'a');
+ }
+ std::remove("overflow.dat");
+ {
+ std::ofstream bs("overflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sputc(0x4E51) == 0x4E51);
+ assert(f.sputc(0x4E52) == 0x4E52);
+ assert(f.sputc(0x4E53) == 0x4E53);
+ }
+ {
+ std::ifstream f("overflow.dat");
+ assert(f.is_open());
+ assert(f.get() == 0xE4);
+ assert(f.get() == 0xB9);
+ assert(f.get() == 0x91);
+ assert(f.get() == 0xE4);
+ assert(f.get() == 0xB9);
+ assert(f.get() == 0x92);
+ assert(f.get() == 0xE4);
+ assert(f.get() == 0xB9);
+ assert(f.get() == 0x93);
+ assert(f.get() == -1);
+ }
+ std::remove("overflow.dat");
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp
new file mode 100644
index 00000000000..bcfb16e050e
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/pbackfail.pass.cpp
@@ -0,0 +1,59 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// int_type pbackfail(int_type c = traits::eof());
+
+// This test is not entirely portable
+
+#include <locale>
+#include <codecvt>
+#include <fstream>
+#include <cassert>
+
+struct test_buf
+ : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
+ typedef base::char_type char_type;
+ typedef base::int_type int_type;
+ typedef base::traits_type traits_type;
+
+ explicit test_buf(std::streambuf* sb) : base(sb) {}
+
+ char_type* eback() const {return base::eback();}
+ char_type* gptr() const {return base::gptr();}
+ char_type* egptr() const {return base::egptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}
+};
+
+int main()
+{
+ {
+ std::ifstream bs("underflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sbumpc() == L'1');
+ assert(f.sgetc() == L'2');
+ assert(f.pbackfail(L'a') == test_buf::traits_type::eof());
+ }
+ {
+ std::fstream bs("underflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sbumpc() == L'1');
+ assert(f.sgetc() == L'2');
+ assert(f.pbackfail(L'a') == test_buf::traits_type::eof());
+ assert(f.sbumpc() == L'2');
+ assert(f.sgetc() == L'3');
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/rdbuf.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/rdbuf.pass.cpp
new file mode 100644
index 00000000000..ffd813f86fe
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/rdbuf.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// streambuf *rdbuf(streambuf *bytebuf);
+
+#include <locale>
+#include <codecvt>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
+ {
+ std::stringstream s;
+ B b;
+ assert(b.rdbuf() == nullptr);
+ b.rdbuf(s.rdbuf());
+ assert(b.rdbuf() == s.rdbuf());
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/seekoff.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/seekoff.pass.cpp
new file mode 100644
index 00000000000..aa9d5e8a95e
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/seekoff.pass.cpp
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// pos_type seekoff(off_type off, ios_base::seekdir way,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+// pos_type seekpos(pos_type sp,
+// ios_base::openmode which = ios_base::in | ios_base::out);
+
+// This test is not entirely portable
+
+#include <locale>
+#include <codecvt>
+#include <fstream>
+#include <cassert>
+
+class test_codecvt
+ : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+ typedef std::codecvt<wchar_t, char, std::mbstate_t> base;
+public:
+ explicit test_codecvt(std::size_t refs = 0) : base(refs) {}
+ ~test_codecvt() {}
+};
+
+int main()
+{
+ {
+ wchar_t buf[10];
+ typedef std::wbuffer_convert<test_codecvt> test_buf;
+ typedef test_buf::pos_type pos_type;
+ std::fstream bs("seekoff.dat", std::ios::trunc | std::ios::in
+ | std::ios::out);
+ test_buf f(bs.rdbuf());
+ f.pubsetbuf(buf, sizeof(buf)/sizeof(buf[0]));
+ f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26);
+ assert(buf[0] == L'v');
+ pos_type p = f.pubseekoff(-15, std::ios_base::cur);
+ assert(p == 11);
+ assert(f.sgetc() == L'l');
+ f.pubseekoff(0, std::ios_base::beg);
+ assert(f.sgetc() == L'a');
+ f.pubseekoff(-1, std::ios_base::end);
+ assert(f.sgetc() == L'z');
+ assert(f.pubseekpos(p) == p);
+ assert(f.sgetc() == L'l');
+ }
+ std::remove("seekoff.dat");
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/state.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/state.pass.cpp
new file mode 100644
index 00000000000..6abf5cee328
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/state.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// state_type state() const;
+
+#include <locale>
+#include <codecvt>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > B;
+ {
+ B b;
+ std::mbstate_t s = b.state();
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/test.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/test.pass.cpp
new file mode 100644
index 00000000000..189ec2bddc1
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/test.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+#include <fstream>
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ {
+ std::ofstream bytestream("myfile.txt");
+ std::wbuffer_convert<std::codecvt_utf8<wchar_t> > mybuf(bytestream.rdbuf());
+ std::wostream mystr(&mybuf);
+ mystr << L"Hello" << std::endl;
+ }
+ {
+ std::ifstream bytestream("myfile.txt");
+ std::wbuffer_convert<std::codecvt_utf8<wchar_t> > mybuf(bytestream.rdbuf());
+ std::wistream mystr(&mybuf);
+ std::wstring ws;
+ mystr >> ws;
+ assert(ws == L"Hello");
+ }
+ std::remove("myfile.txt");
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.dat b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.dat
new file mode 100644
index 00000000000..e2e107ac61a
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.dat
@@ -0,0 +1 @@
+123456789 \ No newline at end of file
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.pass.cpp
new file mode 100644
index 00000000000..9c08a353fbd
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow.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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wbuffer_convert<Codecvt, Elem, Tr>
+
+// int_type underflow();
+
+// This test is not entirely portable
+
+#include <locale>
+#include <codecvt>
+#include <fstream>
+#include <cassert>
+
+struct test_buf
+ : public std::wbuffer_convert<std::codecvt_utf8<wchar_t> >
+{
+ typedef std::wbuffer_convert<std::codecvt_utf8<wchar_t> > base;
+ typedef base::char_type char_type;
+ typedef base::int_type int_type;
+ typedef base::traits_type traits_type;
+
+ explicit test_buf(std::streambuf* sb) : base(sb) {}
+
+ char_type* eback() const {return base::eback();}
+ char_type* gptr() const {return base::gptr();}
+ char_type* egptr() const {return base::egptr();}
+ void gbump(int n) {base::gbump(n);}
+
+ virtual int_type underflow() {return base::underflow();}
+};
+
+int main()
+{
+ {
+ std::ifstream bs("underflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == L'1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == L'1');
+ assert(f.egptr() - f.eback() == 9);
+ }
+ {
+ std::ifstream bs("underflow.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.eback() == 0);
+ assert(f.gptr() == 0);
+ assert(f.egptr() == 0);
+ assert(f.underflow() == L'1');
+ assert(f.eback() != 0);
+ assert(f.eback() == f.gptr());
+ assert(*f.gptr() == L'1');
+ assert(f.egptr() - f.eback() == 9);
+ f.gbump(8);
+ assert(f.sgetc() == L'9');
+ assert(f.eback()[0] == L'1');
+ assert(f.eback()[1] == L'2');
+ assert(f.eback()[2] == L'3');
+ assert(f.eback()[3] == L'4');
+ assert(f.gptr() - f.eback() == 8);
+ assert(*f.gptr() == L'9');
+ assert(f.egptr() - f.gptr() == 1);
+ }
+ {
+ std::ifstream bs("underflow_utf8.dat");
+ test_buf f(bs.rdbuf());
+ assert(f.sbumpc() == 0x4E51);
+ assert(f.sbumpc() == 0x4E52);
+ assert(f.sbumpc() == 0x4E53);
+ assert(f.sbumpc() == test_buf::traits_type::eof());
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow_utf8.dat b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow_utf8.dat
new file mode 100644
index 00000000000..ee7063e1207
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.buffer/underflow_utf8.dat
@@ -0,0 +1 @@
+乑乒乓 \ No newline at end of file
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/tolower.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/tolower.pass.cpp
new file mode 100644
index 00000000000..8c66ad14191
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/tolower.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// template <class charT> charT tolower(charT c, const locale& loc);
+
+#include <locale>
+#include <cassert>
+
+int main()
+{
+ std::locale l;
+ assert(std::tolower(' ', l) == ' ');
+ assert(std::tolower('<', l) == '<');
+ assert(std::tolower('\x8', l) == '\x8');
+ assert(std::tolower('A', l) == 'a');
+ assert(std::tolower('a', l) == 'a');
+ assert(std::tolower('z', l) == 'z');
+ assert(std::tolower('3', l) == '3');
+ assert(std::tolower('.', l) == '.');
+ assert(std::tolower('f', l) == 'f');
+ assert(std::tolower('9', l) == '9');
+ assert(std::tolower('+', l) == '+');
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/toupper.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/toupper.pass.cpp
new file mode 100644
index 00000000000..3299a3d00b2
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.character/toupper.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// template <class charT> charT toupper(charT c, const locale& loc);
+
+#include <locale>
+#include <cassert>
+
+int main()
+{
+ std::locale l;
+ assert(std::toupper(' ', l) == ' ');
+ assert(std::toupper('<', l) == '<');
+ assert(std::toupper('\x8', l) == '\x8');
+ assert(std::toupper('A', l) == 'A');
+ assert(std::toupper('a', l) == 'A');
+ assert(std::toupper('z', l) == 'Z');
+ assert(std::toupper('3', l) == '3');
+ assert(std::toupper('.', l) == '.');
+ assert(std::toupper('f', l) == 'F');
+ assert(std::toupper('9', l) == '9');
+ assert(std::toupper('+', l) == '+');
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp
new file mode 100644
index 00000000000..06df185757d
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/converted.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// size_t converted() const;
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+ Myconv myconv;
+ assert(myconv.converted() == 0);
+ std::string bs = myconv.to_bytes(L"\x40003");
+ assert(myconv.converted() == 1);
+ bs = myconv.to_bytes(L"\x40003\x65");
+ assert(myconv.converted() == 2);
+ std::wstring ws = myconv.from_bytes("\xF1\x80\x80\x83");
+ assert(myconv.converted() == 4);
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt.pass.cpp
new file mode 100644
index 00000000000..9099b5e38fc
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt.pass.cpp
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wstring_convert(Codecvt* pcvt = new Codecvt);
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+ Myconv myconv;
+ assert(myconv.converted() == 0);
+ }
+ {
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+ Myconv myconv(new Codecvt);
+ assert(myconv.converted() == 0);
+#if _LIBCPP_STD_VER > 11
+ static_assert(!std::is_convertible<Codecvt*, Myconv>::value, "");
+ static_assert( std::is_constructible<Myconv, Codecvt*>::value, "");
+#endif
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt_state.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt_state.pass.cpp
new file mode 100644
index 00000000000..7651f8ac3b3
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_codecvt_state.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wstring_convert(Codecvt* pcvt, state_type state);
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+ Myconv myconv(new Codecvt, std::mbstate_t());
+ assert(myconv.converted() == 0);
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
new file mode 100644
index 00000000000..27a3da76270
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wstring_convert(const byte_string& byte_err,
+// const wide_string& wide_err = wide_string());
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+#if _LIBCPP_STD_VER > 11
+ static_assert(!std::is_convertible<std::string, Myconv>::value, "");
+ static_assert( std::is_constructible<Myconv, std::string>::value, "");
+#endif
+ {
+ Myconv myconv;
+ try
+ {
+ myconv.to_bytes(L"\xDA83");
+ assert(false);
+ }
+ catch (const std::range_error&)
+ {
+ }
+ try
+ {
+ myconv.from_bytes('\xA5');
+ assert(false);
+ }
+ catch (const std::range_error&)
+ {
+ }
+ }
+ {
+ Myconv myconv("byte error");
+ std::string bs = myconv.to_bytes(L"\xDA83");
+ assert(bs == "byte error");
+ try
+ {
+ myconv.from_bytes('\xA5');
+ assert(false);
+ }
+ catch (const std::range_error&)
+ {
+ }
+ }
+ {
+ Myconv myconv("byte error", L"wide error");
+ std::string bs = myconv.to_bytes(L"\xDA83");
+ assert(bs == "byte error");
+ std::wstring ws = myconv.from_bytes('\xA5');
+ assert(ws == L"wide error");
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp
new file mode 100644
index 00000000000..8705a5f3bce
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/from_bytes.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// wide_string from_bytes(char byte);
+// wide_string from_bytes(const char* ptr);
+// wide_string from_bytes(const byte_string& str);
+// wide_string from_bytes(const char* first, const char* last);
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ {
+ std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
+ std::string bs("\xF1\x80\x80\x83");
+ std::wstring ws = myconv.from_bytes('a');
+ assert(ws == L"a");
+ ws = myconv.from_bytes(bs.c_str());
+ assert(ws == L"\x40003");
+ ws = myconv.from_bytes(bs);
+ assert(ws == L"\x40003");
+ ws = myconv.from_bytes(bs.data(), bs.data() + bs.size());
+ assert(ws == L"\x40003");
+ ws = myconv.from_bytes("");
+ assert(ws.size() == 0);
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/state.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/state.pass.cpp
new file mode 100644
index 00000000000..08dfa2558be
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/state.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// state_type state() const;
+
+#include <locale>
+#include <codecvt>
+
+int main()
+{
+ typedef std::codecvt_utf8<wchar_t> Codecvt;
+ typedef std::wstring_convert<Codecvt> Myconv;
+ Myconv myconv;
+ std::mbstate_t s = myconv.state();
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp
new file mode 100644
index 00000000000..7253a18a70b
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/to_bytes.pass.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// wstring_convert<Codecvt, Elem, Wide_alloc, Byte_alloc>
+
+// byte_string to_bytes(Elem wchar);
+// byte_string to_bytes(const Elem* wptr);
+// byte_string to_bytes(const wide_string& wstr);
+// byte_string to_bytes(const Elem* first, const Elem* last);
+
+#include <locale>
+#include <codecvt>
+#include <cassert>
+
+int main()
+{
+ {
+ std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
+ std::wstring ws(1, L'\x40003');
+ std::string bs = myconv.to_bytes(ws[0]);
+ assert(bs == "\xF1\x80\x80\x83");
+ bs = myconv.to_bytes(ws.c_str());
+ assert(bs == "\xF1\x80\x80\x83");
+ bs = myconv.to_bytes(ws);
+ assert(bs == "\xF1\x80\x80\x83");
+ bs = myconv.to_bytes(ws.data(), ws.data() + ws.size());
+ assert(bs == "\xF1\x80\x80\x83");
+ bs = myconv.to_bytes(L"");
+ assert(bs.size() == 0);
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/types.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/types.pass.cpp
new file mode 100644
index 00000000000..d46c858fd3c
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/conversions.string/types.pass.cpp
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// template<class Codecvt, class Elem = wchar_t,
+// class Wide_alloc = allocator<Elem>,
+// class Byte_alloc = allocator<char>>
+// class wstring_convert
+// {
+// public:
+// typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string;
+// typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
+// typedef typename Codecvt::state_type state_type;
+// typedef typename wide_string::traits_type::int_type int_type;
+
+#include <locale>
+#include <codecvt>
+
+int main()
+{
+ {
+ typedef std::wstring_convert<std::codecvt_utf8<wchar_t> > myconv;
+ static_assert((std::is_same<myconv::byte_string, std::string>::value), "");
+ static_assert((std::is_same<myconv::wide_string, std::wstring>::value), "");
+ static_assert((std::is_same<myconv::state_type, std::mbstate_t>::value), "");
+ static_assert((std::is_same<myconv::int_type, std::char_traits<wchar_t>::int_type>::value), "");
+ }
+}
diff --git a/libcxx/test/std/localization/locales/locale.convenience/conversions/nothing_to_do.pass.cpp b/libcxx/test/std/localization/locales/locale.convenience/conversions/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/std/localization/locales/locale.convenience/conversions/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
OpenPOWER on IntegriCloud