[maemo-commits] [maemo-commits] r16383 - projects/haf/branches/hildon-fm/fremantle/hildon-fm
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Fri Oct 10 16:15:58 EEST 2008
- Previous message: [maemo-commits] r16381 - in projects/haf/trunk/osso-af-startup: debian top-scripts
- Next message: [maemo-commits] r16384 - projects/connectivity/bluez-debian/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: yangli Date: 2008-10-10 16:15:57 +0300 (Fri, 10 Oct 2008) New Revision: 16383 Modified: projects/haf/branches/hildon-fm/fremantle/hildon-fm/t.c Log: use the existing file t.c for unit test code Modified: projects/haf/branches/hildon-fm/fremantle/hildon-fm/t.c =================================================================== --- projects/haf/branches/hildon-fm/fremantle/hildon-fm/t.c 2008-10-10 12:42:29 UTC (rev 16382) +++ projects/haf/branches/hildon-fm/fremantle/hildon-fm/t.c 2008-10-10 13:15:57 UTC (rev 16383) @@ -1,45 +1,318 @@ +/** + * @file osso_fm_unit_test.c + * + * The unit test for libhildonfm + * + */ + +/* Includes */ +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <glib.h> +#include <string.h> + +#include <locale.h> +#include <libintl.h> + +#include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> -#define GTK_FILE_SYSTEM_ENABLE_UNSUPPORTED -#include <gtk/gtkfilesystem.h> +#include <libgnomevfs/gnome-vfs.h> +#include <libgnomevfs/gnome-vfs-mime-handlers.h> -static void -create_folder_callback (GtkFileSystemHandle *handle, - const GtkFilePath *path, - const GError *error, gpointer data) +#include <hildon/hildon-program.h> +#include <hildon/hildon-window.h> +#include <hildon/hildon-banner.h> +#include <hildon/hildon-sort-dialog.h> +#include <hildon/hildon-note.h> + +#include <hildon-thumbnail/hildon-thumbnail-factory.h> + +#include <hildon/hildon.h> +#include <osso-log.h> +#include "log-functions.h" + +#include <bt-gconf.h> +#include <gconf/gconf.h> +#include <gconf/gconf-value.h> +#include <gconf/gconf-client.h> + +#include <conbtdialogs-dbus.h> +#include <gtk/gtkscrolledwindow.h> + +#include "hildon-file-selection.h" +#include "hildon-file-system-model.h" +#include "hildon-file-chooser-dialog.h" + + +HildonProgram *prog; +HildonWindow *window; +HildonFileSelection *fs = NULL; +HildonFileSystemModel *fsmodel = NULL; +GtkFileSystem *gtkfilesystem; + +GtkWidget *info_view; + +static gboolean create_main_window(); +static gboolean create_file_selection(); + +static void save_as_clicked( GtkWidget *widget, + gpointer data ) { - if (error) - fprintf (stderr, "%s: %s\n", - gtk_file_path_get_string (path), - error->message); + GtkWidget *new_dialog = NULL; + gint response = 0; + if (fsmodel != NULL) { + new_dialog = hildon_file_chooser_dialog_new_with_properties((GtkWindow *) window, + "action", + GTK_FILE_CHOOSER_ACTION_SAVE, + "file-system-model", + fsmodel, + "max-name-length", 255, NULL); + } + response = gtk_dialog_run(GTK_DIALOG(new_dialog)); +} + +static void move_to_clicked( GtkWidget *widget, + gpointer data ) +{ + GtkWidget *move_dialog = NULL; + gint response = 0; + if (fsmodel != NULL) { + move_dialog = hildon_file_chooser_dialog_new_with_properties((GtkWindow *) window, + "file-system-model", + fsmodel, + "action", + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + NULL); + + } + response = gtk_dialog_run(GTK_DIALOG(move_dialog)); +} + +static void open_up_clicked( GtkWidget *widget, + gpointer data ) +{ + GtkWidget *open_dialog = NULL; + gint response = 0; + if (fsmodel != NULL) { + open_dialog = hildon_file_chooser_dialog_new_with_properties((GtkWindow *) window, + "file-system-model", + fsmodel, + "action", + GTK_FILE_CHOOSER_ACTION_OPEN, + NULL); + } + response = gtk_dialog_run(GTK_DIALOG(open_dialog)); +} + +static void print_info(const gchar *info_text) +{ + GtkTextBuffer *info_buffer; + + info_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (info_view)); + gtk_text_buffer_insert_at_cursor (info_buffer, info_text, -1); +} + +static void system_model_test_clicked( GtkWidget *widget, + gpointer data ) +{ + GtkTreeIter *iter; + print_info ("testing API 'hildon_file_system_model_search_uri'\n"); + print_info ("------------------------------------------------\n"); + print_info ("pass the parameter:\n"); + print_info ("path: /MyDocs/.images/tigress.jpg\n"); + print_info ("start iter: NULL\n"); + print_info ("recursive: FALSE\n"); + if (hildon_file_system_model_search_uri (fsmodel, "/home/yali/MyDocs/.images/tigress.jpg", + iter, NULL, TRUE)) { + print_info ("find it, test succeed\n"); + if(strlen(iter->user_data)) { + print_info ("the path is "); + print_info (iter->user_data); + print_info ("\n"); + } + } else - fprintf (stderr, "%s: success\n", - gtk_file_path_get_string (path)); + print_info ("not find it, test failed\n"); + print_info ("-------------------------------------------------\n"); + print_info ("pass the parameter:\n"); + print_info ("path: /MyDocs/.images/tigress.jpg\n"); + print_info ("start iter: NULL\n"); + print_info ("recursive: TRUE\n"); + if (hildon_file_system_model_search_uri (fsmodel, "/home/yali/MyDocs/.images/tigress.jpg", + iter, NULL, TRUE)) { + print_info ("find it, test succeed\n"); + print_info ("the path is "); + if(strlen(iter->user_data)){ + print_info ("the path is "); + print_info (iter->user_data); + print_info ("\n"); + } + } + else + print_info ("not find it, test failed\n"); + print_info ("-------------------------------------------------\n"); + print_info ("pass the parameter:\n"); + print_info ("path: /MyDocs/.images/nowhere.jpg\n"); + print_info ("start iter: NULL\n"); + print_info ("recursive: TRUE\n"); + if (hildon_file_system_model_search_uri (fsmodel, "/home/yali/MyDocs/.images/nowhere.jpg", + iter, NULL, TRUE)) { + print_info ("find it, test succeed\n"); + print_info ("the path is "); + if(strlen(iter->user_data)){ + print_info ("the path is "); + print_info (iter->user_data); + print_info ("\n"); + } + } + else + print_info ("not find it, test failed\n"); + print_info ("-------------------------------------------------\n"); + print_info ("pass the parameter:\n"); + print_info ("path: NULL\n"); + print_info ("start iter: NULL\n"); + print_info ("recursive: TRUE\n"); + /*if (hildon_file_system_model_search_uri (fsmodel, NULL, + iter, NULL, TRUE)) { + print_info ("find it, test succeed\n"); + print_info ("the path is "); + if(strlen(iter->user_data)) + print_info(iter->user_data); + } + else + print_info ("not find it, test failed\n");*/ + print_info ("cause application crash\n"); + print_info ("-------------------------------------------------\n"); - gtk_main_quit (); } -int -main(int argc, char **argv) +gboolean ut_close (GtkWidget *window, GdkEvent *ev, + gpointer userdata) { - GtkFileSystem *fs; - GtkFilePath *p; - GtkFileSystemHandle *h; + gtk_widget_destroy (window); + gdk_flush (); + exit(0); +} - g_thread_init (NULL); - gtk_init (NULL, NULL); +static gboolean create_main_window() +{ + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *save_as; + GtkWidget *move_to; + GtkWidget *open_up; + GtkWidget *model_test; + GtkWidget* scrolled_window; - if (argc > 1) - { - fs = gtk_file_system_create ("gnome-vfs"); - p = gtk_file_system_filename_to_path (fs, argv[1]); - h = gtk_file_system_create_folder (fs, p, - create_folder_callback, - NULL); + prog = hildon_program_get_instance (); + window = HILDON_WINDOW (hildon_window_new ()); + + hildon_program_add_window (prog, window); + + gtk_window_set_title (GTK_WINDOW (window), + "Unit Test"); - if (h) - gtk_main (); - } + save_as = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, + HILDON_BUTTON_ARRANGEMENT_HORIZONTAL); + hildon_button_set_text(HILDON_BUTTON(save_as), + "Save As", NULL); + g_signal_connect (G_OBJECT (save_as), "clicked", + G_CALLBACK (save_as_clicked), NULL); + gtk_widget_show(GTK_WIDGET(save_as)); + move_to = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, + HILDON_BUTTON_ARRANGEMENT_HORIZONTAL); + hildon_button_set_text(HILDON_BUTTON(move_to), + "Move To", NULL); + g_signal_connect (G_OBJECT (move_to), "clicked", + G_CALLBACK (move_to_clicked), NULL); + gtk_widget_show(GTK_WIDGET(move_to)); + + open_up = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, + HILDON_BUTTON_ARRANGEMENT_HORIZONTAL); + hildon_button_set_text(HILDON_BUTTON(open_up), + "Open Up", NULL); + g_signal_connect (G_OBJECT (open_up), "clicked", + G_CALLBACK (open_up_clicked), NULL); + gtk_widget_show(GTK_WIDGET(open_up)); + + model_test = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, + HILDON_BUTTON_ARRANGEMENT_HORIZONTAL); + hildon_button_set_text(HILDON_BUTTON(model_test), + "Hildon System Model Test", NULL); + g_signal_connect (G_OBJECT (model_test), "clicked", + G_CALLBACK (system_model_test_clicked), NULL); + gtk_widget_show(GTK_WIDGET(model_test)); + + + hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), save_as, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), move_to, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), open_up, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), model_test, FALSE, FALSE, 0); + + gtk_widget_show(GTK_WIDGET(hbox)); + vbox = gtk_vbox_new (FALSE, 0); + info_view = gtk_text_view_new (); + + scrolled_window = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + gtk_container_add(GTK_CONTAINER(scrolled_window), info_view); + gtk_widget_show(GTK_WIDGET(scrolled_window)); + + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0); + gtk_widget_show_all(GTK_WIDGET(vbox)); + gtk_container_add (GTK_CONTAINER (window), vbox); + + gtk_widget_show((GtkWidget *) window); + + g_signal_connect(G_OBJECT(window), "delete-event", + G_CALLBACK(ut_close), NULL); + return TRUE; +} + +static gboolean create_file_selection() +{ + if (fs != NULL) { + return FALSE; + } + if (!gnome_vfs_init()) { + return 1; + } + + fsmodel = g_object_new (HILDON_TYPE_FILE_SYSTEM_MODEL, + "ref-widget", window, + NULL); + if (fsmodel == NULL) { + return FALSE; + } + return TRUE; +} + +gint main(int argc, char *argv[]) +{ + if(!g_thread_supported()) { + g_thread_init(NULL); + } + g_set_application_name("unit test for FM library"); + gtk_init(&argc, &argv); + + if(!create_main_window()) { + return 1; + } + gdk_threads_enter(); + create_file_selection(); + gdk_threads_leave(); + gtk_main(); + + gdk_threads_leave(); + return 0; }
- Previous message: [maemo-commits] r16381 - in projects/haf/trunk/osso-af-startup: debian top-scripts
- Next message: [maemo-commits] r16384 - projects/connectivity/bluez-debian/trunk
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]