1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: sanjay@google.com (Sanjay Ghemawat)
4 #include "raw_printer.h"
7 #include "base/logging.h"
11 #define TEST(a, b) void TEST_##a##_##b()
12 #define RUN_TEST(a, b) TEST_##a##_##b()
14 TEST(RawPrinter
, Empty
) {
16 base::RawPrinter
printer(buffer
, arraysize(buffer
));
17 CHECK_EQ(0, printer
.length());
18 CHECK_EQ(string(""), buffer
);
19 CHECK_EQ(0, printer
.space_left());
20 printer
.Printf("foo");
21 CHECK_EQ(string(""), string(buffer
));
22 CHECK_EQ(0, printer
.length());
23 CHECK_EQ(0, printer
.space_left());
26 TEST(RawPrinter
, PartiallyFilled
) {
28 base::RawPrinter
printer(buffer
, arraysize(buffer
));
29 printer
.Printf("%s %s", "hello", "world");
30 CHECK_EQ(string("hello world"), string(buffer
));
31 CHECK_EQ(11, printer
.length());
32 CHECK_LT(0, printer
.space_left());
35 TEST(RawPrinter
, Truncated
) {
37 base::RawPrinter
printer(buffer
, arraysize(buffer
));
38 printer
.Printf("%d", 12345678);
39 CHECK_EQ(string("12"), string(buffer
));
40 CHECK_EQ(2, printer
.length());
41 CHECK_EQ(0, printer
.space_left());
44 TEST(RawPrinter
, ExactlyFilled
) {
46 base::RawPrinter
printer(buffer
, arraysize(buffer
));
47 printer
.Printf("%s %s", "hello", "world");
48 CHECK_EQ(string("hello world"), string(buffer
));
49 CHECK_EQ(11, printer
.length());
50 CHECK_EQ(0, printer
.space_left());
53 int main(int argc
, char **argv
) {
54 RUN_TEST(RawPrinter
, Empty
);
55 RUN_TEST(RawPrinter
, PartiallyFilled
);
56 RUN_TEST(RawPrinter
, Truncated
);
57 RUN_TEST(RawPrinter
, ExactlyFilled
);
59 return 0; // 0 means success