1 #include <glib.h> 2 #include <stdarg.h> 3 #include <stddef.h> 4 #include <setjmp.h> 5 #include <cmocka.h> 6 #include <stdlib.h> 7 #include <string.h> 8 9 #include <stabber.h> 10 #include <expect.h> 11 12 #include "proftest.h" 13 14 void ping_server(void ** state)15ping_server(void **state) 16 { 17 stbbr_for_id("prof_disco_info_onconnect_2", 18 "<iq id='prof_disco_info_onconnect_2' to='stabber@localhost/profanity' type='result' from='localhost'>" 19 "<query xmlns='http://jabber.org/protocol/disco#info'>" 20 "<identity category='server' type='im' name='Prosody'/>" 21 "<feature var='urn:xmpp:ping'/>" 22 "</query>" 23 "</iq>" 24 ); 25 26 stbbr_for_id("prof_ping_4", 27 "<iq id='prof_ping_4' type='result' to='stabber@localhost/profanity'/>" 28 ); 29 stbbr_for_id("prof_ping_5", 30 "<iq id='prof_ping_5' type='result' to='stabber@localhost/profanity'/>" 31 ); 32 33 prof_connect(); 34 35 prof_input("/ping"); 36 assert_true(stbbr_received( 37 "<iq id='prof_ping_4' type='get'>" 38 "<ping xmlns='urn:xmpp:ping'/>" 39 "</iq>" 40 )); 41 assert_true(prof_output_exact("Ping response from server")); 42 43 prof_input("/ping"); 44 assert_true(stbbr_received( 45 "<iq id='prof_ping_5' type='get'>" 46 "<ping xmlns='urn:xmpp:ping'/>" 47 "</iq>" 48 )); 49 assert_true(prof_output_exact("Ping response from server")); 50 } 51 52 void ping_server_not_supported(void ** state)53ping_server_not_supported(void **state) 54 { 55 stbbr_for_id("prof_disco_info_onconnect_2", 56 "<iq id='prof_disco_info_onconnect_2' to='stabber@localhost/profanity' type='result' from='localhost'>" 57 "<query xmlns='http://jabber.org/protocol/disco#info'>" 58 "<identity category='server' type='im' name='Stabber'/>" 59 "</query>" 60 "</iq>" 61 ); 62 63 prof_connect(); 64 65 prof_input("/ping"); 66 assert_true(prof_output_exact("Server does not support ping requests.")); 67 } 68 69 void ping_responds_to_server_request(void ** state)70ping_responds_to_server_request(void **state) 71 { 72 prof_connect(); 73 74 stbbr_send( 75 "<iq id='pingtest1' type='get' to='stabber@localhost/profanity' from='localhost'>" 76 "<ping xmlns='urn:xmpp:ping'/>" 77 "</iq>" 78 ); 79 80 assert_true(stbbr_received( 81 "<iq id='pingtest1' type='result' from='stabber@localhost/profanity' to='localhost'/>" 82 )); 83 } 84 ping_jid(void ** state)85void ping_jid(void **state) 86 { 87 stbbr_for_id("prof_caps_4", 88 "<iq id='prof_caps_4' to='stabber@localhost/profanity' type='result' from='buddy1@localhost/mobile'>" 89 "<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='>" 90 "<identity category='client' type='console' name='Profanity0.6.0'/>" 91 "<feature var='urn:xmpp:ping'/>" 92 "<feature var='http://jabber.org/protocol/disco#info'/>" 93 "<feature var='http://jabber.org/protocol/caps'/>" 94 "</query>" 95 "</iq>" 96 ); 97 98 prof_connect(); 99 100 stbbr_send( 101 "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>" 102 "<priority>10</priority>" 103 "<status>I'm here</status>" 104 "<c " 105 "hash='sha-1' " 106 "xmlns='http://jabber.org/protocol/caps' " 107 "node='http://profanity-im.github.io' " 108 "ver='LpT2xs3nun7jC2sq4gg3WRDQFZ4='" 109 "/>" 110 "</presence>" 111 ); 112 assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\"")); 113 114 assert_true(stbbr_received( 115 "<iq id='prof_caps_4' to='buddy1@localhost/mobile' type='get'>" 116 "<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>" 117 "</iq>" 118 )); 119 120 stbbr_for_id("prof_ping_5", 121 "<iq from='buddy1@localhost/mobile' to='stabber@localhost' id='prof_ping_5' type='result'/>" 122 ); 123 124 prof_input("/ping buddy1@localhost/mobile"); 125 126 assert_true(stbbr_received( 127 "<iq id='prof_ping_5' type='get' to='buddy1@localhost/mobile'>" 128 "<ping xmlns='urn:xmpp:ping'/>" 129 "</iq>" 130 )); 131 assert_true(prof_output_exact("Ping response from buddy1@localhost/mobile")); 132 } 133 ping_jid_not_supported(void ** state)134void ping_jid_not_supported(void **state) 135 { 136 stbbr_for_id("prof_caps_4", 137 "<iq id='prof_caps_4' to='stabber@localhost/profanity' type='result' from='buddy1@localhost/mobile'>" 138 "<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='>" 139 "<identity category='client' type='console' name='Profanity0.6.0'/>" 140 "<feature var='http://jabber.org/protocol/disco#info'/>" 141 "<feature var='http://jabber.org/protocol/caps'/>" 142 "</query>" 143 "</iq>" 144 ); 145 146 prof_connect(); 147 148 stbbr_send( 149 "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>" 150 "<priority>10</priority>" 151 "<status>I'm here</status>" 152 "<c " 153 "hash='sha-1' " 154 "xmlns='http://jabber.org/protocol/caps' " 155 "node='http://profanity-im.github.io' " 156 "ver='LpT2xs3nun7jC2sq4gg3WRDQFZ4='" 157 "/>" 158 "</presence>" 159 ); 160 assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\"")); 161 162 assert_true(stbbr_received( 163 "<iq id='prof_caps_4' to='buddy1@localhost/mobile' type='get'>" 164 "<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>" 165 "</iq>" 166 )); 167 168 prof_input("/ping buddy1@localhost/mobile"); 169 assert_true(prof_output_exact("buddy1@localhost/mobile does not support ping requests.")); 170 } 171