File: testsuitecpp2.C

package info (click to toggle)
maildrop 3.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,896 kB
  • sloc: ansic: 29,827; cpp: 18,027; sh: 5,993; makefile: 882; perl: 94
file content (938 lines) | stat: -rw-r--r-- 16,828 bytes parent folder | download | duplicates (2)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <unistd.h>

#if 0
#define UPDATE_TESTSUITECPP 1
#endif

std::string events;

#define RFC2045_ENTITY_PARSER_TEST(msg)		\
	do { events += msg "\n"; } while (0)

#define RFC2045_ENTITY_PARSER_DECL(d) d


#include "testsuitecpp.H"
#include "rfc2045.h"
#include "rfc2045cpp.C"

template<bool crlf>
rfc2045::entity runtest(std::string message,
			size_t chunksize)
{
	events.clear();

	rfc2045::entity_parser<crlf> parser;

	auto b=message.begin(), e=message.end();

	while (b != e)
	{
		if (static_cast<size_t>(e-b) < chunksize)
			chunksize=e-b;

		auto p=b;
		b += chunksize;
		parser.parse(p, b);
	}

	return parser.parsed_entity();
}

template<bool crlf>
void test1()
{
	const char *nl = crlf ? "\r\n":"\n";
	auto entity=runtest<crlf>(
		std::string{
			"Mime-Version: 1.0"
		}
		+ nl
		+ "Content-Type: text"
		+ nl
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl
		+ std::string(40, '=')
		+ nl, 100);

#if UPDATE_TESTSUITECPP
	parsed_mime_info::dump_entity(entity, "");

	std::cout << events;
#else
	using cte=rfc2045::cte;

	static const parsed_mime_info expected_results{
		0    , // startpos
		38+crlf*3   , // startbody
		325+crlf*10  , // endbody
		10   , // nlines
		7    , // nbodylines
		1    , // mime1
		0, "text", "iso-8859-1",
		"", cte::sevenbit,
		0, // has8bitheader
		0, // has8bitbody
		0  // has8bitcontentchar
	};

	if (expected_results != entity)
	{
		std::cout << "test1 parsing error ("
			  << (crlf ? "\\r\\n":"\\n")
			  << "):\n";
		parsed_mime_info::dump(entity);
		exit(1);
	}

	if (events !=
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "end_of_parse set\n"
	    "end_of_parse received\n"
	    "thread finished\n")
	{
		std::cout << "test1 unexpected event sequence:\n"
			  << events;
		exit(1);
	}
#endif
}

template<bool crlf>
void test2()
{
	const char *nl = crlf ? "\r\n":"\n";
	auto entity=runtest<crlf>(
		std::string{
			"Mime-Version: 1.0"
		}
		+ nl
		+ "Content-Type: text"
		+ nl
		+ "Content-Transfer-Encoding: something"
		+ nl
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl
		+ std::string(40, 'A')
		+ nl, 100);

#if UPDATE_TESTSUITECPP
	parsed_mime_info::dump_entity(entity, "");

	std::cout << events;
#else

	if (events !=
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "parser: chunk\n"
	    "retrieved next chunk\n"
	    "end_of_parse set\n"
	    "end_of_parse received\n"
	    "thread finished\n")
	{
		std::cout << "test2 unexpected event sequence:\n"
			  << events;
		exit(1);
	}

	if (!(entity.errors.code & RFC2045_ERRUNKNOWNTE))
	{
		std::cout << "test2 did not receive expected error\n";
		exit(1);
	}
#endif
}

void test34_setup(std::stringstream &ss, const char *nl)
{
	ss << "Mime-Version: 1.0" << nl
	   << "Content-Type: multipart/mixed; boundary=aaa" << nl
	   << nl
	   << "--aaa" << nl
	   << "Content-Type: text/plain" << nl
	   << "Content-Description: MIME" << nl
	   << " section 1" << nl
	   << nl
	   << "--aaa--" << nl;

	ss.seekg(0);
}

template<bool crlf>
void test3()
{
	const char *nl = crlf ? "\r\n":"\n";

	std::stringstream ss;

	test34_setup(ss, nl);

	auto b=std::istreambuf_iterator<char>{ss};
	auto e=std::istreambuf_iterator<char>{};

	typename rfc2045::entity::line_iter<crlf>::iter<
		std::istreambuf_iterator<char>,
		std::istreambuf_iterator<char>
		> iter{b, e};

	rfc2045::entity entity;

	entity.parse(iter);

	if (entity.subentities.size() != 1)
	{
		std::cout << "test2 (" << (crlf ? "\\r\\n":"\\n") << "): "
			" unexpected parsing error.\n";
		exit(1);
	}

	typename rfc2045::entity::line_iter<crlf>::
		template headers<std::streambuf> h{
		entity.subentities[0],
		*ss.rdbuf()
	};

#if UPDATE_TESTSUITECPP
	bool flag;

	do
	{
		const auto &[n, c]=h.name_content();

		std::cout << "{\n\t\"" << h.current_header() << "\",\n"
			"\t\"" << n << "\", \"" << c << "\", ";

		flag=h.next();

		std::cout << flag << "\n},\n";
	} while (flag);
#else
	static const struct {
		const char *header, *name, *content;
		bool next;
	} default_test[]={
		{
			"content-type: text/plain",
			"content-type", "text/plain", 1
		},
		{
			"content-description: MIME section 1",
			"content-description", "MIME section 1", 1
		},
		{
			"",
			"", "", 0
		},
	};

	for (const auto &t:default_test)
	{
		auto full=h.current_header();
		const auto &[n, c]=h.name_content();

		if (full != t.header || n != t.name || c != t.content)
		{
			std::cout << "test3: unexpected result (default_test)\n"
				"Got: " << full << "\n    " << n
				  << "\n    " << c << "\n"
				"Exp: " << t.header << "\n    " << t.name
				  << "\n    " << t.content << "\n";
			exit(1);
		}

		if (h.next() != t.next)
		{
			std::cout << "test3: unexpected result (default_test)\n"
				  << "Got next=" << !t.next
				  << " for \"" << t.header << "\"\n";
			exit(1);
		}
	}
#endif
}

template<bool crlf>
void test4()
{
	const char *nl = crlf ? "\r\n":"\n";

	std::stringstream ss;

	test34_setup(ss, nl);

	auto b=std::istreambuf_iterator<char>{ss};
	auto e=std::istreambuf_iterator<char>{};

	typename rfc2045::entity::line_iter<crlf>::iter<
		std::istreambuf_iterator<char>,
		std::istreambuf_iterator<char>
		> iter{b, e};

	rfc2045::entity entity;

	entity.parse(iter);

	if (entity.subentities.size() != 1)
	{
		std::cout << "test2 (" << (crlf ? "\\r\\n":"\\n") << "): "
			" unexpected parsing error.\n";
		exit(1);
	}

	typename rfc2045::entity::line_iter<crlf>::
		template headers<std::streambuf> h{
		entity.subentities[0],
		*ss.rdbuf()
	};

	h.name_lc=false;
	h.keep_eol=true;

#if UPDATE_TESTSUITECPP
	bool flag;

	do
	{
		const auto &[n, c]=h.name_content();

		std::cout << "{";

		for (const auto &str
			     : std::array<std::string_view, 3>{
			     h.current_header(), n, c})
		{
			std::cout << "\n\t";

			if (str.empty())
			{
				std::cout << "\"\"";
			}
			else
			{
				bool has_prev=false;
				bool prev_was_nl=true;

				for (char c:str)
				{
					if (c != '\n')
					{
						if (prev_was_nl)
						{
							if (has_prev)
							{
								std::cout <<
									" + ";
							}
							std::cout <<
								"std::string{"
								"\"";
						}
						std::cout << c;
						has_prev=true;
						prev_was_nl=false;
					}
					else
					{
						if (has_prev)
						{
							if (!prev_was_nl)
								std::cout <<
									"\"}";
							std::cout << " + ";
						}
						std::cout << "nl";
						has_prev=true;
						prev_was_nl=true;
					}
				}

				if (!prev_was_nl)
					std::cout << "\"}";
			}
			std::cout << ",";
		}

		flag=h.next();

		std::cout << " " << flag << "\n},\n";
	} while (flag);
#else
	const struct {
		std::string header, name, content;
		bool next;
	} default_test[]={
		{
			std::string{"Content-Type: text/plain"} + nl,
			std::string{"Content-Type"},
			std::string{"text/plain"} + nl, 1
		},
		{
			std::string{"Content-Description: MIME"} + nl + std::string{" section 1"} + nl,
			std::string{"Content-Description"},
			std::string{"MIME"} + nl + std::string{" section 1"} + nl, 1
		},
		{
			nl,
			nl,
			"", 0
		},
	};

	for (const auto &t:default_test)
	{
		auto full=h.current_header();
		const auto &[n, c]=h.name_content();

		if (full != t.header || n != t.name || c != t.content)
		{
			std::cout << "test3: unexpected result (default_test)\n"
				"Got: " << full << "\n    " << n
				  << "\n    " << c << "\n"
				"Exp: " << t.header << "\n    " << t.name
				  << "\n    " << t.content << "\n";
			exit(1);
		}

		if (h.next() != t.next)
		{
			std::cout << "test3: unexpected result (default_test)\n"
				  << "Got next=" << !t.next
				  << " for \"" << t.header << "\"\n";
			exit(1);
		}
	}
#endif
}

template<bool crlf>
void test5()
{
	std::string nl = crlf ? "\r\n":"\n";

	std::stringstream ss;

	ss << "Subject: =?utf-8?q?nob=c3=92dy?=" << nl
	   << " subject" << nl
	   << "From: Nobody1 <test1@example.com>, test2@example.com," << nl
	   << "  =?iso-8859-1?q?No?= =?iso-8859-1?q?b=D2dy?= "
		"<test3@xn--80akhbyknj4f.net>" << nl
	   << "Mime-Version: 1.0" << nl
	   << "Content-Type: multipart/mixed; boundary=aaa" << nl
	   << nl
	   << "preable" << nl
	   << "--aaa" << nl
	   << "Content-Type: text/plain; charset=iso-8859-1" << nl
	   << "Content-Description: =?utf-8?q?quoted-?= "
		"=?utf8?q?printable?=" << nl
	   << "Content-Transfer-Encoding: quoted-printable" << nl
	   << nl
	   << "H=E9llo =" << nl
	   << "H=E9llo" << nl
	   << nl
	   << "--aaa" << nl
	   << "Content-Type: text/plain; charset=iso-8859-1" << nl
	   << "Content-Description: base64 decoded" << nl
	   << "Content-Transfer-Encoding: base64" << nl
	   << nl
	   << "SOlsbG8=" << nl
	   << nl
	   << "--aaa--" << nl << nl;

	auto b=std::istreambuf_iterator<char>{ss};
	auto e=std::istreambuf_iterator<char>{};

	typename rfc2045::entity::line_iter<crlf>::iter<
		std::istreambuf_iterator<char>,
		std::istreambuf_iterator<char>
		> iter{b, e};

	rfc2045::entity entity;

	entity.parse(iter);

	std::string decoded;

	{
		rfc822::mime_decoder<
			std::function<void (const char *, size_t)>,
			std::streambuf> decoder{
			[&]
			(const char *ptr, size_t n)
			{
				decoded.insert(decoded.end(), ptr, ptr+n);
			}, *ss.rdbuf(), "utf-8"
		};

		decoder.decode<crlf>(entity);

		decoded.erase(std::remove(decoded.begin(), decoded.end(),
					  '\r'), decoded.end());
	}
#if UPDATE_TESTSUITECPP

	auto db=decoded.begin(), de=decoded.end();

	const char *str_plus="\t\t";

	while (db != de)
	{
		auto p=std::find(db, de, '\n');

		if (p != de)
			++p;

		std::cout << str_plus << "\"";

		for ( ; db != p; ++db)
		{
			if (*db == '\n')
				std::cout << "\\n";
			else if (*db == '"')
				std::cout << "\\\"";
			else
				std::cout << *db;
		}
		std::cout << "\"";
		str_plus="\n\t\t";
	}
	std::cout << "\n";
#else
	std::string expected =
		"subject: nobÒdy subject\n"
		"from: Nobody1 <test1@example.com>, test2@example.com, NobÒdy <test3@испытание.net>\n"
		"mime-version: 1.0\n"
		"content-type: multipart/mixed; boundary=aaa\n"
		"\n"
		"content-type: text/plain; charset=iso-8859-1\n"
		"content-description: quoted-printable\n"
		"content-transfer-encoding: quoted-printable\n"
		"\n"
		"Héllo Héllo\n"
		"content-type: text/plain; charset=iso-8859-1\n"
		"content-description: base64 decoded\n"
		"content-transfer-encoding: base64\n"
		"\n"
		"Héllo";

	if (expected != decoded)
	{
		std::cout << "test5 (" << (crlf ? "\\r\\n":"\\n") << "): "
			" unexpected decoding result:\n"
			  << decoded << "\n";
		exit(1);
	}
#endif
}

void test6()
{
	std::stringstream ss;

	std::string s="Mime-Version: 1.0\n"
		"Content-Type: multipart/digest; boundary=aaa\n"
		"\n"
		"--aaa\n"
		"\n"
		"Subject: first message\n"
		"\n"
		"one\n"
		"two\n"
		"\n"
		"--aaa\n"
		"\n"
		"Subject: second message\n"
		"\n"
		"one\n"
		"two\n"
		"--aaa---\n";

	ss << s;

	auto b=std::istreambuf_iterator<char>{ss};
	auto e=std::istreambuf_iterator<char>{};

	rfc2045::entity::line_iter<false>::iter<
		std::istreambuf_iterator<char>,
		std::istreambuf_iterator<char>
		> iter{b, e};

	rfc2045::entity entity;

	entity.parse(iter);

	for (auto &mime:entity.subentities)
	{
		if (mime.subentities.size() != 1)
		{
			std::cout << "test6: unexpected structure\n";
			exit(1);
		}
	}

	std::vector<std::array<size_t, 6>> actual;

	actual.push_back(std::array<size_t, 6>{
			{entity.startpos, entity.startbody,
			 entity.endbody,
			 entity.nlines,
			 entity.nbodylines,
			 entity.no_terminating_nl}});

	for (auto &mime:entity.subentities)
	{
		actual.push_back(std::array<size_t, 6>{
				{mime.startpos, mime.startbody,
				 mime.endbody,
				 mime.nlines,
				 mime.nbodylines,
				 mime.no_terminating_nl}});
		actual.push_back(std::array<size_t, 6>{
				{mime.subentities[0].startpos,
				 mime.subentities[0].startbody,
				 mime.subentities[0].endbody,
				 mime.subentities[0].nlines,
				 mime.subentities[0].nbodylines,
				 mime.subentities[0].no_terminating_nl}});
	}
#if 1
	std::vector<std::array<size_t, 6>> expected{
		/*
		 1 Mime-Version: 1.0
		 2 Content-Type: multipart/digest; boundary=aaa
		 3
		 4 --aaa
		 5
		 6 Subject: first message
		 7
		 8 one
		 9 two
		10
		11 --aaa
		12
		13 Subject: second message
		14
		15 one
		16 two
		17 --aaa---
		*/

		/* Header:

		[Mime-Version: 1.0
		Co...gest; boundary=aaa

		]

		Body:

		[--aaa

		Subject: firs...e

		one
		two
		--aaa---
		]

		*/
		{{0, 64, 153, 17, 14, 0}},
		/* Header:

		[
		]

		Body:

		[Subject: first message

		one
		two
		]

		*/
		{{70, 71, 103, 5, 4, 0}},
		/* Header:

		[Subject: first message

		]

		Body:

		[one
		two
		]

		*/
		{{71, 95, 103, 4, 2, 0}},
		/* Header:

		[
		]

		Body:

		[Subject: second message

		one
		two]

		*/
		{{110, 111, 143, 5, 4, 1}},
		/* Header:

		[Subject: second message

		]

		Body:

		[one
		two]

		*/
		{{111, 136, 143, 4, 2, 1}}
	};

	if (expected != actual)
	{
		std::cout << "test6 failed:\n";
		for (auto &a:actual)
		{
			std::cout << "\n";
			const auto &[startpos, startbody, endbody, nlines,
				     nbodylines, no_term_nl]=a;

			std::cout << "startpos:   " << startpos << "\n"
				  << "startbody:  " << startbody << "\n"
				  << "endbody:    " << endbody << "\n"
				  << "nlines:     " << nlines << "\n"
				  << "nbodylines: " << nbodylines << "\n"
				  << "no term nl: " << no_term_nl << "\n";
		}
		exit(1);
	}
#else

	std::cout << "\t\t/*\n";

	{
		std::istringstream i{s};
		std::string line;
		size_t n=0;

		while (std::getline(i, line))
			std::cout << "\t\t" << std::setw(2) << ++n
				  << std::setw(0) << " "
				  << line << "\n";
	}
	std::cout << "\t\t*/\n\n";

	const char *commanl="";

	for (auto &a:actual)
	{
		std::cout << commanl;

		const auto &[startpos, startbody, endbody, nlines, nbodylines,
			     no_term_nl]
			= a;

		std::cout << "\t\t/* Header:\n\n";

		std::string chunk=s.substr(startpos, startbody-startpos);

		if (chunk.size() > 50)
			chunk=chunk.substr(0, 20) + "..." +
				chunk.substr(chunk.size()-20);

		{
			std::istringstream i{"[" + chunk + "]"};

			std::string line;

			while (std::getline(i, line))
				std::cout << "\t\t" << line << "\n";
		}
		std::cout << "\n\t\tBody:\n\n";

		chunk=s.substr(startbody, endbody-startbody);

		if (chunk.size() > 50)
			chunk=chunk.substr(0, 20) + "..." +
				chunk.substr(chunk.size()-20);

		{
			std::istringstream i{"[" + chunk + "]"};

			std::string line;

			while (std::getline(i, line))
				std::cout << "\t\t" << line << "\n";
		}

		std::cout << "\n\t\t*/\n";

		std::cout << "\t\t{{";
		commanl="";

		for (auto v:a)
		{
			std::cout << commanl << v;
			commanl = ", ";
		}
		std::cout << "}}";
		commanl=",\n";
	}
	std::cout << "\n";
#endif
}

void test7()
{
	std::stringstream ss;
	ss << "Mime-Version: 1.0\n"
		"Content-Type: text/plain; charset=iso-8859-1\n"
		"Content-Transfer-Encoding: quoted-printable\n"
		"\n"
		"H=E9llo\n";

	auto b=std::istreambuf_iterator<char>{ss};
	auto e=std::istreambuf_iterator<char>{};

	rfc2045::entity::line_iter<false>::iter<
		std::istreambuf_iterator<char>,
		std::istreambuf_iterator<char>
		> iter{b, e};

	rfc2045::entity entity;

	entity.parse(iter);

	std::u32string us;

	{
		rfc822::mime_unicode_decoder decoder{
			[&]
			(const char32_t *ptr, size_t cnt)
			{
				us.insert(us.end(), ptr, ptr+cnt);
			},

			*ss.rdbuf()
		};

		decoder.decode_header=false;
		decoder.decode(entity);
	}

	{
		auto closure=
			[&]
			(const char32_t *ptr, size_t cnt)
			{
				us.insert(us.end(), ptr, ptr+cnt);
			};

		rfc822::mime_unicode_decoder decoder{
			closure,
			*ss.rdbuf()
		};

		decoder.decode_header=false;
		decoder.decode(entity);
	}

	if (us != U"Héllo\nHéllo\n")
	{
		std::cout << "test7 failed\n";
		exit(1);
	}
}

int main()
{
	alarm(60);
	rfc2045_setdefaultcharset("iso-8859-1");
#if UPDATE_TESTSUITECPP
	// test1<false>();
	// test1<true>();

	// test2<false>();

	// test3<false>();

	// test4<false>();

	test5<false>();
#else
	for (int i=0; i<100; ++i)
	{
		test1<false>();
		test1<true>();
	}

	test2<false>();
	test2<true>();

	test3<false>();
	test3<true>();

	test4<false>();
	test4<true>();

	test5<false>();
	test5<true>();
#endif

	test6();
	test7();
	return 0;
}