test-dialer.c 2.09 KB
Newer Older
Guido Gunther's avatar
Guido Gunther committed
1 2
/*
 * Copyright (C) 2017 Purism SPC
Guido Gunther's avatar
Guido Gunther committed
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1+
Guido Gunther's avatar
Guido Gunther committed
5 6
 */

7
#define HANDY_USE_UNSTABLE_API
Guido Gunther's avatar
Guido Gunther committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <handy.h>

gint notified;


static void
notify_cb(GtkWidget *widget, gpointer data)
{
  notified++;
}


static void
test_hdy_dialer_setnumber(void)
{
  GtkWidget *dialer;

25
  notified = 0;
Guido Gunther's avatar
Guido Gunther committed
26 27 28 29 30 31 32 33
  dialer = hdy_dialer_new();
  g_signal_connect (dialer, "notify::number", G_CALLBACK (notify_cb), NULL);

  g_assert_cmpstr("", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));

  hdy_dialer_set_number(HDY_DIALER (dialer), "#1234");
  g_assert_cmpstr("#1234", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
  g_assert_cmpint(1, ==, notified);
34 35 36 37

  /* Check that we're assigning to the string and not overwriting */
  hdy_dialer_set_number(HDY_DIALER (dialer), "#123");
  g_assert_cmpstr("#1234", !=, hdy_dialer_get_number(HDY_DIALER (dialer)));
38
  g_assert_cmpint(2, ==, notified);
39 40 41 42 43

  /* Do the same using the GObject property */
  g_object_set(G_OBJECT (dialer), "number", "#12", NULL);
  g_assert_cmpstr("#123", !=, hdy_dialer_get_number(HDY_DIALER (dialer)));
  g_assert_cmpstr("#12", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
44
  g_assert_cmpint(3, ==, notified);
Guido Gunther's avatar
Guido Gunther committed
45 46 47
}


48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
static void
test_hdy_dialer_clear_number(void)
{
  GtkWidget *dialer;

  notified = 0;
  dialer = hdy_dialer_new();
  g_signal_connect (dialer, "notify::number", G_CALLBACK (notify_cb), NULL);

  g_assert_cmpstr("", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
  hdy_dialer_clear_number (HDY_DIALER (dialer));
  g_assert_cmpint(0, ==, notified);

  hdy_dialer_set_number(HDY_DIALER (dialer), "#1234");
  g_assert_cmpstr("#1234", ==, hdy_dialer_get_number(HDY_DIALER (dialer)));
  g_assert_cmpint(1, ==, notified);
  hdy_dialer_clear_number (HDY_DIALER (dialer));
  g_assert_cmpint(2, ==, notified);
  hdy_dialer_clear_number (HDY_DIALER (dialer));
  g_assert_cmpint(2, ==, notified);
}


Guido Gunther's avatar
Guido Gunther committed
71 72 73 74
gint
main (gint argc,
      gchar *argv[])
{
75
  gtk_test_init (&argc, &argv, NULL);
Guido Gunther's avatar
Guido Gunther committed
76 77

  g_test_add_func("/Handy/Dialer/setnumber", test_hdy_dialer_setnumber);
78
  g_test_add_func("/Handy/Dialer/clear_number", test_hdy_dialer_clear_number);
Guido Gunther's avatar
Guido Gunther committed
79 80
  return g_test_run();
}