7 g_autofree gchar
*p
= NULL
;
8 g_autofree gchar
*p2
= NULL
;
9 g_autofree gchar
*alwaysnull
= NULL
;
16 g_autofree guint8
*buf
= g_malloc (128);
17 g_autofree gchar
*alwaysnull_again
= NULL
;
24 g_autofree guint8
*buf2
= g_malloc (256);
31 test_g_async_queue (void)
33 g_autoptr(GAsyncQueue
) val
= g_async_queue_new ();
34 g_assert (val
!= NULL
);
38 test_g_bookmark_file (void)
40 g_autoptr(GBookmarkFile
) val
= g_bookmark_file_new ();
41 g_assert (val
!= NULL
);
47 g_autoptr(GBytes
) val
= g_bytes_new ("foo", 3);
48 g_assert (val
!= NULL
);
52 test_g_checksum (void)
54 g_autoptr(GChecksum
) val
= g_checksum_new (G_CHECKSUM_SHA256
);
55 g_assert (val
!= NULL
);
59 test_g_date_time (void)
61 g_autoptr(GDateTime
) val
= g_date_time_new_now_utc ();
62 g_assert (val
!= NULL
);
68 g_autoptr(GDir
) val
= g_dir_open (".", 0, NULL
);
69 g_assert (val
!= NULL
);
75 g_autoptr(GError
) val
= g_error_new_literal (G_FILE_ERROR
, G_FILE_ERROR_FAILED
, "oops");
76 g_assert (val
!= NULL
);
80 test_g_hash_table (void)
82 g_autoptr(GHashTable
) val
= g_hash_table_new (NULL
, NULL
);
83 g_assert (val
!= NULL
);
89 g_autoptr(GHmac
) val
= g_hmac_new (G_CHECKSUM_SHA256
, (guint8
*)"hello", 5);
90 g_assert (val
!= NULL
);
94 test_g_io_channel (void)
96 g_autoptr(GIOChannel
) val
= g_io_channel_new_file ("/dev/null", "r", NULL
);
97 g_assert (val
!= NULL
);
101 test_g_key_file (void)
103 g_autoptr(GKeyFile
) val
= g_key_file_new ();
104 g_assert (val
!= NULL
);
110 g_autoptr(GList
) val
= NULL
;
111 g_autoptr(GList
) val2
= g_list_prepend (NULL
, "foo");
112 g_assert (val
== NULL
);
113 g_assert (val2
!= NULL
);
119 g_autoptr(GArray
) val
= g_array_new (0, 0, sizeof (gpointer
));
120 g_assert (val
!= NULL
);
124 test_g_ptr_array (void)
126 g_autoptr(GPtrArray
) val
= g_ptr_array_new ();
127 g_assert (val
!= NULL
);
131 test_g_byte_array (void)
133 g_autoptr(GByteArray
) val
= g_byte_array_new ();
134 g_assert (val
!= NULL
);
138 test_g_main_context (void)
140 g_autoptr(GMainContext
) val
= g_main_context_new ();
141 g_assert (val
!= NULL
);
145 test_g_main_loop (void)
147 g_autoptr(GMainLoop
) val
= g_main_loop_new (NULL
, TRUE
);
148 g_assert (val
!= NULL
);
154 g_autoptr(GSource
) val
= g_timeout_source_new_seconds (2);
155 g_assert (val
!= NULL
);
159 test_g_mapped_file (void)
161 g_autoptr(GMappedFile
) val
= g_mapped_file_new (g_test_get_filename (G_TEST_DIST
, "keyfiletest.ini", NULL
), FALSE
, NULL
);
162 g_assert (val
!= NULL
);
166 parser_start (GMarkupParseContext
*context
,
167 const gchar
*element_name
,
168 const gchar
**attribute_names
,
169 const gchar
**attribute_values
,
176 parser_end (GMarkupParseContext
*context
,
177 const gchar
*element_name
,
183 static GMarkupParser parser
= {
184 .start_element
= parser_start
,
185 .end_element
= parser_end
189 test_g_markup_parse_context (void)
191 g_autoptr(GMarkupParseContext
) val
= g_markup_parse_context_new (&parser
, 0, NULL
, NULL
);
192 g_assert (val
!= NULL
);
198 g_autoptr(GNode
) val
= g_node_new ("hello");
199 g_assert (val
!= NULL
);
203 test_g_option_context (void)
205 g_autoptr(GOptionContext
) val
= g_option_context_new ("hello");
206 g_assert (val
!= NULL
);
210 test_g_option_group (void)
212 g_autoptr(GOptionGroup
) val
= g_option_group_new ("hello", "world", "helpme", NULL
, NULL
);
213 g_assert (val
!= NULL
);
217 test_g_pattern_spec (void)
219 g_autoptr(GPatternSpec
) val
= g_pattern_spec_new ("plaid");
220 g_assert (val
!= NULL
);
226 g_autoptr(GQueue
) val
= g_queue_new ();
227 g_auto(GQueue
) stackval
= G_QUEUE_INIT
;
228 g_assert (val
!= NULL
);
234 g_autoptr(GRand
) val
= g_rand_new ();
235 g_assert (val
!= NULL
);
241 g_autoptr(GRegex
) val
= g_regex_new (".*", 0, 0, NULL
);
242 g_assert (val
!= NULL
);
246 test_g_match_info (void)
248 g_autoptr(GRegex
) regex
= g_regex_new (".*", 0, 0, NULL
);
249 g_autoptr(GMatchInfo
) match
= NULL
;
251 if (!g_regex_match (regex
, "hello", 0, &match
))
252 g_assert_not_reached ();
256 test_g_scanner (void)
258 GScannerConfig config
= { 0, };
259 g_autoptr(GScanner
) val
= g_scanner_new (&config
);
260 g_assert (val
!= NULL
);
264 test_g_sequence (void)
266 g_autoptr(GSequence
) val
= g_sequence_new (NULL
);
267 g_assert (val
!= NULL
);
273 g_autoptr(GSList
) val
= NULL
;
274 g_autoptr(GSList
) nonempty_val
= g_slist_prepend (NULL
, "hello");
275 g_assert (val
== NULL
);
276 g_assert (nonempty_val
!= NULL
);
282 g_autoptr(GString
) val
= g_string_new ("");
283 g_assert (val
!= NULL
);
287 test_g_string_chunk (void)
289 g_autoptr(GStringChunk
) val
= g_string_chunk_new (42);
290 g_assert (val
!= NULL
);
294 mythread (gpointer data
)
296 g_usleep (G_USEC_PER_SEC
);
303 g_autoptr(GThread
) val
= g_thread_new ("bob", mythread
, NULL
);
304 g_assert (val
!= NULL
);
316 test_g_mutex_locker (void)
320 g_mutex_init (&mutex
);
324 g_autoptr(GMutexLocker
) val
= g_mutex_locker_new (&mutex
);
326 g_assert (val
!= NULL
);
340 g_autoptr(GTimer
) val
= g_timer_new ();
341 g_assert (val
!= NULL
);
345 test_g_time_zone (void)
347 g_autoptr(GTimeZone
) val
= g_time_zone_new ("UTC");
348 g_assert (val
!= NULL
);
354 g_autoptr(GTree
) val
= g_tree_new ((GCompareFunc
)strcmp
);
355 g_assert (val
!= NULL
);
359 test_g_variant (void)
361 g_autoptr(GVariant
) val
= g_variant_new_string ("hello");
362 g_assert (val
!= NULL
);
366 test_g_variant_builder (void)
368 g_autoptr(GVariantBuilder
) val
= g_variant_builder_new (G_VARIANT_TYPE ("as"));
369 g_auto(GVariantBuilder
) stackval
;
371 g_assert (val
!= NULL
);
372 g_variant_builder_init (&stackval
, G_VARIANT_TYPE ("as"));
376 test_g_variant_iter (void)
378 g_autoptr(GVariant
) var
= g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32
, "", 0, sizeof(guint32
));
379 g_autoptr(GVariantIter
) val
= g_variant_iter_new (var
);
380 g_assert (val
!= NULL
);
384 test_g_variant_dict (void)
386 g_autoptr(GVariant
) data
= g_variant_new_from_data (G_VARIANT_TYPE ("a{sv}"), "", 0, FALSE
, NULL
, NULL
);
387 g_auto(GVariantDict
) stackval
;
388 g_autoptr(GVariantDict
) val
= g_variant_dict_new (data
);
390 g_variant_dict_init (&stackval
, data
);
391 g_assert (val
!= NULL
);
395 test_g_variant_type (void)
397 g_autoptr(GVariantType
) val
= g_variant_type_new ("s");
398 g_assert (val
!= NULL
);
404 g_auto(GStrv
) val
= g_strsplit("a:b:c", ":", -1);
405 g_assert (val
!= NULL
);
409 main (int argc
, gchar
*argv
[])
411 g_test_init (&argc
, &argv
, NULL
);
413 g_test_add_func ("/autoptr/autofree", test_autofree
);
414 g_test_add_func ("/autoptr/g_async_queue", test_g_async_queue
);
415 g_test_add_func ("/autoptr/g_bookmark_file", test_g_bookmark_file
);
416 g_test_add_func ("/autoptr/g_bytes", test_g_bytes
);
417 g_test_add_func ("/autoptr/g_checksum", test_g_checksum
);
418 g_test_add_func ("/autoptr/g_date_time", test_g_date_time
);
419 g_test_add_func ("/autoptr/g_dir", test_g_dir
);
420 g_test_add_func ("/autoptr/g_error", test_g_error
);
421 g_test_add_func ("/autoptr/g_hash_table", test_g_hash_table
);
422 g_test_add_func ("/autoptr/g_hmac", test_g_hmac
);
423 g_test_add_func ("/autoptr/g_io_channel", test_g_io_channel
);
424 g_test_add_func ("/autoptr/g_key_file", test_g_key_file
);
425 g_test_add_func ("/autoptr/g_list", test_g_list
);
426 g_test_add_func ("/autoptr/g_array", test_g_array
);
427 g_test_add_func ("/autoptr/g_ptr_array", test_g_ptr_array
);
428 g_test_add_func ("/autoptr/g_byte_array", test_g_byte_array
);
429 g_test_add_func ("/autoptr/g_main_context", test_g_main_context
);
430 g_test_add_func ("/autoptr/g_main_loop", test_g_main_loop
);
431 g_test_add_func ("/autoptr/g_source", test_g_source
);
432 g_test_add_func ("/autoptr/g_mapped_file", test_g_mapped_file
);
433 g_test_add_func ("/autoptr/g_markup_parse_context", test_g_markup_parse_context
);
434 g_test_add_func ("/autoptr/g_node", test_g_node
);
435 g_test_add_func ("/autoptr/g_option_context", test_g_option_context
);
436 g_test_add_func ("/autoptr/g_option_group", test_g_option_group
);
437 g_test_add_func ("/autoptr/g_pattern_spec", test_g_pattern_spec
);
438 g_test_add_func ("/autoptr/g_queue", test_g_queue
);
439 g_test_add_func ("/autoptr/g_rand", test_g_rand
);
440 g_test_add_func ("/autoptr/g_regex", test_g_regex
);
441 g_test_add_func ("/autoptr/g_match_info", test_g_match_info
);
442 g_test_add_func ("/autoptr/g_scanner", test_g_scanner
);
443 g_test_add_func ("/autoptr/g_sequence", test_g_sequence
);
444 g_test_add_func ("/autoptr/g_slist", test_g_slist
);
445 g_test_add_func ("/autoptr/g_string", test_g_string
);
446 g_test_add_func ("/autoptr/g_string_chunk", test_g_string_chunk
);
447 g_test_add_func ("/autoptr/g_thread", test_g_thread
);
448 g_test_add_func ("/autoptr/g_mutex", test_g_mutex
);
449 g_test_add_func ("/autoptr/g_mutex_locker", test_g_mutex_locker
);
450 g_test_add_func ("/autoptr/g_cond", test_g_cond
);
451 g_test_add_func ("/autoptr/g_timer", test_g_timer
);
452 g_test_add_func ("/autoptr/g_time_zone", test_g_time_zone
);
453 g_test_add_func ("/autoptr/g_tree", test_g_tree
);
454 g_test_add_func ("/autoptr/g_variant", test_g_variant
);
455 g_test_add_func ("/autoptr/g_variant_builder", test_g_variant_builder
);
456 g_test_add_func ("/autoptr/g_variant_iter", test_g_variant_iter
);
457 g_test_add_func ("/autoptr/g_variant_dict", test_g_variant_dict
);
458 g_test_add_func ("/autoptr/g_variant_type", test_g_variant_type
);
459 g_test_add_func ("/autoptr/strv", test_strv
);
461 return g_test_run ();