File: test-int-pair.c

package info (click to toggle)
libdazzle 3.44.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,964 kB
  • sloc: ansic: 64,328; xml: 69; javascript: 19; makefile: 12
file content (79 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
75
76
77
78
79
#include <dazzle.h>

static void
test_intpair_basic (void)
{
  DzlIntPair *p;

  p = dzl_int_pair_new (0, 0);
#ifdef DZL_INT_PAIR_64
  /* Technically not ANSI as NULL is allowed to be non-zero, but all the
   * platforms we support, this is the case.
   */
  g_assert (p == NULL);
#else
  g_assert (p != NULL);
#endif

  p = dzl_int_pair_new (4, 5);
  g_assert (p != NULL);
  g_assert_cmpint (dzl_int_pair_first (p), ==, 4);
  g_assert_cmpint (dzl_int_pair_second (p), ==, 5);
  dzl_int_pair_free (p);

  p = dzl_int_pair_new (G_MAXINT, G_MAXINT-1);
  g_assert (p != NULL);
  g_assert_cmpint (dzl_int_pair_first (p), ==, G_MAXINT);
  g_assert_cmpint (dzl_int_pair_second (p), ==, G_MAXINT-1);
  dzl_int_pair_free (p);

  p = dzl_int_pair_new (G_MAXINT-1, G_MAXINT);
  g_assert (p != NULL);
  g_assert_cmpint (dzl_int_pair_first (p), ==, G_MAXINT-1);
  g_assert_cmpint (dzl_int_pair_second (p), ==, G_MAXINT);
  dzl_int_pair_free (p);
}

static void
test_uintpair_basic (void)
{
  DzlUIntPair *p;

  p = dzl_uint_pair_new (0, 0);
#ifdef DZL_INT_PAIR_64
  /* Technically not ANSI as NULL is allowed to be non-zero, but all the
   * platforms we support, this is the case.
   */
  g_assert (p == NULL);
#else
  g_assert (p != NULL);
#endif

  p = dzl_uint_pair_new (4, 5);
  g_assert (p != NULL);
  g_assert_cmpuint (dzl_uint_pair_first (p), ==, 4);
  g_assert_cmpuint (dzl_uint_pair_second (p), ==, 5);
  dzl_uint_pair_free (p);

  p = dzl_uint_pair_new (G_MAXUINT, G_MAXUINT-1);
  g_assert (p != NULL);
  g_assert_cmpuint (dzl_uint_pair_first (p), ==, G_MAXUINT);
  g_assert_cmpuint (dzl_uint_pair_second (p), ==, G_MAXUINT-1);
  dzl_uint_pair_free (p);

  p = dzl_uint_pair_new (G_MAXUINT-1, G_MAXUINT);
  g_assert (p != NULL);
  g_assert_cmpuint (dzl_uint_pair_first (p), ==, G_MAXUINT-1);
  g_assert_cmpuint (dzl_uint_pair_second (p), ==, G_MAXUINT);
  dzl_uint_pair_free (p);
}

gint
main (gint argc,
      gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);
  g_test_add_func ("/Dazzle/IntPair/basic", test_intpair_basic);
  g_test_add_func ("/Dazzle/UIntPair/basic", test_uintpair_basic);
  return g_test_run ();
}