29 #include <gtest/gtest.h> 37 #define CPRINTF_TEST(...) \ 39 std::stringstream ss; \ 40 ccprintf(ss, __VA_ARGS__); \ 41 int maxlen = ss.str().length() + 3; \ 42 char *buf = new char[maxlen]; \ 43 buf[maxlen - 1] = '\0'; \ 44 snprintf(buf, maxlen - 2, __VA_ARGS__); \ 45 EXPECT_EQ(ss.str(), std::string(buf)); \ 55 CPRINTF_TEST(
"%shits%%s + %smisses%%s\n",
"test",
"test");
56 CPRINTF_TEST(
"%%s%-10s %c he went home \'\"%d %#o %#llx %1.5f %1.2E\n",
57 "hello",
'A', 1, 0xff, 0xfffffffffffffULL, 3.141592653589,
62 CPRINTF_TEST(
"%-10s %c he home \'\"%d %#o %#llx %1.5f %1.2E\n",
63 "hello",
'A', 1, 0xff, 0xfffffffffffffULL,
67 TEST(CPrintf, FloatingPoint)
69 double f = 314159.26535897932384;
99 f = 0.00000026535897932384;
127 f = 0.00000026535897932384;
158 std::stringstream
ss;
160 std::string foo1 =
"string test";
165 std::stringstream foo2;
166 foo2 <<
"stringstream test";
168 EXPECT_EQ(ss.str(),
"stringstream test\n");
174 TEST(CPrintf, SpecialFormatting)
void ccprintf(cp::Print &print)
std::true_type foo(void(*)(ThreadContext *, const Ret &ret, State &state))
#define CPRINTF_TEST(...)
#define EXPECT_EQ(lhs, rhs)
A macro which verifies that lhs and rhs are equal to each other.