diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-20 01:07:17 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-20 01:07:17 +0000 |
commit | 12f9766f28712f8ec3755db4558dba4db5bd8a70 (patch) | |
tree | 6ab911b0b85b1851bef201f25825911d4a66849e /dbus/test_service.h | |
parent | 940895b5308ace929396a87bd13cf0764f0c16e2 (diff) | |
download | chromium_src-12f9766f28712f8ec3755db4558dba4db5bd8a70.zip chromium_src-12f9766f28712f8ec3755db4558dba4db5bd8a70.tar.gz chromium_src-12f9766f28712f8ec3755db4558dba4db5bd8a70.tar.bz2 |
Rework TestService using asynchronos API of ExportedObject.
This change is to to exercise asynchronos API of ExportedObject.
The asynchronos API is implemented on top the synchronos API,
hence the synchronos API code is also covered.
Along the way, change EndToEndAsyncTest to use the D-Bus thread.
Simplified the test code per phajdan.jr's comments as well.
TEST=dbus_unittests
BUG=90036
Review URL: http://codereview.chromium.org/7671028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/test_service.h')
-rw-r--r-- | dbus/test_service.h | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/dbus/test_service.h b/dbus/test_service.h index 362ecb7..7d1abf7 100644 --- a/dbus/test_service.h +++ b/dbus/test_service.h @@ -6,10 +6,10 @@ #define DBUS_TEST_SERVICE_H_ #pragma once +#include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/threading/thread.h" -#include "base/synchronization/condition_variable.h" -#include "base/synchronization/lock.h" +#include "base/synchronization/waitable_event.h" namespace dbus { @@ -23,28 +23,53 @@ class Response; // the main thread. Methods such as Echo() and SlowEcho() are exported. class TestService : public base::Thread { public: - // SlowEcho() sleeps for this period of time before returns. - static const int kSlowEchoSleepMs; + // Options for the test service. + struct Options { + Options(); + ~Options(); - TestService(); + // NULL by default (i.e. don't use the D-Bus thread). + base::Thread* dbus_thread; + }; + + // The number of methods we'll export. + static const int kNumMethodsToExport; + + TestService(const Options& options); virtual ~TestService(); // Starts the service in a separate thread. - void StartService(); + // Returns true if the thread is started successfully. + bool StartService(); + + // Waits until the service is started (i.e. all methods are exported). + // Returns true on success. + bool WaitUntilServiceIsStarted() WARN_UNUSED_RESULT; + + // Shuts down the service. + void Shutdown(); + + // Waits until the service is shut down. + // Returns true on success. + bool WaitUntilServiceIsShutdown() WARN_UNUSED_RESULT; - // Waits until the service is started (i.e. methods are exported). - void WaitUntilServiceIsStarted(); + // Returns true if the bus has the D-Bus thread. + bool HasDBusThread(); private: - // Called when the service is started (i.e. the task is run from the - // message loop). - void OnServiceStarted(); + // Helper function used in Shutdown(). + void ShutdownInternal(); - // base::Thread override. - virtual void Run(MessageLoop* message_loop); + // Called when a method is exported. + void OnExported(const std::string& interface_name, + const std::string& method_name, + bool success); + + // Called when the bus is shut down. + void OnShutdown(); // base::Thread override. - virtual void CleanUp(); + virtual void Run(MessageLoop* message_loop); // // Exported methods. @@ -54,15 +79,17 @@ class TestService : public base::Thread { Response* Echo(MethodCall* method_call); // Echos the text message received from the method call, but sleeps for - // kSlowEchoSleepMs before returning the response. + // TestTimeouts::tiny_timeout_ms() before returning the response. Response* SlowEcho(MethodCall* method_call); // Returns NULL, instead of a valid Response. Response* BrokenMethod(MethodCall* method_call); - bool service_started_; - base::Lock service_started_lock_; - base::ConditionVariable on_service_started_; + base::Thread* dbus_thread_; + base::WaitableEvent on_shutdown_; + base::WaitableEvent on_all_methods_exported_; + // The number of methods actually exported. + int num_exported_methods_; scoped_refptr<Bus> bus_; ExportedObject* exported_object_; |