1 /* GLib testing framework examples and tests
2 * Copyright (C) 2008 Red Hat, Inc.
3 * Authors: Tomas Bzatek <tbzatek@redhat.com>
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.
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.
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.
23 #include <glib/glib.h>
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
33 test_assigned_values (GFileInfo
*info
)
35 const char *name
, *display_name
, *mistake
;
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
);
45 /* Retrieve data back and compare */
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
);
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
);
66 test_g_file_info (void)
72 GFileAttributeMatcher
*matcher
;
74 info
= g_file_info_new ();
76 /* Test for empty instance */
77 attr_list
= g_file_info_list_attributes (info
, NULL
);
78 g_assert (attr_list
!= NULL
);
79 g_assert (*attr_list
== NULL
);
80 g_strfreev (attr_list
);
82 g_file_info_set_attribute_byte_string (info
, G_FILE_ATTRIBUTE_STANDARD_NAME
, TEST_NAME
);
83 g_file_info_set_attribute_string (info
, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
, TEST_DISPLAY_NAME
);
84 g_file_info_set_attribute_uint64 (info
, G_FILE_ATTRIBUTE_STANDARD_SIZE
, TEST_SIZE
);
85 g_file_info_set_file_type (info
, G_FILE_TYPE_DIRECTORY
);
87 /* The attr list should not be empty now */
88 attr_list
= g_file_info_list_attributes (info
, NULL
);
89 g_assert (attr_list
!= NULL
);
90 g_assert (*attr_list
!= NULL
);
91 g_strfreev (attr_list
);
93 test_assigned_values (info
);
96 info_dup
= g_file_info_dup (info
);
97 g_assert (info_dup
!= NULL
);
98 test_assigned_values (info_dup
);
100 info_copy
= g_file_info_new ();
101 g_file_info_copy_into (info_dup
, info_copy
);
102 g_assert (info_copy
!= NULL
);
103 test_assigned_values (info_copy
);
105 /* Test remove attribute */
106 g_assert (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) == FALSE
);
107 g_file_info_set_attribute_int32 (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
, 10);
108 g_assert (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) == TRUE
);
110 g_assert (g_file_info_get_attribute_type (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) == G_FILE_ATTRIBUTE_TYPE_INT32
);
111 g_assert (g_file_info_get_attribute_status (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) != G_FILE_ATTRIBUTE_STATUS_ERROR_SETTING
);
113 g_file_info_remove_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
);
114 g_assert (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) == FALSE
);
115 g_assert (g_file_info_get_attribute_type (info
, G_FILE_ATTRIBUTE_STANDARD_SORT_ORDER
) == G_FILE_ATTRIBUTE_TYPE_INVALID
);
117 matcher
= g_file_attribute_matcher_new (G_FILE_ATTRIBUTE_STANDARD_NAME
","
118 G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME
);
120 g_assert (g_file_attribute_matcher_matches (matcher
, G_FILE_ATTRIBUTE_STANDARD_NAME
) == TRUE
);
121 g_assert (g_file_attribute_matcher_matches_only (matcher
, G_FILE_ATTRIBUTE_STANDARD_NAME
) == FALSE
);
122 g_assert (g_file_attribute_matcher_matches (matcher
, G_FILE_ATTRIBUTE_STANDARD_SIZE
) == FALSE
);
124 g_file_info_set_attribute_mask (info
, matcher
);
125 g_file_attribute_matcher_unref (matcher
);
127 g_assert (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_SIZE
) == FALSE
);
128 g_assert (g_file_info_has_attribute (info
, G_FILE_ATTRIBUTE_STANDARD_NAME
) == TRUE
);
130 g_object_unref (info
);
131 g_object_unref (info_dup
);
132 g_object_unref (info_copy
);
139 g_test_init (&argc
, &argv
, NULL
);
141 g_test_add_func ("/g-file-info/test_g_file_info", test_g_file_info
);