summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-12 23:24:17 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-12 23:24:17 +0000
commit76c4725b4165d28e9f147a1d746622aceca482f6 (patch)
treeac9e9adbe9e6b447f3851d01953fc57e3585dada
parentb9c63179499d968be5b9f969cad3d3ac364a90ed (diff)
downloadchromium_src-76c4725b4165d28e9f147a1d746622aceca482f6.zip
chromium_src-76c4725b4165d28e9f147a1d746622aceca482f6.tar.gz
chromium_src-76c4725b4165d28e9f147a1d746622aceca482f6.tar.bz2
Mojo: data pipe boilerplate testing (and hooking up).
I implemented the stupid boilerplate tests ... which then promptly failed, pointing out that I had forgotten to hook up my boilerplate. Oops. R=sky@chromium.org Review URL: https://codereview.chromium.org/99173008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240473 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/system/core_impl.cc24
-rw-r--r--mojo/system/core_impl_unittest.cc30
-rw-r--r--mojo/system/core_test_base.cc118
-rw-r--r--mojo/system/core_test_base.h18
4 files changed, 171 insertions, 19 deletions
diff --git a/mojo/system/core_impl.cc b/mojo/system/core_impl.cc
index a8526b9..60b6325 100644
--- a/mojo/system/core_impl.cc
+++ b/mojo/system/core_impl.cc
@@ -367,9 +367,7 @@ MojoResult CoreImpl::WriteData(MojoHandle data_pipe_producer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->WriteData(elements, num_elements, flags);
}
MojoResult CoreImpl::BeginWriteData(MojoHandle data_pipe_producer_handle,
@@ -381,9 +379,7 @@ MojoResult CoreImpl::BeginWriteData(MojoHandle data_pipe_producer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->BeginWriteData(buffer, buffer_num_elements, flags);
}
MojoResult CoreImpl::EndWriteData(MojoHandle data_pipe_producer_handle,
@@ -393,9 +389,7 @@ MojoResult CoreImpl::EndWriteData(MojoHandle data_pipe_producer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->EndWriteData(num_elements_written);
}
MojoResult CoreImpl::ReadData(MojoHandle data_pipe_consumer_handle,
@@ -407,9 +401,7 @@ MojoResult CoreImpl::ReadData(MojoHandle data_pipe_consumer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->ReadData(elements, num_elements, flags);
}
MojoResult CoreImpl::BeginReadData(MojoHandle data_pipe_consumer_handle,
@@ -421,9 +413,7 @@ MojoResult CoreImpl::BeginReadData(MojoHandle data_pipe_consumer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->BeginReadData(buffer, buffer_num_elements, flags);
}
MojoResult CoreImpl::EndReadData(MojoHandle data_pipe_consumer_handle,
@@ -433,9 +423,7 @@ MojoResult CoreImpl::EndReadData(MojoHandle data_pipe_consumer_handle,
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
- // TODO(vtl)
- NOTIMPLEMENTED();
- return MOJO_RESULT_UNIMPLEMENTED;
+ return dispatcher->EndReadData(num_elements_read);
}
CoreImpl::CoreImpl()
diff --git a/mojo/system/core_impl_unittest.cc b/mojo/system/core_impl_unittest.cc
index b128a52..ca8446f 100644
--- a/mojo/system/core_impl_unittest.cc
+++ b/mojo/system/core_impl_unittest.cc
@@ -62,6 +62,36 @@ TEST_F(CoreImplTest, Basic) {
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(3u, info.GetReadMessageCallCount());
+ EXPECT_EQ(0u, info.GetWriteDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->WriteData(h, NULL, NULL, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, info.GetWriteDataCallCount());
+
+ EXPECT_EQ(0u, info.GetBeginWriteDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->BeginWriteData(h, NULL, NULL, MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, info.GetBeginWriteDataCallCount());
+
+ EXPECT_EQ(0u, info.GetEndWriteDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->EndWriteData(h, 0));
+ EXPECT_EQ(1u, info.GetEndWriteDataCallCount());
+
+ EXPECT_EQ(0u, info.GetReadDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->ReadData(h, NULL, NULL, MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, info.GetReadDataCallCount());
+
+ EXPECT_EQ(0u, info.GetBeginReadDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->BeginReadData(h, NULL, NULL, MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(1u, info.GetBeginReadDataCallCount());
+
+ EXPECT_EQ(0u, info.GetEndReadDataCallCount());
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->EndReadData(h, 0));
+ EXPECT_EQ(1u, info.GetEndReadDataCallCount());
+
EXPECT_EQ(0u, info.GetAddWaiterCallCount());
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
core()->Wait(h, MOJO_WAIT_FLAG_EVERYTHING,
diff --git a/mojo/system/core_test_base.cc b/mojo/system/core_test_base.cc
index a0b0ed4..47fd5ae 100644
--- a/mojo/system/core_test_base.cc
+++ b/mojo/system/core_test_base.cc
@@ -63,7 +63,8 @@ class MockDispatcher : public Dispatcher {
}
virtual MojoResult ReadMessageImplNoLock(
- void* bytes, uint32_t* num_bytes,
+ void* bytes,
+ uint32_t* num_bytes,
std::vector<scoped_refptr<Dispatcher> >* /*dispatchers*/,
uint32_t* /*num_dispatchers*/,
MojoReadMessageFlags /*flags*/) OVERRIDE {
@@ -76,6 +77,55 @@ class MockDispatcher : public Dispatcher {
return MOJO_RESULT_OK;
}
+ virtual MojoResult WriteDataImplNoLock(
+ const void* /*elements*/,
+ uint32_t* /*num_elements*/,
+ MojoWriteDataFlags /*flags*/) OVERRIDE {
+ info_->IncrementWriteDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
+ virtual MojoResult BeginWriteDataImplNoLock(
+ void** /*buffer*/,
+ uint32_t* /*buffer_num_elements*/,
+ MojoWriteDataFlags /*flags*/) OVERRIDE {
+ info_->IncrementBeginWriteDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
+ virtual MojoResult EndWriteDataImplNoLock(
+ uint32_t /*num_elements_written*/) OVERRIDE {
+ info_->IncrementEndWriteDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
+ virtual MojoResult ReadDataImplNoLock(void* /*elements*/,
+ uint32_t* /*num_elements*/,
+ MojoReadDataFlags /*flags*/) OVERRIDE {
+ info_->IncrementReadDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
+ virtual MojoResult BeginReadDataImplNoLock(
+ const void** /*buffer*/,
+ uint32_t* /*buffer_num_elements*/,
+ MojoReadDataFlags /*flags*/) OVERRIDE {
+ info_->IncrementBeginReadDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
+ virtual MojoResult EndReadDataImplNoLock(
+ uint32_t /*num_elements_read*/) OVERRIDE {
+ info_->IncrementEndReadDataCallCount();
+ lock().AssertAcquired();
+ return MOJO_RESULT_UNIMPLEMENTED;
+ }
+
virtual MojoResult AddWaiterImplNoLock(Waiter* /*waiter*/,
MojoWaitFlags /*flags*/,
MojoResult /*wake_result*/) OVERRIDE {
@@ -138,6 +188,12 @@ CoreTestBase_MockHandleInfo::CoreTestBase_MockHandleInfo()
close_call_count_(0),
write_message_call_count_(0),
read_message_call_count_(0),
+ write_data_call_count_(0),
+ begin_write_data_call_count_(0),
+ end_write_data_call_count_(0),
+ read_data_call_count_(0),
+ begin_read_data_call_count_(0),
+ end_read_data_call_count_(0),
add_waiter_call_count_(0),
remove_waiter_call_count_(0),
cancel_all_waiters_call_count_(0) {
@@ -171,6 +227,36 @@ unsigned CoreTestBase_MockHandleInfo::GetReadMessageCallCount() const {
return read_message_call_count_;
}
+unsigned CoreTestBase_MockHandleInfo::GetWriteDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return write_data_call_count_;
+}
+
+unsigned CoreTestBase_MockHandleInfo::GetBeginWriteDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return begin_write_data_call_count_;
+}
+
+unsigned CoreTestBase_MockHandleInfo::GetEndWriteDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return end_write_data_call_count_;
+}
+
+unsigned CoreTestBase_MockHandleInfo::GetReadDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return read_data_call_count_;
+}
+
+unsigned CoreTestBase_MockHandleInfo::GetBeginReadDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return begin_read_data_call_count_;
+}
+
+unsigned CoreTestBase_MockHandleInfo::GetEndReadDataCallCount() const {
+ base::AutoLock locker(lock_);
+ return end_read_data_call_count_;
+}
+
unsigned CoreTestBase_MockHandleInfo::GetAddWaiterCallCount() const {
base::AutoLock locker(lock_);
return add_waiter_call_count_;
@@ -211,6 +297,36 @@ void CoreTestBase_MockHandleInfo::IncrementReadMessageCallCount() {
read_message_call_count_++;
}
+void CoreTestBase_MockHandleInfo::IncrementWriteDataCallCount() {
+ base::AutoLock locker(lock_);
+ write_data_call_count_++;
+}
+
+void CoreTestBase_MockHandleInfo::IncrementBeginWriteDataCallCount() {
+ base::AutoLock locker(lock_);
+ begin_write_data_call_count_++;
+}
+
+void CoreTestBase_MockHandleInfo::IncrementEndWriteDataCallCount() {
+ base::AutoLock locker(lock_);
+ end_write_data_call_count_++;
+}
+
+void CoreTestBase_MockHandleInfo::IncrementReadDataCallCount() {
+ base::AutoLock locker(lock_);
+ read_data_call_count_++;
+}
+
+void CoreTestBase_MockHandleInfo::IncrementBeginReadDataCallCount() {
+ base::AutoLock locker(lock_);
+ begin_read_data_call_count_++;
+}
+
+void CoreTestBase_MockHandleInfo::IncrementEndReadDataCallCount() {
+ base::AutoLock locker(lock_);
+ end_read_data_call_count_++;
+}
+
void CoreTestBase_MockHandleInfo::IncrementAddWaiterCallCount() {
base::AutoLock locker(lock_);
add_waiter_call_count_++;
diff --git a/mojo/system/core_test_base.h b/mojo/system/core_test_base.h
index 114e62e..58b2045 100644
--- a/mojo/system/core_test_base.h
+++ b/mojo/system/core_test_base.h
@@ -52,6 +52,12 @@ class CoreTestBase_MockHandleInfo {
unsigned GetCloseCallCount() const;
unsigned GetWriteMessageCallCount() const;
unsigned GetReadMessageCallCount() const;
+ unsigned GetWriteDataCallCount() const;
+ unsigned GetBeginWriteDataCallCount() const;
+ unsigned GetEndWriteDataCallCount() const;
+ unsigned GetReadDataCallCount() const;
+ unsigned GetBeginReadDataCallCount() const;
+ unsigned GetEndReadDataCallCount() const;
unsigned GetAddWaiterCallCount() const;
unsigned GetRemoveWaiterCallCount() const;
unsigned GetCancelAllWaitersCallCount() const;
@@ -62,6 +68,12 @@ class CoreTestBase_MockHandleInfo {
void IncrementCloseCallCount();
void IncrementWriteMessageCallCount();
void IncrementReadMessageCallCount();
+ void IncrementWriteDataCallCount();
+ void IncrementBeginWriteDataCallCount();
+ void IncrementEndWriteDataCallCount();
+ void IncrementReadDataCallCount();
+ void IncrementBeginReadDataCallCount();
+ void IncrementEndReadDataCallCount();
void IncrementAddWaiterCallCount();
void IncrementRemoveWaiterCallCount();
void IncrementCancelAllWaitersCallCount();
@@ -73,6 +85,12 @@ class CoreTestBase_MockHandleInfo {
unsigned close_call_count_;
unsigned write_message_call_count_;
unsigned read_message_call_count_;
+ unsigned write_data_call_count_;
+ unsigned begin_write_data_call_count_;
+ unsigned end_write_data_call_count_;
+ unsigned read_data_call_count_;
+ unsigned begin_read_data_call_count_;
+ unsigned end_read_data_call_count_;
unsigned add_waiter_call_count_;
unsigned remove_waiter_call_count_;
unsigned cancel_all_waiters_call_count_;