700_Dpkg_Control.t 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. Architecture: any
  38. Depends: libc6
  39. Package: mypackage2
  40. Architecture: all
  41. Depends: hello
  42. Package: mypackage3
  43. Architecture: all
  44. Depends: hello
  45. Description: short one
  46. long one
  47. very long one
  48. ';
  49. is($value, $expected, "Dump of $datadir/control-1");
  50. my $src = $c->get_source();
  51. is($src, $c->[0], "array representation of Dpkg::Control::Info 1/2");
  52. is($src->{'my-field-one'}, 'myvalue1', "Access field through badly capitalized field name");
  53. is($src->{'long-field'},
  54. 'line1
  55. line 2 line 2 line 2
  56. line 3 line 3 line 3
  57. .
  58. line 4', "Get multi-line field");
  59. is($src->{'Empty-field'}, "", "Get empty field");
  60. my $pkg = $c->get_pkg_by_idx(1);
  61. is($pkg, $c->[1], "array representation of Dpkg::Control::Info 2/2");
  62. is($pkg->{package}, 'mypackage1', 'Name of first package');
  63. $pkg = $c->get_pkg_by_name("mypackage3");
  64. is($pkg->{package}, 'mypackage3', 'Name of third package');
  65. is($pkg->{Depends}, 'hello', 'Name of third package');
  66. $pkg = $c->get_pkg_by_idx(2);
  67. $io = IO::String->new();
  68. $pkg->output($io);
  69. is(${$io->string_ref()},
  70. 'Package: mypackage2
  71. Architecture: all
  72. Depends: hello
  73. ', "Dump of second binary package of $datadir/control-1");