Dpkg_Control.t 3.8 KB

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