(root)/
glib-2.79.0/
glib/
tests/
autoptr.c
       1  #include <glib.h>
       2  #include <string.h>
       3  
       4  typedef struct _HNVC HasNonVoidCleanup;
       5  HasNonVoidCleanup * non_void_cleanup (HasNonVoidCleanup *);
       6  
       7  /* Should not cause any warnings with -Wextra */
       8  G_DEFINE_AUTOPTR_CLEANUP_FUNC(HasNonVoidCleanup, non_void_cleanup)
       9  
      10  static void
      11  test_autofree (void)
      12  {
      13  #ifdef __clang_analyzer__
      14    g_test_skip ("autofree tests aren’t understood by the clang analyser");
      15  #else
      16    g_autofree gchar *p = NULL;
      17    g_autofree gchar *p2 = NULL;
      18    g_autofree gchar *alwaysnull = NULL;
      19  
      20    p = g_malloc (10);
      21    p2 = g_malloc (42);
      22  
      23    p[0] = 1;
      24    p2[0] = 1;
      25  
      26    if (TRUE)
      27      {
      28        g_autofree guint8 *buf = g_malloc (128);
      29        g_autofree gchar *alwaysnull_again = NULL;
      30  
      31        buf[0] = 1;
      32  
      33        g_assert_null (alwaysnull_again);
      34      }
      35  
      36    if (TRUE)
      37      {
      38        g_autofree guint8 *buf2 = g_malloc (256);
      39  
      40        buf2[255] = 42;
      41      }
      42  
      43    g_assert_null (alwaysnull);
      44  #endif  /* __clang_analyzer__ */
      45  }
      46  
      47  static void
      48  test_g_async_queue (void)
      49  {
      50    g_autoptr(GAsyncQueue) val = g_async_queue_new ();
      51    g_assert_nonnull (val);
      52  }
      53  
      54  static void
      55  test_g_bookmark_file (void)
      56  {
      57    g_autoptr(GBookmarkFile) val = g_bookmark_file_new ();
      58    g_assert_nonnull (val);
      59  }
      60  
      61  static void
      62  test_g_bytes (void)
      63  {
      64    g_autoptr(GBytes) val = g_bytes_new ("foo", 3);
      65    g_assert_nonnull (val);
      66  }
      67  
      68  static void
      69  test_g_checksum (void)
      70  {
      71    g_autoptr(GChecksum) val = g_checksum_new (G_CHECKSUM_SHA256);
      72    g_assert_nonnull (val);
      73  }
      74  
      75  static void
      76  test_g_date (void)
      77  {
      78    g_autoptr(GDate) val = g_date_new ();
      79    g_assert_nonnull (val);
      80  }
      81  
      82  static void
      83  test_g_date_time (void)
      84  {
      85    g_autoptr(GDateTime) val = g_date_time_new_now_utc ();
      86    g_assert_nonnull (val);
      87  }
      88  
      89  static void
      90  test_g_dir (void)
      91  {
      92    g_autoptr(GDir) val = g_dir_open (".", 0, NULL);
      93    g_assert_nonnull (val);
      94  }
      95  
      96  static void
      97  test_g_error (void)
      98  {
      99    g_autoptr(GError) val = g_error_new_literal (G_FILE_ERROR, G_FILE_ERROR_FAILED, "oops");
     100    g_assert_nonnull (val);
     101  }
     102  
     103  static void
     104  test_g_hash_table (void)
     105  {
     106    g_autoptr(GHashTable) val = g_hash_table_new (NULL, NULL);
     107    g_assert_nonnull (val);
     108  }
     109  
     110  static void
     111  test_g_hmac (void)
     112  {
     113    g_autoptr(GHmac) val = g_hmac_new (G_CHECKSUM_SHA256, (guint8*)"hello", 5);
     114    g_assert_nonnull (val);
     115  }
     116  
     117  static void
     118  test_g_io_channel (void)
     119  {
     120  #ifdef G_OS_WIN32
     121    const gchar *devnull = "nul";
     122  #else
     123    const gchar *devnull = "/dev/null";
     124  #endif
     125  
     126    g_autoptr(GIOChannel) val = g_io_channel_new_file (devnull, "r", NULL);
     127    g_assert_nonnull (val);
     128  }
     129  
     130  static void
     131  test_g_key_file (void)
     132  {
     133    g_autoptr(GKeyFile) val = g_key_file_new ();
     134    g_assert_nonnull (val);
     135  }
     136  
     137  static void
     138  test_g_list (void)
     139  {
     140    g_autoptr(GList) val = NULL;
     141    g_autoptr(GList) val2 = g_list_prepend (NULL, "foo");
     142    g_assert_null (val);
     143    g_assert_nonnull (val2);
     144  }
     145  
     146  static void
     147  test_g_array (void)
     148  {
     149    g_autoptr(GArray) val = g_array_new (0, 0, sizeof (gpointer));
     150    g_assert_nonnull (val);
     151  }
     152  
     153  static void
     154  test_g_ptr_array (void)
     155  {
     156    g_autoptr(GPtrArray) val = g_ptr_array_new ();
     157    g_assert_nonnull (val);
     158  }
     159  
     160  static void
     161  test_g_byte_array (void)
     162  {
     163    g_autoptr(GByteArray) val = g_byte_array_new ();
     164    g_assert_nonnull (val);
     165  }
     166  
     167  static void
     168  test_g_main_context (void)
     169  {
     170    g_autoptr(GMainContext) val = g_main_context_new ();
     171    g_assert_nonnull (val);
     172  }
     173  
     174  static void
     175  test_g_main_context_pusher (void)
     176  {
     177    GMainContext *context, *old_thread_default;
     178  
     179    context = g_main_context_new ();
     180    old_thread_default = g_main_context_get_thread_default ();
     181    g_assert_false (old_thread_default == context);
     182  
     183    if (TRUE)
     184      {
     185        g_autoptr(GMainContextPusher) val = g_main_context_pusher_new (context);
     186        g_assert_nonnull (val);
     187  
     188        /* Check it’s now the thread-default main context */
     189        g_assert_true (g_main_context_get_thread_default () == context);
     190      }
     191  
     192    /* Check it’s now the old thread-default main context */
     193    g_assert_false (g_main_context_get_thread_default () == context);
     194    g_assert_true (g_main_context_get_thread_default () == old_thread_default);
     195  
     196    g_main_context_unref (context);
     197  }
     198  
     199  static void
     200  test_g_main_loop (void)
     201  {
     202    g_autoptr(GMainLoop) val = g_main_loop_new (NULL, TRUE);
     203    g_assert_nonnull (val);
     204  }
     205  
     206  static void
     207  test_g_source (void)
     208  {
     209    g_autoptr(GSource) val = g_timeout_source_new_seconds (2);
     210    g_assert_nonnull (val);
     211  }
     212  
     213  static void
     214  test_g_mapped_file (void)
     215  {
     216    g_autoptr(GMappedFile) val = g_mapped_file_new (g_test_get_filename (G_TEST_DIST, "keyfiletest.ini", NULL), FALSE, NULL);
     217    g_assert_nonnull (val);
     218  }
     219  
     220  static void
     221  parser_start (GMarkupParseContext  *context,
     222                const gchar          *element_name,
     223                const gchar         **attribute_names,
     224                const gchar         **attribute_values,
     225                gpointer              user_data,
     226                GError              **error)
     227  {
     228  }
     229  
     230  static void
     231  parser_end (GMarkupParseContext  *context,
     232              const gchar          *element_name,
     233              gpointer              user_data,
     234              GError              **error)
     235  {
     236  }
     237  
     238  static GMarkupParser parser = {
     239    .start_element = parser_start,
     240    .end_element = parser_end
     241  };
     242  
     243  static void
     244  test_g_markup_parse_context (void)
     245  {
     246    g_autoptr(GMarkupParseContext) val = g_markup_parse_context_new (&parser,
     247                                                                     G_MARKUP_DEFAULT_FLAGS,
     248                                                                     NULL, NULL);
     249    g_assert_nonnull (val);
     250  }
     251  
     252  static void
     253  test_g_node (void)
     254  {
     255    g_autoptr(GNode) val = g_node_new ("hello");
     256    g_assert_nonnull (val);
     257  }
     258  
     259  static void
     260  test_g_option_context (void)
     261  {
     262    g_autoptr(GOptionContext) val = g_option_context_new ("hello");
     263    g_assert_nonnull (val);
     264  }
     265  
     266  static void
     267  test_g_option_group (void)
     268  {
     269    g_autoptr(GOptionGroup) val = g_option_group_new ("hello", "world", "helpme", NULL, NULL);
     270    g_assert_nonnull (val);
     271  }
     272  
     273  static void
     274  test_g_pattern_spec (void)
     275  {
     276    g_autoptr(GPatternSpec) val = g_pattern_spec_new ("plaid");
     277    g_assert_nonnull (val);
     278  }
     279  
     280  static void
     281  test_g_queue (void)
     282  {
     283    g_autoptr(GQueue) val = g_queue_new ();
     284    g_auto(GQueue) stackval = G_QUEUE_INIT;
     285    g_assert_nonnull (val);
     286    g_assert_null (stackval.head);
     287  }
     288  
     289  static void
     290  test_g_rand (void)
     291  {
     292    g_autoptr(GRand) val = g_rand_new ();
     293    g_assert_nonnull (val);
     294  }
     295  
     296  static void
     297  test_g_regex (void)
     298  {
     299    g_autoptr(GRegex) val = g_regex_new (".*", G_REGEX_DEFAULT,
     300                                         G_REGEX_MATCH_DEFAULT, NULL);
     301    g_assert_nonnull (val);
     302  }
     303  
     304  static void
     305  test_g_match_info (void)
     306  {
     307    g_autoptr(GRegex) regex = g_regex_new (".*", G_REGEX_DEFAULT,
     308                                           G_REGEX_MATCH_DEFAULT, NULL);
     309    g_autoptr(GMatchInfo) match = NULL;
     310  
     311    if (!g_regex_match (regex, "hello", 0, &match))
     312      g_assert_not_reached ();
     313  }
     314  
     315  static void
     316  test_g_scanner (void)
     317  {
     318    GScannerConfig config = { 0, };
     319    g_autoptr(GScanner) val = g_scanner_new (&config);
     320    g_assert_nonnull (val);
     321  }
     322  
     323  static void
     324  test_g_sequence (void)
     325  {
     326    g_autoptr(GSequence) val = g_sequence_new (NULL);
     327    g_assert_nonnull (val);
     328  }
     329  
     330  static void
     331  test_g_slist (void)
     332  {
     333    g_autoptr(GSList) val = NULL;
     334    g_autoptr(GSList) nonempty_val = g_slist_prepend (NULL, "hello");
     335    g_assert_null (val);
     336    g_assert_nonnull (nonempty_val);
     337  }
     338  
     339  static void
     340  test_g_string (void)
     341  {
     342    g_autoptr(GString) val = g_string_new ("");
     343    g_assert_nonnull (val);
     344  }
     345  
     346  static void
     347  test_g_string_chunk (void)
     348  {
     349    g_autoptr(GStringChunk) val = g_string_chunk_new (42);
     350    g_assert_nonnull (val);
     351  }
     352  
     353  static gpointer
     354  mythread (gpointer data)
     355  {
     356    g_usleep (G_USEC_PER_SEC);
     357    return NULL;
     358  }
     359  
     360  static void
     361  test_g_thread (void)
     362  {
     363    g_autoptr(GThread) val = g_thread_new ("bob", mythread, NULL);
     364    g_assert_nonnull (val);
     365  }
     366  
     367  static void
     368  test_g_mutex (void)
     369  {
     370    g_auto(GMutex) val;
     371    
     372    g_mutex_init (&val);
     373  }
     374  
     375  /* Thread function to check that a mutex given in @data is locked */
     376  static gpointer
     377  mutex_locked_thread (gpointer data)
     378  {
     379    GMutex *mutex = (GMutex *) data;
     380    g_assert_false (g_mutex_trylock (mutex));
     381    return NULL;
     382  }
     383  
     384  /* Thread function to check that a mutex given in @data is unlocked */
     385  static gpointer
     386  mutex_unlocked_thread (gpointer data)
     387  {
     388    GMutex *mutex = (GMutex *) data;
     389    g_assert_true (g_mutex_trylock (mutex));
     390    g_mutex_unlock (mutex);
     391    return NULL;
     392  }
     393  
     394  static void
     395  test_g_mutex_locker (void)
     396  {
     397    GMutex mutex;
     398    GThread *thread;
     399  
     400    g_mutex_init (&mutex);
     401  
     402    if (TRUE)
     403      {
     404        g_autoptr(GMutexLocker) val = g_mutex_locker_new (&mutex);
     405        
     406        g_assert_nonnull (val);
     407  
     408        /* Verify that the mutex is actually locked */
     409        thread = g_thread_new ("mutex locked", mutex_locked_thread, &mutex);
     410        g_thread_join (thread);
     411      }
     412  
     413      /* Verify that the mutex is unlocked again */
     414      thread = g_thread_new ("mutex unlocked", mutex_unlocked_thread, &mutex);
     415      g_thread_join (thread);
     416  }
     417  
     418  /* Thread function to check that a recursive mutex given in @data is locked */
     419  static gpointer
     420  rec_mutex_locked_thread (gpointer data)
     421  {
     422    GRecMutex *rec_mutex = (GRecMutex *) data;
     423    g_assert_false (g_rec_mutex_trylock (rec_mutex));
     424    return NULL;
     425  }
     426  
     427  /* Thread function to check that a recursive mutex given in @data is unlocked */
     428  static gpointer
     429  rec_mutex_unlocked_thread (gpointer data)
     430  {
     431    GRecMutex *rec_mutex = (GRecMutex *) data;
     432    g_assert_true (g_rec_mutex_trylock (rec_mutex));
     433    g_rec_mutex_unlock (rec_mutex);
     434    return NULL;
     435  }
     436  
     437  static void
     438  test_g_rec_mutex_locker (void)
     439  {
     440    GRecMutex rec_mutex;
     441    GThread *thread;
     442  
     443    g_rec_mutex_init (&rec_mutex);
     444  
     445    if (TRUE)
     446      {
     447        g_autoptr(GRecMutexLocker) val = g_rec_mutex_locker_new (&rec_mutex);
     448        g_autoptr(GRecMutexLocker) other = NULL;
     449  
     450        g_assert_nonnull (val);
     451  
     452        /* Verify that the mutex is actually locked */
     453        thread = g_thread_new ("rec mutex locked", rec_mutex_locked_thread, &rec_mutex);
     454        g_thread_join (g_steal_pointer (&thread));
     455  
     456        other = g_rec_mutex_locker_new (&rec_mutex);
     457        thread = g_thread_new ("rec mutex locked", rec_mutex_locked_thread, &rec_mutex);
     458        g_thread_join (g_steal_pointer (&thread));
     459      }
     460  
     461    /* Verify that the mutex is unlocked again */
     462    thread = g_thread_new ("rec mutex unlocked", rec_mutex_unlocked_thread, &rec_mutex);
     463    g_thread_join (thread);
     464  
     465    g_rec_mutex_clear (&rec_mutex);
     466  }
     467  
     468  /* Thread function to check that an rw lock given in @data cannot be writer locked */
     469  static gpointer
     470  rw_lock_cannot_take_writer_lock_thread (gpointer data)
     471  {
     472    GRWLock *lock = (GRWLock *) data;
     473    g_assert_false (g_rw_lock_writer_trylock (lock));
     474    return NULL;
     475  }
     476  
     477  /* Thread function to check that an rw lock given in @data can be reader locked */
     478  static gpointer
     479  rw_lock_can_take_reader_lock_thread (gpointer data)
     480  {
     481    GRWLock *lock = (GRWLock *) data;
     482    g_assert_true (g_rw_lock_reader_trylock (lock));
     483    g_rw_lock_reader_unlock (lock);
     484    return NULL;
     485  }
     486  
     487  static void
     488  test_g_rw_lock_lockers (void)
     489  {
     490    GRWLock lock;
     491    GThread *thread;
     492  
     493    g_rw_lock_init (&lock);
     494  
     495    if (TRUE)
     496      {
     497        g_autoptr(GRWLockWriterLocker) val = g_rw_lock_writer_locker_new (&lock);
     498  
     499        g_assert_nonnull (val);
     500  
     501        /* Verify that we cannot take another writer lock as a writer lock is currently held */
     502        thread = g_thread_new ("rw lock cannot take writer lock", rw_lock_cannot_take_writer_lock_thread, &lock);
     503        g_thread_join (thread);
     504  
     505        /* Verify that we cannot take a reader lock as a writer lock is currently held */
     506        g_assert_false (g_rw_lock_reader_trylock (&lock));
     507      }
     508  
     509    if (TRUE)
     510      {
     511        g_autoptr(GRWLockReaderLocker) val = g_rw_lock_reader_locker_new (&lock);
     512  
     513        g_assert_nonnull (val);
     514  
     515        /* Verify that we can take another reader lock from another thread */
     516        thread = g_thread_new ("rw lock can take reader lock", rw_lock_can_take_reader_lock_thread, &lock);
     517        g_thread_join (thread);
     518  
     519        /* ... and also that recursive reader locking from the same thread works */
     520        g_assert_true (g_rw_lock_reader_trylock (&lock));
     521        g_rw_lock_reader_unlock (&lock);
     522  
     523        /* Verify that we cannot take a writer lock as a reader lock is currently held */
     524        thread = g_thread_new ("rw lock cannot take writer lock", rw_lock_cannot_take_writer_lock_thread, &lock);
     525        g_thread_join (thread);
     526      }
     527  
     528    /* Verify that we can take a writer lock again: this can only work if all of
     529     * the locks taken above have been correctly released. */
     530    g_assert_true (g_rw_lock_writer_trylock (&lock));
     531    g_rw_lock_writer_unlock (&lock);
     532  
     533    g_rw_lock_clear (&lock);
     534  }
     535  
     536  static void
     537  test_g_cond (void)
     538  {
     539    g_auto(GCond) val;
     540    g_cond_init (&val);
     541  }
     542  
     543  static void
     544  test_g_timer (void)
     545  {
     546    g_autoptr(GTimer) val = g_timer_new ();
     547    g_assert_nonnull (val);
     548  }
     549  
     550  static void
     551  test_g_time_zone (void)
     552  {
     553    g_autoptr(GTimeZone) val = g_time_zone_new_utc ();
     554    g_assert_nonnull (val);
     555  }
     556  
     557  static void
     558  test_g_tree (void)
     559  {
     560    g_autoptr(GTree) val = g_tree_new ((GCompareFunc)strcmp);
     561    g_assert_nonnull (val);
     562  }
     563  
     564  static void
     565  test_g_variant (void)
     566  {
     567    g_autoptr(GVariant) val = g_variant_new_string ("hello");
     568    g_assert_nonnull (val);
     569  }
     570  
     571  static void
     572  test_g_variant_builder (void)
     573  {
     574    g_autoptr(GVariantBuilder) val = g_variant_builder_new (G_VARIANT_TYPE ("as"));
     575    g_auto(GVariantBuilder) stackval;
     576  
     577    g_assert_nonnull (val);
     578    g_variant_builder_init (&stackval, G_VARIANT_TYPE ("as"));
     579  }
     580  
     581  static void
     582  test_g_variant_iter (void)
     583  {
     584    g_autoptr(GVariant) var = g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32, "", 0, sizeof(guint32));
     585    g_autoptr(GVariantIter) val = g_variant_iter_new (var);
     586    g_assert_nonnull (val);
     587  }
     588  
     589  static void
     590  test_g_variant_dict (void)
     591  {
     592    g_autoptr(GVariant) data = g_variant_new_from_data (G_VARIANT_TYPE ("a{sv}"), "", 0, FALSE, NULL, NULL);
     593    g_auto(GVariantDict) stackval;
     594    g_autoptr(GVariantDict) val = g_variant_dict_new (data);
     595  
     596    g_variant_dict_init (&stackval, data);
     597    g_assert_nonnull (val);
     598  }
     599  
     600  static void
     601  test_g_variant_type (void)
     602  {
     603    g_autoptr(GVariantType) val = g_variant_type_new ("s");
     604    g_assert_nonnull (val);
     605  }
     606  
     607  static void
     608  test_strv (void)
     609  {
     610    g_auto(GStrv) val = g_strsplit("a:b:c", ":", -1);
     611    g_assert_nonnull (val);
     612  }
     613  
     614  static void
     615  test_refstring (void)
     616  {
     617    g_autoptr(GRefString) str = g_ref_string_new ("hello, world");
     618    g_assert_nonnull (str);
     619  }
     620  
     621  static void
     622  test_pathbuf (void)
     623  {
     624  #if defined(G_OS_UNIX)
     625    g_autoptr(GPathBuf) buf1 = g_path_buf_new_from_path ("/bin/sh");
     626    g_auto(GPathBuf) buf2 = G_PATH_BUF_INIT;
     627  
     628    g_path_buf_push (&buf2, "/bin/sh");
     629  #elif defined(G_OS_WIN32)
     630    g_autoptr(GPathBuf) buf1 = g_path_buf_new_from_path ("C:\\windows\\system32.dll");
     631    g_auto(GPathBuf) buf2 = G_PATH_BUF_INIT;
     632  
     633    g_path_buf_push (&buf2, "C:\\windows\\system32.dll");
     634  #else
     635    g_test_skip ("Unsupported platform");
     636    return;
     637  #endif
     638  
     639    g_autofree char *path1 = g_path_buf_to_path (buf1);
     640    g_autofree char *path2 = g_path_buf_to_path (&buf2);
     641  
     642    g_assert_cmpstr (path1, ==, path2);
     643  }
     644  
     645  static void
     646  mark_freed (gpointer ptr)
     647  {
     648    gboolean *freed = ptr;
     649    *freed = TRUE;
     650  }
     651  
     652  static void
     653  test_autolist (void)
     654  {
     655    char data[1] = {0};
     656    gboolean freed1 = FALSE;
     657    gboolean freed2 = FALSE;
     658    gboolean freed3 = FALSE;
     659    GBytes *b1 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed1);
     660    GBytes *b2 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed2);
     661    GBytes *b3 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed3);
     662  
     663    {
     664      g_autolist(GBytes) l = NULL;
     665  
     666      l = g_list_prepend (l, b1);
     667      l = g_list_prepend (l, b3);
     668  
     669      /* Squash warnings about dead stores */
     670      (void) l;
     671    }
     672  
     673    /* Only assert if autoptr works */
     674  #ifdef __GNUC__
     675    g_assert_true (freed1);
     676    g_assert_true (freed3);
     677  #endif
     678    g_assert_false (freed2);
     679  
     680    g_bytes_unref (b2);
     681    g_assert_true (freed2);
     682  }
     683  
     684  static void
     685  test_autoslist (void)
     686  {
     687    char data[1] = {0};
     688    gboolean freed1 = FALSE;
     689    gboolean freed2 = FALSE;
     690    gboolean freed3 = FALSE;
     691    GBytes *b1 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed1);
     692    GBytes *b2 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed2);
     693    GBytes *b3 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed3);
     694  
     695    {
     696      g_autoslist(GBytes) l = NULL;
     697  
     698      l = g_slist_prepend (l, b1);
     699      l = g_slist_prepend (l, b3);
     700    }
     701  
     702    /* Only assert if autoptr works */
     703  #ifdef __GNUC__
     704    g_assert_true (freed1);
     705    g_assert_true (freed3);
     706  #endif
     707    g_assert_false (freed2);
     708  
     709    g_bytes_unref (b2);
     710    g_assert_true (freed2);
     711  }
     712  
     713  static void
     714  test_autoqueue (void)
     715  {
     716    char data[1] = {0};
     717    gboolean freed1 = FALSE;
     718    gboolean freed2 = FALSE;
     719    gboolean freed3 = FALSE;
     720    GBytes *b1 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed1);
     721    GBytes *b2 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed2);
     722    GBytes *b3 = g_bytes_new_with_free_func (data, sizeof(data), mark_freed, &freed3);
     723  
     724    {
     725      g_autoqueue(GBytes) q = g_queue_new ();
     726  
     727      g_queue_push_head (q, b1);
     728      g_queue_push_tail (q, b3);
     729    }
     730  
     731    /* Only assert if autoptr works */
     732  #ifdef __GNUC__
     733    g_assert_true (freed1);
     734    g_assert_true (freed3);
     735  #endif
     736    g_assert_false (freed2);
     737  
     738    g_bytes_unref (b2);
     739    g_assert_true (freed2);
     740  }
     741  
     742  int
     743  main (int argc, gchar *argv[])
     744  {
     745    g_test_init (&argc, &argv, NULL);
     746  
     747    g_test_add_func ("/autoptr/autofree", test_autofree);
     748    g_test_add_func ("/autoptr/g_async_queue", test_g_async_queue);
     749    g_test_add_func ("/autoptr/g_bookmark_file", test_g_bookmark_file);
     750    g_test_add_func ("/autoptr/g_bytes", test_g_bytes);
     751    g_test_add_func ("/autoptr/g_checksum", test_g_checksum);
     752    g_test_add_func ("/autoptr/g_date", test_g_date);
     753    g_test_add_func ("/autoptr/g_date_time", test_g_date_time);
     754    g_test_add_func ("/autoptr/g_dir", test_g_dir);
     755    g_test_add_func ("/autoptr/g_error", test_g_error);
     756    g_test_add_func ("/autoptr/g_hash_table", test_g_hash_table);
     757    g_test_add_func ("/autoptr/g_hmac", test_g_hmac);
     758    g_test_add_func ("/autoptr/g_io_channel", test_g_io_channel);
     759    g_test_add_func ("/autoptr/g_key_file", test_g_key_file);
     760    g_test_add_func ("/autoptr/g_list", test_g_list);
     761    g_test_add_func ("/autoptr/g_array", test_g_array);
     762    g_test_add_func ("/autoptr/g_ptr_array", test_g_ptr_array);
     763    g_test_add_func ("/autoptr/g_byte_array", test_g_byte_array);
     764    g_test_add_func ("/autoptr/g_main_context", test_g_main_context);
     765    g_test_add_func ("/autoptr/g_main_context_pusher", test_g_main_context_pusher);
     766    g_test_add_func ("/autoptr/g_main_loop", test_g_main_loop);
     767    g_test_add_func ("/autoptr/g_source", test_g_source);
     768    g_test_add_func ("/autoptr/g_mapped_file", test_g_mapped_file);
     769    g_test_add_func ("/autoptr/g_markup_parse_context", test_g_markup_parse_context);
     770    g_test_add_func ("/autoptr/g_node", test_g_node);
     771    g_test_add_func ("/autoptr/g_option_context", test_g_option_context);
     772    g_test_add_func ("/autoptr/g_option_group", test_g_option_group);
     773    g_test_add_func ("/autoptr/g_pattern_spec", test_g_pattern_spec);
     774    g_test_add_func ("/autoptr/g_queue", test_g_queue);
     775    g_test_add_func ("/autoptr/g_rand", test_g_rand);
     776    g_test_add_func ("/autoptr/g_regex", test_g_regex);
     777    g_test_add_func ("/autoptr/g_match_info", test_g_match_info);
     778    g_test_add_func ("/autoptr/g_scanner", test_g_scanner);
     779    g_test_add_func ("/autoptr/g_sequence", test_g_sequence);
     780    g_test_add_func ("/autoptr/g_slist", test_g_slist);
     781    g_test_add_func ("/autoptr/g_string", test_g_string);
     782    g_test_add_func ("/autoptr/g_string_chunk", test_g_string_chunk);
     783    g_test_add_func ("/autoptr/g_thread", test_g_thread);
     784    g_test_add_func ("/autoptr/g_mutex", test_g_mutex);
     785    g_test_add_func ("/autoptr/g_mutex_locker", test_g_mutex_locker);
     786    g_test_add_func ("/autoptr/g_rec_mutex_locker", test_g_rec_mutex_locker);
     787    g_test_add_func ("/autoptr/g_rw_lock_lockers", test_g_rw_lock_lockers);
     788    g_test_add_func ("/autoptr/g_cond", test_g_cond);
     789    g_test_add_func ("/autoptr/g_timer", test_g_timer);
     790    g_test_add_func ("/autoptr/g_time_zone", test_g_time_zone);
     791    g_test_add_func ("/autoptr/g_tree", test_g_tree);
     792    g_test_add_func ("/autoptr/g_variant", test_g_variant);
     793    g_test_add_func ("/autoptr/g_variant_builder", test_g_variant_builder);
     794    g_test_add_func ("/autoptr/g_variant_iter", test_g_variant_iter);
     795    g_test_add_func ("/autoptr/g_variant_dict", test_g_variant_dict);
     796    g_test_add_func ("/autoptr/g_variant_type", test_g_variant_type);
     797    g_test_add_func ("/autoptr/strv", test_strv);
     798    g_test_add_func ("/autoptr/refstring", test_refstring);
     799    g_test_add_func ("/autoptr/pathbuf", test_pathbuf);
     800    g_test_add_func ("/autoptr/autolist", test_autolist);
     801    g_test_add_func ("/autoptr/autoslist", test_autoslist);
     802    g_test_add_func ("/autoptr/autoqueue", test_autoqueue);
     803  
     804    return g_test_run ();
     805  }