From d0a26db992188b442356758477be89a312c2d02e Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 8 Sep 2002 20:06:00 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'SODIPODI_0_25'. svn path=/tags/SODIPODI_0_25/; revision=18015 --- camel/tests/message/test2.c | 326 -------------------------------------------- 1 file changed, 326 deletions(-) delete mode 100644 camel/tests/message/test2.c (limited to 'camel/tests/message/test2.c') diff --git a/camel/tests/message/test2.c b/camel/tests/message/test2.c deleted file mode 100644 index 95b0e324aa..0000000000 --- a/camel/tests/message/test2.c +++ /dev/null @@ -1,326 +0,0 @@ -#include "camel-test.h" -#include "messages.h" -#include "addresses.h" - -/* for stat */ -#include -#include -#include -#include -#include - -#include -#include - -#include "address-data.h" - -static char *convert(const char *in, const char *from, const char *to) -{ - iconv_t ic = iconv_open(to, from); - char *out, *outp; - const char *inp; - int inlen, outlen; - - if (ic == (iconv_t)-1) - return g_strdup(in); - - inlen = strlen(in); - outlen = inlen*5 + 16; - - outp = out = g_malloc(outlen); - inp = in; - - if (iconv(ic, &inp, &inlen, &outp, &outlen) == -1) { - test_free(out); - iconv_close(ic); - return g_strdup(in); - } - - if (iconv(ic, NULL, 0, &outp, &outlen) == -1) { - test_free(out); - iconv_close(ic); - return g_strdup(in); - } - - iconv_close(ic); - - *outp = 0; - -#if 0 - /* lets see if we can convert back again? */ - { - char *nout, *noutp; - iconv_t ic = iconv_open(from, to); - - inp = out; - inlen = strlen(out); - outlen = inlen*5 + 16; - noutp = nout = g_malloc(outlen); - if (iconv(ic, &inp, &inlen, &noutp, &outlen) == -1 - || iconv(ic, NULL, 0, &noutp, &outlen) == -1) { - g_warning("Cannot convert '%s' \n from %s to %s: %s\n", in, to, from, strerror(errno)); - } - iconv_close(ic); - } - - /* and lets see what camel thinks out optimal charset is */ - { - printf("Camel thinks the best encoding of '%s' is %s, although we converted from %s\n", - in, camel_charset_best(out, strlen(out)), from); - } -#endif - - return out; -} - -#define to_utf8(in, type) convert(in, type, "utf-8") -#define from_utf8(in, type) convert(in, "utf-8", type) - -#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0])) - -int main(int argc, char **argv) -{ - int i; - CamelInternetAddress *addr, *addr2; - char *name; - char *charset; - const char *real, *where; - char *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", "nowhere@here.com.au"); - 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, "nowhere@here.com.au") == 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++) { - char 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, "nowhere@here-1.com.au", &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, "nowhere@here-20.com.au ", &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