Ejemplo n.º 1
0
int test_collection_04()
{
	//
	struct collection *col = NULL;

	// Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad)..
	col = collection_new();

	//
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);
	collection_add(col, NULL);

	// Zde budu testovat hodnoty položky kolekce..
	struct collection_item *item = col -> first_item;
	while(item)
	{
		//
		void *object = NULL;

		//
		if(item -> object)
		{
			object = item -> object;
		}

		//
		if(object != NULL)
		{
			ctest_assert_null(object, "Hodnota položky object v kolekci je neplatná měla by být NULL..");
			break;
		}

		//
		item = item -> next;
	}

	//
	collection_delete(col);

	//
	char *assert_message = "Testing collection for new/several add(null)/delete..";
	ctest_assert_pass(assert_message);

	//
	return 0;
}
Ejemplo n.º 2
0
static gint collect_manager_process_entry(CollectManagerEntry *entry)
{
	CollectionData *cd;
	gint success;
	GList *work;

	if (!entry->action_list) return FALSE;

	cd = collection_new(entry->path);
	success = collection_load_private(cd, entry->path, FALSE, FALSE);

	work = g_list_last(entry->action_list);
	while (work)
		{
		CollectManagerAction *action;

		action = work->data;
		work = work->prev;

		if (!action->oldpath)
			{
			/* add image */
			if (collection_list_find(cd->list, action->newpath) == NULL)
				{
				collection_add_check(cd, action->newpath, FALSE, FALSE);
				}
			}
		else if (action->newpath)
			{
			/* rename image */
			while (collection_rename(cd, action->oldpath, action->newpath));
			}
		else
			{
			/* remove image */
			while (collection_remove(cd, action->oldpath));
			}
		collect_manager_action_unref(action);
		}

	if (success && cd->changed)
		{
		collection_save_private(cd, entry->path);
		if (debug) printf("collection manager updated: %s\n", entry->path);
		}
	collection_unref(cd);

	g_list_free(entry->action_list);
	entry->action_list = NULL;

	return TRUE;
}
Ejemplo n.º 3
0
static gboolean collect_manager_process_entry(CollectManagerEntry *entry)
{
	CollectionData *cd;

	if (entry->empty) return FALSE;

	cd = collection_new(entry->path);
	(void) collection_load_private(cd, entry->path, COLLECTION_LOAD_NONE);

	collection_unref(cd);

	return TRUE;
}
Ejemplo n.º 4
0
int test_collection_01()
{
	//
	struct collection *col;

	//
	col = collection_new();
	collection_delete(col);

	//
	char *assert_message = "Testing collection for simple new/delete..";
	ctest_assert_pass(assert_message);

	//
	return 0;
}
Ejemplo n.º 5
0
int test_collection_03()
{
	//
	struct collection *col = NULL;

	// Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad)..
	col = collection_new();
	collection_add(col, NULL);
	collection_delete(col);

	//
	char *assert_message = "Testing collection for new/add(null)/delete..";
	ctest_assert_pass(assert_message);

	//
	return 0;
}
Ejemplo n.º 6
0
int cprocessor_open()
{
	//
	co_collection = collection_new();

	//
	cprocessor_signal_exit = 0;

	// Přidání příkazu pro exit..
	cprocessor_command_exit = cprocessor_command_new(COMMAND_EXIT_NAZEV, COMMAND_EXIT_KATEGORIE, &cprocessor_command_exit_function);
	cprocessor_command_show_commands = cprocessor_command_new(COMMAND_SHOW_COMMANDS_NAZEV, COMMAND_SHOW_COMMANDS_KATEGORIE, &cprocessor_command_show_commands_function);

	//
	collection_add(co_collection, cprocessor_command_exit);
	collection_add(co_collection, cprocessor_command_show_commands);

	//
	return 0;
}
Ejemplo n.º 7
0
void view_window_new(FileData *fd)
{
	GList *list;

	if (file_extension_match(fd->path, GQ_COLLECTION_EXT))
		{
		ViewWindow *vw;
		CollectionData *cd;
		CollectInfo *info;

		cd = collection_new(fd->path);
		if (collection_load(cd, fd->path, COLLECTION_LOAD_NONE))
			{
			info = collection_get_first(cd);
			}
		else
			{
			collection_unref(cd);
			cd = NULL;
			info = NULL;
			}
		vw = real_view_window_new(NULL, NULL, cd, info);
		if (vw && cd)
			{
			g_signal_connect(G_OBJECT(vw->window), "destroy",
					 G_CALLBACK(view_window_collection_unref_cb), cd);
			}
		}
	else if (isdir(fd->path) && filelist_read(fd, &list, NULL))
		{
		list = filelist_sort_path(list);
		list = filelist_filter(list, FALSE);
		real_view_window_new(NULL, list, NULL, NULL);
		filelist_free(list);
		}
	else
		{
		real_view_window_new(fd, NULL, NULL, NULL);
		}
}
Ejemplo n.º 8
0
CollectWindow *collection_window_new(const gchar *path)
{
	CollectWindow *cw;
	GtkWidget *vbox;
	GtkWidget *frame;
	GtkWidget *status_label;
	GtkWidget *extra_label;
	GdkGeometry geometry;

	cw = g_new0(CollectWindow, 1);

	collection_window_list = g_list_append(collection_window_list, cw);

	cw->cd = collection_new(path);

	cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL);

	geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
	geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
	geometry.base_width = COLLECT_DEF_WIDTH;
	geometry.base_height = COLLECT_DEF_HEIGHT;
	gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), NULL, &geometry,
				      GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);


	if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path))
		{
		/* FIXME: x, y is not implemented */
		gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h);
		}
	else
		{
		gtk_window_set_default_size(GTK_WINDOW(cw->window), COLLECT_DEF_WIDTH, COLLECT_DEF_HEIGHT);
		}

	gtk_window_set_resizable(GTK_WINDOW(cw->window), TRUE);
	collection_window_update_title(cw);
	gtk_container_set_border_width(GTK_CONTAINER(cw->window), 0);

	g_signal_connect(G_OBJECT(cw->window), "delete_event",
			 G_CALLBACK(collection_window_delete), cw);

	g_signal_connect(G_OBJECT(cw->window), "key_press_event",
			 G_CALLBACK(collection_window_keypress), cw);

	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(cw->window), vbox);
	gtk_widget_show(vbox);

	cw->table = collection_table_new(cw->cd);
	gtk_box_pack_start(GTK_BOX(vbox), cw->table->scrolled, TRUE, TRUE, 0);
	gtk_widget_show(cw->table->scrolled);

	cw->status_box = gtk_hbox_new(TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), cw->status_box, FALSE, FALSE, 0);
	gtk_widget_show(cw->status_box);

	frame = gtk_frame_new(NULL);
	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
	gtk_box_pack_start(GTK_BOX(cw->status_box), frame, TRUE, TRUE, 0);
	gtk_widget_show(frame);

	status_label = gtk_label_new("");
	gtk_container_add(GTK_CONTAINER(frame), status_label);
	gtk_widget_show(status_label);

	extra_label = gtk_progress_bar_new();
	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(extra_label), 0.0);
	gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0);
	gtk_widget_show(extra_label);

	collection_table_set_labels(cw->table, status_label, extra_label);

	gtk_widget_show(cw->window);
	gtk_widget_grab_focus(cw->table->listview);

	collection_set_update_info_func(cw->cd, collection_window_update_info, cw);

	if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, NULL, COLLECTION_LOAD_NONE);

	return cw;
}
Ejemplo n.º 9
0
#include <stdlib.h>
#include "collection.h"
#include "assertc.h"

module(collection)
{
    suite("collection _test")
    {
        test("# new")
        {
            collection_t * c = collection_new(sizeof(int));
            expect_int((int)c) to not be equal(0);
            collection_destroy(c);
        } end
        test("# add")
        {
            collection_t * c = collection_new(sizeof(int));
            int p = 10;
            collection_add(c, &p);
            expect_int(collection_count(c)) to be equal(1);
            collection_destroy(c);

        } end

        test("# at#int")
        {
            collection_t * c = collection_new(sizeof(int));
            int p = 10;
            collection_add(c, &p);
            int v;
            collection_at(c, 0, &v);
Ejemplo n.º 10
0
int test_collection_05()
{
	//
	struct collection *col = NULL;

	//
	int my_number = 1234;
	int *my_object = &my_number;

	// Pokud to proběhne bez toho aniž by spadlo na neoprávněný přístup do paměti, je to OK (snad)..
	col = collection_new();

	//
	collection_add(col, my_object);
	collection_add(col, my_object);
	collection_add(col, my_object);
	collection_add(col, my_object);

	//
	struct collection_item *item = col -> first_item;

	//
	while(item)
	{
		//
		void *object = NULL;

		//
		object = item -> object;
	
		//
		if(object == NULL)
		{
			ctest_assert_fail("Object has to by valid object to pass this test!");
			break;
		}

		//
		if(object != my_object)
		{
			ctest_assert_fail("Object address is not the expected one!");
			break;
		}

		//
		int value = *(int *) object;
		if(value != my_number)
		{
			ctest_assert_fail("Object value is not the excepted one!");
			break;
		}

		//
		item = item -> next;
	}

	//
	collection_delete(col);

	//
	char *assert_message = "Testing collection for new/several add(null)/delete..";
	ctest_assert_pass(assert_message);

	//
	return 0;
}
Ejemplo n.º 11
0
			ctest_assert_true(assert_result, assert_message);
		}

		// Samotné odebrání objektu..
		free(ptr);

		// 
		{
			char *assert_message = "Adresa objektu pro uvolnění paměti se schoduje s adresou alokovanou..";
			int assert_result = (object == ptr) ? TRUE : FALSE;
			ctest_assert_true(assert_result, assert_message);
		}
	}

	// Vytvoření kolekce..
	struct collection *col = collection_new();

	// Vložení objektu do kolekce..
	collection_add(col, object);

	// A nyní objekt odstraňujeme
	collection_object_delete(col, &delete_function);

	// Odebrání samotné kolekce a ukončení testu..
	collection_delete(col);
}

///
int test_collection_foreach_01()
{
	//