shared_files.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <iostream>
13 #include <gtest/gtest.h>
14 #include <ecl/threads/thread.hpp>
15 #include <ecl/time/timestamp.hpp>
16 #include "../../include/ecl/devices/shared_file.hpp"
17 
18 /*****************************************************************************
19 ** Using
20 *****************************************************************************/
21 
22 using ecl::New;
23 using ecl::SharedFile;
24 using ecl::Thread;
25 
26 /*****************************************************************************
27 ** Namespaces
28 *****************************************************************************/
29 
30 namespace ecl {
31 namespace devices {
32 namespace tests {
33 
34 /*****************************************************************************
35 ** Globals
36 *****************************************************************************/
37 
39  SharedFile file("shared.txt");
40  long n;
41  for (unsigned int i = 0; i < 3; ++i ) {
42  n = file.write("Thread\n",7);
43  EXPECT_EQ(7,n);
44  }
45  file.flush();
46 }
47 
48 
49 } // namespace tests
50 } // namespace devices
51 } // namespace ecl
52 
53 /*****************************************************************************
54 ** Using
55 *****************************************************************************/
56 
57 using namespace ecl::devices::tests;
58 
59 TEST(SharedFileTests,allEggsInTheBasket) {
60 
61  SharedFile file("shared.txt");
62  Thread thread(shared_files_f);
63  long n;
64  for (unsigned int i = 0; i < 3; ++i ) {
65  n = file.write("Main\n",5);
66  EXPECT_EQ(5,n);
67  }
68  file.flush();
69  thread.join();
70 }
71 
72 /*****************************************************************************
73 ** Main program
74 *****************************************************************************/
75 
76 int main(int argc, char **argv) {
77 
78  testing::InitGoogleTest(&argc,argv);
79  return RUN_ALL_TESTS();
80 }
Embedded control libraries.
TEST(SharedFileTests, allEggsInTheBasket)
Frameworks created for the unit tests.
int main(int argc, char **argv)
Multi-instance (also thread-safe) output file device.
bool flush() ecl_debug_throw_decl(StandardException)
Flush the internal buffer.
long write(const char &c) ecl_debug_throw_decl(StandardException)
Write a character to the buffer.
Opens a new object (deletes existing objects).
Definition: modes.hpp:36


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