Home | History | Annotate | Download | only in core
      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_CORE_CORE_TEST_BASE_H_
      6 #define MOJO_CORE_CORE_TEST_BASE_H_
      7 
      8 #include <stddef.h>
      9 
     10 #include "base/macros.h"
     11 #include "base/synchronization/lock.h"
     12 #include "mojo/core/test_utils.h"
     13 #include "mojo/public/c/system/types.h"
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 
     16 namespace mojo {
     17 namespace core {
     18 
     19 class Core;
     20 
     21 namespace test {
     22 
     23 class CoreTestBase_MockHandleInfo;
     24 
     25 class CoreTestBase : public testing::Test {
     26  public:
     27   using MockHandleInfo = CoreTestBase_MockHandleInfo;
     28 
     29   CoreTestBase();
     30   ~CoreTestBase() override;
     31 
     32  protected:
     33   // |info| must remain alive until the returned handle is closed.
     34   MojoHandle CreateMockHandle(MockHandleInfo* info);
     35 
     36   Core* core();
     37 
     38  private:
     39   DISALLOW_COPY_AND_ASSIGN(CoreTestBase);
     40 };
     41 
     42 class CoreTestBase_MockHandleInfo {
     43  public:
     44   CoreTestBase_MockHandleInfo();
     45   ~CoreTestBase_MockHandleInfo();
     46 
     47   unsigned GetCtorCallCount() const;
     48   unsigned GetDtorCallCount() const;
     49   unsigned GetCloseCallCount() const;
     50   unsigned GetWriteMessageCallCount() const;
     51   unsigned GetReadMessageCallCount() const;
     52   unsigned GetWriteDataCallCount() const;
     53   unsigned GetBeginWriteDataCallCount() const;
     54   unsigned GetEndWriteDataCallCount() const;
     55   unsigned GetReadDataCallCount() const;
     56   unsigned GetBeginReadDataCallCount() const;
     57   unsigned GetEndReadDataCallCount() const;
     58 
     59   // For use by |MockDispatcher|:
     60   void IncrementCtorCallCount();
     61   void IncrementDtorCallCount();
     62   void IncrementCloseCallCount();
     63   void IncrementWriteMessageCallCount();
     64   void IncrementReadMessageCallCount();
     65   void IncrementWriteDataCallCount();
     66   void IncrementBeginWriteDataCallCount();
     67   void IncrementEndWriteDataCallCount();
     68   void IncrementReadDataCallCount();
     69   void IncrementBeginReadDataCallCount();
     70   void IncrementEndReadDataCallCount();
     71 
     72  private:
     73   mutable base::Lock lock_;  // Protects the following members.
     74   unsigned ctor_call_count_;
     75   unsigned dtor_call_count_;
     76   unsigned close_call_count_;
     77   unsigned write_message_call_count_;
     78   unsigned read_message_call_count_;
     79   unsigned write_data_call_count_;
     80   unsigned begin_write_data_call_count_;
     81   unsigned end_write_data_call_count_;
     82   unsigned read_data_call_count_;
     83   unsigned begin_read_data_call_count_;
     84   unsigned end_read_data_call_count_;
     85 
     86   DISALLOW_COPY_AND_ASSIGN(CoreTestBase_MockHandleInfo);
     87 };
     88 
     89 }  // namespace test
     90 }  // namespace core
     91 }  // namespace mojo
     92 
     93 #endif  // MOJO_CORE_CORE_TEST_BASE_H_
     94