| 883 | }; |
| 884 | |
| 885 | void test_error_handling() |
| 886 | { |
| 887 | std::cout << "testing error handling..." << std::endl; |
| 888 | |
| 889 | std::locale global_loc = std::locale(); |
| 890 | std::locale loc(global_loc, new error_codecvt); |
| 891 | std::cout << " imbuing error locale ..." << std::endl; |
| 892 | std::locale old_loc = path::imbue(loc); |
| 893 | |
| 894 | // These tests rely on a path constructor that fails in the locale conversion. |
| 895 | // Thus construction has to call codecvt. Force that by using a narrow string |
| 896 | // for Windows, and a wide string for POSIX. |
| 897 | # ifdef BOOST_WINDOWS_API |
| 898 | # define STRING_FOO_ "foo" |
| 899 | # else |
| 900 | # define STRING_FOO_ L"foo" |
| 901 | # endif |
| 902 | |
| 903 | { |
| 904 | std::cout << " testing std::codecvt_base::partial error..." << std::endl; |
| 905 | bool exception_thrown (false); |
| 906 | try { path(STRING_FOO_); } |
| 907 | catch (const bs::system_error & ex) |
| 908 | { |
| 909 | exception_thrown = true; |
| 910 | BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, |
| 911 | fs::codecvt_error_category())); |
| 912 | } |
| 913 | catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } |
| 914 | BOOST_TEST(exception_thrown); |
| 915 | } |
| 916 | |
| 917 | { |
| 918 | std::cout << " testing std::codecvt_base::error error..." << std::endl; |
| 919 | bool exception_thrown (false); |
| 920 | try { path(STRING_FOO_); } |
| 921 | catch (const bs::system_error & ex) |
| 922 | { |
| 923 | exception_thrown = true; |
| 924 | BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, |
| 925 | fs::codecvt_error_category())); |
| 926 | } |
| 927 | catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } |
| 928 | BOOST_TEST(exception_thrown); |
| 929 | } |
| 930 | |
| 931 | { |
| 932 | std::cout << " testing std::codecvt_base::noconv error..." << std::endl; |
| 933 | bool exception_thrown (false); |
| 934 | try { path(STRING_FOO_); } |
| 935 | catch (const bs::system_error & ex) |
| 936 | { |
| 937 | exception_thrown = true; |
| 938 | BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, |
| 939 | fs::codecvt_error_category())); |
| 940 | } |
| 941 | catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } |
| 942 | BOOST_TEST(exception_thrown); |