#include "gtest-extra.h"
#include "util.h"
-#ifdef fileno
-# undef fileno
-#endif
-
using fmt::buffered_file;
using testing::HasSubstr;
using wstring_view = fmt::basic_string_view<wchar_t>;
}
template <typename Converter, typename Char>
-void check_utf_conversion_error(
- const char* message,
- fmt::basic_string_view<Char> str = fmt::basic_string_view<Char>(0, 1)) {
+void check_utf_conversion_error(const char* message,
+ fmt::basic_string_view<Char> str =
+ fmt::basic_string_view<Char>(nullptr, 1)) {
fmt::memory_buffer out;
fmt::detail::format_windows_error(out, ERROR_INVALID_PARAMETER, message);
auto error = std::system_error(std::error_code());
TEST(util_test, utf16_to_utf8_convert) {
fmt::detail::utf16_to_utf8 u;
- EXPECT_EQ(ERROR_INVALID_PARAMETER, u.convert(wstring_view(0, 1)));
+ EXPECT_EQ(ERROR_INVALID_PARAMETER, u.convert(wstring_view(nullptr, 1)));
EXPECT_EQ(ERROR_INVALID_PARAMETER,
u.convert(wstring_view(L"foo", INT_MAX + 1u)));
}
}
TEST(os_test, format_windows_error) {
- LPWSTR message = 0;
+ LPWSTR message = nullptr;
auto result = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
- 0, ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- reinterpret_cast<LPWSTR>(&message), 0, 0);
+ nullptr, ERROR_FILE_EXISTS, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ reinterpret_cast<LPWSTR>(&message), 0, nullptr);
fmt::detail::utf16_to_utf8 utf8_message(wstring_view(message, result - 2));
LocalFree(message);
fmt::memory_buffer actual_message;
}
TEST(os_test, format_long_windows_error) {
- LPWSTR message = 0;
+ LPWSTR message = nullptr;
// this error code is not available on all Windows platforms and
// Windows SDKs, so do not fail the test if the error string cannot
// be retrieved.
int provisioning_not_allowed = 0x80284013L; // TBS_E_PROVISIONING_NOT_ALLOWED
- auto result = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- 0, static_cast<DWORD>(provisioning_not_allowed),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- reinterpret_cast<LPWSTR>(&message), 0, 0);
+ auto result = FormatMessageW(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, static_cast<DWORD>(provisioning_not_allowed),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ reinterpret_cast<LPWSTR>(&message), 0, nullptr);
if (result == 0) {
LocalFree(message);
return;
TEST(buffered_file_test, move_assignment_closes_file) {
buffered_file bf = open_buffered_file();
buffered_file bf2 = open_buffered_file();
- int old_fd = bf2.fileno();
+ int old_fd = bf2.descriptor();
bf2 = std::move(bf);
EXPECT_TRUE(isclosed(old_fd));
}
TEST(buffered_file_test, move_from_temporary_in_assignment_closes_file) {
buffered_file f = open_buffered_file();
- int old_fd = f.fileno();
+ int old_fd = f.descriptor();
f = open_buffered_file();
EXPECT_TRUE(isclosed(old_fd));
}
int fd = 0;
{
buffered_file f = open_buffered_file();
- fd = f.fileno();
+ fd = f.descriptor();
}
EXPECT_TRUE(isclosed(fd));
}
// otherwise the system may recycle closed file descriptor when
// redirecting the output in EXPECT_STDERR and the second close
// will break output redirection.
- FMT_POSIX(close(f->fileno()));
+ FMT_POSIX(close(f->descriptor()));
SUPPRESS_ASSERT(f.reset(nullptr));
},
system_error_message(EBADF, "cannot close file") + "\n");
TEST(buffered_file_test, close) {
buffered_file f = open_buffered_file();
- int fd = f.fileno();
+ int fd = f.descriptor();
f.close();
EXPECT_TRUE(f.get() == nullptr);
EXPECT_TRUE(isclosed(fd));
TEST(buffered_file_test, close_error) {
buffered_file f = open_buffered_file();
- FMT_POSIX(close(f.fileno()));
+ FMT_POSIX(close(f.descriptor()));
EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file");
EXPECT_TRUE(f.get() == nullptr);
}
-TEST(buffered_file_test, fileno) {
+TEST(buffered_file_test, descriptor) {
auto f = open_buffered_file();
- EXPECT_TRUE(f.fileno() != -1);
- file copy = file::dup(f.fileno());
+ EXPECT_TRUE(f.descriptor() != -1);
+ file copy = file::dup(f.descriptor());
EXPECT_READ(copy, file_content);
}
EXPECT_EQ("foo", read(in, 4));
}
+TEST(ostream_test, flush) {
+ auto out = fmt::output_file("test-file");
+ out.print("x");
+ out.flush();
+ auto in = fmt::file("test-file", file::RDONLY);
+ EXPECT_READ(in, "x");
+}
+
TEST(file_test, default_ctor) {
file f;
EXPECT_EQ(-1, f.descriptor());
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