~ubuntu-branches/ubuntu/maverick/telepathy-glib/maverick

« back to all changes in this revision

Viewing changes to tests/intset.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon McVittie
  • Date: 2010-05-10 17:59:54 UTC
  • mfrom: (1.6.1 upstream) (27.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100510175954-bxvqq3xx0sy4itmp
Tags: 0.11.5-1
New upstream version with new API/ABI

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <glib.h>
2
2
#include <telepathy-glib/intset.h>
 
3
#include <telepathy-glib/util.h>
3
4
 
4
5
int main (int argc, char **argv)
5
6
{
6
7
  TpIntSet *set1 = tp_intset_new ();
7
 
  TpIntSet *a, *b;
 
8
  TpIntSet *a, *b, *copy;
8
9
  TpIntSet *ab_union, *ab_expected_union;
9
10
  TpIntSet *ab_inter, *ab_expected_inter;
10
11
  TpIntSet *a_diff_b, *a_expected_diff_b;
11
12
  TpIntSet *b_diff_a, *b_expected_diff_a;
12
13
  TpIntSet *ab_symmdiff, *ab_expected_symmdiff;
 
14
  GValue *value;
 
15
 
 
16
  g_type_init ();
13
17
 
14
18
  tp_intset_add (set1, 0);
15
19
 
75
79
  g_assert (tp_intset_is_equal (ab_union, ab_expected_union));
76
80
  tp_intset_destroy (ab_union);
77
81
  tp_intset_destroy (ab_expected_union);
 
82
  ab_union = NULL;
 
83
  ab_expected_union = NULL;
78
84
 
79
85
  ab_expected_inter = tp_intset_new ();
80
86
  tp_intset_add (ab_expected_inter, NUM_C);
84
90
  g_assert (tp_intset_is_equal (ab_inter, ab_expected_inter));
85
91
  tp_intset_destroy (ab_inter);
86
92
  tp_intset_destroy (ab_expected_inter);
 
93
  ab_inter = NULL;
 
94
  ab_expected_inter = NULL;
87
95
 
88
96
  a_expected_diff_b = tp_intset_new ();
89
97
  tp_intset_add (a_expected_diff_b, NUM_A);
93
101
  g_assert (tp_intset_is_equal (a_diff_b, a_expected_diff_b));
94
102
  tp_intset_destroy (a_diff_b);
95
103
  tp_intset_destroy (a_expected_diff_b);
 
104
  a_diff_b = NULL;
 
105
  a_expected_diff_b = NULL;
96
106
 
97
107
  b_expected_diff_a = tp_intset_new ();
98
108
  tp_intset_add (b_expected_diff_a, NUM_E);
102
112
  g_assert (tp_intset_is_equal (b_diff_a, b_expected_diff_a));
103
113
  tp_intset_destroy (b_diff_a);
104
114
  tp_intset_destroy (b_expected_diff_a);
 
115
  b_diff_a = NULL;
 
116
  b_expected_diff_a = NULL;
105
117
 
106
118
  ab_expected_symmdiff = tp_intset_new ();
107
119
  tp_intset_add (ab_expected_symmdiff, NUM_A);
113
125
  g_assert (tp_intset_is_equal (ab_symmdiff, ab_expected_symmdiff));
114
126
  tp_intset_destroy (ab_symmdiff);
115
127
  tp_intset_destroy (ab_expected_symmdiff);
 
128
  ab_symmdiff = NULL;
 
129
  ab_expected_symmdiff = NULL;
116
130
 
117
131
  {
118
132
    GArray *arr;
123
137
    g_assert (tp_intset_is_equal (a, tmp));
124
138
    g_array_free (arr, TRUE);
125
139
    tp_intset_destroy (tmp);
 
140
    arr = NULL;
 
141
    tmp = NULL;
126
142
 
127
143
    arr = tp_intset_to_array (b);
128
144
    tmp = tp_intset_from_array (arr);
129
145
    g_assert (tp_intset_is_equal (b, tmp));
130
146
    g_array_free (arr, TRUE);
131
147
    tp_intset_destroy (tmp);
 
148
    arr = NULL;
 
149
    tmp = NULL;
132
150
  }
133
151
 
134
 
  tp_intset_destroy (a);
 
152
  value = tp_g_value_slice_new_take_boxed (TP_TYPE_INTSET, a);
 
153
  copy = g_value_dup_boxed (value);
 
154
 
 
155
  g_assert (copy != a);
 
156
  g_assert (tp_intset_is_equal (copy, a));
 
157
  g_boxed_free (TP_TYPE_INTSET, copy);
 
158
 
 
159
  /* a is owned by value now, so don't free it explicitly */
 
160
  tp_g_value_slice_free (value);
135
161
  tp_intset_destroy (b);
 
162
  a = NULL;
 
163
  value = NULL;
 
164
  b = NULL;
136
165
 
137
166
  return 0;
138
167
}