Use kAudioObjectPropertyElementMaster on macOS for compatibility
[openal-soft.git] / fmt-11.0.2 / test / util.h
blob803cdeea9632ab63ae7e552c9bb84f4d2e80a992
1 // Formatting library for C++ - test utilities
2 //
3 // Copyright (c) 2012 - present, Victor Zverovich
4 // All rights reserved.
5 //
6 // For the license information refer to format.h.
8 #include <cstdarg>
9 #include <cstdio>
10 #include <locale>
11 #include <string>
13 #include "fmt/os.h"
15 #ifdef _MSC_VER
16 # define FMT_VSNPRINTF vsprintf_s
17 #else
18 # define FMT_VSNPRINTF vsnprintf
19 #endif
21 template <size_t SIZE>
22 void safe_sprintf(char (&buffer)[SIZE], const char* format, ...) {
23 std::va_list args;
24 va_start(args, format);
25 FMT_VSNPRINTF(buffer, SIZE, format, args);
26 va_end(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.
37 FILE* f = nullptr;
38 errno = fopen_s(&f, filename, mode);
39 return f;
40 #else
41 return std::fopen(filename, mode);
42 #endif
45 template <typename Char> class basic_test_string {
46 private:
47 std::basic_string<Char> value_;
49 static const Char empty[];
51 public:
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>& {
65 os << s.value();
66 return os;
69 class date {
70 int year_, month_, day_;
72 public:
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
81 // otherwise.
82 auto get_locale(const char* name, const char* alt_name = nullptr)
83 -> std::locale;