~attente/glib/gicon-upstream

« back to all changes in this revision

Viewing changes to gio/tests/file.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-03-26 13:24:05 UTC
  • mfrom: (1.63.18)
  • Revision ID: package-import@ubuntu.com-20130326132405-rwwke1lhar1e02sl
Tags: 2.36.0-1ubuntu1
* Merge with Debian experimental. Remaining Ubuntu changes:
  - Build-depend on python:any for cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include <stdlib.h>
4
4
#include <gio/gio.h>
5
5
#include <gio/gfiledescriptorbased.h>
 
6
#ifdef G_OS_UNIX
 
7
#include <sys/stat.h>
 
8
#endif
6
9
 
7
10
static void
8
11
test_basic (void)
727
730
  g_object_unref (file);
728
731
}
729
732
 
 
733
#ifdef G_OS_UNIX
 
734
static void
 
735
test_copy_preserve_mode (void)
 
736
{
 
737
  GFile *tmpfile;
 
738
  GFile *dest_tmpfile;
 
739
  GFileInfo *dest_info;
 
740
  GFileIOStream *iostream;
 
741
  GError *local_error = NULL;
 
742
  GError **error = &local_error;
 
743
  guint32 romode = S_IFREG | 0600;
 
744
  guint32 dest_mode;
 
745
 
 
746
  tmpfile = g_file_new_tmp ("tmp-copy-preserve-modeXXXXXX",
 
747
                            &iostream, error);
 
748
  g_assert_no_error (local_error);
 
749
  g_io_stream_close ((GIOStream*)iostream, NULL, error);
 
750
  g_assert_no_error (local_error);
 
751
  g_clear_object (&iostream);
 
752
 
 
753
  g_file_set_attribute (tmpfile, G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_ATTRIBUTE_TYPE_UINT32,
 
754
                        &romode, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
755
                        NULL, error);
 
756
  g_assert_no_error (local_error);
 
757
 
 
758
  dest_tmpfile = g_file_new_tmp ("tmp-copy-preserve-modeXXXXXX",
 
759
                                 &iostream, error);
 
760
  g_assert_no_error (local_error);
 
761
  g_io_stream_close ((GIOStream*)iostream, NULL, error);
 
762
  g_assert_no_error (local_error);
 
763
  g_clear_object (&iostream);
 
764
 
 
765
  g_file_copy (tmpfile, dest_tmpfile, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_ALL_METADATA,
 
766
               NULL, NULL, NULL, error);
 
767
  g_assert_no_error (local_error);
 
768
 
 
769
  dest_info = g_file_query_info (dest_tmpfile, G_FILE_ATTRIBUTE_UNIX_MODE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
 
770
                                 NULL, error);
 
771
  g_assert_no_error (local_error);
 
772
 
 
773
  dest_mode = g_file_info_get_attribute_uint32 (dest_info, G_FILE_ATTRIBUTE_UNIX_MODE);
 
774
  
 
775
  g_assert_cmpint (dest_mode, ==, romode);
 
776
 
 
777
  (void) g_file_delete (tmpfile, NULL, NULL);
 
778
  (void) g_file_delete (dest_tmpfile, NULL, NULL);
 
779
  
 
780
  g_clear_object (&tmpfile);
 
781
  g_clear_object (&dest_tmpfile);
 
782
  g_clear_object (&dest_info);
 
783
}
 
784
#endif
 
785
 
730
786
int
731
787
main (int argc, char *argv[])
732
788
{
746
802
  g_test_add_func ("/file/replace-load", test_replace_load);
747
803
  g_test_add_func ("/file/replace-cancel", test_replace_cancel);
748
804
  g_test_add_func ("/file/async-delete", test_async_delete);
 
805
#ifdef G_OS_UNIX
 
806
  g_test_add_func ("/file/copy-preserve-mode", test_copy_preserve_mode);
 
807
#endif
749
808
 
750
809
  return g_test_run ();
751
810
}