3 #include "gmock/gmock.h" 4 #include "gtest/gtest.h" 13 #define CONV_SET_CASE(c) \ 14 if (Contains(conv, Conv::c)) out += #c; 22 Conv conv = ArgumentToConv<std::string>();
23 EXPECT_EQ(ConvToString(conv),
"s");
25 conv = ArgumentToConv<const char*>();
26 EXPECT_EQ(ConvToString(conv),
"sp");
28 conv = ArgumentToConv<double>();
29 EXPECT_EQ(ConvToString(conv),
"fFeEgGaA");
31 conv = ArgumentToConv<int>();
32 EXPECT_EQ(ConvToString(conv),
"cdiouxXfFeEgGaA*");
34 conv = ArgumentToConv<std::string*>();
35 EXPECT_EQ(ConvToString(conv),
"p");
38 #if ABSL_INTERNAL_ENABLE_FORMAT_CHECKER 45 template <
typename... Args>
46 constexpr Case ValidFormat(
const char*
format) {
47 return {ValidFormatImpl<ArgumentToConv<Args>()...>(format), format};
50 TEST(StrFormatChecker, ValidFormat) {
57 constexpr Case trues[] = {
61 ValidFormat<e2>(
"%d"),
62 ValidFormat<int>(
"%% %d"),
63 ValidFormat<int>(
"%ld"),
64 ValidFormat<int>(
"%lld"),
65 ValidFormat<std::string>(
"%s"),
66 ValidFormat<std::string>(
"%10s"),
67 ValidFormat<int>(
"%.10x"),
68 ValidFormat<int, int>(
"%*.3x"),
69 ValidFormat<int>(
"%1.d"),
70 ValidFormat<int>(
"%.d"),
71 ValidFormat<int, double>(
"%d %g"),
72 ValidFormat<int, std::string>(
"%*s"),
73 ValidFormat<int, double>(
"%.*f"),
74 ValidFormat<
void (*)(),
volatile int*>(
"%p %p"),
75 ValidFormat<string_view, const char*, double, void*>(
76 "string_view=%s const char*=%s double=%f void*=%p)"),
78 ValidFormat<int>(
"%% %1$d"),
79 ValidFormat<int>(
"%1$ld"),
80 ValidFormat<int>(
"%1$lld"),
81 ValidFormat<std::string>(
"%1$s"),
82 ValidFormat<std::string>(
"%1$10s"),
83 ValidFormat<int>(
"%1$.10x"),
84 ValidFormat<int>(
"%1$*1$.*1$d"),
85 ValidFormat<int, int>(
"%1$*2$.3x"),
86 ValidFormat<int>(
"%1$1.d"),
87 ValidFormat<int>(
"%1$.d"),
88 ValidFormat<double, int>(
"%2$d %1$g"),
89 ValidFormat<int, std::string>(
"%2$*1$s"),
90 ValidFormat<int, double>(
"%2$.*1$f"),
91 ValidFormat<void*, string_view, const char*, double>(
92 "string_view=%2$s const char*=%3$s double=%4$f void*=%1$p " 95 for (Case c : trues) {
96 EXPECT_TRUE(c.result) << c.format;
99 constexpr Case falses[] = {
100 ValidFormat<int>(
""),
102 ValidFormat<e>(
"%s"),
103 ValidFormat<e2>(
"%s"),
106 ValidFormat<int>(
"%s"),
107 ValidFormat<int>(
"%.1.d"),
108 ValidFormat<int>(
"%*1d"),
109 ValidFormat<int>(
"%1-d"),
110 ValidFormat<std::string, int>(
"%*s"),
111 ValidFormat<int>(
"%*d"),
112 ValidFormat<std::string>(
"%p"),
113 ValidFormat<int (*)(int)>(
"%d"),
115 ValidFormat<>(
"%3$d"),
116 ValidFormat<>(
"%1$r"),
117 ValidFormat<int>(
"%1$s"),
118 ValidFormat<int>(
"%1$.1.d"),
119 ValidFormat<int>(
"%1$*2$1d"),
120 ValidFormat<int>(
"%1$1-d"),
121 ValidFormat<std::string, int>(
"%2$*1$s"),
122 ValidFormat<std::string>(
"%1$p"),
124 ValidFormat<int, int>(
"%d %2$d"),
127 for (Case c : falses) {
128 EXPECT_FALSE(c.result) << c.format;
132 TEST(StrFormatChecker, LongFormat) {
133 #define CHARS_X_40 "1234567890123456789012345678901234567890" 134 #define CHARS_X_400 \ 135 CHARS_X_40 CHARS_X_40 CHARS_X_40 CHARS_X_40 CHARS_X_40 CHARS_X_40 CHARS_X_40 \ 136 CHARS_X_40 CHARS_X_40 CHARS_X_40 137 #define CHARS_X_4000 \ 138 CHARS_X_400 CHARS_X_400 CHARS_X_400 CHARS_X_400 CHARS_X_400 CHARS_X_400 \ 139 CHARS_X_400 CHARS_X_400 CHARS_X_400 CHARS_X_400 140 constexpr
char long_format[] =
141 CHARS_X_4000
"%d" CHARS_X_4000
"%s" CHARS_X_4000;
142 constexpr
bool is_valid = ValidFormat<int, std::string>(long_format).result;
143 EXPECT_TRUE(is_valid);
146 #endif // ABSL_INTERNAL_ENABLE_FORMAT_CHECKER
#define ABSL_CONVERSION_CHARS_EXPAND_(X_VAL, X_SEP)
TEST(NotificationTest, SanityTest)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)