700_Dpkg_Control.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 => 9;
  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->{'my-field-one'}, 'myvalue1', "Access field through badly capitalized field name");
  49. is($src->{'long-field'},
  50. 'line1
  51. line 2 line 2 line 2
  52. line 3 line 3 line 3
  53. .
  54. line 4', "Get multi-line field");
  55. is($src->{'Empty-field'}, "", "Get empty field");
  56. my $pkg = $c->get_pkg_by_idx(1);
  57. is($pkg->{package}, 'mypackage1', 'Name of first package');
  58. $pkg = $c->get_pkg_by_name("mypackage3");
  59. is($pkg->{package}, 'mypackage3', 'Name of third package');
  60. is($pkg->{Depends}, 'hello', 'Name of third package');
  61. $pkg = $c->get_pkg_by_idx(2);
  62. $io = IO::String->new();
  63. $pkg->output($io);
  64. is(${$io->string_ref()},
  65. 'Package: mypackage2
  66. Depends: hello
  67. ', "Dump of second binary package of $datadir/control-1");