- add sources.
[platform/framework/web/crosswalk.git] / src / mojo / system / core_test_base.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_SYSTEM_CORE_TEST_BASE_H_
6 #define MOJO_SYSTEM_CORE_TEST_BASE_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/synchronization/lock.h"
11 #include "mojo/public/system/core.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace mojo {
15 namespace system {
16
17 class CoreImpl;
18
19 namespace test {
20
21 class CoreTestBase_MockHandleInfo;
22
23 class CoreTestBase : public testing::Test {
24  public:
25   typedef CoreTestBase_MockHandleInfo MockHandleInfo;
26
27   CoreTestBase();
28   virtual ~CoreTestBase();
29
30   virtual void SetUp() OVERRIDE;
31   virtual void TearDown() OVERRIDE;
32
33  protected:
34   // |info| must remain alive until the returned handle is closed.
35   MojoHandle CreateMockHandle(MockHandleInfo* info);
36
37   CoreImpl* core() { return core_; }
38
39  private:
40   CoreImpl* core_;
41
42   DISALLOW_COPY_AND_ASSIGN(CoreTestBase);
43 };
44
45 class CoreTestBase_MockHandleInfo {
46  public:
47   CoreTestBase_MockHandleInfo();
48   ~CoreTestBase_MockHandleInfo();
49
50   unsigned GetCtorCallCount() const;
51   unsigned GetDtorCallCount() const;
52   unsigned GetCloseCallCount() const;
53   unsigned GetWriteMessageCallCount() const;
54   unsigned GetReadMessageCallCount() const;
55   unsigned GetAddWaiterCallCount() const;
56   unsigned GetRemoveWaiterCallCount() const;
57   unsigned GetCancelAllWaitersCallCount() const;
58
59   // For use by |MockDispatcher|:
60   void IncrementCtorCallCount();
61   void IncrementDtorCallCount();
62   void IncrementCloseCallCount();
63   void IncrementWriteMessageCallCount();
64   void IncrementReadMessageCallCount();
65   void IncrementAddWaiterCallCount();
66   void IncrementRemoveWaiterCallCount();
67   void IncrementCancelAllWaitersCallCount();
68
69  private:
70   mutable base::Lock lock_;  // Protects the following members.
71   unsigned ctor_call_count_;
72   unsigned dtor_call_count_;
73   unsigned close_call_count_;
74   unsigned write_message_call_count_;
75   unsigned read_message_call_count_;
76   unsigned add_waiter_call_count_;
77   unsigned remove_waiter_call_count_;
78   unsigned cancel_all_waiters_call_count_;
79
80   DISALLOW_COPY_AND_ASSIGN(CoreTestBase_MockHandleInfo);
81 };
82
83 }  // namespace test
84 }  // namespace system
85 }  // namespace mojo
86
87 #endif  // MOJO_SYSTEM_CORE_TEST_BASE_H_