1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <pan/base/article.h>
#include <pan/base/base-prefs.h>
#include <pan/base/debug.h>
#include <pan/base/group.h>
#include <pan/base/pan-glib-extensions.h>
#include <pan/base/server.h>
static void
pan_init (void)
{
gchar * base;
gchar * data_dir;
gchar * download_dir;
base = getenv ("srcdir");
base = g_strdup_printf ("%s/", base!=NULL ? base : getenv("PWD"));
data_dir = g_strdup_printf ("%s/data/", base);
download_dir = g_strdup_printf ("%s/data/save/", base);
base_prefs_init (data_dir, download_dir, 1000, FALSE, FALSE);
g_free (data_dir);
g_free (download_dir);
}
int
main (void)
{
gint test = 0;
Server * s;
Group * g;
Article * a;
Article * a1;
const gchar * cpch;
gchar buf[512];
g_thread_init (NULL);
pan_init ();
s = server_new ();
s->name = g_strdup ("Server");
g = group_new (s, "alt.test");
group_ref_articles (g, NULL);
/* ctor sanity */
++test;
a1 = article_new (g);
if (a1==NULL) return test;
if (a1->crosspost_qty != 0) return test;
if (a1->part != 0) return test;
if (a1->parts != 0) return test;
if (a1->linecount != 0) return test;
if (a1->state != 0) return test;
if (a1->unread_children != 0) return test;
if (a1->date != 0) return test;
if (a1->threads != NULL) return test;
if (a1->parent != NULL) return test;
if (a1->author_addr != NULL) return test;
if (a1->author_real != NULL) return test;
if (a1->subject != NULL) return test;
if (a1->message_id != NULL) return test;
if (a1->references != NULL) return test;
g_message ("PASS article ctor sanity check");
a1->message_id = g_strdup ("<foobar.foo.bar>");
a1->number = 1;
/* set header: no chunk */
++test;
cpch = "When the Levee Breaks";
article_set_header (a1, HEADER_SUBJECT, cpch, 0);
if (a1->subject!=cpch) return test;
g_message ("PASS article_set_header, no chunk");
/* clear header */
++test;
article_remove_header (a1, HEADER_SUBJECT);
if (a1->subject!=NULL) return test;
g_message ("PASS article_remove_header");
/* set header: chunk */
++test;
article_set_header (a1, HEADER_SUBJECT, cpch, DO_CHUNK);
if (a1->subject==NULL || a1->subject==cpch) return test;
if (pan_strcmp(a1->subject, cpch)) return test;
g_message ("PASS article_set_header, do chunk");
/* set-author-from-header */
++test;
a = a1;
article_set_author_from_header (a, "joe@foo.com");
article_get_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "\"joe\" <joe@foo.com>")) return test;
article_get_short_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "joe")) return test;
article_set_author_from_header (a, "joe@foo.com (Joe Bob)");
article_get_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "\"Joe Bob\" <joe@foo.com>")) return test;
article_get_short_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "Joe Bob")) return test;
article_set_author_from_header (a, "Joe Bob <joe@foo.com>");
article_get_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "\"Joe Bob\" <joe@foo.com>")) return test;
article_get_short_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "Joe Bob")) return test;
article_set_author_from_header (a, "Joe Bob");
article_get_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "\"Joe Bob\" <unknown@spammesenseless.net>")) return test;
article_get_short_author_str (a, buf, sizeof(buf));
if (pan_strcmp(buf, "Joe Bob")) return test;
g_message ("PASS article_set_author_from_header 1");
/* encoded authors */
++test;
article_set_author_from_header (a1,
"\"Jrgen Irgendwie\" <juergen.irgendwie@email.com>");
if (pan_strcmp(a1->author_addr,
"juergen.irgendwie@email.com")) return test;
if (pan_strcmp(a1->author_real, "Jrgen Irgendwie")) return test;
article_get_author_str (a1, buf, sizeof(buf));
if (pan_strcmp(buf, "\"Jrgen Irgendwie\" <juergen.irgendwie@email.com>")) return test;
article_get_short_author_str (a1, buf, sizeof(buf));
if (pan_strcmp(buf,"Jrgen Irgendwie")) return test;
g_message ("PASS article_set_author_from_header");
/* more encoded authors */
++test;
cpch = "some@email.com (M. =?ISO-8859-1?Q?H=F6lle?=)";
article_set_author_from_header (a, cpch);
if (pan_strcmp (a->author_addr,"some@email.com")) return test;
if (pan_strcmp (a->author_real,"M. Hlle")) return test;
article_get_author_str (a, buf, sizeof(buf));
if (pan_strcmp (buf, "\"M. Hlle\" <some@email.com>")) return test;
article_get_short_author_str (a, buf, sizeof(buf));
if (pan_strcmp (buf, "M. Hlle")) return test;
g_message ("PASS encoded author header test");
/* success */
g_message ("All article tests passed");
return 0;
}
|