Exemple #1
0
int main(void)
{
    const struct CMUnitTest tests[] =
    {
        cmocka_unit_test(new_folder_files_zeroCount),
        cmocka_unit_test(folder_add_new_file_filesCount_oneCount),
        cmocka_unit_test(folder_add_new_file_filesCount_threeCount),
        cmocka_unit_test(new_dictionary_wordsCount_zerowords),
        cmocka_unit_test(process_and_remove_file_wordscount_in_dictionary_fivewords),
        cmocka_unit_test(process_and_remove_file_wordscount_in_dictionary_fivewords_and_one_word_passing_two_times),
        cmocka_unit_test(process_and_remove_file_wordscount_in_dictionary_twentywords),
        cmocka_unit_test(process_and_remove_file_filesCount_zeroCount),
    };

    dic_t * dictionary = dic_new();
    folder_t * myFolder = folder_new("Go");
    file_t * FirstFile = folder_add_new_file(myFolder, "This file is empty bitch!");

    file_t * SecondFile = folder_add_new_file(myFolder, "This file is not empty , first file also is not empty, bitch!alliluya");

    folder_process_and_remove_files(myFolder, FirstFile, dictionary);

    folder_process_and_remove_files(myFolder, SecondFile, dictionary);
    printf("dictionary:::\n");
    printdic(dictionary);

    folder_free(myFolder);

    dic_free(dictionary);

    return cmocka_run_group_tests(tests, NULL, NULL);

}
Exemple #2
0
static void process_and_remove_file_wordscount_in_dictionary_twentywords(void ** state)
{
    dic_t * dictionary = dic_new();
    folder_t * myFolder = folder_new("MyFolder");
    file_t * FirstFile = folder_add_new_file(myFolder, "This file is empty bitch! a b c d e r t y u w v n m l p");
    folder_process_and_remove_files(myFolder, FirstFile, dictionary);
    assert_int_equal(dic_getwordscount(dictionary), 20);
    dic_free(dictionary);
    folder_free(myFolder);
}
Exemple #3
0
static void process_and_remove_file_filesCount_zeroCount(void ** state)
{
    dic_t * dictionary = dic_new();
    folder_t * myFolder = folder_new("MyFolder");
    file_t * FirstFile = folder_add_new_file(myFolder, "This file is empty bitch! a b c d e r t y u w v n m l p");
    folder_process_and_remove_files(myFolder, FirstFile, dictionary);
    assert_int_equal(folder_get_files_count(myFolder), 0);
    dic_free(dictionary);
    folder_free(myFolder);
}
Exemple #4
0
static void process_and_remove_file_wordscount_in_dictionary_fivewords_and_one_word_passing_two_times(void ** state)
{
    dic_t * dictionary = dic_new();
    folder_t * myFolder = folder_new("MyFolder");
    file_t * FirstFile = folder_add_new_file(myFolder, "This file file is empty bitch!");
    folder_process_and_remove_files(myFolder, FirstFile, dictionary);
    assert_int_equal(dic_getwordcount(dictionary, "file"), 2);
    assert_int_equal(dic_getwordscount(dictionary), 5);
    dic_free(dictionary);
    folder_free(myFolder);
}
Exemple #5
0
static void folder_add_new_file_filesCount_threeCount(void **state)
{
    dic_t * dictionary = dic_new();
    folder_t * myFolder = folder_new("MyFolder");
    file_t * FirstFile = folder_add_new_file(myFolder, "This file is empty bitch!");
    file_t * SecondFile = folder_add_new_file(myFolder, "This file is empty bitch!");
    file_t * ThirdFile = folder_add_new_file(myFolder, "This file is empty bitch!");
    assert_int_equal(folder_get_files_count(myFolder), 3);
    folder_process_and_remove_files(myFolder, FirstFile, dictionary);
    folder_process_and_remove_files(myFolder, SecondFile, dictionary);
    folder_process_and_remove_files(myFolder, ThirdFile, dictionary);
    assert_int_equal(folder_get_files_count(myFolder), 0);
    folder_free(myFolder);
}
Exemple #6
0
static void add_mailbox(GtkAction *action, gpointer callback_data)
{
	MainWindow *mainwin = (MainWindow *) callback_data;
	gchar *path, *basename;
	Folder *folder;

	path = input_dialog(_("Add mailbox"),
			    _("Input the location of mailbox.\n"
			      "If the existing mailbox is specified, it will be\n"
			      "scanned automatically."),
			    "Mail");
	if (!path) return;
	if (folder_find_from_path(path)) {
		alertpanel_error(_("The mailbox '%s' already exists."), path);
		g_free(path);
		return;
	}
	basename = g_path_get_basename(path);

	if (!folder_local_name_ok(basename)) {
		g_free(path);
		g_free(basename);
		return;
	}

	folder = folder_new(folder_get_class_from_string("mailmbox"), 
			    !strcmp(path, "Mail") ? _("Mailbox") : basename,
			    path);
	g_free(basename);
	g_free(path);

	if (folder->klass->create_tree(folder) < 0) {
		alertpanel_error(_("Creation of the mailbox failed.\n"
				   "Maybe some files already exist, or you don't have the permission to write there."));
		folder_destroy(folder);
		return;
	}

	folder_add(folder);
	folder_scan_tree(folder, TRUE);

	folderview_set(mainwin->folderview);

	return;
}
Exemple #7
0
static void rssyl_update_format_func(FolderItem *item, gpointer data)
{
	RFolderItem *ritem;
	RUpdateFormatCtx *ctx = (RUpdateFormatCtx *)data;
	Folder *f = NULL;
	FolderItem *new_item = NULL;
	gchar *name;
	OldRFeed *of;

	if( !IS_RSSYL_FOLDER_ITEM(item) )
		return;

	/* Do not do anything once we reached first new folder
	 * (which we created earlier in this process) */
	if( ctx->reached_first_new )
		return;

	if( item->folder == ctx->n_first ) {
		ctx->reached_first_new = TRUE;
		debug_print("RSSyl: (FORMAT) reached first new folder\n");
		return;
	}

	debug_print("RSSyl: (FORMAT) item '%s'\n", item->name);

	if( folder_item_parent(item) == NULL ) {
		/* Root rssyl folder */
		ctx->oldroots = g_slist_prepend(ctx->oldroots, item);

		/* Create its counterpart */
		name = rssyl_strreplace(folder_item_get_name(item), " (RSSyl)", "");
		debug_print("RSSyl: (FORMAT) adding new root folder '%s'\n", name);
		f = folder_new(rssyl_folder_get_class(), name, NULL);
		g_free(name);
		g_return_if_fail(f != NULL);
		folder_add(f);

		folder_write_list();

		new_item = FOLDER_ITEM(f->node->data);

		/* If user has more than one old rssyl foldertrees, keep the n_first
		 * pointer at the beginning of first one. */
		if (ctx->n_first == NULL)
			ctx->n_first = f;

		ctx->n_parent = new_item;
	} else {
		/* Non-root folder */

		if (folder_item_parent(item) == ctx->o_prev) {
			/* We went one step deeper in folder hierarchy, adjust pointers
			 * to parents */
			ctx->o_parent = ctx->o_prev;
			ctx->n_parent = ctx->n_prev;
		} else if (folder_item_parent(item) != ctx->o_parent) {
			/* We are not in same folder anymore, which can only mean we have
			 * moved up in the hierarchy. Find a correct parent */
			while (folder_item_parent(item) != ctx->o_parent) {
				ctx->o_parent = folder_item_parent(ctx->o_parent);
				ctx->n_parent = folder_item_parent(ctx->n_parent);
				if (ctx->o_parent == NULL) {
					/* This shouldn't happen, unless we are magically moved to a
					 * completely different folder structure */
					debug_print("RSSyl: MISHAP WHILE UPGRADING STORAGE FORMAT: couldn't find folder parent\n");
					alertpanel_error(_("Internal problem while upgrading storage format. This should not happen. Please report this, with debug output attached.\n"));
					return;
				}
			}
		} else {
			/* We have remained in the same subfolder, nothing to do here */
		}

		debug_print("RSSyl: (FORMAT) adding folder '%s'\n", item->name);
		new_item = folder_create_folder(ctx->n_parent, item->name);

		if (new_item == NULL) {
			debug_print("RSSyl: (FORMAT) couldn't add folder '%s', skipping it\n",
					item->name);
			return;
		}

		of = rssyl_old_feed_get_by_name(ctx->oldfeeds, item->name);
		if (of != NULL && of->url != NULL) {
			/* Folder with an actual subscribed feed */
			debug_print("RSSyl: (FORMAT) making '%s' a feed with URL '%s'\n",
					item->name, of->url);

			ritem = (RFolderItem *)new_item;
			ritem->url = g_strdup(of->url);

			rssyl_feed_start_refresh_timeout(ritem);

			ritem->official_title = g_strdup(of->official_name);
			ritem->default_refresh_interval =
				(of->default_refresh_interval != 0 ? TRUE : FALSE);
			ritem->refresh_interval = of->refresh_interval;
			ritem->keep_old = (of->expired_num > -1 ? TRUE : FALSE);
			ritem->fetch_comments =
				(of->fetch_comments != 0 ? TRUE : FALSE);
			ritem->fetch_comments_max_age = of->fetch_comments_for;
			ritem->silent_update = of->silent_update;
			ritem->ssl_verify_peer = of->ssl_verify_peer;

			folder_item_prefs_copy_prefs(item, &ritem->item);
		}

		rssyl_update_format_move_contents(item, new_item);

		/* destroy the new folder's cache so we'll re-read the migrated one */
		if (new_item->cache) {
			msgcache_destroy(new_item->cache);
			new_item->cache = NULL;
		}

		/* Store folderlist with the new folder */
		folder_item_scan(new_item);
		folder_write_list();
	}

	ctx->o_prev = item;
	ctx->n_prev = new_item;
}
Exemple #8
0
static void new_folder_files_zeroCount(void ** state)
{
    folder_t * myFolder = folder_new("MyFolder");
    assert_int_equal(folder_get_files_count(myFolder), 0);
    folder_free(myFolder);
}