Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / test_prebufferedstreambuf.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "common/PrebufferedStreambuf.h"
5 #include "gtest/gtest.h"
6
7 TEST(PrebufferedStreambuf, Empty)
8 {
9   char buf[10];
10   PrebufferedStreambuf sb(buf, sizeof(buf));
11
12   std::istream is(&sb);
13   std::string out;
14   getline(is, out);
15   ASSERT_EQ("", out);
16 }
17
18 TEST(PrebufferedStreambuf, Simple)
19 {
20   char buf[10];
21   PrebufferedStreambuf sb(buf, sizeof(buf));
22
23   std::ostream os(&sb);
24   os << "test";
25
26   std::istream is(&sb);
27   std::string out;
28   getline(is, out);
29   ASSERT_EQ("test", out);
30 }
31
32 TEST(PrebufferedStreambuf, Multiline)
33 {
34   char buf[10];
35   PrebufferedStreambuf sb(buf, sizeof(buf));
36
37   std::ostream os(&sb);
38   const char *s = "this is a line\nanother line\nand a third\nwhee!\n";
39   os << s;
40
41   std::istream is(&sb);
42   std::string out;
43   getline(is, out, is.widen(0));
44   ASSERT_EQ(s, out);
45 }
46
47 TEST(PrebufferedStreambuf, Withnull)
48 {
49   char buf[10];
50   PrebufferedStreambuf sb(buf, sizeof(buf));
51
52   std::ostream os(&sb);
53   std::string s("null \0 and more", 15);
54   os << s;
55
56   std::istream is(&sb);
57   std::string out;
58   getline(is, out);
59   ASSERT_EQ(s, out);
60 }
61
62 TEST(PrebufferedStreambuf, SimpleOverflow)
63 {
64   char buf[10];
65   PrebufferedStreambuf sb(buf, sizeof(buf));
66
67   std::ostream os(&sb);
68   const char *s = "hello, this is longer than buf[10]";
69   os << s;
70
71   ASSERT_EQ(s, sb.get_str());
72
73   std::istream is(&sb);
74   std::string out;
75   getline(is, out);
76   ASSERT_EQ(s, out);
77 }
78
79 TEST(PrebufferedStreambuf, ManyOverflow)
80 {
81   char buf[10];
82   PrebufferedStreambuf sb(buf, sizeof(buf));
83
84   std::ostream os(&sb);
85   const char *s = "hello, this way way way way way way way way way way way way way way way way way way way way way way way way way _way_ longer than buf[10]";
86   os << s;
87
88   ASSERT_EQ(s, sb.get_str());
89
90   std::istream is(&sb);
91   std::string out;
92   getline(is, out);
93   ASSERT_EQ(s, out);
94 }
95