Back to index

unity  6.0.0
Defines | Functions
TestUBus.cpp File Reference
#include "config.h"
#include "ubus-server.h"

Go to the source code of this file.

Defines

#define MESSAGE1   "TEST MESSAGE ONE"
#define MESSAGE2   "ՄᕅᏆⲤꙨႧΈ Ϊટ ಗשׁຣ໐ɱË‼‼❢"
#define _DOMAIN   "/Unit/UBus"

Functions

static void TestAllocation (void)
static void TestMainLoop (void)
static void TestPropagation (void)
void TestUBusCreateSuite ()
void test_handler_inc_counter (GVariant *data, gpointer val)
void test_handler_inc_counter_2 (GVariant *data, gpointer val)
gboolean main_loop_bailout (gpointer data)
void test_handler_mainloop (GVariant *data, gpointer val)

Define Documentation

#define _DOMAIN   "/Unit/UBus"
#define MESSAGE1   "TEST MESSAGE ONE"

Definition at line 25 of file TestUBus.cpp.

#define MESSAGE2   "ՄᕅᏆⲤꙨႧΈ Ϊટ ಗשׁຣ໐ɱË‼‼❢"

Definition at line 26 of file TestUBus.cpp.


Function Documentation

gboolean main_loop_bailout ( gpointer  data)

Definition at line 118 of file TestUBus.cpp.

{
  GMainLoop* mainloop = (GMainLoop*)data;
  g_main_quit(mainloop);
  return FALSE;
}

Here is the caller graph for this function:

void test_handler_inc_counter ( GVariant *  data,
gpointer  val 
)

Definition at line 56 of file TestUBus.cpp.

{
  // inc a counter when we get called
  gint* counter = (gint*)val;
  *counter = *counter + 1;
}

Here is the caller graph for this function:

void test_handler_inc_counter_2 ( GVariant *  data,
gpointer  val 
)

Definition at line 64 of file TestUBus.cpp.

{
  // inc a counter by two when called
  gint* counter = (gint*)val;
  *counter = *counter + 2;
}

Here is the caller graph for this function:

void test_handler_mainloop ( GVariant *  data,
gpointer  val 
)

Definition at line 126 of file TestUBus.cpp.

{
  // inc a counter when we get called
  gint* counter = (gint*)val;
  *counter = *counter + 1;

}

Here is the caller graph for this function:

static void TestAllocation ( void  ) [static]

Definition at line 42 of file TestUBus.cpp.

{
  UBusServer* serv_1 = ubus_server_get_default();
  UBusServer* serv_2 = ubus_server_get_default();

  g_assert(serv_1 != NULL);
  g_assert(serv_2 != NULL);

  // i used a different way of making a singleton than i am used to
  // so i'm not 100% confident in it yet
  g_assert(serv_1 == serv_2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestMainLoop ( void  ) [static]

Definition at line 135 of file TestUBus.cpp.

{
  GMainLoop*  mainloop;
  UBusServer* ubus;
  gint        counter = 0;

  ubus = ubus_server_get_default();
  mainloop = g_main_loop_new(NULL, TRUE);

  g_timeout_add_seconds(1, main_loop_bailout, mainloop);

  ubus_server_register_interest(ubus, MESSAGE1,
                                test_handler_mainloop,
                                &counter);

  ubus_server_send_message(ubus, MESSAGE1, NULL);
  g_main_loop_run(mainloop);

  g_assert(counter == 1);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void TestPropagation ( void  ) [static]

Definition at line 72 of file TestUBus.cpp.

{
  UBusServer* ubus;
  gint        counter, i;
  guint       handler1, handler2;

  ubus = ubus_server_get_default();
  handler1 = ubus_server_register_interest(ubus, MESSAGE1,
                                           test_handler_inc_counter,
                                           &counter);

  handler2 = ubus_server_register_interest(ubus, MESSAGE2,  // tests UNICODE
                                           test_handler_inc_counter_2,
                                           &counter);

  counter = 0;
  for (i = 0; i < 1000; i++)
  {
    ubus_server_send_message(ubus, MESSAGE1, NULL);
  }

  ubus_server_force_message_pump(ubus);

  counter = 0;
  for (i = 0; i < 1000; i++)
  {
    ubus_server_send_message(ubus, MESSAGE1, NULL);
    ubus_server_send_message(ubus, MESSAGE2, NULL);
  }
  ubus_server_force_message_pump(ubus);

  g_assert(counter == 3000);

  ubus_server_unregister_interest(ubus, handler1);
  ubus_server_unregister_interest(ubus, handler2);

  counter = 0;
  ubus_server_send_message(ubus, MESSAGE1, NULL);
  ubus_server_send_message(ubus, MESSAGE2, NULL);

  ubus_server_force_message_pump(ubus);

  g_assert(counter == 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 33 of file TestUBus.cpp.

{
#define _DOMAIN "/Unit/UBus"
  g_test_add_func(_DOMAIN"/Allocation", TestAllocation);
  g_test_add_func(_DOMAIN"/Propagation", TestPropagation);
  g_test_add_func(_DOMAIN"/MainLoop", TestMainLoop);
}

Here is the call graph for this function:

Here is the caller graph for this function: