00001 #include <iostream>
00002 #include <fstream>
00003 #include <string>
00004
00005 #include <stdio.h>
00006 #include <string.h>
00007 #include <unistd.h>
00008
00009 #include "Logger.h"
00010 #include "Article.h"
00011
00012 using namespace std;
00013
00014 char *articleList[] = { "article5283", "article9621", "article9622" };
00015
00016 Logger slog;
00017 Article art1;
00018
00019 int checkArticle(const char *artfn)
00020 {
00021 char buf[256];
00022 int la1;
00023 ifstream is;
00024 ofstream os;
00025 Article *art2;
00026
00027 sprintf(buf, "%s.in", artfn);
00028 is.open(buf);
00029 art1.read(is);
00030 is.close();
00031 la1 = art1.length();
00032
00033 art2 = new Article(art1);
00034 if (strcmp(art1.c_str(), art2->c_str()))
00035 return -11;
00036 if (la1 != art1.length() || la1 != art2->length())
00037 return -12;
00038
00039 art1.settext(art2->gettext());
00040 if (strcmp(art1.c_str(), art2->c_str()))
00041 return -21;
00042 if (la1 != art1.length() || la1 != art2->length())
00043 return -22;
00044
00045 strcpy(buf, artfn);
00046 strcat(buf, ".out");
00047 os.open(buf);
00048 art2->write(os);
00049 os.close();
00050
00051 sprintf(buf, "%s.in", artfn);
00052 is.open(buf);
00053 art1.read(is);
00054 is.close();
00055 la1 = art1.length();
00056
00057 delete art2;
00058 art2 = new Article(0, art1.c_str(), art1.length());
00059 if (strcmp(art1.c_str(), art2->c_str()))
00060 return -31;
00061 if (la1 != art1.length() || la1 != art2->length())
00062 return -32;
00063
00064 if (!art1.has_field("from:"))
00065 return -41;
00066 if (!art2->has_field("FROM:"))
00067 return -42;
00068
00069 if (art1.has_field("foobar:"))
00070 return -51;
00071
00072
00073
00074 if (art1.getfield("dummy:") != "dummy")
00075 return -61;
00076 if (art2->getfield("DuMmY:", 1) != "dummy: dummy")
00077 return -71;
00078
00079 art1.setfield("dummy:", "dummy: dummy2\r\n");
00080 art1.setfield("dummy2:", "dummy2: dummy2\r\n");
00081 if (!strcmp(art1.c_str(), art2->c_str()))
00082 return -81;
00083 if (la1 == art1.length())
00084 return -82;
00085 if (art1.getfield("dummy:") != "dummy2")
00086 return -83;
00087 if (art1.getfield("dummy2:") != "dummy2")
00088 return -84;
00089
00090 return 0;
00091 }
00092
00093 int main(int argc, char *argv[])
00094 {
00095 char **al = articleList;
00096 int e, ef = 0, i, j = sizeof(articleList) / sizeof(articleList[0]);
00097
00098 chdir(getenv("srcdir"));
00099 if (argc > 1) {
00100 al = argv + 1;
00101 j = argc - 1;
00102 }
00103
00104 cout << "cArticle:\n";
00105 for (i = 0; i < j; i++) {
00106 if ((e = checkArticle(al[i])) < 0) {
00107 cout << "checkArticle(" << al[i] <<
00108 ") failed with: " << e << endl;
00109 ef++;
00110 } else {
00111 cout << "checkArticle(" << al[i] <<
00112 ") succeeded\n";
00113 }
00114 }
00115 if (ef == 0) {
00116 cout << "cArticle: all tests succeeded\n";
00117 exit(0);
00118 } else {
00119 cout << "cArticle: " << ef << " failures\n";
00120 exit(-1);
00121 }
00122 }