700_Dpkg_Control.t 3.5 KB

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