files.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <cstdlib>
13 #include <iostream>
14 #include <algorithm>
15 #include <gtest/gtest.h>
17 #include <ecl/containers/array.hpp>
18 #include "../../include/ecl/devices/detail/character_buffer.hpp"
19 #include "../../include/ecl/devices/ofile.hpp"
20 
21 /*****************************************************************************
22 ** Using
23 *****************************************************************************/
24 
25 using ecl::Append;
27 using ecl::New;
28 using ecl::OFile;
30 
31 /*****************************************************************************
32 ** Tests
33 *****************************************************************************/
34 
35 TEST(FilesTests,construct) {
36 
37  bool result = true;
38  try {
39  OFile o_file1("odude.txt",New);
40  OFile o_file2;
41  o_file2.open("odude2.txt",New);
42  } catch ( const StandardException& e ) {
43  result = false;
44  }
45  EXPECT_TRUE(result);
46 }
47 
48 TEST(FilesTests,write) {
49  OFile o_file1("odude.txt",New);
50  OFile o_file2;
51  o_file2.open("odude2.txt",New);
52  long n;
53  n = o_file1.write("Heya Dude\n",10);
54  o_file1.flush();
55  EXPECT_EQ(10,n);
56  n = o_file2.write("Heya Dude\n",10);
57  o_file2.flush();
58  EXPECT_EQ(10,n);
59  std::string heya_dude("Heya Dude From Array\n");
60  ecl::Array<char,256> buffer;
61  std::copy(heya_dude.begin(), heya_dude.end(), buffer.begin());
62  n = o_file2.write(buffer.stencil(0,heya_dude.size()));
63  o_file2.flush();
64  EXPECT_EQ(21,n);
65 // This is an interesting test of the buffer which sometimes gets autoflushed
66 // for ( unsigned int i = 0; i < CharStringBuffer::buffer_size/10 + 1; ++i ) {
67 // o_file1.write("Heya Dude\n",10);
68 // o_file1.flush();
69 // o_file2.write("Heya Dude\n",10);
70 // o_file2.flush();
71 // }
72 }
73 
74 TEST(FilesTests,append) {
75  OFile o_file("odude.txt",Append);
76  long n;
77  n = o_file.write("Appending Dude\n",15);
78  EXPECT_EQ(15,n);
79  EXPECT_TRUE( o_file.flush());
80 }
81 
82 TEST(FilesTest,isOpen) {
83  OFile o_file1("odude2.txt",Append);
84  EXPECT_TRUE( o_file1.open());
85  OFile o_file2;
86  EXPECT_FALSE( o_file2.open());
87 }
88 
89 /*****************************************************************************
90 ** Main program
91 *****************************************************************************/
92 
93 int main(int argc, char **argv) {
94 
95  testing::InitGoogleTest(&argc,argv);
96  return RUN_ALL_TESTS();
97 }
98 
int main(int argc, char **argv)
Definition: files.cpp:93
Stencil< Array< Type, Size > > stencil(const unsigned int &start_index, const unsigned int &n) ecl_assert_throw_decl(StandardException)
TEST(FilesTests, construct)
Definition: files.cpp:35
Simple char string buffer class for use internally by the devices.
iterator begin()
Opens a new object (deletes existing objects).
Definition: modes.hpp:36
Appends to an existing object (opens if not existing).
Definition: modes.hpp:37


ecl_devices
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:45