mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-10-01 05:23:56 +00:00
vfs-file: Turn file metadata tests into unittests
These were previously commented out in `file-directory.c`. They couldn't have functioned anymore, as setting arbitrary metadata values is prevented by the nautilus-metadata hash table. By reusing already existing metadata tags, that don't have any effect on the file they are used on, these tests can be reactivated. In order to work in test environments without gvfsd-metadata running, bypass GIO and set metadata directly.
This commit is contained in:
parent
8a6ad0451b
commit
48c521eb8f
|
@ -1963,18 +1963,6 @@ nautilus_directory_dump (NautilusDirectory *directory)
|
|||
void
|
||||
nautilus_self_check_directory (void)
|
||||
{
|
||||
/* FIXME: these need to be updated to the new metadata infrastructure
|
||||
* as make check doesn't pass.
|
||||
* nautilus_file_set_metadata (file, "test", "default", "value");
|
||||
* EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value");
|
||||
*
|
||||
* nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE);
|
||||
* EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE);
|
||||
* nautilus_file_set_boolean_metadata (file, "test_boolean", FALSE);
|
||||
* EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE);
|
||||
* EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE);
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
||||
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
|
||||
|
|
|
@ -159,13 +159,9 @@ vfs_file_set_metadata (NautilusFile *file,
|
|||
const char *key,
|
||||
const char *value)
|
||||
{
|
||||
GFileInfo *info;
|
||||
GFile *location;
|
||||
char *gio_key;
|
||||
g_autoptr (GFileInfo) info = g_file_info_new ();
|
||||
g_autofree char *gio_key = g_strconcat ("metadata::", key, NULL);
|
||||
|
||||
info = g_file_info_new ();
|
||||
|
||||
gio_key = g_strconcat ("metadata::", key, NULL);
|
||||
if (value != NULL)
|
||||
{
|
||||
g_file_info_set_attribute_string (info, gio_key, value);
|
||||
|
@ -177,9 +173,14 @@ vfs_file_set_metadata (NautilusFile *file,
|
|||
G_FILE_ATTRIBUTE_TYPE_INVALID,
|
||||
NULL);
|
||||
}
|
||||
g_free (gio_key);
|
||||
|
||||
location = nautilus_file_get_location (file);
|
||||
if (g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE") == 0)
|
||||
{
|
||||
nautilus_file_update_metadata_from_info (file, info);
|
||||
return;
|
||||
}
|
||||
|
||||
g_autoptr (GFile) location = nautilus_file_get_location (file);
|
||||
g_file_set_attributes_async (location,
|
||||
info,
|
||||
0,
|
||||
|
@ -187,8 +188,6 @@ vfs_file_set_metadata (NautilusFile *file,
|
|||
NULL,
|
||||
set_metadata_callback,
|
||||
nautilus_file_ref (file));
|
||||
g_object_unref (location);
|
||||
g_object_unref (info);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -196,13 +195,9 @@ vfs_file_set_metadata_as_list (NautilusFile *file,
|
|||
const char *key,
|
||||
char **value)
|
||||
{
|
||||
GFile *location;
|
||||
GFileInfo *info;
|
||||
char *gio_key;
|
||||
g_autoptr (GFileInfo) info = g_file_info_new ();
|
||||
g_autofree char *gio_key = g_strconcat ("metadata::", key, NULL);
|
||||
|
||||
info = g_file_info_new ();
|
||||
|
||||
gio_key = g_strconcat ("metadata::", key, NULL);
|
||||
if (value == NULL)
|
||||
{
|
||||
g_file_info_set_attribute (info, gio_key, G_FILE_ATTRIBUTE_TYPE_INVALID, NULL);
|
||||
|
@ -211,9 +206,14 @@ vfs_file_set_metadata_as_list (NautilusFile *file,
|
|||
{
|
||||
g_file_info_set_attribute_stringv (info, gio_key, value);
|
||||
}
|
||||
g_free (gio_key);
|
||||
|
||||
location = nautilus_file_get_location (file);
|
||||
if (g_strcmp0 (g_getenv ("RUNNING_TESTS"), "TRUE") == 0)
|
||||
{
|
||||
nautilus_file_update_metadata_from_info (file, info);
|
||||
return;
|
||||
}
|
||||
|
||||
g_autoptr (GFile) location = nautilus_file_get_location (file);
|
||||
g_file_set_attributes_async (location,
|
||||
info,
|
||||
0,
|
||||
|
@ -221,8 +221,6 @@ vfs_file_set_metadata_as_list (NautilusFile *file,
|
|||
NULL,
|
||||
set_metadata_callback,
|
||||
nautilus_file_ref (file));
|
||||
g_object_unref (info);
|
||||
g_object_unref (location);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -6,6 +6,9 @@ tests = [
|
|||
['test-directory', [
|
||||
'test-directory.c'
|
||||
]],
|
||||
['test-file-metadata', [
|
||||
'test-file-metadata.c'
|
||||
]],
|
||||
['test-file-utilities-get-common-filename-prefix', [
|
||||
'test-file-utilities-get-common-filename-prefix.c'
|
||||
]],
|
||||
|
|
71
test/automated/displayless/test-file-metadata.c
Normal file
71
test/automated/displayless/test-file-metadata.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include <nautilus-file.h>
|
||||
#include <nautilus-file-utilities.h>
|
||||
#include <nautilus-metadata.h>
|
||||
|
||||
static const char *TEST_FILE = "file:///etc/passwd";
|
||||
static const char *KEY_BOOL = NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED;
|
||||
static const char *KEY_STR = NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY;
|
||||
|
||||
static void
|
||||
test_file_metadata_bool_set_true (void)
|
||||
{
|
||||
g_autoptr (NautilusFile) file = nautilus_file_get_by_uri (TEST_FILE);
|
||||
nautilus_file_set_boolean_metadata (file, KEY_BOOL, TRUE);
|
||||
g_assert_true (nautilus_file_get_boolean_metadata (file, KEY_BOOL, FALSE));
|
||||
}
|
||||
|
||||
static void
|
||||
test_file_metadata_bool_set_false (void)
|
||||
{
|
||||
g_autoptr (NautilusFile) file = nautilus_file_get_by_uri (TEST_FILE);
|
||||
nautilus_file_set_boolean_metadata (file, KEY_BOOL, FALSE);
|
||||
g_assert_false (nautilus_file_get_boolean_metadata (file, KEY_BOOL, TRUE));
|
||||
}
|
||||
|
||||
static void
|
||||
test_file_metadata_bool_get_null (void)
|
||||
{
|
||||
g_assert_true (nautilus_file_get_boolean_metadata (NULL, KEY_BOOL, TRUE));
|
||||
|
||||
g_assert_false (nautilus_file_get_boolean_metadata (NULL, KEY_BOOL, FALSE));
|
||||
}
|
||||
|
||||
static void
|
||||
test_file_metadata_str_set (void)
|
||||
{
|
||||
g_autoptr (NautilusFile) file = nautilus_file_get_by_uri (TEST_FILE);
|
||||
nautilus_file_set_metadata (file, KEY_STR, "default", "value");
|
||||
g_autofree char *metadata = nautilus_file_get_metadata (file, KEY_STR, "default");
|
||||
g_assert_cmpstr (metadata, ==, "value");
|
||||
}
|
||||
|
||||
static void
|
||||
test_file_metadata_str_get_null (void)
|
||||
{
|
||||
g_autofree char *metadata = nautilus_file_get_metadata (NULL, KEY_STR, "default");
|
||||
g_assert_cmpstr (metadata, ==, "default");
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
g_test_set_nonfatal_assertions ();
|
||||
nautilus_ensure_extension_points ();
|
||||
|
||||
g_test_add_func ("/file-metadata-set-bool/true",
|
||||
test_file_metadata_bool_set_true);
|
||||
g_test_add_func ("/file-metadata-set-bool/false",
|
||||
test_file_metadata_bool_set_false);
|
||||
g_test_add_func ("/file-metadata-set-bool/null",
|
||||
test_file_metadata_bool_get_null);
|
||||
g_test_add_func ("/file-metadata-str-set/default",
|
||||
test_file_metadata_str_set);
|
||||
g_test_add_func ("/file-metadata-str-set/null",
|
||||
test_file_metadata_str_get_null);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Loading…
Reference in a new issue