OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/system/core_test_base.h" | 5 #include "mojo/edk/system/core_test_base.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "mojo/edk/embedder/embedder_internal.h" | 15 #include "mojo/edk/embedder/embedder_internal.h" |
16 #include "mojo/edk/system/configuration.h" | 16 #include "mojo/edk/system/configuration.h" |
17 #include "mojo/edk/system/core.h" | 17 #include "mojo/edk/system/core.h" |
18 #include "mojo/edk/system/dispatcher.h" | 18 #include "mojo/edk/system/dispatcher.h" |
| 19 #include "mojo/edk/system/message_for_transit.h" |
19 | 20 |
20 namespace mojo { | 21 namespace mojo { |
21 namespace edk { | 22 namespace edk { |
22 namespace test { | 23 namespace test { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // MockDispatcher -------------------------------------------------------------- | 27 // MockDispatcher -------------------------------------------------------------- |
27 | 28 |
28 class MockDispatcher : public Dispatcher { | 29 class MockDispatcher : public Dispatcher { |
29 public: | 30 public: |
30 static scoped_refptr<MockDispatcher> Create( | 31 static scoped_refptr<MockDispatcher> Create( |
31 CoreTestBase::MockHandleInfo* info) { | 32 CoreTestBase::MockHandleInfo* info) { |
32 return make_scoped_refptr(new MockDispatcher(info)); | 33 return make_scoped_refptr(new MockDispatcher(info)); |
33 } | 34 } |
34 | 35 |
35 // Dispatcher: | 36 // Dispatcher: |
36 Type GetType() const override { return Type::UNKNOWN; } | 37 Type GetType() const override { return Type::UNKNOWN; } |
37 | 38 |
38 MojoResult Close() override { | 39 MojoResult Close() override { |
39 info_->IncrementCloseCallCount(); | 40 info_->IncrementCloseCallCount(); |
40 return MOJO_RESULT_OK; | 41 return MOJO_RESULT_OK; |
41 } | 42 } |
42 | 43 |
43 MojoResult WriteMessage( | 44 MojoResult WriteMessage( |
44 const void* bytes, | 45 std::unique_ptr<MessageForTransit> message, |
45 uint32_t num_bytes, | |
46 const DispatcherInTransit* dispatchers, | |
47 uint32_t num_dispatchers, | |
48 MojoWriteMessageFlags /*flags*/) override { | 46 MojoWriteMessageFlags /*flags*/) override { |
49 info_->IncrementWriteMessageCallCount(); | 47 info_->IncrementWriteMessageCallCount(); |
50 | 48 |
51 if (num_bytes > GetConfiguration().max_message_num_bytes) | 49 if (message->num_bytes() > GetConfiguration().max_message_num_bytes) |
52 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 50 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
53 | 51 |
54 if (dispatchers) | 52 if (message->num_handles()) |
55 return MOJO_RESULT_UNIMPLEMENTED; | 53 return MOJO_RESULT_UNIMPLEMENTED; |
56 | 54 |
57 return MOJO_RESULT_OK; | 55 return MOJO_RESULT_OK; |
58 } | 56 } |
59 | 57 |
60 MojoResult ReadMessage(void* bytes, | 58 MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, |
61 uint32_t* num_bytes, | 59 uint32_t* num_bytes, |
62 MojoHandle* handle, | 60 MojoHandle* handle, |
63 uint32_t* num_handles, | 61 uint32_t* num_handles, |
64 MojoReadMessageFlags /*flags*/) override { | 62 MojoReadMessageFlags /*flags*/, |
| 63 bool ignore_num_bytes) override { |
65 info_->IncrementReadMessageCallCount(); | 64 info_->IncrementReadMessageCallCount(); |
66 | 65 |
67 if (num_handles) | 66 if (num_handles) |
68 *num_handles = 1; | 67 *num_handles = 1; |
69 | 68 |
70 return MOJO_RESULT_OK; | 69 return MOJO_RESULT_OK; |
71 } | 70 } |
72 | 71 |
73 MojoResult WriteData(const void* elements, | 72 MojoResult WriteData(const void* elements, |
74 uint32_t* num_bytes, | 73 uint32_t* num_bytes, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 334 } |
336 | 335 |
337 void CoreTestBase_MockHandleInfo::AwakableWasAdded(Awakable* awakable) { | 336 void CoreTestBase_MockHandleInfo::AwakableWasAdded(Awakable* awakable) { |
338 base::AutoLock locker(lock_); | 337 base::AutoLock locker(lock_); |
339 added_awakables_.push_back(awakable); | 338 added_awakables_.push_back(awakable); |
340 } | 339 } |
341 | 340 |
342 } // namespace test | 341 } // namespace test |
343 } // namespace edk | 342 } // namespace edk |
344 } // namespace mojo | 343 } // namespace mojo |
OLD | NEW |