Exemplo n.º 1
0
static void
check_fi (CamelFolderInfo *fi,
          CamelFolderInfo *list,
          gint len)
{
	GPtrArray *folders = g_ptr_array_new ();
	gint i;

	add_fi (folders, fi);
	check_msg (folders->len == len, "unexpected number of folders returned from folderinfo");
	qsort (folders->pdata, folders->len, sizeof (folders->pdata[0]), cmp_fi);
	for (i = 0; i < len; i++) {
		CamelFolderInfo *f = folders->pdata[i];

		camel_test_push ("checking folder '%s'", list[i].display_name);

		check (!strcmp (f->full_name, list[i].full_name));

		/* this might be translated, but we can't know */
		camel_test_nonfatal ("Inbox not english");
		check (!strcmp (f->display_name, list[i].display_name));
		camel_test_fatal ();

		camel_test_nonfatal ("Flags mismatch");
		check (f->flags == list[i].flags);
		camel_test_fatal ();

		camel_test_pull ();
	}

	g_ptr_array_free (folders, TRUE);
}
Exemplo n.º 2
0
gint main (gint argc, gchar **argv)
{
	CamelSession *session;
	gint i;
	gchar *path;

	camel_test_init (argc, argv);
	camel_test_provider_init (1, nntp_drivers);

	/* clear out any camel-test data */
	system ("/bin/rm -rf /tmp/camel-test");

	session = camel_test_session_new ("/tmp/camel-test");

	for (i = 0; i < G_N_ELEMENTS (remote_providers); i++) {
		path = getenv (remote_providers[i]);

		if (path == NULL) {
			printf ("Aborted (ignored).\n");
			printf ("Set '%s', to re-run test.\n", remote_providers[i]);
			/* tells make check to ignore us in the total count */
			_exit (77);
		}
		camel_test_nonfatal ("Dont know how many tests apply to NNTP");
		test_folder_message_ops (session, path, FALSE, "testbox");
		camel_test_fatal ();
	}

	check_unref (session, 1);

	return 0;
}
Exemplo n.º 3
0
static void
test_folder_search (CamelFolder *folder,
                    const gchar *expr,
                    gint expected)
{
	gchar *matchall;

#if 0
	/* FIXME: ??? */
	camel_test_nonfatal ("most searches require match-all construct");
	push ("Testing search: %s", expr);
	test_folder_search_sub (folder, expr, expected);
	pull ();
	camel_test_fatal ();
#endif

	matchall = g_strdup_printf ("(match-all %s)", expr);
	push ("Testing search: %s", matchall);
	test_folder_search_sub (folder, matchall, expected);
	test_free (matchall);
	pull ();
}
Exemplo n.º 4
0
gint main (gint argc, gchar **argv)
{
	gint i;
	CamelInternetAddress *addr, *addr2;
	gchar *name;
	const gchar *charset;
	const gchar *real, *where;
	gchar *enc, *enc2, *format, *format2;

	camel_test_init (argc, argv);

	camel_test_start ("CamelInternetAddress, basics");

	addr = camel_internet_address_new ();

	push ("Test blank address");
	check (camel_address_length (CAMEL_ADDRESS (addr)) == 0);
	check (camel_internet_address_get (addr, 0, &real, &where) == FALSE);
	pull ();

	push ("Test blank clone");
	addr2 = CAMEL_INTERNET_ADDRESS (camel_address_new_clone (CAMEL_ADDRESS (addr)));
	test_address_compare (addr, addr2);
	check_unref (addr2, 1);
	pull ();

	push ("Test add 1");
	camel_internet_address_add (addr, "Zed", "*****@*****.**");
	check (camel_address_length (CAMEL_ADDRESS (addr)) == 1);
	check (camel_internet_address_get (addr, 0, &real, &where) == TRUE);
	check_msg (string_equal ("Zed", real), "real = '%s'", real);
	check (strcmp (where, "*****@*****.**") == 0);
	pull ();

	push ("Test clone 1");
	addr2 = CAMEL_INTERNET_ADDRESS (camel_address_new_clone (CAMEL_ADDRESS (addr)));
	test_address_compare (addr, addr2);
	check_unref (addr2, 1);
	pull ();

	push ("Test add many");
	for (i = 1; i < 10; i++) {
		gchar name[16], a[32];
		sprintf (name, "Zed %d", i);
		sprintf (a, "nowhere@here-%d.com.au", i);
		camel_internet_address_add (addr, name, a);
		check (camel_address_length (CAMEL_ADDRESS (addr)) == i + 1);
		check (camel_internet_address_get (addr, i, &real, &where) == TRUE);
		check_msg (string_equal (name, real), "name = '%s' real = '%s'", name, real);
		check (strcmp (where, a) == 0);
	}
	pull ();

	/* put a few of these in to make it look like its doing something impressive ... :) */
	camel_test_end ();
	camel_test_start ("CamelInternetAddress, search");

	push ("Test search");
	camel_test_nonfatal ("Address comparisons should ignore whitespace??");
	check (camel_internet_address_find_name (addr, "Zed 1", &where) == 1);
	check (camel_internet_address_find_name (addr, "Zed 9", &where) == 9);
	check (camel_internet_address_find_name (addr, "Zed", &where) == 0);
	check (camel_internet_address_find_name (addr, " Zed", &where) == 0);
	check (camel_internet_address_find_name (addr, "Zed ", &where) == 0);
	check (camel_internet_address_find_name (addr, "  Zed ", &where) == 0);
	check (camel_internet_address_find_name (addr, "Zed 20", &where) == -1);
	check (camel_internet_address_find_name (addr, "", &where) == -1);
	/* interface dont handle nulls :) */
	/*check(camel_internet_address_find_name(addr, NULL, &where) == -1);*/

	check (camel_internet_address_find_address (addr, "*****@*****.**", &where) == 1);
	check (camel_internet_address_find_address (addr, "nowhere@here-1 . com.au", &where) == 1);
	check (camel_internet_address_find_address (addr, "nowhere@here-2 .com.au ", &where) == 2);
	check (camel_internet_address_find_address (addr, " nowhere @here-3.com.au", &where) == 3);
	check (camel_internet_address_find_address (addr, "[email protected] ", &where) == -1);
	check (camel_internet_address_find_address (addr, "", &where) == -1);
	/*check(camel_internet_address_find_address(addr, NULL, &where) == -1);*/
	camel_test_fatal ();
	pull ();

	camel_test_end ();
	camel_test_start ("CamelInternetAddress, copy/cat/clone");

	push ("Test clone many");
	addr2 = CAMEL_INTERNET_ADDRESS (camel_address_new_clone (CAMEL_ADDRESS (addr)));
	test_address_compare (addr, addr2);
	pull ();

	push ("Test remove items");
	camel_address_remove (CAMEL_ADDRESS (addr2), 0);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 9);
	camel_address_remove (CAMEL_ADDRESS (addr2), 0);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 8);
	camel_address_remove (CAMEL_ADDRESS (addr2), 5);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 7);
	camel_address_remove (CAMEL_ADDRESS (addr2), 10);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 7);
	camel_address_remove (CAMEL_ADDRESS (addr2), -1);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 0);
	check_unref (addr2, 1);
	pull ();

	push ("Testing copy/cat");
	push ("clone + cat");
	addr2 = CAMEL_INTERNET_ADDRESS (camel_address_new_clone (CAMEL_ADDRESS (addr)));
	camel_address_cat (CAMEL_ADDRESS (addr2), CAMEL_ADDRESS (addr));
	check (camel_address_length (CAMEL_ADDRESS (addr)) == 10);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 20);
	check_unref (addr2, 1);
	pull ();

	push ("cat + cat + copy");
	addr2 = camel_internet_address_new ();
	camel_address_cat (CAMEL_ADDRESS (addr2), CAMEL_ADDRESS (addr));
	test_address_compare (addr, addr2);
	camel_address_cat (CAMEL_ADDRESS (addr2), CAMEL_ADDRESS (addr));
	check (camel_address_length (CAMEL_ADDRESS (addr)) == 10);
	check (camel_address_length (CAMEL_ADDRESS (addr2)) == 20);
	camel_address_copy (CAMEL_ADDRESS (addr2), CAMEL_ADDRESS (addr));
	test_address_compare (addr, addr2);
	check_unref (addr2, 1);
	pull ();

	push ("copy");
	addr2 = camel_internet_address_new ();
	camel_address_copy (CAMEL_ADDRESS (addr2), CAMEL_ADDRESS (addr));
	test_address_compare (addr, addr2);
	check_unref (addr2, 1);
	pull ();

	pull ();

	check_unref (addr, 1);

	camel_test_end ();

	camel_test_start ("CamelInternetAddress, I18N");

	for (i = 0; i < G_N_ELEMENTS (test_lines); i++) {
		push ("Testing text line %d (%s) '%s'", i, test_lines[i].type, test_lines[i].line);

		addr = camel_internet_address_new ();

		/* first, convert to api format (utf-8) */
		charset = test_lines[i].type;
		name = to_utf8 (test_lines[i].line, charset);

		push ("Address setup");
		camel_internet_address_add (addr, name, "*****@*****.**");
		check (camel_internet_address_get (addr, 0, &real, &where) == TRUE);
		check_msg (string_equal (name, real), "name = '%s' real = '%s'", name, real);
		check (strcmp (where, "*****@*****.**") == 0);
		test_free (name);

		check (camel_internet_address_get (addr, 1, &real, &where) == FALSE);
		check (camel_address_length (CAMEL_ADDRESS (addr)) == 1);
		pull ();

		push ("Address encode/decode");
		enc = camel_address_encode (CAMEL_ADDRESS (addr));

		addr2 = camel_internet_address_new ();
		check (camel_address_decode (CAMEL_ADDRESS (addr2), enc) == 1);
		check (camel_address_length (CAMEL_ADDRESS (addr2)) == 1);

		enc2 = camel_address_encode (CAMEL_ADDRESS (addr2));
		check_msg (string_equal (enc, enc2), "enc = '%s' enc2 = '%s'", enc, enc2);
		test_free (enc2);

		push ("Compare addresses");
		test_address_compare (addr, addr2);
		pull ();
		check_unref (addr2, 1);
		test_free (enc);
		pull ();

		/* FIXME: format/unformat arne't guaranteed to be reversible, at least at the moment */
		camel_test_nonfatal ("format/unformat not (yet) reversible for all cases");

		push ("Address format/unformat");
		format = camel_address_format (CAMEL_ADDRESS (addr));

		addr2 = camel_internet_address_new ();
		check (camel_address_unformat (CAMEL_ADDRESS (addr2), format) == 1);
		check (camel_address_length (CAMEL_ADDRESS (addr2)) == 1);

		format2 = camel_address_format (CAMEL_ADDRESS (addr2));
		check_msg (string_equal (format, format2), "format = '%s\n\tformat2 = '%s'", format, format2);
		test_free (format2);

		/* currently format/unformat doesn't handle ,'s and other special chars at all */
		if (camel_address_length (CAMEL_ADDRESS (addr2)) == 1) {
			push ("Compare addresses");
			test_address_compare (addr, addr2);
			pull ();
		}

		test_free (format);
		pull ();

		camel_test_fatal ();

		check_unref (addr2, 1);

		check_unref (addr, 1);
		pull ();

	}

	camel_test_end ();

	camel_test_start ("CamelInternetAddress, I18N decode");

	for (i = 0; i < G_N_ELEMENTS (test_address); i++) {
		push ("Testing address line %d '%s'", i, test_address[i].addr);

		addr = camel_internet_address_new ();
		push ("checking decoded");
		check (camel_address_decode (CAMEL_ADDRESS (addr), test_address[i].addr) == test_address[i].count);
		format = camel_address_format (CAMEL_ADDRESS (addr));
		check (strcmp (format, test_address[i].utf8) == 0);
		test_free (format);
		pull ();

		push ("Comparing re-encoded output");
		addr2 = CAMEL_INTERNET_ADDRESS (camel_internet_address_new ());
		enc = camel_address_encode (CAMEL_ADDRESS (addr));
		check_msg (camel_address_decode (CAMEL_ADDRESS (addr2), enc) == test_address[i].count, "enc = '%s'", enc);
		test_free (enc);
		test_address_compare (addr, addr2);
		check_unref (addr2, 1);
		pull ();

		check_unref (addr, 1);

		pull ();
	}

	camel_test_end ();

	camel_test_start ("CamelInternerAddress name & email decoder");

	for (i = 0; i < G_N_ELEMENTS (test_decode); i++) {
		gchar *line;
		const gchar *name, *email;
		gint jj;

		name = test_decode[i].name;
		email = test_decode[i].email;

		for (jj = 0; jj < G_N_ELEMENTS (line_decode_formats); jj++) {
			if (line_decode_formats[jj].without_name) {
				line = g_strdup_printf (line_decode_formats[jj].without_name, email);
				check_address_line_decode (i, line, NULL, email);
				g_free (line);
			}

			if (!name)
				continue;

			line = g_strdup_printf (line_decode_formats[jj].with_name, name, email);
			check_address_line_decode (i, line, name, email);
			g_free (line);
		}
	}

	camel_test_end ();

	return 0;
}
Exemplo n.º 5
0
gint
main (gint argc,
      gchar **argv)
{
	CamelService *service;
	CamelSession *session;
	CamelStore *store;
	CamelFolder *folder;
	CamelMimeMessage *msg;
	gint i, j;
	gint indexed;
	GPtrArray *uids;
	GError *error = NULL;

	camel_test_init (argc, argv);
	camel_test_provider_init (1, local_drivers);

	/* clear out any camel-test data */
	system ("/bin/rm -rf /tmp/camel-test");

	session = camel_test_session_new ("/tmp/camel-test");

	/* todo: cross-check everything with folder_info checks as well */
	/* todo: work out how to do imap/pop/nntp tests */

	/* we iterate over all stores we want to test, with indexing or indexing turned on or off */
	for (i = 0; i < G_N_ELEMENTS (stores); i++) {
		const gchar *name = stores[i];
		for (indexed = 0; indexed < 2; indexed++) {
			gchar *what = g_strdup_printf ("folder search: %s (%sindexed)", name, indexed?"":"non-");
			gchar *uid;
			gint flags;

			camel_test_start (what);
			test_free (what);

			push ("getting store");
			uid = g_strdup_printf ("test-uid-%d", i);
			service = camel_session_add_service (
				session, uid, stores[i],
				CAMEL_PROVIDER_STORE, &error);
			g_free (uid);
			check_msg (error == NULL, "adding store: %s", error->message);
			check (CAMEL_IS_STORE (service));
			store = CAMEL_STORE (service);
			g_clear_error (&error);
			pull ();

			push ("creating %sindexed folder", indexed?"":"non-");
			if (indexed)
				flags = CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX;
			else
				flags = CAMEL_STORE_FOLDER_CREATE;
			folder = camel_store_get_folder_sync (
				store, "testbox", flags, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);

			/* we need an empty folder for this to work */
			test_folder_counts (folder, 0, 0);
			g_clear_error (&error);
			pull ();

			/* append a bunch of messages with specific content */
			push ("appending 100 test messages");
			for (j = 0; j < 100; j++) {
				gchar *content, *subject;

				push ("creating test message");
				msg = test_message_create_simple ();
				content = g_strdup_printf ("data%d content\n", j);
				test_message_set_content_simple (
					(CamelMimePart *) msg, 0, "text/plain",
								content, strlen (content));
				test_free (content);
				subject = g_strdup_printf ("Test%d message%d subject", j, 100 - j);
				camel_mime_message_set_subject (msg, subject);

				camel_mime_message_set_date (msg, j * 60 * 24, 0);
				pull ();

				push ("appending simple message %d", j);
				camel_folder_append_message_sync (
					folder, msg, NULL, NULL, NULL, &error);
				check_msg (error == NULL, "%s", error->message);
				g_clear_error (&error);
				pull ();

				test_free (subject);

				check_unref (msg, 1);
			}
			pull ();

			push ("Setting up some flags &c");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < 100; j++) {
				gchar *uid = uids->pdata[j];

				if ((j / 13) * 13 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every13", TRUE);
				}
				if ((j / 17) * 17 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every17", TRUE);
				}
				if ((j / 7) * 7 == j) {
					gchar *tag = g_strdup_printf ("7tag%d", j / 7);
					camel_folder_set_message_user_tag (folder, uid, "every7", tag);
					test_free (tag);
				}
				if ((j / 11) * 11 == j) {
					camel_folder_set_message_user_tag (folder, uid, "every11", "11tag");
				}
			}
			camel_folder_free_uids (folder, uids);
			pull ();

			camel_test_nonfatal ("Index not guaranteed to be accurate before sync: should be fixed eventually");
			push ("Search before sync");
			run_search (folder, 100);
			pull ();
			camel_test_fatal ();

			push ("syncing folder, searching");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("syncing wiht expunge, search");
			camel_folder_synchronize_sync (
				folder, TRUE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("deleting every 2nd message");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < uids->len; j+=2) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 100);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 100);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			pull ();

			push ("closing and re-opening folder");
			check_unref (folder, 1);
			folder = camel_store_get_folder_sync (
				store, "testbox",
				flags & ~(CAMEL_STORE_FOLDER_CREATE),
				NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);
			g_clear_error (&error);

			push ("deleting remaining messages");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 50);
			for (j = 0; j < uids->len; j++) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 50);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 0);
			g_clear_error (&error);
			pull ();

			pull ();

			check_unref (folder, 1);
			pull ();

			push ("deleting test folder, with no messages in it");
			camel_store_delete_folder_sync (
				store, "testbox", NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);
			pull ();

			check_unref (store, 1);
			camel_test_end ();
		}
	}

	check_unref (session, 1);

	return 0;
}