Welcome to mirror list, hosted at ThFree Co, Russian Federation.

vcard_tests.erl « test - github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8e16f7ac015a230121ec6f75a84b0e2fed67acca (plain)
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
%%%-------------------------------------------------------------------
%%% Author  : Evgeny Khramtsov <ekhramtsov@process-one.net>
%%% Created : 16 Nov 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
%%%
%%%
%%% ejabberd, Copyright (C) 2002-2021   ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License along
%%% with this program; if not, write to the Free Software Foundation, Inc.,
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%%%
%%%----------------------------------------------------------------------

-module(vcard_tests).

%% API
-compile(export_all).
-import(suite, [send_recv/2, disconnect/1, is_feature_advertised/2,
		is_feature_advertised/3, server_jid/1,
		my_jid/1, wait_for_slave/1, wait_for_master/1,
		recv_presence/1, recv/1]).

-include("suite.hrl").

%%%===================================================================
%%% API
%%%===================================================================
%%%===================================================================
%%% Single user tests
%%%===================================================================
single_cases() ->
    {vcard_single, [sequence],
     [single_test(feature_enabled),
      single_test(get_set),
      single_test(service_vcard)]}.

feature_enabled(Config) ->
    BareMyJID = jid:remove_resource(my_jid(Config)),
    true = is_feature_advertised(Config, ?NS_VCARD),
    true = is_feature_advertised(Config, ?NS_VCARD, BareMyJID),
    disconnect(Config).

get_set(Config) ->
    VCard =
        #vcard_temp{fn = <<"Peter Saint-Andre">>,
		    n = #vcard_name{family = <<"Saint-Andre">>,
				    given = <<"Peter">>},
		    nickname = <<"stpeter">>,
		    bday = <<"1966-08-06">>,
		    adr = [#vcard_adr{work = true,
				      extadd = <<"Suite 600">>,
				      street = <<"1899 Wynkoop Street">>,
				      locality = <<"Denver">>,
				      region = <<"CO">>,
				      pcode = <<"80202">>,
				      ctry = <<"USA">>},
			   #vcard_adr{home = true,
				      locality = <<"Denver">>,
				      region = <<"CO">>,
				      pcode = <<"80209">>,
				      ctry = <<"USA">>}],
		    tel = [#vcard_tel{work = true,voice = true,
				      number = <<"303-308-3282">>},
			   #vcard_tel{home = true,voice = true,
				      number = <<"303-555-1212">>}],
		    email = [#vcard_email{internet = true,pref = true,
					  userid = <<"stpeter@jabber.org">>}],
		    jabberid = <<"stpeter@jabber.org">>,
		    title = <<"Executive Director">>,role = <<"Patron Saint">>,
		    org = #vcard_org{name = <<"XMPP Standards Foundation">>},
		    url = <<"http://www.xmpp.org/xsf/people/stpeter.shtml">>,
		    desc = <<"More information about me is located on my "
			     "personal website: http://www.saint-andre.com/">>},
    #iq{type = result, sub_els = []} =
        send_recv(Config, #iq{type = set, sub_els = [VCard]}),
    %% TODO: check if VCard == VCard1.
    #iq{type = result, sub_els = [_VCard1]} =
        send_recv(Config, #iq{type = get, sub_els = [#vcard_temp{}]}),
    disconnect(Config).

service_vcard(Config) ->
    JID = server_jid(Config),
    ct:comment("Retreiving vCard from ~s", [jid:encode(JID)]),
    VCard = mod_vcard_opt:vcard(?config(server, Config)),
    #iq{type = result, sub_els = [VCard]} =
	send_recv(Config, #iq{type = get, to = JID, sub_els = [#vcard_temp{}]}),
    disconnect(Config).

%%%===================================================================
%%% Master-slave tests
%%%===================================================================
master_slave_cases() ->
    {vcard_master_slave, [sequence], []}.
   %%[master_slave_test(xupdate)]}.

xupdate_master(Config) ->
    Img = <<137, "PNG\r\n", 26, $\n>>,
    ImgHash = p1_sha:sha(Img),
    MyJID = my_jid(Config),
    Peer = ?config(slave, Config),
    wait_for_slave(Config),
    #presence{from = MyJID, type = available} = send_recv(Config, #presence{}),
    #presence{from = Peer, type = available} = recv_presence(Config),
    VCard = #vcard_temp{photo = #vcard_photo{type = <<"image/png">>, binval = Img}},
    #iq{type = result, sub_els = []} =
	send_recv(Config, #iq{type = set, sub_els = [VCard]}),
    #presence{from = MyJID, type = available,
	      sub_els = [#vcard_xupdate{hash = ImgHash}]} = recv_presence(Config),
    #iq{type = result, sub_els = []} =
	send_recv(Config, #iq{type = set, sub_els = [#vcard_temp{}]}),
    ?recv2(#presence{from = MyJID, type = available,
		     sub_els = [#vcard_xupdate{hash = undefined}]},
	   #presence{from = Peer, type = unavailable}),
    disconnect(Config).

xupdate_slave(Config) ->
    Img = <<137, "PNG\r\n", 26, $\n>>,
    ImgHash = p1_sha:sha(Img),
    MyJID = my_jid(Config),
    Peer = ?config(master, Config),
    #presence{from = MyJID, type = available} = send_recv(Config, #presence{}),
    wait_for_master(Config),
    #presence{from = Peer, type = available} = recv_presence(Config),
    #presence{from = Peer, type = available,
	      sub_els = [#vcard_xupdate{hash = ImgHash}]} = recv_presence(Config),
    #presence{from = Peer, type = available,
	      sub_els = [#vcard_xupdate{hash = undefined}]} = recv_presence(Config),
    disconnect(Config).

%%%===================================================================
%%% Internal functions
%%%===================================================================
single_test(T) ->
    list_to_atom("vcard_" ++ atom_to_list(T)).

master_slave_test(T) ->
    {list_to_atom("vcard_" ++ atom_to_list(T)), [parallel],
     [list_to_atom("vcard_" ++ atom_to_list(T) ++ "_master"),
      list_to_atom("vcard_" ++ atom_to_list(T) ++ "_slave")]}.