Dpkg_Control.t 3.7 KB

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