Skip to content

Commit

Permalink
Depreate strtod and remove problematic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 28, 2021
1 parent 74c1118 commit 729a44e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 36 deletions.
2 changes: 1 addition & 1 deletion include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class locale {

// Converts string to floating-point number and advances str past the end
// of the parsed input.
double strtod(const char*& str) const {
FMT_DEPRECATED double strtod(const char*& str) const {
char* end = nullptr;
double result = strtod_l(str, &end, locale_);
str = end;
Expand Down
9 changes: 0 additions & 9 deletions test/os-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,4 @@ TEST(file_test, fdopen) {
int read_fd = read_end.descriptor();
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
26 changes: 0 additions & 26 deletions test/posix-mock-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,6 @@ struct locale_mock {
MOCK_METHOD3(newlocale, locale_type(int category_mask, const char* locale,
locale_type base));
MOCK_METHOD1(freelocale, void(locale_type locale));

MOCK_METHOD3(strtod_l,
double(const char* nptr, char** endptr, locale_type locale));
} * locale_mock::instance;

# ifdef _MSC_VER
Expand All @@ -487,10 +484,6 @@ _locale_t _create_locale(int category, const char* locale) {
void _free_locale(_locale_t 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__
# pragma clang diagnostic pop
# endif
Expand All @@ -516,11 +509,6 @@ FreeLocaleResult freelocale(locale_type locale) FMT_LOCALE_THROW {
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

# ifndef _WIN32
Expand Down Expand Up @@ -549,18 +537,4 @@ TEST(locale_test, locale) {
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

0 comments on commit 729a44e

Please sign in to comment.