1 //: Mu scenarios. This will get long, but these are the tests we want to 2 //: support in this layer. 3 4 //: We avoid raw numeric locations in Mu -- except in scenarios, where they're 5 //: handy to check the values of specific variables 6 :(scenarios run_mu_scenario) 7 :(scenario scenario_block) 8 scenario foo [ 9 run [ 10 1:num <- copy 13 11 ] 12 memory-should-contain [ 13 1 <- 13 14 ] 15 ] 16 # checks are inside scenario 17 18 :(scenario scenario_multiple_blocks) 19 scenario foo [ 20 run [ 21 1:num <- copy 13 22 ] 23 memory-should-contain [ 24 1 <- 13 25 ] 26 run [ 27 2:num <- copy 13 28 ] 29 memory-should-contain [ 30 1 <- 13 31 2 <- 13 32 ] 33 ] 34 # checks are inside scenario 35 36 :(scenario scenario_check_memory_and_trace) 37 scenario foo [ 38 run [ 39 1:num <- copy 13 40 trace 1, [a], [a b c] 41 ] 42 memory-should-contain [ 43 1 <- 13 44 ] 45 trace-should-contain [ 46 a: a b c 47 ] 48 trace-should-not-contain [ 49 a: x y z 50 ] 51 ] 52 # checks are inside scenario 53 54 //:: Core data structure 55 56 :(before "End Types") 57 pre { line-height: 125%; } td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #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 <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include "event/server_events.h" #include "xmpp/roster_list.h" #include "xmpp/chat_session.h" #include "config/preferences.h" #include "ui/ui.h" #include "ui/stub_ui.h" #include "xmpp/muc.h" #include "plugins/plugins.h" #include "ui/window_list.h" void console_shows_online_presence_when_set_online(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "online"); plugins_init(); roster_create(); roster_process_pending_presence(); char *barejid = "test1@server"; roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL); roster_destroy(); plugins_shutdown(); } void console_shows_online_presence_when_set_all(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "all"); plugins_init(); roster_create(); roster_process_pending_presence(); char *barejid = "test1@server"; roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL); roster_destroy(); plugins_shutdown(); } void console_shows_dnd_presence_when_set_all(void **state) { prefs_set_string(PREF_STATUSES_CONSOLE, "all"); plugins_init(); roster_create(); roster_process_pending_presence(); char *barejid = "test1@server"; roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10); expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid)); expect_memory(ui_contact_online, resource, resource, sizeof(resource)); expect_value(ui_contact_online, last_activity, NULL); sv_ev_contact_online(barejid, resource, NULL, NULL); roster_destroy(); plugins_shutdown(); } void handle_offline_removes_chat_session(void **state) { plugins_init(); roster_create(); roster_process_pending_presence(); chat_sessions_init(); char *barejid = "friend@server.chat.com"; char *resource = "home"; roster_add(barejid, "bob", NULL, "both", FALSE); Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10); roster_update_presence(barejid, resourcep, NULL); chat_session_recipient_active(barejid, resource, FALSE); ProfConsoleWin *console = malloc(sizeof(ProfConsoleWin)); will_return(win_create_console, &console->window); wins_init(); sv_ev_contact_offline(barejid, resource, NULL); ChatSession *session = chat_session_get(barejid); assert_null(session); roster_destroy(); chat_sessions_clear(); plugins_shutdown(); } void lost_connection_clears_chat_sessions(void **state) { roster_create(); roster_process_pending_presence(); chat_sessions_init(); chat_session_recipient_active("bob@server.org", "laptop", FALSE); chat_session_recipient_active("steve@server.org", "mobile", FALSE); expect_any_cons_show_error(); sv_ev_lost_connection(); ChatSession *session1 = chat_session_get("bob@server.org"); ChatSession *session2 = chat_session_get("steve@server.org"); assert_null(session1); assert_null(session2); }