]>
git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/fmt/test/util.h
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.
12 #include "fmt/posix.h"
14 enum {BUFFER_SIZE
= 256};
17 # define FMT_VSNPRINTF vsprintf_s
19 # define FMT_VSNPRINTF vsnprintf
22 template <std::size_t SIZE
>
23 void safe_sprintf(char (&buffer
)[SIZE
], const char *format
, ...) {
25 va_start(args
, format
);
26 FMT_VSNPRINTF(buffer
, SIZE
, format
, args
);
30 // Increment a number in a string.
31 void increment(char *s
);
33 std::string
get_system_error(int error_code
);
35 extern const char *const FILE_CONTENT
;
37 // Opens a buffered file for reading.
38 fmt::buffered_file
open_buffered_file(FILE **fp
= nullptr);
40 inline FILE *safe_fopen(const char *filename
, const char *mode
) {
41 #if defined(_WIN32) && !defined(__MINGW32__)
42 // Fix MSVC warning about "unsafe" fopen.
44 errno
= fopen_s(&f
, filename
, mode
);
47 return std::fopen(filename
, mode
);
51 template <typename Char
>
52 class BasicTestString
{
54 std::basic_string
<Char
> value_
;
56 static const Char EMPTY
[];
59 explicit BasicTestString(const Char
*value
= EMPTY
) : value_(value
) {}
61 const std::basic_string
<Char
> &value() const { return value_
; }
64 template <typename Char
>
65 const Char BasicTestString
<Char
>::EMPTY
[] = {0};
67 typedef BasicTestString
<char> TestString
;
68 typedef BasicTestString
<wchar_t> TestWString
;
70 template <typename Char
>
71 std::basic_ostream
<Char
> &operator<<(
72 std::basic_ostream
<Char
> &os
, const BasicTestString
<Char
> &s
) {
78 int year_
, month_
, day_
;
80 Date(int year
, int month
, int day
) : year_(year
), month_(month
), day_(day
) {}
82 int year() const { return year_
; }
83 int month() const { return month_
; }
84 int day() const { return day_
; }