Dpkg_Control.t 3.7 KB

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