700_Dpkg_Control.t 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/usr/bin/perl
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 22;
  16. use strict;
  17. use warnings;
  18. use IO::String;
  19. BEGIN {
  20. use_ok('Dpkg::Control');
  21. use_ok('Dpkg::Control::Info');
  22. }
  23. my $srcdir = $ENV{srcdir} || '.';
  24. my $datadir = $srcdir . '/t/700_Dpkg_Control';
  25. sub parse_dsc {
  26. my ($path) = @_;
  27. my $dsc = Dpkg::Control->new(type => CTRL_PKG_SRC);
  28. eval {
  29. $dsc->load($path);
  30. 1;
  31. } or return;
  32. return $dsc;
  33. }
  34. my $c = Dpkg::Control::Info->new("$datadir/control-1");
  35. my $io = IO::String->new();
  36. $c->output($io);
  37. my $value = ${$io->string_ref()};
  38. my $expected = 'Source: mysource
  39. My-Field-One: myvalue1
  40. My-Field-Two: myvalue2
  41. Long-Field: line1
  42. line 2 line 2 line 2
  43. .
  44. line 3 line 3 line 3
  45. ..
  46. line 4
  47. Empty-Field:
  48. Package: mypackage1
  49. Architecture: any
  50. Depends: libc6
  51. Package: mypackage2
  52. Architecture: all
  53. Depends: hello
  54. Package: mypackage3
  55. Architecture: all
  56. Depends: hello
  57. Description: short one
  58. long one
  59. very long one
  60. ';
  61. is($value, $expected, "Dump of $datadir/control-1");
  62. my $src = $c->get_source();
  63. is($src, $c->[0], 'array representation of Dpkg::Control::Info 1/2');
  64. is($src->{'my-field-one'}, 'myvalue1', 'Access field through badly capitalized field name');
  65. is($src->{'long-field'},
  66. 'line1
  67. line 2 line 2 line 2
  68. line 3 line 3 line 3
  69. .
  70. line 4', 'Get multi-line field');
  71. is($src->{'Empty-field'}, '', 'Get empty field');
  72. my $pkg = $c->get_pkg_by_idx(1);
  73. is($pkg, $c->[1], 'array representation of Dpkg::Control::Info 2/2');
  74. is($pkg->{package}, 'mypackage1', 'Name of first package');
  75. $pkg = $c->get_pkg_by_name('mypackage3');
  76. is($pkg->{package}, 'mypackage3', 'Name of third package');
  77. is($pkg->{Depends}, 'hello', 'Name of third package');
  78. $pkg = $c->get_pkg_by_idx(2);
  79. $io = IO::String->new();
  80. $pkg->output($io);
  81. is(${$io->string_ref()},
  82. 'Package: mypackage2
  83. Architecture: all
  84. Depends: hello
  85. ', "Dump of second binary package of $datadir/control-1");
  86. # Check OpenPGP armored signatures in source control files
  87. my $dsc;
  88. $dsc = parse_dsc("$datadir/bogus-unsigned.dsc");
  89. is($dsc, undef, 'Unsigned .dsc w/ OpenPGP armor');
  90. $dsc = parse_dsc("$datadir/bogus-armor-no-sig.dsc");
  91. is($dsc, undef, 'Signed .dsc w/ OpenPGP armor missing signature');
  92. $dsc = parse_dsc("$datadir/bogus-armor-trail.dsc");
  93. is($dsc, undef, 'Signed .dsc w/ bogus OpenPGP armor trailer');
  94. $dsc = parse_dsc("$datadir/bogus-armor-inline.dsc");
  95. is($dsc, undef, 'Signed .dsc w/ bogus OpenPGP inline armor');
  96. $dsc = parse_dsc("$datadir/bogus-armor-double.dsc");
  97. ok(defined $dsc, 'Signed .dsc w/ two OpenPGP armor signatures');
  98. is($dsc->{Source}, 'pass', 'Signed spaced .dsc package name');
  99. $dsc = parse_dsc("$datadir/bogus-armor-spaces.dsc");
  100. ok(defined $dsc, 'Signed .dsc w/ spaced OpenPGP armor');
  101. is($dsc->{Source}, 'pass', 'Signed spaced .dsc package name');
  102. $dsc = parse_dsc("$datadir/bogus-armor-nested.dsc");
  103. ok(defined $dsc, 'Signed .dsc w/ nested OpenPGP armor');
  104. is($dsc->{Source}, 'pass', 'Signed nested .dsc package name');