File: charset1.t

package info (click to toggle)
libxml-rss-perl 1.48-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 756 kB
  • ctags: 231
  • sloc: perl: 6,888; xml: 378; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl

# This is a regression test for:
# http://rt.cpan.org/Public/Bug/Display.html?id=5438
# based on the original script supplied with the report.

use strict;
use warnings;

use XML::RSS;
use File::Spec;

use Test::More;

if (eval "require Test::Differences") {
    Test::Differences->import;
    plan tests => 2;
}
else {
    plan skip_all => 'Test::Differences required';
}

{
    my $rss_file = File::Spec->catfile("t", "generated", "charset1-generated.xml");

    my %rss_new = (version => '1.0', encoding => 'iso-8859-1', output => '1.0');
    my $rss = XML::RSS->new(%rss_new);

    #
    # Add a channel
    #

    $rss->channel (title => "Channel Title",
               link  => "http://channel.url/",
               description => "Channel Description");

    #
    # Add an item with accented characters
    #

    $rss->add_item (title => "Item Title",
            link => "http://item.url/",
            description => "Item Description (©)");

    #
    # Save RSS content to file.
    #

    open (RSS, ">", $rss_file) || 
        die "Unable to open $rss_file.";


    my $rss1 = $rss->as_string;
    print RSS $rss1;

    close (RSS);

    #
    # Now read it back in
    #

    $rss = XML::RSS->new(%rss_new);
    $rss->parsefile($rss_file);

    #
    # save it again
    #

    open (RSS, ">", $rss_file) || die "Unable to open $rss_file.";

    my $rss2 = $rss->as_string;
    print RSS $rss2;

    close (RSS);

    eq_or_diff($rss1, $rss2, 'got the same RSS both times'); 

    #
    # And read it back in again.
    #

    $rss = XML::RSS->new;
    $rss->parsefile($rss_file);

    # Check that no exception was thrown along the way.
    ok(1);
}