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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include "config.h"
#include <ctype.h>
#include "canonicalize.h"
#include "mystring/mystring.h"
#include "address.h"
#include "fdbuf/fdbuf.h"
#include "itoa.h"
static bool test(const mystring& in,
const mystring& out,
const mystring& list)
{
mystring line = in;
mystring tmplist;
if(!parse_addresses(line, tmplist)) {
fout << "Parsing of '" << in << "' failed." << endl;
return false;
}
bool status = true;
if(!!list && tmplist != list) {
fout << "Parsing of '" << in << "' failed: bad result list, was:\n"
<< tmplist
<< "should be:\n"
<< list;
status = false;
}
if(!!out && line != out) {
fout << "Parsing of '" << in << "' failed: bad result string, was:\n"
<< line
<< "should be:\n"
<< out;
status = false;
}
return status;
}
#define TEST(X,Y,Z) do{ ++count; if(!test(X,Y,Z)) ++failed; }while(0)
mystring defaulthost = "a";
mystring defaultdomain = "b.c";
int main()
{
int count = 0;
int failed = 0;
// empty list
TEST("",
"",
"");
// empty list with comment
TEST("(no addresses)",
"(no addresses)",
"");
// periods in local
TEST("a.b@c.d",
"a.b@c.d",
"a.b@c.d\n");
// quoted local
TEST("\"e\"@c.d",
"e@c.d",
"e@c.d\n");
// missing host and domain
TEST("e",
"e@a.b.c",
"e@a.b.c\n");
// missing domain
TEST("e@x",
"e@x.b.c",
"e@x.b.c\n");
// trailing period
TEST("e@c.d.",
"e@c.d",
"e@c.d\n");
// comment <address> style
TEST("x<y@a.b>",
"x <y@a.b>",
"y@a.b\n");
TEST("<y@a.b>",
"<y@a.b>",
"y@a.b\n");
// address (comment) style
TEST("y@a.b(x)",
"y@a.b (x)",
"y@a.b\n");
// internal comments before local
TEST("(j)y@a.b",
"y@a.b (j)",
"y@a.b\n");
// internal comments after local
TEST("y(j)@a.b",
"y@a.b (j)",
"y@a.b\n");
// internal comments before domain
TEST("y@(j)a.b",
"y@a.b (j)",
"y@a.b\n");
// internal comments before period
TEST("y@a(j).b",
"y@a.b (j)",
"y@a.b\n");
// internal comments after period
TEST("y@a.(j)b",
"y@a.b (j)",
"y@a.b\n");
// normal list
TEST("a@b.c,d@e.f",
"a@b.c, d@e.f",
"a@b.c\nd@e.f\n");
// list with comments
TEST("a@b.c(j),d@e.f(k)",
"a@b.c (j), d@e.f (k)",
"a@b.c\nd@e.f\n");
// list without commas
TEST("a@b.c d@e.f",
"a@b.c, d@e.f",
"a@b.c\nd@e.f\n");
// list without commas with comments
TEST("a@b.c(j) d@e.f(k)",
"a@b.c (j), d@e.f (k)",
"a@b.c\nd@e.f\n");
// simple group
TEST("g: a@b.c, d@e.f;",
"g: a@b.c, d@e.f;",
"a@b.c\nd@e.f\n");
// group with spaces in name
TEST("g h: a@b.c, d@e.f;",
"g h: a@b.c, d@e.f;",
"a@b.c\nd@e.f\n");
// empty group
TEST("g: ;",
"g: ;",
"");
// group with a comment
TEST("g: a@b.c(j);",
"g: a@b.c (j);",
"a@b.c\n");
// group with comments
TEST("g:a@b.c(j),d@e.f(k);",
"g: a@b.c (j), d@e.f (k);",
"a@b.c\nd@e.f\n");
// group with no commas
TEST("g:a@b.c d@e.f;",
"g: a@b.c, d@e.f;",
"a@b.c\nd@e.f\n");
// group with route addresses
TEST("g:foo<a@b.c>;",
"g: foo <a@b.c>;",
"a@b.c\n");
// route-path syntax (stripped)
TEST("f<@g.h:a@b.c>",
"f <a@b.c>",
"a@b.c\n");
// multiple route-path syntax
TEST("f<@g.h@i.j:a@b.c>",
"f <a@b.c>",
"a@b.c\n");
// comments with quoted brackets
TEST("(f\\)\\()a@b.c",
"a@b.c (f\\)\\()",
"a@b.c\n");
// nested comments
TEST("(f(g)h)a@b.c",
"a@b.c (f(g)h)",
"a@b.c\n");
// simple quoted addresses
TEST("\"a\"@b.c",
"a@b.c",
"a@b.c\n");
// quoted parts of address
TEST("a.\"b\".c@d.e",
"a.b.c@d.e",
"a.b.c@d.e\n");
// escaped characters within quotes
TEST("\"s\\'b\"@d.e",
"s'b@d.e",
"s'b@d.e\n");
// escaped specials
TEST("\"s\\\"a\\\"b\"@d.e",
"\"s\\\"a\\\"b\"@d.e",
"s\"a\"b@d.e\n");
// twisted syntax
//TEST("\"\\\"d\\\" <\"<@_._:e@f.g>",
// "who knows",
// "e@f.g\n");
fout << itoa(count) << " tests run, ";
fout << itoa(failed) << " failed." << endl;
return failed;
}
|