- add sources.
[platform/framework/web/crosswalk.git] / src / third_party / tcmalloc / chromium / src / tests / raw_printer_test.cc
1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: sanjay@google.com (Sanjay Ghemawat)
3
4 #include "raw_printer.h"
5 #include <stdio.h>
6 #include <string>
7 #include "base/logging.h"
8
9 using std::string;
10
11 #define TEST(a, b)  void TEST_##a##_##b()
12 #define RUN_TEST(a, b)  TEST_##a##_##b()
13
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());
24 }
25
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());
33 }
34
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());
42 }
43
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());
51 }
52
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
60 }