700_Dpkg_Control.t 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- mode: cperl;-*-
  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 <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 11;
  16. use strict;
  17. use warnings;
  18. use IO::String;
  19. use_ok('Dpkg::Control::Info');
  20. my $srcdir = $ENV{srcdir} || '.';
  21. my $datadir = $srcdir . '/t/700_Dpkg_Control';
  22. my $c = Dpkg::Control::Info->new("$datadir/control-1");
  23. my $io = IO::String->new();
  24. $c->output($io);
  25. my $value = ${$io->string_ref()};
  26. my $expected = 'Source: mysource
  27. My-Field-One: myvalue1
  28. My-Field-Two: myvalue2
  29. Long-Field: line1
  30. line 2 line 2 line 2
  31. .
  32. line 3 line 3 line 3
  33. ..
  34. line 4
  35. Empty-Field:
  36. Package: mypackage1
  37. Depends: libc6
  38. Package: mypackage2
  39. Depends: hello
  40. Package: mypackage3
  41. Depends: hello
  42. Description: short one
  43. long one
  44. very long one
  45. ';
  46. is($value, $expected, "Dump of $datadir/control-1");
  47. my $src = $c->get_source();
  48. is($src, $c->[0], "array representation of Dpkg::Control::Info 1/2");
  49. is($src->{'my-field-one'}, 'myvalue1', "Access field through badly capitalized field name");
  50. is($src->{'long-field'},
  51. 'line1
  52. line 2 line 2 line 2
  53. line 3 line 3 line 3
  54. .
  55. line 4', "Get multi-line field");
  56. is($src->{'Empty-field'}, "", "Get empty field");
  57. my $pkg = $c->get_pkg_by_idx(1);
  58. is($pkg, $c->[1], "array representation of Dpkg::Control::Info 2/2");
  59. is($pkg->{package}, 'mypackage1', 'Name of first package');
  60. $pkg = $c->get_pkg_by_name("mypackage3");
  61. is($pkg->{package}, 'mypackage3', 'Name of third package');
  62. is($pkg->{Depends}, 'hello', 'Name of third package');
  63. $pkg = $c->get_pkg_by_idx(2);
  64. $io = IO::String->new();
  65. $pkg->output($io);
  66. is(${$io->string_ref()},
  67. 'Package: mypackage2
  68. Depends: hello
  69. ', "Dump of second binary package of $datadir/control-1");