| 1049 | }; |
| 1050 | |
| 1051 | void test_error_handling() |
| 1052 | { |
| 1053 | std::cout << "testing error handling..." << std::endl; |
| 1054 | |
| 1055 | std::locale global_loc = std::locale(); |
| 1056 | std::locale loc(global_loc, new error_codecvt); |
| 1057 | std::cout << " imbuing error locale ..." << std::endl; |
| 1058 | std::locale old_loc = path::imbue(loc); |
| 1059 | |
| 1060 | // These tests rely on a path constructor that fails in the locale conversion. |
| 1061 | // Thus construction has to call codecvt. Force that by using a narrow string |
| 1062 | // for Windows, and a wide string for POSIX. |
| 1063 | #ifdef BOOST_FILESYSTEM_WINDOWS_API |
| 1064 | #define STRING_FOO_ "foo" |
| 1065 | #else |
| 1066 | #define STRING_FOO_ L"foo" |
| 1067 | #endif |
| 1068 | |
| 1069 | { |
| 1070 | std::cout << " testing std::codecvt_base::partial error..." << std::endl; |
| 1071 | bool exception_thrown(false); |
| 1072 | try |
| 1073 | { |
| 1074 | path(STRING_FOO_); |
| 1075 | } |
| 1076 | catch (const bs::system_error& ex) |
| 1077 | { |
| 1078 | exception_thrown = true; |
| 1079 | BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, fs::codecvt_error_category())); |
| 1080 | } |
| 1081 | catch (...) |
| 1082 | { |
| 1083 | std::cout << "***** unexpected exception type *****" << std::endl; |
| 1084 | } |
| 1085 | BOOST_TEST(exception_thrown); |
| 1086 | } |
| 1087 | |
| 1088 | { |
| 1089 | std::cout << " testing std::codecvt_base::error error..." << std::endl; |
| 1090 | bool exception_thrown(false); |
| 1091 | try |
| 1092 | { |
| 1093 | path(STRING_FOO_); |
| 1094 | } |
| 1095 | catch (const bs::system_error& ex) |
| 1096 | { |
| 1097 | exception_thrown = true; |
| 1098 | BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, fs::codecvt_error_category())); |
| 1099 | } |
| 1100 | catch (...) |
| 1101 | { |
| 1102 | std::cout << "***** unexpected exception type *****" << std::endl; |
| 1103 | } |
| 1104 | BOOST_TEST(exception_thrown); |
| 1105 | } |
| 1106 | |
| 1107 | { |
| 1108 | std::cout << " testing std::codecvt_base::noconv error..." << std::endl; |