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
;
21 g_assert_null (alwaysnull_again
);
26 g_autofree guint8
*buf2
= g_malloc (256);
31 g_assert_null (alwaysnull
);
35 test_g_async_queue (void)
37 g_autoptr(GAsyncQueue
) val
= g_async_queue_new ();
38 g_assert (val
!= NULL
);
42 test_g_bookmark_file (void)
44 g_autoptr(GBookmarkFile
) val
= g_bookmark_file_new ();
45 g_assert (val
!= NULL
);
51 g_autoptr(GBytes
) val
= g_bytes_new ("foo", 3);
52 g_assert (val
!= NULL
);
56 test_g_checksum (void)
58 g_autoptr(GChecksum
) val
= g_checksum_new (G_CHECKSUM_SHA256
);
59 g_assert (val
!= NULL
);
63 test_g_date_time (void)
65 g_autoptr(GDateTime
) val
= g_date_time_new_now_utc ();
66 g_assert (val
!= NULL
);
72 g_autoptr(GDir
) val
= g_dir_open (".", 0, NULL
);
73 g_assert (val
!= NULL
);
79 g_autoptr(GError
) val
= g_error_new_literal (G_FILE_ERROR
, G_FILE_ERROR_FAILED
, "oops");
80 g_assert (val
!= NULL
);
84 test_g_hash_table (void)
86 g_autoptr(GHashTable
) val
= g_hash_table_new (NULL
, NULL
);
87 g_assert (val
!= NULL
);
93 g_autoptr(GHmac
) val
= g_hmac_new (G_CHECKSUM_SHA256
, (guint8
*)"hello", 5);
94 g_assert (val
!= NULL
);
98 test_g_io_channel (void)
100 g_autoptr(GIOChannel
) val
= g_io_channel_new_file ("/dev/null", "r", NULL
);
101 g_assert (val
!= NULL
);
105 test_g_key_file (void)
107 g_autoptr(GKeyFile
) val
= g_key_file_new ();
108 g_assert (val
!= NULL
);
114 g_autoptr(GList
) val
= NULL
;
115 g_autoptr(GList
) val2
= g_list_prepend (NULL
, "foo");
116 g_assert (val
== NULL
);
117 g_assert (val2
!= NULL
);
123 g_autoptr(GArray
) val
= g_array_new (0, 0, sizeof (gpointer
));
124 g_assert (val
!= NULL
);
128 test_g_ptr_array (void)
130 g_autoptr(GPtrArray
) val
= g_ptr_array_new ();
131 g_assert (val
!= NULL
);
135 test_g_byte_array (void)
137 g_autoptr(GByteArray
) val
= g_byte_array_new ();
138 g_assert (val
!= NULL
);
142 test_g_main_context (void)
144 g_autoptr(GMainContext
) val
= g_main_context_new ();
145 g_assert (val
!= NULL
);
149 test_g_main_loop (void)
151 g_autoptr(GMainLoop
) val
= g_main_loop_new (NULL
, TRUE
);
152 g_assert (val
!= NULL
);
158 g_autoptr(GSource
) val
= g_timeout_source_new_seconds (2);
159 g_assert (val
!= NULL
);
163 test_g_mapped_file (void)
165 g_autoptr(GMappedFile
) val
= g_mapped_file_new (g_test_get_filename (G_TEST_DIST
, "keyfiletest.ini", NULL
), FALSE
, NULL
);
166 g_assert (val
!= NULL
);
170 parser_start (GMarkupParseContext
*context
,
171 const gchar
*element_name
,
172 const gchar
**attribute_names
,
173 const gchar
**attribute_values
,
180 parser_end (GMarkupParseContext
*context
,
181 const gchar
*element_name
,
187 static GMarkupParser parser
= {
188 .start_element
= parser_start
,
189 .end_element
= parser_end
193 test_g_markup_parse_context (void)
195 g_autoptr(GMarkupParseContext
) val
= g_markup_parse_context_new (&parser
, 0, NULL
, NULL
);
196 g_assert (val
!= NULL
);
202 g_autoptr(GNode
) val
= g_node_new ("hello");
203 g_assert (val
!= NULL
);
207 test_g_option_context (void)
209 g_autoptr(GOptionContext
) val
= g_option_context_new ("hello");
210 g_assert (val
!= NULL
);
214 test_g_option_group (void)
216 g_autoptr(GOptionGroup
) val
= g_option_group_new ("hello", "world", "helpme", NULL
, NULL
);
217 g_assert (val
!= NULL
);
221 test_g_pattern_spec (void)
223 g_autoptr(GPatternSpec
) val
= g_pattern_spec_new ("plaid");
224 g_assert (val
!= NULL
);
230 g_autoptr(GQueue
) val
= g_queue_new ();
231 g_auto(GQueue
) stackval
= G_QUEUE_INIT
;
232 g_assert (val
!= NULL
);
233 g_assert_null (stackval
.head
);
239 g_autoptr(GRand
) val
= g_rand_new ();
240 g_assert (val
!= NULL
);
246 g_autoptr(GRegex
) val
= g_regex_new (".*", 0, 0, NULL
);
247 g_assert (val
!= NULL
);
251 test_g_match_info (void)
253 g_autoptr(GRegex
) regex
= g_regex_new (".*", 0, 0, NULL
);
254 g_autoptr(GMatchInfo
) match
= NULL
;
256 if (!g_regex_match (regex
, "hello", 0, &match
))
257 g_assert_not_reached ();
261 test_g_scanner (void)
263 GScannerConfig config
= { 0, };
264 g_autoptr(GScanner
) val
= g_scanner_new (&config
);
265 g_assert (val
!= NULL
);
269 test_g_sequence (void)
271 g_autoptr(GSequence
) val
= g_sequence_new (NULL
);
272 g_assert (val
!= NULL
);
278 g_autoptr(GSList
) val
= NULL
;
279 g_autoptr(GSList
) nonempty_val
= g_slist_prepend (NULL
, "hello");
280 g_assert (val
== NULL
);
281 g_assert (nonempty_val
!= NULL
);
287 g_autoptr(GString
) val
= g_string_new ("");
288 g_assert (val
!= NULL
);
292 test_g_string_chunk (void)
294 g_autoptr(GStringChunk
) val
= g_string_chunk_new (42);
295 g_assert (val
!= NULL
);
299 mythread (gpointer data
)
301 g_usleep (G_USEC_PER_SEC
);
308 g_autoptr(GThread
) val
= g_thread_new ("bob", mythread
, NULL
);
309 g_assert (val
!= NULL
);
321 test_g_mutex_locker (void)
325 g_mutex_init (&mutex
);
329 g_autoptr(GMutexLocker
) val
= g_mutex_locker_new (&mutex
);
331 g_assert (val
!= NULL
);
345 g_autoptr(GTimer
) val
= g_timer_new ();
346 g_assert (val
!= NULL
);
350 test_g_time_zone (void)
352 g_autoptr(GTimeZone
) val
= g_time_zone_new ("UTC");
353 g_assert (val
!= NULL
);
359 g_autoptr(GTree
) val
= g_tree_new ((GCompareFunc
)strcmp
);
360 g_assert (val
!= NULL
);
364 test_g_variant (void)
366 g_autoptr(GVariant
) val
= g_variant_new_string ("hello");
367 g_assert (val
!= NULL
);
371 test_g_variant_builder (void)
373 g_autoptr(GVariantBuilder
) val
= g_variant_builder_new (G_VARIANT_TYPE ("as"));
374 g_auto(GVariantBuilder
) stackval
;
376 g_assert (val
!= NULL
);
377 g_variant_builder_init (&stackval
, G_VARIANT_TYPE ("as"));
381 test_g_variant_iter (void)
383 g_autoptr(GVariant
) var
= g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32
, "", 0, sizeof(guint32
));
384 g_autoptr(GVariantIter
) val
= g_variant_iter_new (var
);
385 g_assert (val
!= NULL
);
389 test_g_variant_dict (void)
391 g_autoptr(GVariant
) data
= g_variant_new_from_data (G_VARIANT_TYPE ("a{sv}"), "", 0, FALSE
, NULL
, NULL
);
392 g_auto(GVariantDict
) stackval
;
393 g_autoptr(GVariantDict
) val
= g_variant_dict_new (data
);
395 g_variant_dict_init (&stackval
, data
);
396 g_assert (val
!= NULL
);
400 test_g_variant_type (void)
402 g_autoptr(GVariantType
) val
= g_variant_type_new ("s");
403 g_assert (val
!= NULL
);
409 g_auto(GStrv
) val
= g_strsplit("a:b:c", ":", -1);
410 g_assert (val
!= NULL
);
414 mark_freed (gpointer ptr
)
416 gboolean
*freed
= ptr
;
424 gboolean freed1
= FALSE
;
425 gboolean freed2
= FALSE
;
426 gboolean freed3
= FALSE
;
427 GBytes
*b1
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed1
);
428 GBytes
*b2
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed2
);
429 GBytes
*b3
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed3
);
432 g_autolist(GBytes
) l
= NULL
;
434 l
= g_list_prepend (l
, b1
);
435 l
= g_list_prepend (l
, b3
);
438 /* Only assert if autoptr works */
450 test_autoslist (void)
453 gboolean freed1
= FALSE
;
454 gboolean freed2
= FALSE
;
455 gboolean freed3
= FALSE
;
456 GBytes
*b1
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed1
);
457 GBytes
*b2
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed2
);
458 GBytes
*b3
= g_bytes_new_with_free_func (data
, sizeof(data
), mark_freed
, &freed3
);
461 g_autoslist(GBytes
) l
= NULL
;
463 l
= g_slist_prepend (l
, b1
);
464 l
= g_slist_prepend (l
, b3
);
467 /* Only assert if autoptr works */
479 main (int argc
, gchar
*argv
[])
481 g_test_init (&argc
, &argv
, NULL
);
483 g_test_add_func ("/autoptr/autofree", test_autofree
);
484 g_test_add_func ("/autoptr/g_async_queue", test_g_async_queue
);
485 g_test_add_func ("/autoptr/g_bookmark_file", test_g_bookmark_file
);
486 g_test_add_func ("/autoptr/g_bytes", test_g_bytes
);
487 g_test_add_func ("/autoptr/g_checksum", test_g_checksum
);
488 g_test_add_func ("/autoptr/g_date_time", test_g_date_time
);
489 g_test_add_func ("/autoptr/g_dir", test_g_dir
);
490 g_test_add_func ("/autoptr/g_error", test_g_error
);
491 g_test_add_func ("/autoptr/g_hash_table", test_g_hash_table
);
492 g_test_add_func ("/autoptr/g_hmac", test_g_hmac
);
493 g_test_add_func ("/autoptr/g_io_channel", test_g_io_channel
);
494 g_test_add_func ("/autoptr/g_key_file", test_g_key_file
);
495 g_test_add_func ("/autoptr/g_list", test_g_list
);
496 g_test_add_func ("/autoptr/g_array", test_g_array
);
497 g_test_add_func ("/autoptr/g_ptr_array", test_g_ptr_array
);
498 g_test_add_func ("/autoptr/g_byte_array", test_g_byte_array
);
499 g_test_add_func ("/autoptr/g_main_context", test_g_main_context
);
500 g_test_add_func ("/autoptr/g_main_loop", test_g_main_loop
);
501 g_test_add_func ("/autoptr/g_source", test_g_source
);
502 g_test_add_func ("/autoptr/g_mapped_file", test_g_mapped_file
);
503 g_test_add_func ("/autoptr/g_markup_parse_context", test_g_markup_parse_context
);
504 g_test_add_func ("/autoptr/g_node", test_g_node
);
505 g_test_add_func ("/autoptr/g_option_context", test_g_option_context
);
506 g_test_add_func ("/autoptr/g_option_group", test_g_option_group
);
507 g_test_add_func ("/autoptr/g_pattern_spec", test_g_pattern_spec
);
508 g_test_add_func ("/autoptr/g_queue", test_g_queue
);
509 g_test_add_func ("/autoptr/g_rand", test_g_rand
);
510 g_test_add_func ("/autoptr/g_regex", test_g_regex
);
511 g_test_add_func ("/autoptr/g_match_info", test_g_match_info
);
512 g_test_add_func ("/autoptr/g_scanner", test_g_scanner
);
513 g_test_add_func ("/autoptr/g_sequence", test_g_sequence
);
514 g_test_add_func ("/autoptr/g_slist", test_g_slist
);
515 g_test_add_func ("/autoptr/g_string", test_g_string
);
516 g_test_add_func ("/autoptr/g_string_chunk", test_g_string_chunk
);
517 g_test_add_func ("/autoptr/g_thread", test_g_thread
);
518 g_test_add_func ("/autoptr/g_mutex", test_g_mutex
);
519 g_test_add_func ("/autoptr/g_mutex_locker", test_g_mutex_locker
);
520 g_test_add_func ("/autoptr/g_cond", test_g_cond
);
521 g_test_add_func ("/autoptr/g_timer", test_g_timer
);
522 g_test_add_func ("/autoptr/g_time_zone", test_g_time_zone
);
523 g_test_add_func ("/autoptr/g_tree", test_g_tree
);
524 g_test_add_func ("/autoptr/g_variant", test_g_variant
);
525 g_test_add_func ("/autoptr/g_variant_builder", test_g_variant_builder
);
526 g_test_add_func ("/autoptr/g_variant_iter", test_g_variant_iter
);
527 g_test_add_func ("/autoptr/g_variant_dict", test_g_variant_dict
);
528 g_test_add_func ("/autoptr/g_variant_type", test_g_variant_type
);
529 g_test_add_func ("/autoptr/strv", test_strv
);
530 g_test_add_func ("/autoptr/autolist", test_autolist
);
531 g_test_add_func ("/autoptr/autoslist", test_autoslist
);
533 return g_test_run ();