Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include <cstdlib>
00013 #include <iostream>
00014 #include <algorithm>
00015 #include <gtest/gtest.h>
00016 #include <ecl/exceptions/standard_exception.hpp>
00017 #include <ecl/containers/array.hpp>
00018 #include "../../include/ecl/devices/detail/character_buffer.hpp"
00019 #include "../../include/ecl/devices/ofile.hpp"
00020
00021
00022
00023
00024
00025 using ecl::Append;
00026 using ecl::devices::CharStringBuffer;
00027 using ecl::New;
00028 using ecl::OFile;
00029 using ecl::StandardException;
00030
00031
00032
00033
00034
00035 TEST(FilesTests,construct) {
00036
00037 bool result = true;
00038 try {
00039 OFile o_file1("odude.txt",New);
00040 OFile o_file2;
00041 o_file2.open("odude2.txt",New);
00042 } catch ( const StandardException& e ) {
00043 result = false;
00044 }
00045 EXPECT_TRUE(result);
00046 }
00047
00048 TEST(FilesTests,write) {
00049 OFile o_file1("odude.txt",New);
00050 OFile o_file2;
00051 o_file2.open("odude2.txt",New);
00052 long n;
00053 n = o_file1.write("Heya Dude\n",10);
00054 o_file1.flush();
00055 EXPECT_EQ(10,n);
00056 n = o_file2.write("Heya Dude\n",10);
00057 o_file2.flush();
00058 EXPECT_EQ(10,n);
00059 std::string heya_dude("Heya Dude From Array\n");
00060 ecl::Array<char,256> buffer;
00061 std::copy(heya_dude.begin(), heya_dude.end(), buffer.begin());
00062 n = o_file2.write(buffer.stencil(0,heya_dude.size()));
00063 o_file2.flush();
00064 EXPECT_EQ(21,n);
00065
00066
00067
00068
00069
00070
00071
00072 }
00073
00074 TEST(FilesTests,append) {
00075 OFile o_file("odude.txt",Append);
00076 long n;
00077 n = o_file.write("Appending Dude\n",15);
00078 EXPECT_EQ(15,n);
00079 EXPECT_TRUE( o_file.flush());
00080 }
00081
00082 TEST(FilesTest,isOpen) {
00083 OFile o_file1("odude2.txt",Append);
00084 EXPECT_TRUE( o_file1.open());
00085 OFile o_file2;
00086 EXPECT_FALSE( o_file2.open());
00087 }
00088
00089
00090
00091
00092
00093 int main(int argc, char **argv) {
00094
00095 testing::InitGoogleTest(&argc,argv);
00096 return RUN_ALL_TESTS();
00097 }
00098