File: get_time_stamp.test

package info (click to toggle)
libnet-xmpp-perl 1.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 588 kB
  • sloc: perl: 4,286; makefile: 2; xml: 1
file content (166 lines) | stat: -r--r--r-- 5,190 bytes parent folder | download | duplicates (6)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# OK I give up!
# This test is disabled because it won't run on windows due to a bug in
# XML::Stream
# It should fail on Net::XMPP 1.0.1 and earlier
# and is the primary reason for bothering to release 1.0.2

use Test::More tests=>25;
#use Data::Dump qw(pp);

use XML::Stream qw(Tree);

BEGIN{ use_ok( "Net::XMPP" ); }

my $debug_level = 100;

my $debug = new Net::XMPP::Debug(setdefault=>1,
                                 level=>$debug_level,
                                 file=>"stdout",
                                 header=>"test",
                                );

require "t/mytestlib.pl";

my $message_node = new XML::Stream::Node("message");
ok( defined($message_node), "new()");
isa_ok( $message_node, "XML::Stream::Node" );

$message_node->put_attrib(to=>"jer\@jabber.org",
                          from=>"reatmon\@jabber.org",
                          type=>'groupchat',
                          'xml:lang'=>'en');
my $body_node = $message_node->add_child("body");
$body_node->add_cdata("body");

my $html_node = $message_node->add_child("html");
$html_node->put_attrib(xmlns=>"http://jabber.org/protocol/xhtml-im");

my $html_node_body = $html_node->add_child("body");
$html_node_body->put_attrib(
	'xmlns'	=> "http://www.w3.org/1999/xhtml",
);
my $html_node_span = $html_node_body->add_child("span");

$html_node_span->put_attrib(
	'style'	=> "font-weight: normal; font-size: 10pt; color: #ff0000; font-style: normal; font-family: arial black",
);
$html_node_span->add_cdata("body");

my $x0038_node = $message_node->add_child("x");
$x0038_node->put_attrib(xmlns=>"jisp:x:jep-0038",
                    );
my $name_38_node = $x0038_node->add_child("name");
$name_38_node->add_cdata("shinyicons");

is( $message_node->GetXML(), "<message from='".'reatmon@jabber.org'."' to='".'jer@jabber.org'."' type='groupchat' xml:lang='en'><body>body</body><html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'><span style='font-weight: normal; font-size: 10pt; color: #ff0000; font-style: normal; font-family: arial black'>body</span></body></html><x xmlns='jisp:x:jep-0038'><name>shinyicons</name></x></message>", "GetXML()" );

#diag "Message Node ". pp($message_node);

my $message = new Net::XMPP::Message($message_node);
ok( defined($message), "new()" );
isa_ok( $message, "Net::XMPP::Message" );

is( $message->GetTo(), "jer\@jabber.org", "GetTo");
is( $message->GetFrom(), "reatmon\@jabber.org", "GetFrom");
is( $message->GetBody(), "body", "GetBody");

my @xdelays = $message->GetChild("jabber:x:delay");
is( @xdelays, 0, "no delays");

my $timestamp = $message->GetTimeStamp();

ok($timestamp, "GetTimeStamp");

#diag "Message ". pp($message);

my $message_node2 = new XML::Stream::Node("message");
ok( defined($message_node2), "new()");
isa_ok( $message_node2, "XML::Stream::Node" );

$message_node2->put_attrib(to=>"jer\@jabber.org",
                          from=>"reatmon\@jabber.org",
                          type=>'groupchat',
                          'xml:lang'=>'en');
my $body_node2 = $message_node2->add_child("body");
$body_node2->add_cdata("body");

my $html_node2 = $message_node2->add_child("html");
$html_node2->put_attrib(xmlns=>"http://jabber.org/protocol/xhtml-im");

my $html_node2_body = $html_node2->add_child("body");
$html_node2_body->put_attrib(
	'xmlns'	=> "http://www.w3.org/1999/xhtml",
);
my $html_node2_span = $html_node2_body->add_child("span");

$html_node2_span->put_attrib(
	'style'	=> "font-weight: normal; font-size: 10pt; color: #ff0000; font-style: normal; font-family: arial black",
);
$html_node2_span->add_cdata("body");

my $x0038_node2 = $message_node2->add_child("x");
$x0038_node2->put_attrib(xmlns=>"jisp:x:jep-0038",
                    );
my $name_38_node2 = $x0038_node2->add_child("name");
$name_38_node2->add_cdata("shinyicons");

#diag "Message Node2 ". $message_node2->GetXML;

my $client = Net::XMPP::Client->new(
  		'debuglevel'	=> $debug_level,
		'debugfile'		=> 'stderr',
);

my $stream = new XML::Stream(style=>"node",
	'debug'		=>"stdout",
	'debuglevel'=>$debug_level,
);

$stream->SetCallBacks(node=>\&noder);

$stream->OpenFile("t/node1.xml");

# What if there was a custom namespace
$client->AddNamespace(
			ns    => "tcli:request",
            tag   => "tcli",
            xpath => {
            	'Version'	=> { 'path' => 'version/text()' },
             	'Yaml'		=> { 'path' => 'yaml/text()' },
             	'Request'	=> { 'type' => 'master'},
	       }
);

$stream->OpenFile("t/node1.xml");

# What if there was a custom namespace that's in the node
$client->AddNamespace(
			ns    => "jisp:x:jep-0038",
            tag   => "x",
            xpath => {
            	'Name'		=> { 'path' => 'name/text()' },
	       }
);

$stream->OpenFile("t/node1.xml");

#$stream->OpenFile('./t/node2.xml');

sub noder {
	my ($sid,$node) = @_;

#diag "Sid1 ".$sid." ".pp($node);

is_deeply($node,$message_node2, " Nodes the same");


my $message = $client->BuildObject("message",$node);
ok( defined($message), "new()" );
isa_ok( $message, "Net::XMPP::Message" );

my $timestamp = $message->GetTimeStamp();
#diag "Message ". pp($message);

ok($timestamp, "GetTimeStamp");

}