1 // Formatting library for C++ - test utilities
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
6 // For the license information refer to format.h.
16 # define FMT_VSNPRINTF vsprintf_s
18 # define FMT_VSNPRINTF vsnprintf
21 template <size_t SIZE
>
22 void safe_sprintf(char (&buffer
)[SIZE
], const char* format
, ...) {
24 va_start(args
, format
);
25 FMT_VSNPRINTF(buffer
, SIZE
, format
, args
);
29 extern const char* const file_content
;
31 // Opens a buffered file for reading.
32 auto open_buffered_file(FILE** fp
= nullptr) -> fmt::buffered_file
;
34 inline auto safe_fopen(const char* filename
, const char* mode
) -> FILE* {
35 #if defined(_WIN32) && !defined(__MINGW32__)
36 // Fix MSVC warning about "unsafe" fopen.
38 errno
= fopen_s(&f
, filename
, mode
);
41 return std::fopen(filename
, mode
);
45 template <typename Char
> class basic_test_string
{
47 std::basic_string
<Char
> value_
;
49 static const Char empty
[];
52 explicit basic_test_string(const Char
* value
= empty
) : value_(value
) {}
54 auto value() const -> const std::basic_string
<Char
>& { return value_
; }
57 template <typename Char
> const Char basic_test_string
<Char
>::empty
[] = {0};
59 using test_string
= basic_test_string
<char>;
60 using test_wstring
= basic_test_string
<wchar_t>;
62 template <typename Char
>
63 auto operator<<(std::basic_ostream
<Char
>& os
, const basic_test_string
<Char
>& s
)
64 -> std::basic_ostream
<Char
>& {
70 int year_
, month_
, day_
;
73 date(int year
, int month
, int day
) : year_(year
), month_(month
), day_(day
) {}
75 auto year() const -> int { return year_
; }
76 auto month() const -> int { return month_
; }
77 auto day() const -> int { return day_
; }
80 // Returns a locale with the given name if available or classic locale
82 auto get_locale(const char* name
, const char* alt_name
= nullptr)