Dpkg_Control.t 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <https://www.gnu.org/licenses/>.
  15. use strict;
  16. use warnings;
  17. use Test::More tests => 24;
  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/Dpkg_Control';
  25. sub parse_dsc {
  26. my $path = shift;
  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. Numeric-Field: 0
  40. My-Field-One: myvalue1
  41. My-Field-Two: myvalue2
  42. Long-Field: line1
  43. line 2 line 2 line 2
  44. .
  45. line 3 line 3 line 3
  46. ..
  47. line 4
  48. Empty-Field:
  49. Package: mypackage1
  50. Architecture: any
  51. Depends: libc6
  52. Package: mypackage2
  53. Architecture: all
  54. Depends: hello
  55. Package: mypackage3
  56. Architecture: all
  57. Depends: hello
  58. Description: short one
  59. long one
  60. very long one
  61. ';
  62. is($value, $expected, "Dump of $datadir/control-1");
  63. my $src = $c->get_source();
  64. is($src, $c->[0], 'array representation of Dpkg::Control::Info 1/2');
  65. is($src->{'numeric-field'}, '0', 'Numeric 0 value parsed correctly');
  66. is($src->{'my-field-one'}, 'myvalue1', 'Access field through badly capitalized field name');
  67. is($src->{'long-field'},
  68. 'line1
  69. line 2 line 2 line 2
  70. line 3 line 3 line 3
  71. .
  72. line 4', 'Get multi-line field');
  73. is($src->{'Empty-field'}, '', 'Get empty field');
  74. my $pkg = $c->get_pkg_by_idx(1);
  75. is($pkg, $c->[1], 'array representation of Dpkg::Control::Info 2/2');
  76. is($pkg->{package}, 'mypackage1', 'Name of first package');
  77. $pkg = $c->get_pkg_by_name('mypackage3');
  78. is($pkg->{package}, 'mypackage3', 'Name of third package');
  79. is($pkg->{Depends}, 'hello', 'Name of third package');
  80. $pkg = $c->get_pkg_by_idx(2);
  81. $io = IO::String->new();
  82. $pkg->output($io);
  83. is(${$io->string_ref()},
  84. 'Package: mypackage2
  85. Architecture: all
  86. Depends: hello
  87. ', "Dump of second binary package of $datadir/control-1");
  88. # Check OpenPGP armored signatures in source control files
  89. my $dsc;
  90. $dsc = parse_dsc("$datadir/bogus-unsigned.dsc");
  91. is($dsc, undef, 'Unsigned .dsc w/ OpenPGP armor');
  92. $dsc = parse_dsc("$datadir/bogus-armor-no-sig.dsc");
  93. is($dsc, undef, 'Signed .dsc w/ OpenPGP armor missing signature');
  94. $dsc = parse_dsc("$datadir/bogus-armor-trail.dsc");
  95. is($dsc, undef, 'Signed .dsc w/ bogus OpenPGP armor trailer');
  96. $dsc = parse_dsc("$datadir/bogus-armor-inline.dsc");
  97. is($dsc, undef, 'Signed .dsc w/ bogus OpenPGP inline armor');
  98. $dsc = parse_dsc("$datadir/bogus-armor-formfeed.dsc");
  99. is($dsc, undef, 'Signed .dsc w/ bogus OpenPGP armor line');
  100. $dsc = parse_dsc("$datadir/bogus-armor-double.dsc");
  101. ok(defined $dsc, 'Signed .dsc w/ two OpenPGP armor signatures');
  102. is($dsc->{Source}, 'pass', 'Signed spaced .dsc package name');
  103. $dsc = parse_dsc("$datadir/bogus-armor-spaces.dsc");
  104. ok(defined $dsc, 'Signed .dsc w/ spaced OpenPGP armor');
  105. is($dsc->{Source}, 'pass', 'Signed spaced .dsc package name');
  106. $dsc = parse_dsc("$datadir/bogus-armor-nested.dsc");
  107. ok(defined $dsc, 'Signed .dsc w/ nested OpenPGP armor');
  108. is($dsc->{Source}, 'pass', 'Signed nested .dsc package name');