Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / third_party / tcmalloc / chromium / src / tests / raw_printer_test.cc
blob3138b50c5ee970ce1859f15da05e46a9a334b13b
1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: sanjay@google.com (Sanjay Ghemawat)
4 #include "raw_printer.h"
5 #include <stdio.h>
6 #include <string>
7 #include "base/logging.h"
9 using std::string;
11 #define TEST(a, b) void TEST_##a##_##b()
12 #define RUN_TEST(a, b) TEST_##a##_##b()
14 TEST(RawPrinter, Empty) {
15 char buffer[1];
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) {
27 char buffer[100];
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) {
36 char buffer[3];
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) {
45 char buffer[12];
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);
58 printf("PASS\n");
59 return 0; // 0 means success