thread_test.cpp
Go to the documentation of this file.
1 
11 #include <opc/common/thread.h>
12 
13 #include <gmock/gmock.h>
14 #include <gtest/gtest.h>
15 
16 using namespace testing;
17 
18 namespace
19 {
20 
21 class TestThreadObserver : public Common::ThreadObserver
22 {
23 public:
24  TestThreadObserver()
25  : OnSuccessCallCount(0)
26  , OnErrorCallCount(0)
27  {
28  }
29 
30  virtual void OnSuccess() override
31  {
32  ++OnSuccessCallCount;
33  }
34 
35  virtual void OnError(const std::exception & exc) override
36  {
37  ++OnErrorCallCount;
38  }
39 
40 public:
41  volatile unsigned OnSuccessCallCount;
42  volatile unsigned OnErrorCallCount;
43 };
44 
45 void DoNothing()
46 {
47 }
48 
49 void ThrowsException()
50 {
51  throw std::logic_error("oppps!");
52 }
53 
54 }
55 
56 TEST(Thread, CallsOnSuccess)
57 {
58  TestThreadObserver observer;
59 
60  Common::Thread thread(std::function<void()>(DoNothing), &observer);
61  thread.Join();
62  EXPECT_EQ(observer.OnSuccessCallCount, 1);
63  EXPECT_EQ(observer.OnErrorCallCount, 0);
64 }
65 
66 TEST(Thread, CallsOnError)
67 {
68  TestThreadObserver observer;
69 
70  Common::Thread thread(std::function<void()>(ThrowsException), &observer);
71  thread.Join();
72  EXPECT_EQ(observer.OnSuccessCallCount, 0);
73  EXPECT_EQ(observer.OnErrorCallCount, 1);
74 }
75 
void Join()
Wait until started thread stop.
Definition: thread.cpp:37
TEST(GTestEnvVarTest, Dummy)
#define EXPECT_EQ(expected, actual)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08