Remove g_type_init() calls
[platform/upstream/glib.git] / gio / tests / g-file-info.c
1 /* GLib testing framework examples and tests
2  * Copyright (C) 2008 Red Hat, Inc.
3  * Authors: Tomas Bzatek <tbzatek@redhat.com>
4  *
5  * This work is provided "as is"; redistribution and modification
6  * in whole or in part, in any medium, physical or electronic is
7  * permitted without restriction.
8  *
9  * This work is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * In no event shall the authors or contributors be liable for any
14  * direct, indirect, incidental, special, exemplary, or consequential
15  * damages (including, but not limited to, procurement of substitute
16  * goods or services; loss of use, data, or profits; or business
17  * interruption) however caused and on any theory of liability, whether
18  * in contract, strict liability, or tort (including negligence or
19  * otherwise) arising in any way out of the use of this software, even
20  * if advised of the possibility of such damage.
21  */
22
23 #include <glib/glib.h>
24 #include <gio/gio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #define TEST_NAME                       "Prilis zlutoucky kun"
29 #define TEST_DISPLAY_NAME               "UTF-8 p\xc5\x99\xc3\xadli\xc5\xa1 \xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd k\xc5\xaf\xc5\x88"
30 #define TEST_SIZE                       0xFFFFFFF0
31
32 static void
33 test_assigned_values (GFileInfo *info)
34 {
35   const char *name, *display_name, *mistake;
36   guint64 size;
37   GFileType type;
38   
39   /*  Test for attributes presence */
40   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_NAME) == TRUE);
41   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) == TRUE);
42   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE) == TRUE);
43   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME) == FALSE);
44         
45   /*  Retrieve data back and compare */
46   
47   name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME);
48   display_name = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
49   mistake = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME);
50   size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
51   type = g_file_info_get_file_type (info);
52   
53   g_assert_cmpstr (name, ==, TEST_NAME);
54   g_assert_cmpstr (display_name, ==, TEST_DISPLAY_NAME);
55   g_assert (mistake == NULL);
56   g_assert_cmpint (size, ==, TEST_SIZE);
57   g_assert_cmpstr (name, ==, g_file_info_get_name (info));
58   g_assert_cmpstr (display_name, ==, g_file_info_get_display_name (info));
59   g_assert_cmpint (size, ==, g_file_info_get_size (info)        );
60   g_assert_cmpint (type, ==, G_FILE_TYPE_DIRECTORY);
61 }
62
63
64
65 static void
66 test_g_file_info (void)
67 {
68   GFileInfo *info;
69   GFileInfo *info_dup;
70   GFileInfo *info_copy;
71   char **attr_list;
72   
73   info = g_file_info_new ();
74   
75   /*  Test for empty instance */
76   attr_list = g_file_info_list_attributes (info, NULL);
77   g_assert (attr_list != NULL);
78   g_assert (*attr_list == NULL);
79   g_strfreev (attr_list);
80
81   g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME, TEST_NAME);
82   g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, TEST_DISPLAY_NAME);
83   g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE, TEST_SIZE);
84   g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
85         
86   /*  The attr list should not be empty now */
87   attr_list = g_file_info_list_attributes (info, NULL);
88   g_assert (attr_list != NULL);
89   g_assert (*attr_list != NULL);
90   g_strfreev (attr_list);
91
92   test_assigned_values (info);
93         
94   /*  Test dups */
95   info_dup = g_file_info_dup (info);
96   g_assert (info_dup != NULL);
97   test_assigned_values (info_dup);
98   
99   info_copy = g_file_info_new ();
100   g_file_info_copy_into (info_dup, info_copy);
101   g_assert (info_copy != NULL);
102   test_assigned_values (info_copy);
103         
104   /*  Test remove attribute */
105   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER) == FALSE);
106   g_file_info_set_attribute_int32 (info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER, 10);
107   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER) == TRUE);
108         
109   g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER);
110   g_assert (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER) == FALSE);
111         
112   g_object_unref (info);
113   g_object_unref (info_dup);
114   g_object_unref (info_copy);
115 }
116
117 int
118 main (int   argc,
119       char *argv[])
120 {
121   g_test_init (&argc, &argv, NULL);
122
123   g_test_add_func ("/g-file-info/test_g_file_info", test_g_file_info);
124   
125   return g_test_run();
126 }