file_streams.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 
00012 #include <string>
00013 #include <gtest/gtest.h>
00014 #include <ecl/devices/ofile.hpp>
00015 #include <ecl/exceptions/standard_exception.hpp>
00016 #include "../../include/ecl/streams/file_streams.hpp"
00017 
00018 /*****************************************************************************
00019 ** Using
00020 *****************************************************************************/
00021 
00022 using std::string;
00023 using ecl::OFile;
00024 using ecl::Append;
00025 using ecl::New;
00026 using ecl::StandardException;
00027 using ecl::TextStream;
00028 using ecl::OFileStream;
00029 
00030 /*****************************************************************************
00031 ** Tests
00032 *****************************************************************************/
00033 
00034 TEST(OFileStreamTests,construct) {
00035     OFileStream ostream("dude_stream.txt",New);
00036     EXPECT_TRUE(ostream.device().open());
00037 }
00038 
00039 TEST(OFileStreamTests,writeChar) {
00040     OFileStream ostream("dude_stream.txt",Append);
00041     bool result = true;
00042     try {
00043         ostream << 'c' << '\n';
00044         ostream.flush();
00045     } catch ( const StandardException &e ) {
00046         result = false;
00047     }
00048     EXPECT_TRUE(result);
00049 }
00050 
00051 TEST(OFileStreamTests,writeCharString) {
00052     OFileStream ostream("dude_stream.txt",Append);
00053     bool result = true;
00054     try {
00055         ostream << "Dude\n";
00056         ostream.flush();
00057     } catch ( const StandardException &e ) {
00058         result = false;
00059     }
00060     EXPECT_TRUE(result);
00061 }
00062 
00063 TEST(OFileStreamTests,writeString) {
00064     OFileStream ostream("dude_stream.txt",Append);
00065     bool result = true;
00066     try {
00067         string dude("dude_string\n");
00068         ostream << dude;
00069         ostream.flush();
00070     } catch ( const StandardException &e ) {
00071         result = false;
00072     }
00073     EXPECT_TRUE(result);
00074 }
00075 
00076 TEST(OFileStreamTests,writeIntegralTypes) {
00077     OFileStream ostream("dude_stream.txt",Append);
00078     bool result = true;
00079     try {
00080         short si = 1;
00081         ostream << si << '\n';
00082         int i = 2;
00083         ostream << i << '\n';
00084         long l = 3;
00085         ostream << l << '\n';
00086         long long ll = 4;
00087         ostream << ll << '\n';
00088         unsigned short us = 5;
00089         ostream << us << '\n';
00090         unsigned int ui = 6;
00091         ostream << ui << '\n';
00092         unsigned long ul = 77;
00093         ostream << ul << '\n';
00094         unsigned long long ull = 8888;
00095         ostream << ull << '\n';
00096         ostream << 77 << '\n';
00097         ostream.flush();
00098     } catch ( const StandardException &e ) {
00099         result = false;
00100     }
00101     EXPECT_TRUE(result);
00102 }
00103 
00104 TEST(OFileStreamTests,writeBool) {
00105     OFileStream ostream("dude_stream.txt",Append);
00106     bool result = true;
00107     try {
00108         bool test = true;
00109         ostream << test << '\n';
00110         ostream << false << '\n';
00111         ostream.flush();
00112     } catch ( const StandardException &e ) {
00113         result = false;
00114     }
00115     EXPECT_TRUE(result);
00116 }
00117 
00118 TEST(OFileStreamTests,writeFloatTypes) {
00119     OFileStream ostream("dude_stream.txt",Append);
00120     bool result = true;
00121     try {
00122         float f = 32.1;
00123         double d = -33.3;
00124         ostream << f << '\n';
00125         ostream << d << '\n';
00126         ostream.flush();
00127     } catch ( const StandardException &e ) {
00128         result = false;
00129     }
00130     EXPECT_TRUE(result);
00131 }
00132 
00133 /*****************************************************************************
00134 ** Main
00135 *****************************************************************************/
00136 
00137 int main(int argc, char** argv) {
00138         testing::InitGoogleTest(&argc,argv);
00139         return RUN_ALL_TESTS();
00140 }


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:40