File: z_08_vcard_hook.t

package info (click to toggle)
libanyevent-xmpp-perl 0.52-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 896 kB
  • sloc: perl: 7,937; makefile: 12
file content (47 lines) | stat: -rw-r--r-- 1,294 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
#!perl

use strict;
no warnings;
use Test::More;
use Digest::SHA qw/sha1_hex/;
use AnyEvent::XMPP;
use AnyEvent::XMPP::TestClient;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use AnyEvent::XMPP::Util qw/bare_jid prep_bare_jid/;

my $cl    = AnyEvent::XMPP::TestClient->new_or_exit (tests => 3, finish_count => 1);
my $C     = $cl->client;
my $vcard = $cl->instance_ext ('AnyEvent::XMPP::Ext::VCard');

my $got_my_vcard;
my $my_avatar;
my $my_avatar_hash;

open AVATAR, "t/n_xmpp2_avatar.png" or die "Couldn't open avatar: $!";
my $real_avatar = do { local $/; binmode AVATAR; <AVATAR> };
my $real_avatar_hash = sha1_hex ($real_avatar);
close AVATAR;

$C->reg_cb (
   stream_ready => sub {
      my ($C, $acc) = @_;
      $vcard->reg_cb (
         vcard => sub {
            my ($vcard, $jid, $vc) = @_;
            if (my $vc = $vcard->my_vcard ($jid)) {
               $got_my_vcard = 1;
               $my_avatar = $vc->{_avatar};
               $my_avatar_hash = $vc->{_avatar_hash};
               $cl->finish;
            }
         }
      );
      $vcard->hook_on ($acc->connection);
   },
);

$cl->wait;

ok ($got_my_vcard, "retrieved my vcard on connect");
is ($my_avatar_hash, $real_avatar_hash, "hashes of the avatars match");
ok ($my_avatar eq $real_avatar, "avatar data matches");