diff options
Diffstat (limited to 'test/interactive')
-rw-r--r-- | test/interactive/file-torture.py | 266 | ||||
-rw-r--r-- | test/interactive/meson.build | 8 | ||||
-rw-r--r-- | test/interactive/test-copy.c | 102 | ||||
-rw-r--r-- | test/interactive/test.c | 125 | ||||
-rw-r--r-- | test/interactive/test.h | 35 |
5 files changed, 536 insertions, 0 deletions
diff --git a/test/interactive/file-torture.py b/test/interactive/file-torture.py new file mode 100644 index 0000000..865795f --- /dev/null +++ b/test/interactive/file-torture.py @@ -0,0 +1,266 @@ +#!/usr/bin/env python +# +# file-torture.py - Simple torture test for file notificatins in Nautilus +# Copyright (C) 2006 Federico Mena-Quintero +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see <http://www.gnu.org/licenses/>. +# +# Author: Federico Mena-Quintero <federico@novell.com> + +import random +import os +import sys +import optparse +import time + +output_dir = "" +random_gen = None +verbose = False + +extensions = (".doc", ".gif", ".jpg", ".png", ".xls", ".odt", ".odp", ".ods", ".txt", ".zip", ".gz") + +files = [] +directories = [] + +def get_random_file_index (): + n = len (files) + if n == 0: + return -1 + else: + return random_gen.randrange (n) + +def get_random_directory_index (): + n = len (directories) + if n == 0: + return -1 + else: + return random_gen.randrange (n) + +def get_random_filename (): + chars = [] + for i in range (20): + chars.append ("abcdefghijklmnopqrstuvwxyz"[random_gen.randrange (26)]) + + extension = extensions[random_gen.randrange (len (extensions))] + filename = "".join (chars) + extension + return filename + +def get_random_path (): + return os.path.join (output_dir, get_random_filename ()) + +def op_create_file (): + filename = get_random_path () + files.append (filename) + f = open (filename, "w") + f.close () + + if verbose: + print 'create file %s' % filename + + return True + +def op_move_file (): + idx = get_random_file_index () + if idx == -1: + return False + + new_name = get_random_path () + old_name = files[idx] + os.rename (old_name, new_name) + files[idx] = new_name + + if verbose: + print 'rename file %s to %s' % (old_name, new_name) + + return True + +def op_delete_file (): + idx = get_random_file_index () + if idx == -1: + return False + + filename = files[idx] + + os.unlink (filename) + files.pop (idx) + + if verbose: + print 'delete file %s' % filename + + return True + +def op_write_file (): + idx = get_random_file_index () + if idx == -1: + return False + + name = files[idx] + f = open (name, "a") + f.write ("blah blah blah blah blah blah blah\n") + f.close () + + if verbose: + print 'write to file %s' % name + + return True + +def op_create_dir (): + name = get_random_path () + os.mkdir (name) + directories.append (name) + + if verbose: + print 'create directory %s' % name + + return True + +def op_move_dir (): + idx = get_random_directory_index () + if idx == -1: + return False + + new_name = get_random_path () + old_name = directories[idx] + os.rename (old_name, new_name) + directories[idx] = new_name + + if verbose: + print 'move directory %s to %s' % (old_name, new_name) + + return True + +def op_delete_dir (): + idx = get_random_directory_index () + if idx == -1: + return False + + name = directories[idx] + os.rmdir (name) + directories.pop (idx) + + if verbose: + print 'delete directory %s' % name + + return True + +def op_file_to_dir (): + idx = get_random_file_index () + if idx == -1: + return False + + name = files[idx] + os.unlink (name) + files.pop (idx) + os.mkdir (name) + directories.append (name) + + if verbose: + print 'file to dir %s' % name + + return True + +def op_dir_to_file (): + idx = get_random_directory_index () + if idx == -1: + return False + + name = directories[idx] + os.rmdir (name) + directories.pop (idx) + f = open (name, "w") + f.close () + files.append (name) + + if verbose: + print 'dir to file %s' % name + + return True + +operations = ( + op_create_file, + op_move_file, + op_delete_file, + op_write_file, + op_create_dir, + op_move_dir, + op_delete_dir, + op_file_to_dir, + op_dir_to_file, + ) + +def main (): + option_parser = optparse.OptionParser (usage="usage: %prog -o <dirname>") + option_parser.add_option ("-o", + "--output", dest="output", + metavar="FILE", + help="Name of output directory") + option_parser.add_option ("-s", + "--seed", dest="seed", + metavar="NUMBER", + help="Random number seed") + option_parser.add_option ("", + "--no-sleep", dest="sleep_enabled", action="store_false", default=True, + help="Disable short sleeps between operations. Will use a lot of CPU!") + option_parser.add_option ("-v", + "--verbose", dest="verbose", action="store_true", default=False, + help="Enable verbose output") + + (options, args) = option_parser.parse_args () + + if not options.output: + print 'Please specify an output directory with "-o outputdir"' + return 1 + + sleep_enabled = options.sleep_enabled + + if len (args) != 0: + print 'No extra arguments are supported' + return 1 + + global output_dir + global random_gen + global verbose + + verbose = options.verbose + + random_gen = random.Random () + if options.seed: + seed = int (options.seed) + else: + seed = int (time.time ()) + + print 'Use "--seed=%s" to reproduce this run' % seed + random_gen.seed (seed) + + if sleep_enabled: + print 'Using short sleeps between operations (use --no-sleep to disable)' + else: + print 'Disabling short sleeps between operations' + + output_dir = options.output + try: + os.mkdir (output_dir) + except: + 1 # nothing + + while True: + op = operations [random_gen.randrange (len (operations))] + op () + if sleep_enabled: + time.sleep (random_gen.random () / 100) + + return 0 + +if __name__ == "__main__": + sys.exit (main ()) diff --git a/test/interactive/meson.build b/test/interactive/meson.build new file mode 100644 index 0000000..eb8cf8a --- /dev/null +++ b/test/interactive/meson.build @@ -0,0 +1,8 @@ +test_copy = executable( + 'test-copy', [ + 'test-copy.c', + 'test.c', + 'test.h' + ], + dependencies: libnautilus_dep +) diff --git a/test/interactive/test-copy.c b/test/interactive/test-copy.c new file mode 100644 index 0000000..194eda4 --- /dev/null +++ b/test/interactive/test-copy.c @@ -0,0 +1,102 @@ +#include "test.h" + +#include <src/nautilus-file-operations.h> +#include <src/nautilus-progress-info.h> +#include <src/nautilus-progress-info-manager.h> + +static void +copy_done (GHashTable *debuting_uris, + gboolean success, + gpointer data) +{ + g_print ("Copy done\n"); +} + +static void +changed_cb (NautilusProgressInfo *info, + gpointer data) +{ + g_print ("Changed: %s -- %s\n", + nautilus_progress_info_get_status (info), + nautilus_progress_info_get_details (info)); +} + +static void +progress_changed_cb (NautilusProgressInfo *info, + gpointer data) +{ + g_print ("Progress changed: %f\n", + nautilus_progress_info_get_progress (info)); +} + +static void +finished_cb (NautilusProgressInfo *info, + gpointer data) +{ + g_print ("Finished\n"); + gtk_main_quit (); +} + +int +main (int argc, + char *argv[]) +{ + GtkWidget *window; + GList *sources; + GFile *dest; + GFile *source; + int i; + GList *infos; + NautilusProgressInfoManager *manager; + NautilusProgressInfo *progress_info; + + test_init (&argc, &argv); + + if (argc < 3) + { + g_print ("Usage test-copy <sources...> <dest dir>\n"); + return 1; + } + + sources = NULL; + for (i = 1; i < argc - 1; i++) + { + source = g_file_new_for_commandline_arg (argv[i]); + sources = g_list_prepend (sources, source); + } + sources = g_list_reverse (sources); + + dest = g_file_new_for_commandline_arg (argv[i]); + + window = test_window_new ("copy test", 5); + + gtk_widget_show (window); + + manager = nautilus_progress_info_manager_dup_singleton (); + + nautilus_file_operations_copy_async (sources, + dest, + GTK_WINDOW (window), + NULL, + copy_done, NULL); + + infos = nautilus_progress_info_manager_get_all_infos (manager); + + if (infos == NULL) + { + g_object_unref (manager); + return 0; + } + + progress_info = NAUTILUS_PROGRESS_INFO (infos->data); + + g_signal_connect (progress_info, "changed", (GCallback) changed_cb, NULL); + g_signal_connect (progress_info, "progress-changed", (GCallback) progress_changed_cb, NULL); + g_signal_connect (progress_info, "finished", (GCallback) finished_cb, NULL); + + gtk_main (); + + g_object_unref (manager); + + return 0; +} diff --git a/test/interactive/test.c b/test/interactive/test.c new file mode 100644 index 0000000..43e8fbc --- /dev/null +++ b/test/interactive/test.c @@ -0,0 +1,125 @@ +#include "test.h" +#include <sys/types.h> +#include <unistd.h> + +void +test_init (int *argc, + char ***argv) +{ + gtk_init (argc, argv); + + eel_make_warnings_and_criticals_stop_in_debugger (); +} + +int +test_quit (int exit_code) +{ + if (gtk_main_level () > 0) + { + gtk_main_quit (); + } + + return exit_code; +} + +void +test_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer callback_data) +{ + test_quit (0); +} + +GtkWidget * +test_window_new (const char *title, + guint border_width) +{ + GtkWidget *window; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + if (title != NULL) + { + gtk_window_set_title (GTK_WINDOW (window), title); + } + + g_signal_connect (window, "delete_event", + G_CALLBACK (test_delete_event), NULL); + + gtk_container_set_border_width (GTK_CONTAINER (window), border_width); + + return window; +} + +GdkPixbuf * +test_pixbuf_new_named (const char *name, + float scale) +{ + GdkPixbuf *pixbuf; + char *path; + + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (scale >= 0.0, NULL); + + if (name[0] == '/') + { + path = g_strdup (name); + } + else + { + path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name); + } + + pixbuf = gdk_pixbuf_new_from_file (path, NULL); + + g_free (path); + + g_return_val_if_fail (pixbuf != NULL, NULL); + + if (scale != 1.0) + { + GdkPixbuf *scaled; + float width = gdk_pixbuf_get_width (pixbuf) * scale; + float height = gdk_pixbuf_get_width (pixbuf) * scale; + + scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); + + g_object_unref (pixbuf); + + g_return_val_if_fail (scaled != NULL, NULL); + + pixbuf = scaled; + } + + return pixbuf; +} + +GtkWidget * +test_label_new (const char *text, + gboolean with_background, + int num_sizes_larger) +{ + GtkWidget *label; + + if (text == NULL) + { + text = "Foo"; + } + + label = gtk_label_new (text); + + return label; +} + +void +test_window_set_title_with_pid (GtkWindow *window, + const char *title) +{ + char *tmp; + + g_return_if_fail (GTK_IS_WINDOW (window)); + + tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title); + gtk_window_set_title (GTK_WINDOW (window), tmp); + g_free (tmp); +} diff --git a/test/interactive/test.h b/test/interactive/test.h new file mode 100644 index 0000000..fc20a77 --- /dev/null +++ b/test/interactive/test.h @@ -0,0 +1,35 @@ +#pragma once + +#include <config.h> +#include <gtk/gtk.h> + +#include <eel/eel-debug.h> +#include <eel/eel.h> +#include <src/nautilus-file-utilities.h> + +void test_init (int *argc, + char ***argv); +int test_quit (int exit_code); +void test_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer callback_data); +GtkWidget *test_window_new (const char *title, + guint border_width); +void test_gtk_widget_set_background_image (GtkWidget *widget, + const char *image_name); +void test_gtk_widget_set_background_color (GtkWidget *widget, + const char *color_spec); +GdkPixbuf *test_pixbuf_new_named (const char *name, + float scale); +GtkWidget *test_label_new (const char *text, + gboolean with_background, + int num_sizes_larger); +void test_pixbuf_draw_rectangle_tiled (GdkPixbuf *pixbuf, + const char *tile_name, + int x0, + int y0, + int x1, + int y1, + int opacity); +void test_window_set_title_with_pid (GtkWindow *window, + const char *title);
\ No newline at end of file |