diff options
| author | Michal Hruby <michal.mhr@gmail.com> | 2012-11-13 15:11:24 +0100 | 
|---|---|---|
| committer | Michal Hruby <michal.mhr@gmail.com> | 2012-11-13 15:11:24 +0100 | 
| commit | 01d77af4108751948d0b46817fd1b14d192f8496 (patch) | |
| tree | 8b5efab047c792e10377de54ddc52c73e7a70310 | |
| parent | acb5650c8fa9cd7be7fc505e85947f14374c71e9 (diff) | |
Add a few more tests
(bzr r2866.7.3)
| -rw-r--r-- | UnityCore/GLibDBusProxy.cpp | 6 | ||||
| -rw-r--r-- | tests/test_gdbus_proxy.cpp | 71 | 
2 files changed, 73 insertions, 4 deletions
| diff --git a/UnityCore/GLibDBusProxy.cpp b/UnityCore/GLibDBusProxy.cpp index cacdbb969..bcd22bb18 100644 --- a/UnityCore/GLibDBusProxy.cpp +++ b/UnityCore/GLibDBusProxy.cpp @@ -325,10 +325,12 @@ void DBusProxy::Impl::Call(string const& method_name,  GDBusCallFlags flags,  int timeout_msec)  { + GCancellable* target_canc = cancellable != NULL ? cancellable : cancellable_; +  if (!proxy_)  {  glib::Variant sinked_parameters(parameters); - glib::Object<GCancellable>canc(cancellable, glib::AddRef()); + glib::Object<GCancellable>canc(target_canc, glib::AddRef());  WaitForProxy(canc, timeout_msec, [this, method_name, sinked_parameters, callback, canc, flags, timeout_msec] (glib::Error const& err)  {  if (err) @@ -354,7 +356,7 @@ void DBusProxy::Impl::Call(string const& method_name,  parameters,  flags,  timeout_msec, - cancellable != NULL ? cancellable : cancellable_, + target_canc,  DBusProxy::Impl::OnCallCallback,  data);  } diff --git a/tests/test_gdbus_proxy.cpp b/tests/test_gdbus_proxy.cpp index 50347b55f..3e46913c3 100644 --- a/tests/test_gdbus_proxy.cpp +++ b/tests/test_gdbus_proxy.cpp @@ -28,6 +28,21 @@ public:  glib::DBusProxy proxy;  }; +class TestGDBusProxyInvalidService: public ::testing::Test +{ +public: + TestGDBusProxyInvalidService() + : got_result_return(false) + , proxy("com.canonical.Unity.Test.NonExistant", + "/com/canonical/gdbus_wrapper", + "com.canonical.gdbus_wrapper") + { + } + + bool got_result_return; + glib::DBusProxy proxy; +}; +  TEST_F(TestGDBusProxy, TestConstruction)  {  EXPECT_FALSE(proxy.IsConnected()); @@ -96,13 +111,65 @@ TEST_F(TestGDBusProxy, TestCancelling)  glib::Object<GCancellable> cancellable(g_cancellable_new());  // but this has to work eitherway  proxy.Call("TestMethod", g_variant_new("(s)", "TestStringTestString"), - method_connection, cancellable); + method_connection, cancellable);  // this could mostly cause the next test to fail  g_cancellable_cancel(cancellable);  EXPECT_FALSE(got_result_return);  } +TEST_F(TestGDBusProxy, TestAcquiring) +{ + const int NUM_REQUESTS = 10; + int completed = 0; + std::string call_return; + // method callback + auto method_connection = [&](GVariant* variant, glib::Error const& err) + { + if (variant != nullptr) + { + call_return = g_variant_get_string(g_variant_get_child_value(variant, 0), NULL); + } + + if (++completed >= NUM_REQUESTS) got_result_return = true; + }; + + EXPECT_FALSE(proxy.IsConnected()); // we shouldn't be connected yet + for (int i = 0; i < NUM_REQUESTS; i++) + { + proxy.CallBegin("TestMethod", g_variant_new("(s)", "TestStringTestString"), + method_connection, nullptr); + Utils::WaitForTimeoutMSec(150); + } + Utils::WaitUntil(got_result_return); +} + +TEST_F(TestGDBusProxyInvalidService, TestTimeouting) +{ + std::string call_return; + // method callback + auto method_connection = [&](GVariant* variant, glib::Error const& err) + { + if (variant != nullptr) + { + call_return = g_variant_get_string(g_variant_get_child_value(variant, 0), NULL); + } + + got_result_return = true; + }; + + EXPECT_FALSE(proxy.IsConnected()); // we shouldn't be connected yet + + proxy.CallBegin("TestMethod", g_variant_new("(s)", "TestStringTestString"), + method_connection, nullptr, (GDBusCallFlags) 0, 100); + // want to test timeout, if non-blocking sleep was used, the proxy would + // be acquired (with a dbus error) + g_usleep(110000); + + Utils::WaitUntil(got_result_return); + EXPECT_EQ(call_return, ""); +} +  TEST_F(TestGDBusProxy, TestMethodCall)  {  std::string call_return; @@ -120,7 +187,7 @@ TEST_F(TestGDBusProxy, TestMethodCall)  EXPECT_FALSE(proxy.IsConnected()); // we shouldn't be connected yet  // but this has to work eitherway  proxy.Call("TestMethod", g_variant_new("(s)", "TestStringTestString"), - method_connection); + method_connection);  Utils::WaitUntil(got_result_return); | 
