test/test_printf.cpp

changeset 648
4e115b610b37
parent 636
cfcc8cf0168c
equal deleted inserted replaced
645:ec50abb285ad 648:4e115b610b37
113 113
114 r = cx_fprintf(&buf, PrintfFixture::write_func, "%o %#o %#o", 10, 10, 4); 114 r = cx_fprintf(&buf, PrintfFixture::write_func, "%o %#o %#o", 10, 10, 4);
115 EXPECT_EQ(r, 9); 115 EXPECT_EQ(r, 9);
116 EXPECT_EQ(buf, "12 012 04"); 116 EXPECT_EQ(buf, "12 012 04");
117 117
118 r = cx_fprintf(&buf, PrintfFixture::write_func, "%f %.0f %.32f", 1.5, 1.5, 1.3);
119 EXPECT_EQ(r, 45);
120 EXPECT_EQ(buf, "1.500000 2 1.30000000000000004440892098500626");
121
122 r = cx_fprintf(&buf, PrintfFixture::write_func, "%05.2f %.2f %5.2f", 1.5, 1.5, 1.5); 118 r = cx_fprintf(&buf, PrintfFixture::write_func, "%05.2f %.2f %5.2f", 1.5, 1.5, 1.5);
123 EXPECT_EQ(r, 16); 119 EXPECT_EQ(r, 16);
124 EXPECT_EQ(buf, "01.50 1.50 1.50"); 120 EXPECT_EQ(buf, "01.50 1.50 1.50");
125
126 r = cx_fprintf(&buf, PrintfFixture::write_func, "%E %e", 1.5, 1.5);
127 EXPECT_EQ(r, 25);
128 EXPECT_EQ(buf, "1.500000E+00 1.500000e+00");
129
130 r = cx_fprintf(&buf, PrintfFixture::write_func, "%a %A", 1.5, 1.5);
131 EXPECT_EQ(r, 17);
132 EXPECT_EQ(buf, "0x1.8p+0 0X1.8P+0");
133
134 r = cx_fprintf(&buf, PrintfFixture::write_func, "0/0=%g 1/0=%g", 0.0 / 0.0, 1.0 / 0.0);
135 EXPECT_EQ(r, 16);
136 EXPECT_EQ(buf, "0/0=-nan 1/0=inf");
137 121
138 r = cx_fprintf(&buf, PrintfFixture::write_func, "'%*c'", 5, 'x'); 122 r = cx_fprintf(&buf, PrintfFixture::write_func, "'%*c'", 5, 'x');
139 EXPECT_EQ(r, 7); 123 EXPECT_EQ(r, 7);
140 EXPECT_EQ(buf, "' x'"); 124 EXPECT_EQ(buf, "' x'");
141 125
228 r = cx_asprintf_a(&alloc, "%o %#o %#o", 10, 10, 4); 212 r = cx_asprintf_a(&alloc, "%o %#o %#o", 10, 10, 4);
229 EXPECT_EQ(r.length, 9); 213 EXPECT_EQ(r.length, 9);
230 EXPECT_STREQ(r.ptr, "12 012 04"); 214 EXPECT_STREQ(r.ptr, "12 012 04");
231 fl.push_back(r.ptr); 215 fl.push_back(r.ptr);
232 216
233 r = cx_asprintf_a(&alloc, "%f %.0f %.32f", 1.5, 1.5, 1.3);
234 EXPECT_EQ(r.length, 45);
235 EXPECT_STREQ(r.ptr, "1.500000 2 1.30000000000000004440892098500626");
236 fl.push_back(r.ptr);
237
238 r = cx_asprintf_a(&alloc, "%05.2f %.2f %5.2f", 1.5, 1.5, 1.5); 217 r = cx_asprintf_a(&alloc, "%05.2f %.2f %5.2f", 1.5, 1.5, 1.5);
239 EXPECT_EQ(r.length, 16); 218 EXPECT_EQ(r.length, 16);
240 EXPECT_STREQ(r.ptr, "01.50 1.50 1.50"); 219 EXPECT_STREQ(r.ptr, "01.50 1.50 1.50");
241 fl.push_back(r.ptr);
242
243 r = cx_asprintf_a(&alloc, "%E %e", 1.5, 1.5);
244 EXPECT_EQ(r.length, 25);
245 EXPECT_STREQ(r.ptr, "1.500000E+00 1.500000e+00");
246 fl.push_back(r.ptr);
247
248 r = cx_asprintf_a(&alloc, "%a %A", 1.5, 1.5);
249 EXPECT_EQ(r.length, 17);
250 EXPECT_STREQ(r.ptr, "0x1.8p+0 0X1.8P+0");
251 fl.push_back(r.ptr);
252
253 r = cx_asprintf_a(&alloc, "0/0=%g 1/0=%g", 0.0 / 0.0, 1.0 / 0.0);
254 EXPECT_EQ(r.length, 16);
255 EXPECT_STREQ(r.ptr, "0/0=-nan 1/0=inf");
256 fl.push_back(r.ptr); 220 fl.push_back(r.ptr);
257 221
258 r = cx_asprintf_a(&alloc, "'%*c'", 5, 'x'); 222 r = cx_asprintf_a(&alloc, "'%*c'", 5, 'x');
259 EXPECT_EQ(r.length, 7); 223 EXPECT_EQ(r.length, 7);
260 EXPECT_STREQ(r.ptr, "' x'"); 224 EXPECT_STREQ(r.ptr, "' x'");

mercurial