Fix unit tests using async + read message marker

This commit is contained in:
fiaxh 2017-11-17 16:06:54 +01:00
parent 48cd057bd5
commit 2a514d0969
6 changed files with 21 additions and 26 deletions

View file

@ -14,7 +14,6 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
public signal void received_message_displayed(Account account, Jid jid, Entities.Message message);
private StreamInteractor stream_interactor;
private HashMap<Jid, Entities.Message> last_read = new HashMap<Jid, Entities.Message>(Jid.hash_bare_func, Jid.equals_bare_func);
private HashMap<Jid, string> chat_states = new HashMap<Jid, string>(Jid.hash_bare_func, Jid.equals_bare_func);
public static void start(StreamInteractor stream_interactor) {
@ -32,10 +31,6 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
return chat_states[jid];
}
public Entities.Message? get_last_read(Account account, Jid jid) {
return last_read[jid];
}
private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Xep.ChatMarkers.Module.IDENTITY).marker_received.connect( (stream, jid, marker, id) => {
on_chat_marker_received(account, new Jid(jid), marker, id);
@ -63,7 +58,6 @@ public class CounterpartInteractionManager : StreamInteractionModule, Object {
message.marked = Entities.Message.Marked.RECEIVED;
break;
case Xep.ChatMarkers.MARKER_DISPLAYED:
last_read[jid] = message;
received_message_displayed(account, jid, message);
Gee.List<Entities.Message> messages = stream_interactor.get_module(MessageStorage.IDENTITY).get_messages(conversation);
foreach (Entities.Message m in messages) {

View file

@ -102,7 +102,7 @@ protected class ConferenceDetailsFragment : Box {
stream_interactor.get_module(MucManager.IDENTITY).enter_error.connect(on_enter_error);
notification_button.clicked.connect(() => { notification_revealer.set_reveal_child(false); });
ok_button.clicked.connect(() => {
ok_button.label = _("Joining...");
ok_button.label = _("Joining");
ok_button.sensitive = false;
});
}

View file

@ -54,7 +54,7 @@ class ChatStatePopulator : Plugins.ConversationItemPopulator, Object {
if (state_ != null) {
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING || state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
if (state_ == Xep.ChatStateNotifications.STATE_COMPOSING) {
new_text = _("is typing...");
new_text = _("is typing");
} else if (state_ == Xep.ChatStateNotifications.STATE_PAUSED) {
new_text = _("has stopped typing");
}

View file

@ -95,7 +95,7 @@ private class AccountSettingsWidget : Stack, Plugins.AccountSettingsWidget {
TreeIter iter;
list_store.clear();
list_store.append(out iter);
label.set_markup(build_markup_string(_("Loading..."), _("Querying GnuPG")));
label.set_markup(build_markup_string(_("Loading"), _("Querying GnuPG")));
new Thread<void*> (null, () => { // Querying GnuPG might take some time
try {
keys = GPGHelper.get_keylist(null, true);

View file

@ -15,8 +15,9 @@ namespace Xmpp.Message {
public signal void received_message(XmppStream stream, Message.Stanza message);
public void send_message(XmppStream stream, Message.Stanza message) {
send_pipeline.run.begin(stream, message);
send_pipeline.run.begin(stream, message, (obj, res) => {
stream.write(message.stanza);
});
}
public async void received_message_stanza_async(XmppStream stream, StanzaNode node) {

View file

@ -6,12 +6,12 @@ class StanzaTest : Gee.TestCase {
public StanzaTest() {
base("Stanza");
add_test("node_one", test_node_one);
add_test("typical_stream", test_typical_stream);
add_test("ack_stream", test_ack_stream);
add_test("node_one", () => { test_node_one.begin(); });
add_test("typical_stream", () => { test_typical_stream.begin(); });
add_test("ack_stream", () => { test_ack_stream.begin(); });
}
private void test_node_one() {
private async void test_node_one() {
var node1 = new StanzaNode.build("test", "ns1_uri")
.add_self_xmlns()
.put_attribute("ns2", "ns2_uri", XMLNS_URI)
@ -22,12 +22,12 @@ class StanzaTest : Gee.TestCase {
.add_self_xmlns());
var xml1 = node1.to_xml();
var node2 = new StanzaReader.for_string(xml1).read_node();
var node2 = yield new StanzaReader.for_string(xml1).read_node();
fail_if_not(node1.equals(node2));
fail_if_not_eq_str(node1.to_string(), node2.to_string());
}
private void test_typical_stream() {
private async void test_typical_stream() {
var stream = """
<?xml version='1.0' encoding='UTF-8'?>
<stream:stream
@ -55,13 +55,13 @@ class StanzaTest : Gee.TestCase {
.put_node(new StanzaNode.text("I'll send a friar with speed, to Mantua, with my letters to thy lord.")));
var reader = new StanzaReader.for_string(stream);
fail_if_not_eq_node(root_node_cmp, reader.read_root_node());
fail_if_not_eq_node(node_cmp, reader.read_node());
reader.read_node();
fail_if_not_eq_node(root_node_cmp, yield reader.read_root_node());
fail_if_not_eq_node(node_cmp, yield reader.read_node());
yield reader.read_node();
fail_if_not_error_code(() => reader.read_node(), 3, "end of stream should be reached");
}
private void test_ack_stream() {
private async void test_ack_stream() {
var stream = """
<?xml version='1.0' encoding='UTF-8'?>
<stream:stream
@ -93,10 +93,10 @@ class StanzaTest : Gee.TestCase {
var node2_cmp = new StanzaNode.build("r", "http://jabber.org/protocol/ack");
var reader = new StanzaReader.for_string(stream);
fail_if_not_eq_node(root_node_cmp, reader.read_root_node());
fail_if_not_eq_node(node_cmp, reader.read_node());
fail_if_not_eq_node(node2_cmp, reader.read_node());
reader.read_node();
fail_if_not_eq_node(root_node_cmp, yield reader.read_root_node());
fail_if_not_eq_node(node_cmp, yield reader.read_node());
fail_if_not_eq_node(node2_cmp, yield reader.read_node());
yield reader.read_node();
fail_if_not_error_code(() => reader.read_node(), 3, "end of stream should be reached");
}