about summary refs log blame commit diff stats
path: root/tests/functionaltests/test_receipts.c
blob: 59333a871cf762db83d105e96365619d4d301482 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                     
                                                      







                                                       
                                                                  
                                   




































                                                                                                                                           
                                                  


                    








                                     
                                                                                                                   
                                          
                                                  



                               

                                                                 


                    
#include <glib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>

#include <stabber.h>
#include <expect.h>

#include "proftest.h"

void
does_not_send_receipt_request_to_barejid(void **state)
{
    prof_input("/receipts request on");

    prof_connect();

    prof_input("/msg somejid@someserver.com Hi there");

    assert_true(stbbr_received(
        "<message id='*' type='chat' to='somejid@someserver.com'>"
            "<body>Hi there</body>"
        "</message>"
    ));
}

void
send_receipt_request(void **state)
{
    prof_input("/receipts request on");

    prof_connect();

    stbbr_for_id("prof_caps_4",
        "<iq from='buddy1@localhost/laptop' to='stabber@localhost' id='prof_caps_4' type='result'>"
            "<query xmlns='http://jabber.org/protocol/disco#info' node='http://www.profanity.im#hAkb1xZdJV9BQpgGNw8zG5Xsals='>"
                "<identity category='client' name='Profanity 0.5.0' type='console'/>"
                "<feature var='urn:xmpp:receipts'/>"
            "</query>"
        "</iq>"
    );

    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/laptop'>"
            "<priority>15</priority>"
            "<status>My status</status>"
            "<c hash='sha-256' xmlns='http://jabber.org/protocol/caps' node='http://www.profanity.im' ver='hAkb1xZdJV9BQpgGNw8zG5Xsals='/>"
        "</presence>"
    );

    prof_output_exact("Buddy1 is online, \"My status\"");

    prof_input("/msg Buddy1");
    prof_input("/resource set laptop");
    prof_input("Hi there, where is my receipt?");

    assert_true(stbbr_received(
        "<message id='*' type='chat' to='buddy1@localhost/laptop'>"
            "<body>Hi there, where is my receipt?</body>"
            "<request xmlns='urn:xmpp:receipts'/>"
        "</message>"
    ));
}

void
send_receipt_on_request(void **state)
{
    prof_input("/receipts send on");

    prof_connect();

    stbbr_send(
        "<message id='msg12213' type='chat' to='stabber@localhost/profanity' from='someuser@server.org/profanity'>"
            "<body>Wants a receipt</body>"
            "<request xmlns='urn:xmpp:receipts'/>"
        "</message>"
    );

    assert_true(stbbr_received(
        "<message id='*' to='someuser@server.org/profanity'>"
            "<received id='msg12213' xmlns='urn:xmpp:receipts'/>"
        "</message>"
    ));
}

                                
                                                                                                                                                                                                                                                          
                                                                                                                                             
                                                                                                                               




                                                                                                                                                                                               
                                                                                                                                                                                                                                                              


                                                                               


                                                                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                               

                                                                                                                                                                                                                                                                                                                                                                               
                                    


                                                                                                        




                                                                                              



                                     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 044space_surround.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.traceContains { color: #008000; }
.Constant { color: #00a0a0; }
.Comment { color: #9090ff; }
.Delimiter { color: #a04060; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.Identifier { color: #804000; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: So far you can have global variables by not setting default-space, and</span>
<span class="Comment">//: local variables by setting default-space. You can isolate variables</span>
<span class="Comment">//: between those extremes by creating 'surrounding' spaces.</span>
<span class="Comment">//:</span>
<span class="Comment">//: (Surrounding spaces are like lexical scopes in other languages.)</span>

<span class="Delimiter">:(scenario surrounding_space)</span>
<span class="Comment"># location 1 in space 1 refers to the space surrounding the default space, here 20.</span>
recipe main [
  <span class="Constant">10</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>:literal  <span class="Comment"># pretend array</span>
  <span class="Constant">20</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">5</span>:literal  <span class="Comment"># pretend array</span>
  default-space:address:array:location<span class="Special"> &lt;- </span>copy <span class="Constant">10</span>:literal
  <span class="Constant">0</span>:address:array:location/names:dummy<span class="Special"> &lt;- </span>copy <span class="Constant">20</span>:literal  <span class="Comment"># later layers will explain the /names: property</span>
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>copy <span class="Constant">32</span>:literal
  <span class="Constant">1</span>:number/space:<span class="Constant">1</span><span class="Special"> &lt;- </span>copy <span class="Constant">33</span>:literal
]
<span class="Comment"># chain space</span>
<span class="traceContains">+mem: storing 20 in location 11</span>
<span class="Comment"># store to default-space</span>
<span class="traceContains">+mem: storing 32 in location 12</span>
<span class="Comment"># store to chained space</span>
<span class="traceContains">+mem: storing 33 in location 22</span>

<span class="Comment">//: If you think of a space as a collection of variables with a common</span>
<span class="Comment">//: lifetime, surrounding allows managing shorter lifetimes inside a longer</span>
<span class="Comment">//: one.</span>

<span class="Delimiter">:(replace{} &quot;long long int space_base(const reagent&amp; x)&quot;)</span>
long long int space_base<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;space_base: &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  <span class="Identifier">return</span> space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index<span class="Delimiter">(</span>x<span class="Delimiter">),</span> Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>front<span class="Delimiter">().</span>default_space<span class="Delimiter">);</span>
<span class="Delimiter">}</span>

long long int space_base<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">,</span> long long int space_index<span class="Delimiter">,</span> long long int base<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   trace(&quot;foo&quot;) &lt;&lt; &quot;base of space &quot; &lt;&lt; space_index &lt;&lt; '\n'; //? 1</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;space_base sub: &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  if <span class="Delimiter">(</span>space_index == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?     trace(&quot;foo&quot;) &lt;&lt; &quot;base of space &quot; &lt;&lt; space_index &lt;&lt; &quot; is &quot; &lt;&lt; base &lt;&lt; '\n'; //? 1</span>
    <span class="Identifier">return</span> base<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
<span class="CommentedCode">//?   trace(&quot;foo&quot;) &lt;&lt; &quot;base of space &quot; &lt;&lt; space_index &lt;&lt; &quot; is &quot; &lt;&lt; Memory[base+1] &lt;&lt; '\n'; //? 1</span>
  long long int result = space_base<span class="Delimiter">(</span>x<span class="Delimiter">,</span> space_index-<span class="Constant">1</span><span class="Delimiter">,</span> Memory[base+<span class="Constant">1</span>]<span class="Delimiter">);</span>
  <span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>

long long int space_index<span class="Delimiter">(</span>const reagent&amp; x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//?   cerr &lt;&lt; &quot;space_index: &quot; &lt;&lt; x.to_string() &lt;&lt; '\n'; //? 1</span>
  for <span class="Delimiter">(</span>long long int i = <span class="Comment">/*</span><span class="Comment">skip name:type</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i &lt; SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>first == <span class="Constant">&quot;space&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
      assert<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">);</span>
      <span class="Identifier">return</span> to_integer<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>second<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span>
    <span class="Delimiter">}</span>
  <span class="Delimiter">}</span>
  <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>

<span class="Delimiter">:(scenario permit_space_as_variable_name)</span>
recipe main [
  space:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>:literal
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->