Skip to content

Commit ad24c36

Browse files
committed
Updating locale tests to silently pass if the necessary locale isn't installed on the machine.
1 parent 23332cb commit ad24c36

File tree

4 files changed

+70
-21
lines changed

4 files changed

+70
-21
lines changed

Release/tests/functional/http/client/building_request_tests.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,22 @@ TEST_FIXTURE(uri_address, set_body_with_charset)
250250

251251
TEST_FIXTURE(uri_address, set_content_length_locale, "Ignore:Android", "Locale unsupported on Android")
252252
{
253+
std::locale changedLocale;
254+
try
255+
{
253256
#ifdef _WIN32
254-
std::string changedLocale("fr-FR");
257+
changedLocale = std::locale("fr-FR");
255258
#else
256-
std::string changedLocale("fr_FR.UTF-8");
259+
changedLocale = std::locale("fr_FR.UTF-8");
257260
#endif
261+
}
262+
catch (const std::exception &)
263+
{
264+
// Silently pass if locale isn't installed on the machine.
265+
return;
266+
}
258267

259-
tests::common::utilities::locale_guard loc(std::locale(changedLocale.c_str()));
268+
tests::common::utilities::locale_guard loc(changedLocale);
260269

261270
http_request req(methods::PUT);
262271
req.headers().set_content_length(1000);
@@ -276,12 +285,22 @@ TEST_FIXTURE(uri_address, set_port_locale, "Ignore:Android", "Locale unsupported
276285
});
277286

278287
{
288+
std::locale changedLocale;
289+
try
290+
{
279291
#ifdef _WIN32
280-
std::string changedLocale("fr-FR");
292+
changedLocale = std::locale("fr-FR");
281293
#else
282-
std::string changedLocale("fr_FR.UTF-8");
294+
changedLocale = std::locale("fr_FR.UTF-8");
283295
#endif
284-
tests::common::utilities::locale_guard loc(std::locale(changedLocale.c_str()));
296+
}
297+
catch (const std::exception &)
298+
{
299+
// Silently pass if locale isn't installed on machine.
300+
return;
301+
}
302+
303+
tests::common::utilities::locale_guard loc(changedLocale);
285304
http_request msg(methods::PUT);
286305
msg.set_body(data);
287306
http_asserts::assert_response_equals(client.request(msg).get(), status_codes::OK);

Release/tests/functional/json/json_numbers_tests.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ TEST(parsing_doubles_setlocale, "Ignore:Android", "Locale not supported on Andro
201201
#else
202202
std::string changedLocale("fr_FR.UTF-8");
203203
#endif
204-
setlocale(LC_ALL, changedLocale.c_str());
205204

206-
test_double(1.91563);
207-
test_double(2.0e93);
208-
setlocale(LC_ALL, "C");
205+
// If locale isn't installed on system just silently pass.
206+
if (setlocale(LC_ALL, changedLocale.c_str()) != nullptr)
207+
{
208+
test_double(1.91563);
209+
test_double(2.0e93);
210+
setlocale(LC_ALL, "C");
211+
}
209212
}
210213

211214
TEST(parsing_very_large_doubles)

Release/tests/functional/uri/uri_builder_tests.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,22 @@ TEST(to_string_invalid_uri)
458458

459459
TEST(append_query_locale, "Ignore:Android", "Locale unsupported on Android")
460460
{
461+
std::locale changedLocale;
462+
try
463+
{
461464
#ifdef _WIN32
462-
std::string changedLocale("fr-FR");
465+
changedLocale = std::locale("fr-FR");
463466
#else
464-
std::string changedLocale("fr_FR.UTF-8");
467+
changedLocale = std::locale("fr_FR.UTF-8");
465468
#endif
469+
}
470+
catch (const std::exception &)
471+
{
472+
// Silently pass if locale isn't installed on machine.
473+
return;
474+
}
466475

467-
tests::common::utilities::locale_guard loc(std::locale(changedLocale.c_str()));
476+
tests::common::utilities::locale_guard loc(changedLocale);
468477

469478
uri_builder builder;
470479
auto const &key = U("key1000");

Release/tests/functional/utils/strings.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,22 @@ TEST(latin1_to_utf16)
7171

7272
TEST(print_string_locale, "Ignore:Android", "Locale unsupported on Android")
7373
{
74+
std::locale changedLocale;
75+
try
76+
{
7477
#ifdef _WIN32
75-
std::string changedLocale("fr-FR");
78+
changedLocale = std::locale("fr-FR");
7679
#else
77-
std::string changedLocale("fr_FR.UTF-8");
80+
changedLocale = std::locale("fr_FR.UTF-8");
7881
#endif
82+
}
83+
catch (const std::exception &)
84+
{
85+
// Silently pass if locale isn't installed on machine.
86+
return;
87+
}
7988

80-
tests::common::utilities::locale_guard loc(std::locale(changedLocale.c_str()));
89+
tests::common::utilities::locale_guard loc(changedLocale);
8190

8291
utility::ostringstream_t oss;
8392
oss << 1000;
@@ -87,20 +96,29 @@ TEST(print_string_locale, "Ignore:Android", "Locale unsupported on Android")
8796

8897
TEST(scan_string_locale, "Ignore:Android", "Locale unsupported on Android")
8998
{
99+
std::locale changedLocale;
100+
try
101+
{
90102
#ifdef _WIN32
91-
std::string changedLocale("fr-FR");
103+
changedLocale = std::locale("fr-FR");
92104
#else
93-
std::string changedLocale("fr_FR.UTF-8");
105+
changedLocale = std::locale("fr_FR.UTF-8");
94106
#endif
107+
}
108+
catch (const std::exception &)
109+
{
110+
// Silently pass if locale isn't installed on machine.
111+
return;
112+
}
95113

96114
VERIFY_ARE_EQUAL(_XPLATSTR("1000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1000"))));
97115
VERIFY_ARE_EQUAL(_XPLATSTR("1,000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1,000"))));
98116

99-
VERIFY_ARE_EQUAL(_XPLATSTR("1000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1000")), std::locale(changedLocale.c_str())));
100-
VERIFY_ARE_EQUAL(_XPLATSTR("1,000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1,000")), std::locale(changedLocale.c_str())));
117+
VERIFY_ARE_EQUAL(_XPLATSTR("1000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1000")), changedLocale));
118+
VERIFY_ARE_EQUAL(_XPLATSTR("1,000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1,000")), changedLocale));
101119

102120
{
103-
tests::common::utilities::locale_guard loc(std::locale(changedLocale.c_str()));
121+
tests::common::utilities::locale_guard loc(changedLocale);
104122
VERIFY_ARE_EQUAL(_XPLATSTR("1000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1000")), std::locale::classic()));
105123
VERIFY_ARE_EQUAL(_XPLATSTR("1,000"), utility::conversions::scan_string<utility::string_t>(utility::string_t(_XPLATSTR("1,000")), std::locale::classic()));
106124
}

0 commit comments

Comments
 (0)