file_streams.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <string>
13 #include <gtest/gtest.h>
14 #include <ecl/devices/ofile.hpp>
16 #include "../../include/ecl/streams/file_streams.hpp"
17 
18 /*****************************************************************************
19 ** Using
20 *****************************************************************************/
21 
22 using std::string;
23 using ecl::OFile;
24 using ecl::Append;
25 using ecl::New;
27 using ecl::TextStream;
28 using ecl::OFileStream;
29 
30 /*****************************************************************************
31 ** Tests
32 *****************************************************************************/
33 
34 TEST(OFileStreamTests,construct) {
35  OFileStream ostream("dude_stream.txt",New);
36  EXPECT_TRUE(ostream.device().open());
37 }
38 
39 TEST(OFileStreamTests,writeChar) {
40  OFileStream ostream("dude_stream.txt",Append);
41  bool result = true;
42  try {
43  ostream << 'c' << '\n';
44  ostream.flush();
45  } catch ( const StandardException &e ) {
46  result = false;
47  }
48  EXPECT_TRUE(result);
49 }
50 
51 TEST(OFileStreamTests,writeCharString) {
52  OFileStream ostream("dude_stream.txt",Append);
53  bool result = true;
54  try {
55  ostream << "Dude\n";
56  ostream.flush();
57  } catch ( const StandardException &e ) {
58  result = false;
59  }
60  EXPECT_TRUE(result);
61 }
62 
63 TEST(OFileStreamTests,writeString) {
64  OFileStream ostream("dude_stream.txt",Append);
65  bool result = true;
66  try {
67  string dude("dude_string\n");
68  ostream << dude;
69  ostream.flush();
70  } catch ( const StandardException &e ) {
71  result = false;
72  }
73  EXPECT_TRUE(result);
74 }
75 
76 TEST(OFileStreamTests,writeIntegralTypes) {
77  OFileStream ostream("dude_stream.txt",Append);
78  bool result = true;
79  try {
80  short si = 1;
81  ostream << si << '\n';
82  int i = 2;
83  ostream << i << '\n';
84  long l = 3;
85  ostream << l << '\n';
86  long long ll = 4;
87  ostream << ll << '\n';
88  unsigned short us = 5;
89  ostream << us << '\n';
90  unsigned int ui = 6;
91  ostream << ui << '\n';
92  unsigned long ul = 77;
93  ostream << ul << '\n';
94  unsigned long long ull = 8888;
95  ostream << ull << '\n';
96  ostream << 77 << '\n';
97  ostream.flush();
98  } catch ( const StandardException &e ) {
99  result = false;
100  }
101  EXPECT_TRUE(result);
102 }
103 
104 TEST(OFileStreamTests,writeBool) {
105  OFileStream ostream("dude_stream.txt",Append);
106  bool result = true;
107  try {
108  bool test = true;
109  ostream << test << '\n';
110  ostream << false << '\n';
111  ostream.flush();
112  } catch ( const StandardException &e ) {
113  result = false;
114  }
115  EXPECT_TRUE(result);
116 }
117 
118 TEST(OFileStreamTests,writeFloatTypes) {
119  OFileStream ostream("dude_stream.txt",Append);
120  bool result = true;
121  try {
122  float f = 32.1;
123  double d = -33.3;
124  ostream << f << '\n';
125  ostream << d << '\n';
126  ostream.flush();
127  } catch ( const StandardException &e ) {
128  result = false;
129  }
130  EXPECT_TRUE(result);
131 }
132 
133 /*****************************************************************************
134 ** Main
135 *****************************************************************************/
136 
137 int main(int argc, char** argv) {
138  testing::InitGoogleTest(&argc,argv);
139  return RUN_ALL_TESTS();
140 }
ecl::demos::f
void f()
Definition: log_streams.cpp:55
ecl::TextStream
A text streaming interface.
Definition: text_stream.hpp:100
ecl::New
New
ecl::Append
Append
TEST
TEST(OFileStreamTests, construct)
Definition: file_streams.cpp:34
d
void d()
ecl::StandardException
ofile.hpp
standard_exception.hpp
main
int main(int argc, char **argv)
Definition: file_streams.cpp:137
ecl::OFileStream
Convenience class for OFile TextStream definitions.
Definition: file_streams.hpp:48


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:48