Depreate strtod and remove problematic tests

This commit is contained in:
Victor Zverovich 2021-08-28 09:20:36 -07:00
parent 74c1118964
commit 729a44e67d
3 changed files with 1 additions and 36 deletions

View File

@ -502,7 +502,7 @@ class locale {
// Converts string to floating-point number and advances str past the end // Converts string to floating-point number and advances str past the end
// of the parsed input. // of the parsed input.
double strtod(const char*& str) const { FMT_DEPRECATED double strtod(const char*& str) const {
char* end = nullptr; char* end = nullptr;
double result = strtod_l(str, &end, locale_); double result = strtod_l(str, &end, locale_);
str = end; str = end;

View File

@ -548,13 +548,4 @@ TEST(file_test, fdopen) {
int read_fd = read_end.descriptor(); int read_fd = read_end.descriptor();
EXPECT_EQ(read_fd, FMT_POSIX(fileno(read_end.fdopen("r").get()))); EXPECT_EQ(read_fd, FMT_POSIX(fileno(read_end.fdopen("r").get())));
} }
# ifdef FMT_LOCALE
TEST(locale_test, strtod) {
fmt::locale loc;
const char *start = "4.2", *ptr = start;
EXPECT_EQ(4.2, loc.strtod(ptr));
EXPECT_EQ(start + 3, ptr);
}
# endif
#endif // FMT_USE_FCNTL #endif // FMT_USE_FCNTL

View File

@ -467,9 +467,6 @@ struct locale_mock {
MOCK_METHOD3(newlocale, locale_type(int category_mask, const char* locale, MOCK_METHOD3(newlocale, locale_type(int category_mask, const char* locale,
locale_type base)); locale_type base));
MOCK_METHOD1(freelocale, void(locale_type locale)); MOCK_METHOD1(freelocale, void(locale_type locale));
MOCK_METHOD3(strtod_l,
double(const char* nptr, char** endptr, locale_type locale));
} * locale_mock::instance; } * locale_mock::instance;
# ifdef _MSC_VER # ifdef _MSC_VER
@ -487,10 +484,6 @@ _locale_t _create_locale(int category, const char* locale) {
void _free_locale(_locale_t locale) { void _free_locale(_locale_t locale) {
locale_mock::instance->freelocale(locale); locale_mock::instance->freelocale(locale);
} }
double _strtod_l(const char* nptr, char** endptr, _locale_t locale) {
return locale_mock::instance->strtod_l(nptr, endptr, locale);
}
# ifdef __clang__ # ifdef __clang__
# pragma clang diagnostic pop # pragma clang diagnostic pop
# endif # endif
@ -516,11 +509,6 @@ FreeLocaleResult freelocale(locale_type locale) FMT_LOCALE_THROW {
return FreeLocaleResult(); return FreeLocaleResult();
} }
double strtod_l(const char* nptr, char** endptr,
locale_type locale) FMT_LOCALE_THROW {
return locale_mock::instance->strtod_l(nptr, endptr, locale);
}
# undef FMT_LOCALE_THROW # undef FMT_LOCALE_THROW
# ifndef _WIN32 # ifndef _WIN32
@ -549,18 +537,4 @@ TEST(locale_test, locale) {
EXPECT_EQ(impl, loc.get()); EXPECT_EQ(impl, loc.get());
} }
TEST(locale_test, strtod) {
scoped_mock<locale_mock> mock;
EXPECT_CALL(mock, newlocale(_, _, _))
.WillOnce(Return(reinterpret_cast<locale_type>(42)));
EXPECT_CALL(mock, freelocale(_));
fmt::locale loc;
const char* str = "4.2";
char end = 'x';
EXPECT_CALL(mock, strtod_l(str, _, loc.get()))
.WillOnce(testing::DoAll(testing::SetArgPointee<1>(&end), Return(777)));
EXPECT_EQ(777, loc.strtod(str));
EXPECT_EQ(&end, str);
}
#endif // FMT_LOCALE #endif // FMT_LOCALE