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 
38 void shared_files_f() {
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 }
TEST
TEST(SharedFileTests, allEggsInTheBasket)
Definition: shared_files.cpp:59
ecl::SharedFile::write
long write(const char &c)
Write a character to the buffer.
Definition: shared_file.cpp:177
ecl::devices::tests
Frameworks created for the unit tests.
thread.hpp
main
int main(int argc, char **argv)
Definition: shared_files.cpp:76
ecl::devices::tests::shared_files_f
void shared_files_f()
Definition: shared_files.cpp:44
ecl::New
@ New
Opens a new object (deletes existing objects).
Definition: modes.hpp:50
ecl::SharedFile
Multi-instance (also thread-safe) output file device.
Definition: shared_file.hpp:126
ecl::SharedFile::flush
bool flush()
Flush the internal buffer.
Definition: shared_file.cpp:200
ecl
Embedded control libraries.
timestamp.hpp


ecl_devices
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:45