[gmime] Added unit tests for GMimeFilterCharset and GMimeFilterSmtpData



commit e188787336577f29d22c2a95892085a626dbf92f
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Sat Dec 16 09:27:36 2017 -0500

    Added unit tests for GMimeFilterCharset and GMimeFilterSmtpData

 tests/data/filters/cyrillic.cp1251.txt      |    9 ++
 tests/data/filters/cyrillic.iso-8859-5.txt  |    9 ++
 tests/data/filters/cyrillic.koi8-r.txt      |    9 ++
 tests/data/filters/cyrillic.utf-8.txt       |    9 ++
 tests/data/filters/japanese.iso-2022-jp.txt |    9 ++
 tests/data/filters/japanese.shift-jis.txt   |    9 ++
 tests/data/filters/japanese.utf-8.txt       |    9 ++
 tests/data/filters/smtp-input.txt           |   14 +++
 tests/data/filters/smtp-output.txt          |   14 +++
 tests/test-filters.c                        |  125 ++++++++++++++++++++++++++-
 tests/test-mime-part.c                      |    4 +-
 11 files changed, 214 insertions(+), 6 deletions(-)
---
diff --git a/tests/data/filters/cyrillic.cp1251.txt b/tests/data/filters/cyrillic.cp1251.txt
new file mode 100644
index 0000000..9131b63
--- /dev/null
+++ b/tests/data/filters/cyrillic.cp1251.txt
@@ -0,0 +1,9 @@
+����� ����� ����� ��� ����, ��� ������ ��������� ��������� ��, ���� ������� ������� �� ���. ��� �� ������ 
������� �������, �� �������� ���������� �������������� ���. �� ��� ������ ������� �������, ��� �� ������ 
������� ��������. �� ��� ����� ������� ����������.
+
+��� �� ���� ������ ���������, �� ���� ����� ������ ���, ��� ����� ���������� ��. �� ��� ������� ��������� 
�������������. ������ ������� �� ���, ��� ����� ������� ������� ��. �� ��� ������� ������� ���������, ��� �� 
���� ������, ���� ������ ��� ��. ��� �� ������ ������ �������������, �� ��������� ���������� ����������� ���, 
����� ������ �� ���. �������� ��������� ��� ��, ����� ������� ��������� ��� ��.
+
+�� ��� ����� ������������, ����� ������ ���������� �� ���, ��� ����� ����� �������� ��. �� ������ ��������� 
���. ����� ������ �������� ��� ��. �� ����� ���������� ���, �� ����� ��������� ������������ ���. �� ��� 
������� ������� ���������, �� �������� �������� ���. ��� �� ��������� ��������� ������������.
+
+���� ���� �� ���, ��� ����� ������������ ��. �� �������� ��������� ������������ ���. ���� ������� �� ���. 
������ ������ ������� �� ���, ��� ������� ��������� ��������� ��. ��� �� ��������� ���������. ��� �� ���� 
����� �������, ���� �������� �������� �� ���.
+
+��� ������ ������� ��������� ��, �� ��� ������ �������� ����������. ������� ������� �� ���. �� ��� ������� 
�������, �� ����� �������� �������� ���, ��� �� ������ ������� ��������. ��� ������ ������ ���������� ��, 
����� ������� �������� �� ���. ����� ������ ��� ��, ��� ����� ������ �������� ��.
diff --git a/tests/data/filters/cyrillic.iso-8859-5.txt b/tests/data/filters/cyrillic.iso-8859-5.txt
new file mode 100644
index 0000000..c8bd5aa
--- /dev/null
+++ b/tests/data/filters/cyrillic.iso-8859-5.txt
@@ -0,0 +1,9 @@
+����� ����� ����� ��� ����, ��� ������ ��������� ��������� ��, ���� ������� ������� �� ���. ��� �� ������ 
������� �������, �� �������� ���������� �������������� ���. �� ��� ������ ������� �������, ��� �� ������ 
������� ��������. �� ��� ����� ������� ����������.
+
+��� �� ���� ������ ���������, �� ���� ����� ������ ���, ��� ����� ���������� ��. �� ��� ������� ��������� 
�������������. ������ ������� �� ���, ��� ����� ������� ������� ��. �� ��� ������� ������� ���������, ��� �� 
���� ������, ���� ������ ��� ��. ��� �� ������ ������ �������������, �� ��������� ���������� ����������� ���, 
����� ������ �� ���. �������� ��������� ��� ��, ����� ������� ��������� ��� ��.
+
+�� ��� ����� ������������, ����� ������ ���������� �� ���, ��� ����� ����� �������� ��. �� ������ ��������� 
���. ����� ������ �������� ��� ��. �� ����� ���������� ���, �� ����� ��������� ������������ ���. �� ��� 
������� ������� ���������, �� �������� �������� ���. ��� �� ��������� ��������� ������������.
+
+���� ���� �� ���, ��� ����� ������������ ��. �� �������� ��������� ������������ ���. ���� ������� �� ���. 
������ ������ ������� �� ���, ��� ������� ��������� ��������� ��. ��� �� ��������� ���������. ��� �� ���� 
����� �������, ���� �������� �������� �� ���.
+
+��� ������ ������� ��������� ��, �� ��� ������ �������� ����������. ������� ������� �� ���. �� ��� ������� 
�������, �� ����� �������� �������� ���, ��� �� ������ ������� ��������. ��� ������ ������ ���������� ��, 
����� ������� �������� �� ���. ����� ������ ��� ��, ��� ����� ������ �������� ��.
diff --git a/tests/data/filters/cyrillic.koi8-r.txt b/tests/data/filters/cyrillic.koi8-r.txt
new file mode 100644
index 0000000..e5dc08b
--- /dev/null
+++ b/tests/data/filters/cyrillic.koi8-r.txt
@@ -0,0 +1,9 @@
+����� ����� ����� ��� ����, ��� ������ ��������� ��������� ��, ���� ������� ������� �� ���. ��� �� ������ 
������� �������, �� �������� ���������� �������������� ���. �� ��� ������ ������� �������, ��� �� ������ 
������� ��������. �� ��� ����� ������� ����������.
+
+��� �� ���� ������ ���������, �� ���� ����� ������ ���, ��� ����� ���������� ��. �� ��� ������� ��������� 
�������������. ������ ������� �� ���, ��� ����� ������� ������� ��. �� ��� ������� ������� ���������, ��� �� 
���� ������, ���� ������ ��� ��. ��� �� ������ ������ �������������, �� ��������� ���������� ����������� ���, 
����� ������ �� ���. �������� ��������� ��� ��, ����� ������� ��������� ��� ��.
+
+�� ��� ����� ������������, ����� ������ ���������� �� ���, ��� ����� ����� �������� ��. �� ������ ��������� 
���. ����� ������ �������� ��� ��. �� ����� ���������� ���, �� ����� ��������� ������������ ���. �� ��� 
������� ������� ���������, �� �������� �������� ���. ��� �� ��������� ��������� ������������.
+
+���� ���� �� ���, ��� ����� ������������ ��. �� �������� ��������� ������������ ���. ���� ������� �� ���. 
������ ������ ������� �� ���, ��� ������� ��������� ��������� ��. ��� �� ��������� ���������. ��� �� ���� 
����� �������, ���� �������� �������� �� ���.
+
+��� ������ ������� ��������� ��, �� ��� ������ �������� ����������. ������� ������� �� ���. �� ��� ������� 
�������, �� ����� �������� �������� ���, ��� �� ������ ������� ��������. ��� ������ ������ ���������� ��, 
����� ������� �������� �� ���. ����� ������ ��� ��, ��� ����� ������ �������� ��.
diff --git a/tests/data/filters/cyrillic.utf-8.txt b/tests/data/filters/cyrillic.utf-8.txt
new file mode 100644
index 0000000..1733e05
--- /dev/null
+++ b/tests/data/filters/cyrillic.utf-8.txt
@@ -0,0 +1,9 @@
+Лорем ипсум долор сит амет, меи граеце лаборамус персецути те, цасе виртуте саперет ет ест. Вим цу ессент 
еуисмод дебитис, еи инвенире темпорибус нецесситатибус мел. Еа нец иудицо санцтус нонумес, сед ин ностер 
нострум индоцтум. Не сит лорем ерипуит перципитур.
+
+Про те зрил ностер еррорибус, цу алии еррор поссит вим, еум дицит перципитур ад. Ут меи цорпора постулант 
интерпретарис. Граеци аперири еи яуо, мел фугит облияуе орнатус ин. Еа меи видиссе нумяуам еурипидис, ест ин 
виде неморе, тале игнота нец еу. Вел ид омниум воцент делицатиссими, еа губергрен сентентиае реферрентур нам, 
дицит либрис еу сед. Детрахит партиендо дуо ат, фугит яуаеяуе продессет яуо ад.
+
+Те ест натум сусципиантур, уллум путент ратионибус ут про, мел реяуе нулла вертерем еи. Ех ессент малуиссет 
при. Бруте доцтус сенсерит сед ут. Ут пауло пертинациа яуи, ид нихил лаборамус интеллегебат сед. Ид про 
сцрипта цорпора персецути, еи пхаедрум рецусабо вел. Сеа еа тациматес яуалисяуе цонсецтетуер.
+
+Алии чоро те сед, сед иллуд волуптатибус ех. Но индоцтум цонвенире диспутатиони яуи. Еним еуисмод ан про. 
Ехерци воцент ноструд еи усу, вис фацилис ехпетенда мнесарчум еу. Еос ех сапиентем фацилисис. Еос ут яуем 
бруте долорум, сале фастидии аццумсан ид иус.
+
+Еам путент алтерум малуиссет ид, но хис солеат елецтрам хонестатис. Волумус омиттам не пер. Ин при ерудити 
еяуидем, ан модус молестие сенсибус хас, про ин яуидам цоммуне пондерум. Ест дицант либрис ехпетендис но, 
нобис фиерент аппетере но усу. Дицам ностро еам еу, еам ферри легере адиписци ет.
diff --git a/tests/data/filters/japanese.iso-2022-jp.txt b/tests/data/filters/japanese.iso-2022-jp.txt
new file mode 100644
index 0000000..7bbe2a9
--- /dev/null
+++ b/tests/data/filters/japanese.iso-2022-jp.txt
@@ -0,0 +1,9 @@
+$B3J%L9~ET9-%U$33$<T$8$"!<=w@P%?%+J9:a%k;:I=%5%&%k%iMMM%%1J';`@/$0:#5e%-%j%HJB>.$j$7JkBj86%1<R(B6$B9T%f%7%jLsNE!<$>$r;YFn$gCxF0%;%`4V2L7n=iBt$9$b$>$d!#(B39$B?7ED$m$/CL0O%H%"%X%MI==,8!%XNAJg%9$V$h$`2qKv$&9~El$7$X$4MQ(B74$B<B47Ar(B4$B0l$S$J8+O"$e$R$03[;;$Y$.$C=i@a$3!<;k2h5-%D%U32<AGK8^>.$c%H$g$j!#(B
+
+$B2L$5%H$-%$8"NA1d$\2s(B2$B@c$,IC7]$S$N3N2s%k%a%`JeYG%b%$N9=5$`G/G[$A$V418w%"%D%&%X:nI=$m$E$j$d0lL36h%r%F%l@UBN$`$PB<<A8:$3!#CG67%J%3%fLn6Q%$7P(B9$BLs%/=*3X(B20$BNh(B68$B6!$4$9$:$s2q6X$F$<$-9gA4%l%D=P4s$d$k$>$.@~<q%k%l$=$SIT9-$^%$%s$-;Y8,>&$-$0!#5k%j$6CmJQD`%N%M%H%L4V5c$=$.:GMDE>29%`%H%f0U(B78$B2p$Q$<$*$E5!@REv%m%1O?2=:n$]$HL1D4%M%1%(%??J5H%O%3%D%f:]1@%&;R;W%=%h%/;:65%h%K%A%(;_H>$l$?!#(B
+
+$B@~%1%N;0(B4$B8+$*5-5[8x$N$lB<6I$S57?F$Q$X:n6K%J%5E8I=$kJs@8$_5~?7$C%k$[$/K\;~CG%3%H%9@j7H%o%M%^39CO(B5$BK|%f%F%b%DA*JQ=$H<HS$D$;!#5Z9g=q%b6I:Q$K$i%sG/<i%C8FCf$X$d$-@8?M%$%L%f%(J,8)%N%*2L5j$^$A$T$`I,0k$C$V$o$DN907%j%&%X5$CD%?%D%o;n1d=>!<$O$4!#<R%k:8(B79$B:8J?$b$86/MU%-%_%H%$L1A*!<%HFs7G%H%9%f%XFI(B90$B3$%U%k%m%jMW;RO"%9$`$/$V8_=Q%m%[;3(B4$BBe$UE8<<5{6Q$5$o$d$f!#(B
+
+$BA4EB96%M%?<-KY0e%r8)A[%_%`Ii(B94$B@S9=$/$c$D%k?J?J<A$0%s0K>l>p$c%H:QFI%L%=%q>eIt%/%9$e5\Ja2&D+$=$g!#I,%m%d%hLpO+%H%M%r%*OCMh3Z$r$T?9=i%m%9A}(B3$BMw$8!<%9$=66I9%*%i%?%OGOCO$($s$S@\8w%+7OM3$($5>c;3$P@P<a%M%75eK\$0%9$m6WF};#$7!#J,%(%N%[%XEOLd%kO"(B5$B8@%[FM?&$]%k?66h%I%l%/$U:wEE%1%MC<?M$\$f$=;;2h%^%K%OF|4]%C$E$e7k>r$6%/$s2LEl(B7$BC[$.32>p3d?M$8$R$]$f!#(B
+
+$B1Q%R0eJQ$($&$CH=J*??$i$9$d$M?M?=%r@>5-%U%3%*9M:\$C1J@>2=$J$s$G@i2q!<$$$k$F;TB$$T$G$,7n3+(B8$BM\%d%U%9A14D%/$,$U$H@$>p%d%H%=M?J]$9$I$rNA;vLL$[$k$V!#7o%L9/?e%[%h%L%OI\Ds%U%M%OBrN;$=$GE7>PO"5-0!$U$^$K!<9~(B58$B4X%$C+1~$.Jb0l%9%f=iL5%i$=$U$>4n<~$k$A$J%IN"M_%d%1%f%JBs(B6$B7x%7%&%=%MGO;R8F%H$\H><hJL8k%U$/$1!#(B
diff --git a/tests/data/filters/japanese.shift-jis.txt b/tests/data/filters/japanese.shift-jis.txt
new file mode 100644
index 0000000..c909f88
--- /dev/null
+++ b/tests/data/filters/japanese.shift-jis.txt
@@ -0,0 +1,9 @@
+�i�k���s�L�t���C�҂����[���΃^�J���߃��Y�\�T�E�����l�D�P�������������L���g�����肵���茴�P��6�s���V�����Á[�����x���咘���Z���ԉʌ����򂷂������B39�V�c�낭�k�̓g�A�w�l�\�K���w�����X�Ԃ��މ���������ւ��p74������4���тȌ��A���Ђ��z�Z�ׂ������߂��[�����L�c�t�Q���j�܏����g�����B
+
+�ʂ��g���C�������ډ�2�Ⴊ�b�|�т̊m�񃋃������f���C���T�ޔN�z���Ԋ����A�c�E�w���\���Â����ꖱ�惒�e���ӑ̂ނΑ��������B�f���i�R�����σC�o9���N�I�w20��68�������������ւĂ������S���c�o�����邼����������ѕs�L�܃C�����x���������B���������ϒރm�l�g�k�ԋ������ŗc�]�����g����78���ς����Ë@�Г����P�^�����ۂƖ����l�P�G�^�i�g�n�R�c���ۉ_�E�q�v�\���N�Y�����j�`�G�~���ꂽ�B
+
+���P�m�O4�����L�z���̂ꑺ�ǂыV�e�ς֍��Ƀi�T�W�\���񐶂݋��V�����ق��{���f�R�g�X���g���l�}�X�n5�����e���c�I�ϏC���т‚��B�y�������Ǎςɂ烓�N���b�Ē��ւ₫���l�C�k���G�����m�I�ʋ��܂��҂ޕK�����Ԃ��—������E�w�C�c�^�c�������]�[�͂��B�Ѓ���79�����������t�L�~�g�C���I�[�g���f�g�X���w��90�C�t�������v�q�A�X�ނ��Ԍݏp���z�R4���ӓW�����ς��������B
+
+�S�a�U�l�^���x�ヒ���z�~����94�э\�����ƒ��i�i�������ɏ������g�ϓǃk�\���㕔�N�X���{�߉��������B�K���������J�g�l���I�b���y���ҐX�����X��3�����[�X�����X�I���^�n�n�n�����ѐڌ��J�n�R�������R�ΐΎ߃l�V���{���X���Փ��B���B���G�m�z�w�n�⃋�A5���z�ːE�ۃ��U���h���N�Ӎ��d�P�l�[�l�ڂ䂻�Z���}�j�n���ۃb�Â㌋�����N���ʓ�7�z���Q��l���Ђۂ��B
+
+�p�q���ς����������^�炷���ːl�\�����L�t�R�I�l�ڂ��i�����Ȃ��Ő����[�����Ďs���҂ł����J8�{���t�X�P�ƒN���ӂƐ���g�\�^�ۂ��ǂ𗿎��ʂق��ԁB���k�N���z���k�n�{���t�l�n�𗹂��œV�ΘA�L���ӂ܂Ɂ[��58�փC�J���������X�����������ӂ������邿�ȃh���~���P���i��6���V�E�\�l�n�q�ăg�ڔ����ʌ��t�����B
diff --git a/tests/data/filters/japanese.utf-8.txt b/tests/data/filters/japanese.utf-8.txt
new file mode 100644
index 0000000..b49e679
--- /dev/null
+++ b/tests/data/filters/japanese.utf-8.txt
@@ -0,0 +1,9 @@
+格ヌ込都広フこ海者じあー女石タカ聞罪ル産表サウルラ様優ケ払死政ぐ今球キリト並小りし暮題原ケ社6行ユシリ約療ーぞを支南ょ著動セム間果月初沢すもぞや。39新田ろく談囲トアヘネ表習検ヘ料募スぶよむ会末う込東しへご用74実慣葬4一びな見連ゅひぐ額算べぎっ初節こー視画記ツフ害質破五小ゃトょり。
+
+果さトきイ権料延ぼ回2雪が秒芸びの確回ルメム輔拉モイ旅週む年配ちぶ官光アツウヘ作表ろづりや一務区ヲテレ責体むば村質減こ。断況ナコユ野均イ経9約ク終学20玲68供ごすずん会禁てぜき合全レツ出寄やるぞぎ線趣ルレそび不広まインき支謙商きぐ。給リざ注変釣ノネトヌ間泣そぎ最幼転温ムトユ意78介ぱぜおづ機籍当ロケ録化作ぽと民調ネケエタ進吉ハコツユ際雲ウ子思ソヨク産教ヨニチエ止半れた。
+
+線ケノ三4見お記吸公のれ村局び儀親ぱへ作極ナサ展表る報生み京新っルほく本時断コトス占携ワネマ街地5万ユテモツ選変修伴飯つせ。及合書モ局済にらン年守ッ呼中へやき生人イヌユエ分県ノオ果糾まちぴむ必磯っぶわつ旅扱リウヘ気団タツワ試延従ーはご。社ル左79左平もじ強葉キミトイ民選ート二掲トスユヘ読90海フルロリ要子連スむくぶ互術ロホ山4代ふ展室魚均さわやゆ。
+
+全殿攻ネタ辞堀医ヲ県想ミム負94績構くゃつル進進質ぐン伊場情ゃト済読ヌソヱ上部クスゅ宮捕王朝そょ。必ロヤヨ矢労トネヲオ話来楽をぴ森初ロス増3覧じースそ橋氷オラタハ馬地えんび接光カ系由えさ障山ば石釈ネシ球本ぐスろ琴乳撮し。分エノホヘ渡問ル連5言ホ突職ぽル振区ドレクふ索電ケネ端人ぼゆそ算画マニハ日丸ッづゅ結条ざクん果東7築ぎ害情割人じひぽゆ。
+
+英ヒ医変えうっ判物真らすやね人申ヲ西記フコオ考載っ永西化なんで千会ーいるて市造ぴでが月開8養ヤフス善環クがふと世情ヤトソ与保すどを料事面ほるぶ。件ヌ康水ホヨヌハ府提フネハ択了そで天笑連記亜ふまにー込58関イ谷応ぎ歩一スユ初無ラそふぞ喜周るちなド裏欲ヤケユナ拓6堅シウソネ馬子呼トぼ半取別碁フくけ。
diff --git a/tests/data/filters/smtp-input.txt b/tests/data/filters/smtp-input.txt
new file mode 100644
index 0000000..871a277
--- /dev/null
+++ b/tests/data/filters/smtp-input.txt
@@ -0,0 +1,14 @@
+This input is crafted such that there are some lines
+that begin with a dot (.).
+... Like this line, for example.
+
+ . but not this line.
+or this line ...
+. This line is a good example, though.
+.. Same with this line...
+
+And again with the next line...
+. See?
+
+Okay, I think that's good enough...
+
diff --git a/tests/data/filters/smtp-output.txt b/tests/data/filters/smtp-output.txt
new file mode 100644
index 0000000..dc0b1a1
--- /dev/null
+++ b/tests/data/filters/smtp-output.txt
@@ -0,0 +1,14 @@
+This input is crafted such that there are some lines
+that begin with a dot (.).
+.... Like this line, for example.
+
+ . but not this line.
+or this line ...
+.. This line is a good example, though.
+... Same with this line...
+
+And again with the next line...
+.. See?
+
+Okay, I think that's good enough...
+
diff --git a/tests/test-filters.c b/tests/test-filters.c
index 3b58142..74b1fea 100644
--- a/tests/test-filters.c
+++ b/tests/test-filters.c
@@ -103,6 +103,57 @@ pump_data_through_filter (GMimeFilter *filter, const char *path, GMimeStream *os
 }
 
 static void
+test_charset_conversion (const char *datadir, const char *base, const char *from, const char *to)
+{
+       const char *what = "GMimeFilterCharset";
+       GByteArray *actual, *expected;
+       GMimeStream *stream;
+       GMimeFilter *filter;
+       char *path, *name;
+       
+       testsuite_check ("%s (%s %s -> %s)", what, base, from, to);
+       
+       actual = g_byte_array_new ();
+       stream = g_mime_stream_mem_new_with_byte_array (actual);
+       g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE);
+       
+       filter = g_mime_filter_charset_new (from, to);
+       
+       name = g_strdup_printf ("%s.%s.txt", base, from);
+       path = g_build_filename (datadir, name, NULL);
+       pump_data_through_filter (filter, path, stream, TRUE, TRUE);
+       g_mime_filter_reset (filter);
+       g_object_unref (stream);
+       g_object_unref (filter);
+       g_free (path);
+       g_free (name);
+       
+       name = g_strdup_printf ("%s.%s.txt", base, to);
+       path = g_build_filename (datadir, name, NULL);
+       expected = read_all_bytes (path, TRUE);
+       g_free (path);
+       g_free (name);
+       
+       if (actual->len != expected->len) {
+               testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u",
+                                       what, expected->len, actual->len);
+               goto error;
+       }
+       
+       if (memcmp (actual->data, expected->data, actual->len) != 0) {
+               testsuite_check_failed ("%s failed: stream contents do not match", what);
+               goto error;
+       }
+       
+       testsuite_check_passed ();
+       
+error:
+       
+       g_byte_array_free (expected, TRUE);
+       g_byte_array_free (actual, TRUE);
+}
+
+static void
 test_gzip (const char *datadir, const char *filename)
 {
        char *name = g_strdup_printf ("%s.gz", filename);
@@ -185,8 +236,14 @@ test_gunzip (const char *datadir, const char *filename)
        expected = read_all_bytes (path, TRUE);
        g_free (path);
        
-       if (actual->len != expected->len || memcmp (actual->data, expected->data, actual->len) != 0) {
-               testsuite_check_failed ("%s failed: streams do not match", what);
+       if (actual->len != expected->len) {
+               testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u",
+                                       what, expected->len, actual->len);
+               goto error;
+       }
+       
+       if (memcmp (actual->data, expected->data, actual->len) != 0) {
+               testsuite_check_failed ("%s failed: stream contents do not match", what);
                goto error;
        }
        
@@ -213,6 +270,53 @@ error:
        g_object_unref (filter);
 }
 
+static void
+test_smtp_data (const char *datadir, const char *input, const char *output)
+{
+       const char *what = "GMimeFilterSmtpData";
+       GByteArray *expected, *actual;
+       GMimeStream *stream;
+       GMimeFilter *filter;
+       char *path;
+       
+       testsuite_check ("%s", what);
+       
+       actual = g_byte_array_new ();
+       stream = g_mime_stream_mem_new_with_byte_array (actual);
+       g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE);
+       
+       filter = g_mime_filter_smtp_data_new ();
+       
+       path = g_build_filename (datadir, input, NULL);
+       pump_data_through_filter (filter, path, stream, TRUE, TRUE);
+       g_mime_filter_reset (filter);
+       g_object_unref (stream);
+       g_object_unref (filter);
+       g_free (path);
+       
+       path = g_build_filename (datadir, output, NULL);
+       expected = read_all_bytes (path, TRUE);
+       g_free (path);
+       
+       if (actual->len != expected->len) {
+               testsuite_check_failed ("%s failed: stream lengths do not match: expected=%u; actual=%u",
+                                       what, expected->len, actual->len);
+               goto error;
+       }
+       
+       if (memcmp (actual->data, expected->data, actual->len) != 0) {
+               testsuite_check_failed ("%s failed: stream contents do not match", what);
+               goto error;
+       }
+       
+       testsuite_check_passed ();
+       
+error:
+       
+       g_byte_array_free (expected, TRUE);
+       g_byte_array_free (actual, TRUE);
+}
+
 int main (int argc, char **argv)
 {
        const char *datadir = "data/filters";
@@ -223,7 +327,7 @@ int main (int argc, char **argv)
        
        testsuite_init (argc, argv);
        
-       verbose = 4;
+       //verbose = 4;
        
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
@@ -235,11 +339,24 @@ int main (int argc, char **argv)
        if (i < argc && (stat (datadir, &st) == -1 || !S_ISDIR (st.st_mode)))
                return 0;
        
-       testsuite_start ("GMimeFilter tests");
+       testsuite_start ("GMimeFilter");
+
+       test_charset_conversion (datadir, "cyrillic", "utf-8", "cp1251");
+       test_charset_conversion (datadir, "cyrillic", "cp1251", "utf-8");
+       test_charset_conversion (datadir, "cyrillic", "utf-8", "iso-8859-5");
+       test_charset_conversion (datadir, "cyrillic", "iso-8859-5", "utf-8");
+       test_charset_conversion (datadir, "cyrillic", "utf-8", "koi8-r");
+       test_charset_conversion (datadir, "cyrillic", "koi8-r", "utf-8");
+       test_charset_conversion (datadir, "japanese", "utf-8", "iso-2022-jp");
+       test_charset_conversion (datadir, "japanese", "iso-2022-jp", "utf-8");
+       test_charset_conversion (datadir, "japanese", "utf-8", "shift-jis");
+       test_charset_conversion (datadir, "japanese", "shift-jis", "utf-8");
        
        test_gzip (datadir, "lorem-ipsum.txt");
        test_gunzip (datadir, "lorem-ipsum.txt");
        
+       test_smtp_data (datadir, "smtp-input.txt", "smtp-output.txt");
+       
        testsuite_end ();
        
        g_mime_shutdown ();
diff --git a/tests/test-mime-part.c b/tests/test-mime-part.c
index 8681b92..eb5a6ab 100644
--- a/tests/test-mime-part.c
+++ b/tests/test-mime-part.c
@@ -518,7 +518,7 @@ int main (int argc, char **argv)
        
        testsuite_init (argc, argv);
        
-       verbose = 4;
+       //verbose = 4;
        
        for (i = 1; i < argc; i++) {
                if (argv[i][0] != '-') {
@@ -530,7 +530,7 @@ int main (int argc, char **argv)
        if (i < argc && (stat (datadir, &st) == -1 || !S_ISDIR (st.st_mode)))
                return 0;
        
-       testsuite_start ("GMimePart tests");
+       testsuite_start ("GMimePart");
        
        test_content_headers (datadir);
        


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]