string_streams.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <iostream>
13 #include <string>
14 #include <gtest/gtest.h>
15 #include "../../include/ecl/streams/string_stream.hpp"
16 
17 /*****************************************************************************
18 ** Using
19 *****************************************************************************/
20 
21 using std::string;
22 using ecl::StringStream;
23 
24 /*****************************************************************************
25 ** Tests
26 *****************************************************************************/
27 
28 TEST(StringStreams,floatTypes) {
29  StringStream sstream;
30  float f = 33.33;
31  double d = -1.0;
32  sstream << f;
33  sstream >> d;
34  EXPECT_FALSE(sstream.fail());
35  // Give it some room for rounding off
36  EXPECT_GT(33.34,d);
37  EXPECT_LT(33.32,d);
38 }
39 
40 TEST(StringStreams,clearStream) {
41  StringStream sstream;
42  sstream << "dude";
43  sstream.clear();
44  sstream << "aha";
45  EXPECT_FALSE(sstream.fail());
46  EXPECT_EQ(string("aha"),sstream.str());
47 }
48 
49 TEST(StringStreams,integralTypes) {
50  StringStream sstream;
51  int i = 3;
52  int j = -1;
53  sstream << i;
54  sstream >> j;
55  EXPECT_FALSE(sstream.fail());
56  // Give it some room for rounding off
57  EXPECT_EQ(3,j);
58 }
59 
60 TEST(StringStreams,hexTypes) {
61  StringStream sstream;
62  int j = -1;
63  sstream << "0xA0";
64  sstream >> j;
65  EXPECT_FALSE(sstream.fail());
66  // Give it some room for rounding off
67  EXPECT_EQ(160,j);
68 }
69 TEST(StringStreams,multipleOps) {
70  StringStream sstream;
71  string s;
72  sstream << "Hello";
73  sstream >> s;
74  EXPECT_FALSE(sstream.fail());
75  EXPECT_EQ(string("Hello"),s);
76  sstream << "Dude";
77  sstream >> s;
78  EXPECT_FALSE(sstream.fail());
79  EXPECT_EQ(string("Dude"),s);
80 }
81 
82 TEST(StringStreams,readEmptyFail) {
83  StringStream sstream;
84  int j;
85  sstream >> j;
86  EXPECT_TRUE(sstream.fail());
87 }
88 
89 TEST(StringStreams,remaining) {
90  StringStream sstream;
91  sstream << "Dude";
92  EXPECT_EQ(4,sstream.device().remaining());
93 }
94 
95 /*****************************************************************************
96 ** Main
97 *****************************************************************************/
98 
99 int main(int argc, char** argv) {
100  testing::InitGoogleTest(&argc,argv);
101  return RUN_ALL_TESTS();
102 }
103 
104 
int main(int argc, char **argv)
TEST(StringStreams, floatTypes)
void d()
void clear()
Clears the underlying device&#39;s internal buffers.
Convenience wrapper for string device based textstreams.
std::string str()
String representation of the underlying device&#39;s contents.


ecl_streams
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:50