27 #include "Properties.hpp"
43 cout <<
"--> test()" << endl;
47 const wstring k(L
"key");
48 const wstring v(L
"value");
53 "",
"\n",
"\r",
"\n\n",
"\n\r",
"\r\n",
"\r\r",
"\r\n\r",
"\n\r\n",
54 "#",
"#k",
"#\n",
"#\\",
"#\\\\",
"#\\\n",
"#\\\n\n",
55 "!",
"!k",
"!\n",
"!\\",
"!\\\\",
"!\\\n",
"!\\\n\n",
56 " #k",
"\f#k",
"\t#k",
57 " #k",
"\f #k",
"\t #k",
58 "#kkk",
"#kkk vvv",
"#kkk= vvv",
"#kkk: vvv",
59 "# kkk",
"# kkk vvv",
"# kkk= vvv",
"# kkk: vvv",
61 const int n0 =
sizeof(kv0)/
sizeof(*kv0);
62 for (
int i = 0;
i < n0; ++
i ) {
66 assert (p.size() == 0);
71 "key=value",
"key=value\n",
"key=value\r",
"key=value\r\n",
72 "key:value",
"key=value\n",
"key=value\r",
"key=value\r\n",
73 "key value",
"key\fvalue",
"key\tvalue",
"key value\n",
74 " key=value",
"\fkey=value",
"\tkey=value",
75 "key =value",
"key\f=value",
"key\t=value",
76 " key =value",
"\fkey\f=value",
"\tkey\t=value",
77 "key= value",
"key=\fvalue",
"key=\tvalue",
78 "key= value",
"key value",
"key value",
"key \t \fvalue",
80 const int n1 =
sizeof(kv1)/
sizeof(*kv1);
81 for (
int i = 0;
i < n1; ++
i ) {
85 assert (p.size() == 1);
86 Properties::const_iterator e = p.begin();
88 assert (e->first == k);
89 assert (e->second == v);
95 "key",
"key ",
" key ",
"key\n",
" \fkey \t\n",
96 "key=",
"key =",
"key= ",
"key = ",
"key=\n",
" \fkey \t= \f\r\n",
98 const int n2 =
sizeof(kv2)/
sizeof(*kv2);
99 for (
int i = 0;
i < n2; ++
i ) {
101 stringbuf sb(kv2[
i]);
103 assert (p.size() == 1);
104 Properties::const_iterator e = p.begin();
106 assert (e->first == k);
107 assert (e->second == w);
112 const char* kv3[] = {
113 "key=value",
"key=value\\\n",
"key=value\\\r",
"key=value\\\r\n",
114 "k\\\ney=va\\\nlue",
"k\\\rey=va\\\rlue",
"k\\\r\ney=va\\\r\nlue",
115 "k\\\n ey=va\\\n lue",
"k\\\r ey=va\\\r lue",
"k\\\r\n ey=va\\\r\n lue",
116 "k\\\n\\\ney=va\\\n\\\nlue",
"k\\\r\\\ney=va\\\r\\\nlue",
117 "k\\\n \\\n ey=va\\\n \\\n lue",
"k\\\r \\\n ey=va\\\r \\\n lue",
119 "\\u006b\\u0065\\u0079=\\u0076\\u0061\\u006C\\u0075\\u0065",
121 const int n3 =
sizeof(kv3)/
sizeof(*kv3);
122 for (
int i = 0;
i < n3; ++
i ) {
124 stringbuf sb(kv3[
i]);
126 assert (p.size() == 1);
127 Properties::const_iterator e = p.begin();
129 assert (e->first == k);
130 assert (e->second == v);
135 const char* kv4 = (
"\\ a\\ key\\ =\\ a value \n"
138 "key0=value0\n" "key1=value1\n"
141 "key\\==value\\=\n");
152 assert (ib.str() == ob.str());
162 cout <<
"all tests passed." << endl;
163 cout <<
"<-- test()" << endl;
169 cout <<
"usage: [options]" << endl
170 <<
" -p <file name> properties file name" << endl
171 <<
" -h|--help print usage message and exit" << endl
177 main(
int argc,
const char* argv[])
179 cout <<
"--> main()" << endl;
185 const char* fn = NULL;
186 const string arg = argv[1];
187 if (arg.compare(
"-p") == 0) {
192 }
else if (arg.compare(
"-h") == 0 || arg.compare(
"--help") == 0) {
195 cout <<
"unknown option: " << arg << endl;
201 cout <<
"read: " << fn << endl;
204 cout <<
"print:" << endl;
205 wstring h(L
"this header string passed to store() should be first");
210 cout <<
"<-- main()" << endl;