about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
Diffstat (limited to 'subx')
-rw-r--r--subx/034compute_segment_address.cc3
-rw-r--r--subx/035labels.cc17
2 files changed, 19 insertions, 1 deletions
diff --git a/subx/034compute_segment_address.cc b/subx/034compute_segment_address.cc
index c4645fac..0c569c65 100644
--- a/subx/034compute_segment_address.cc
+++ b/subx/034compute_segment_address.cc
@@ -27,7 +27,7 @@ void compute_segment_starts(program& p) {
     segment& curr = p.segments.at(i);
     if (curr.start == 0) {
       curr.start = CODE_START + i*SEGMENT_SIZE + p_offset;
-      trace(99, "transform") << "segment " << i << " begins at address " << curr.start << end();
+      trace(99, "transform") << "segment " << i << " begins at address 0x" << HEXWORD << curr.start << end();
     }
     p_offset += size_of(curr);
     assert(p_offset < SEGMENT_SIZE);  // for now we get less and less available space in each successive segment
@@ -48,6 +48,7 @@ uint32_t num_bytes(const line& inst) {
     const word& curr = inst.words.at(i);
     if (has_operand_metadata(curr, "disp32") || has_operand_metadata(curr, "imm32"))  // only multi-byte operands
       sum += 4;
+    // End num_bytes(curr) Special-cases
     else
       sum++;
   }
diff --git a/subx/035labels.cc b/subx/035labels.cc
index df54bf2f..6edae0d9 100644
--- a/subx/035labels.cc
+++ b/subx/035labels.cc
@@ -216,3 +216,20 @@ xz:
  -a:  # indent to avoid looking like a trace_should_not_contain command for this scenario
             05                                                                                                                              0x0d0c0b0a/imm32  # add to EAX
 +error: '-a' starts with '-', which can be confused with a negative number; use a different name
+
+//: now that we have labels, we need to adjust segment size computation to
+//: ignore them.
+
+:(scenario segment_size_ignores_labels)
+% Mem_offset = CODE_START;
+== code  # 0x08048074
+05/add 0x0d0c0b0a/imm32  # 5 bytes
+foo:                     # 0 bytes
+== data  # 0x08049079
+bar:
+00
++transform: segment 1 begins at address 0x08049079
+
+:(before "End num_bytes(curr) Special-cases")
+else if (is_label(curr))
+  ;  // don't count it
#000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#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
send_software_version_request(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
    prof_input("/software buddy1@localhost/mobile");

    assert_true(stbbr_received(
        "<iq id='*' to='buddy1@localhost/mobile' type='get'>"
            "<query xmlns='jabber:iq:version'/>"
        "</iq>"
    ));
}

void
display_software_version_result(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));

    stbbr_for_query("jabber:iq:version",
        "<iq id='*' type='result' lang='en' to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
            "<query xmlns='jabber:iq:version'>"
                "<name>Profanity</name>"
                "<version>0.4.7dev.master.2cb2f83</version>"
            "</query>"
        "</iq>"
    );
    prof_input("/software buddy1@localhost/mobile");

//    assert_true(prof_output_exact("buddy1@localhost/mobile:"));
//    assert_true(prof_output_exact("Name    : Profanity"));
    assert_true(prof_output_exact("Version : 0.4.7dev.master.2cb2f83"));
}

void
shows_message_when_software_version_error(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));

    stbbr_for_query("jabber:iq:version",
        "<iq id='*' lang='en' type='error' to='stabber@localhost/profanity' from='buddy1@localhost/laptop'>"
            "<query xmlns='jabber:iq:version'/>"
            "<error code='503' type='cancel'>"
                "<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
            "</error>"
        "</iq>"
    );
    prof_input("/software buddy1@localhost/laptop");

    assert_true(prof_output_exact("Could not get software version: service-unavailable"));
}

// Typical use case for gateways that don't support resources
void
display_software_version_result_when_from_domainpart(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 is online, \"I'm here\""));

    stbbr_for_query("jabber:iq:version",
        "<iq id='*' type='result' lang='en' to='stabber@localhost/profanity' from='localhost'>"
            "<query xmlns='jabber:iq:version'>"
                "<name>Some Gateway</name>"
                "<version>1.0</version>"
            "</query>"
        "</iq>"
    );
    prof_input("/software buddy1@localhost/__prof_default");

//    assert_true(prof_output_exact("buddy1@localhost/__prof_default:"));
//    assert_true(prof_output_exact("Name    : Some Gateway"));
    assert_true(prof_output_exact("Version : 1.0"));
}

void
show_message_in_chat_window_when_no_resource(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));

    prof_input("/msg Buddy1");
    prof_input("/software");

    assert_true(prof_output_exact("Unknown resource for /software command."));
}

void
display_software_version_result_in_chat(void **state)
{
    prof_connect();
    stbbr_send(
        "<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
            "<priority>10</priority>"
            "<status>I'm here</status>"
        "</presence>"
    );
    assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
    prof_input("/msg Buddy1");

    stbbr_send(
        "<message id='message1' to='stabber@localhost' from='buddy1@localhost/mobile' type='chat'>"
            "<body>Here's a message</body>"
        "</message>"
    );
    assert_true(prof_output_exact("Here's a message"));

    stbbr_for_query("jabber:iq:version",
        "<iq id='*' type='result' lang='en' to='stabber@localhost/profanity' from='buddy1@localhost/mobile'>"
            "<query xmlns='jabber:iq:version'>"
                "<name>Profanity</name>"
                "<version>0.4.7dev.master.2cb2f83</version>"
            "</query>"
        "</iq>"
    );

    prof_input("/software");

//    assert_true(prof_output_exact("buddy1@localhost/mobile:"));
//    assert_true(prof_output_exact("Name    : Profanity"));
    assert_true(prof_output_exact("Version : 0.4.7dev.master.2cb2f83"));
}