From 2f02189ddcdeb7d25b0ca9bd5b955b764d41a1a7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 21 May 2016 17:44:53 -0700 Subject: 2996 --- html/078hash.cc.html | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'html/078hash.cc.html') diff --git a/html/078hash.cc.html b/html/078hash.cc.html index 0f3153f7..aa8c8724 100644 --- a/html/078hash.cc.html +++ b/html/078hash.cc.html @@ -57,7 +57,7 @@ put(Recipe_ordinal,} :(before "End Primitive Recipe Implementations") case HASH: { - reagent input = current_instruction().ingredients.at(0); // copy + reagent/*copy*/ input = current_instruction().ingredients.at(0); products.resize(1); products.at(0).push_back(hash(0, input)); break; @@ -111,11 +111,11 @@ put(Recipe_ordinal,size_t hash_mu_array(size_t h, const reagent& r) { int size = get_or_insert(Memory, r.value); - reagent elem = r; + reagent/*copy*/ elem = r; delete elem.type; - elem.type = new type_tree(*array_element(r.type)); + elem.type = copy_array_element(r.type); for (int i=0, address = r.value+1; i < size; ++i, address += size_of(elem)) { - reagent tmp = elem; + reagent/*copy*/ tmp = elem; tmp.value = address; h = hash(h, tmp); //? cerr << i << " (" << address << "): " << h << '\n'; @@ -123,19 +123,13 @@ put(Recipe_ordinal,return h; } -bool is_mu_container(const reagent& r) { - if (r.type->value == 0) return false; - type_info& info = get(Type, r.type->value); - return info.kind == CONTAINER; -} - size_t hash_mu_container(size_t h, const reagent& r) { assert(r.type->value); type_info& info = get(Type, r.type->value); int address = r.value; int offset = 0; for (int i = 0; i < SIZE(info.elements); ++i) { - reagent element = element_type(r, i); + reagent/*copy*/ element = element_type(r.type, i); if (has_property(element, "ignore-for-hash")) continue; element.set_value(address+offset); h = hash(h, element); @@ -145,16 +139,10 @@ put(Recipe_ordinal,return h; } -bool is_mu_exclusive_container(const reagent& r) { - if (r.type->value == 0) return false; - type_info& info = get(Type, r.type->value); - return info.kind == EXCLUSIVE_CONTAINER; -} - size_t hash_mu_exclusive_container(size_t h, const reagent& r) { assert(r.type->value); int tag = get(Memory, r.value); - reagent variant = variant_type(r, tag); + reagent/*copy*/ variant = variant_type(r, tag); // todo: move this error to container definition time if (has_property(variant, "ignore-for-hash")) raise << get(Type, r.type->value).name << ": /ignore-for-hash won't work in exclusive containers\n" << end(); @@ -402,7 +390,7 @@ put(Recipe_ordinal,break; } if (!is_mu_string(inst.ingredients.at(0))) { - raise << maybe(get(Recipe, r).name) << "'hash_old' currently only supports strings (address:array:character), but got " << inst.ingredients.at(0).original_string << '\n' << end(); + raise << maybe(get(Recipe, r).name) << "'hash_old' currently only supports strings (address:array:character), but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); break; } break; -- cgit 1.4.1-2-gfad0 '>282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#include "xmpp/xmpp.h"
#include "xmpp/mock_xmpp.h"

#include "ui/ui.h"
#include "ui/mock_ui.h"

#include "config/accounts.h"
#include "config/mock_accounts.h"

#include "command/commands.h"

void cmd_account_shows_usage_when_not_connected_and_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { NULL };

    mock_connection_status(JABBER_DISCONNECTED);

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_shows_account_when_connected_and_no_args(void **state)
{
    mock_cons_show_account();
    mock_accounts_get_account();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
        TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);
    gchar *args[] = { NULL };

    mock_connection_status(JABBER_CONNECTED);
    mock_connection_account_name("account_name");

    accounts_get_account_return(account);

    expect_cons_show_account(account);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_list_shows_accounts(void **state)
{
    mock_cons_show_account_list();
    mock_accounts_get_list();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "list", NULL };

    gchar **accounts = malloc(sizeof(gchar *) * 4);
    accounts[0] = strdup("account1");
    accounts[1] = strdup("account2");
    accounts[2] = strdup("account3");
    accounts[3] = NULL;

    accounts_get_list_return(accounts);

    expect_cons_show_account_list(accounts);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_show_shows_usage_when_no_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "show", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_show_shows_message_when_account_does_not_exist(void **state)
{
    mock_cons_show();
    mock_accounts_get_account();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "show", "account_name", NULL };

    accounts_get_account_return(NULL);

    expect_cons_show("No such account.");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_show_shows_account_when_exists(void **state)
{
    mock_cons_show_account();
    mock_accounts_get_account();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "show", "account_name", NULL };
    ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
        TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL);

    accounts_get_account_return(account);

    expect_cons_show_account(account);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_add_shows_usage_when_no_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "add", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_add_adds_account(void **state)
{
    stub_cons_show();
    mock_accounts_add();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "add", "new_account", NULL };

    accounts_add_expect_account_name("new_account");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_add_shows_message(void **state)
{
    mock_cons_show();
    stub_accounts_add();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "add", "new_account", NULL };

    expect_cons_show("Account created.");;
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_enable_shows_usage_when_no_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "enable", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_enable_enables_account(void **state)
{
    stub_cons_show();
    mock_accounts_enable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "enable", "account_name", NULL };

    accounts_enable_expect("account_name");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_enable_shows_message_when_enabled(void **state)
{
    mock_cons_show();
    mock_accounts_enable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "enable", "account_name", NULL };

    accounts_enable_return(TRUE);

    expect_cons_show("Account enabled.");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_enable_shows_message_when_account_doesnt_exist(void **state)
{
    mock_cons_show();
    mock_accounts_enable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "enable", "account_name", NULL };

    accounts_enable_return(FALSE);

    expect_cons_show("No such account: account_name");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_disable_shows_usage_when_no_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "disable", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_disable_disables_account(void **state)
{
    stub_cons_show();
    mock_accounts_disable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "disable", "account_name", NULL };

    accounts_disable_expect("account_name");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_disable_shows_message_when_disabled(void **state)
{
    mock_cons_show();
    mock_accounts_disable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "disable", "account_name", NULL };

    accounts_disable_return(TRUE);

    expect_cons_show("Account disabled.");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_disable_shows_message_when_account_doesnt_exist(void **state)
{
    mock_cons_show();
    mock_accounts_disable();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "disable", "account_name", NULL };

    accounts_disable_return(FALSE);

    expect_cons_show("No such account: account_name");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_rename_shows_usage_when_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "rename", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_rename_shows_usage_when_one_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "rename", "original_name", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_rename_renames_account(void **state)
{
    stub_cons_show();
    mock_accounts_rename();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "rename", "original_name", "new_name", NULL };

    accounts_rename_expect("original_name", "new_name");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_rename_shows_message_when_renamed(void **state)
{
    mock_cons_show();
    mock_accounts_rename();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "rename", "original_name", "new_name", NULL };

    accounts_rename_return(TRUE);

    expect_cons_show("Account renamed.");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_rename_shows_message_when_not_renamed(void **state)
{
    mock_cons_show();
    mock_accounts_rename();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "rename", "original_name", "new_name", NULL };

    accounts_rename_return(FALSE);

    expect_cons_show("Either account original_name doesn't exist, or account new_name already exists.");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_shows_usage_when_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "set", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_shows_usage_when_one_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "set", "a_account", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_shows_usage_when_two_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "set", "a_account", "a_property", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_checks_account_exists(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL };

    accounts_account_exists_expect("a_account");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_shows_message_when_account_doesnt_exist(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "a_property", "a_value", NULL };

    accounts_account_exists_return(FALSE);

    expect_cons_show("Account a_account doesn't exist");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_jid_shows_message_for_malformed_jid(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "jid", "@malformed", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Malformed jid: @malformed");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_jid_sets_barejid(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_jid();
    stub_accounts_set_resource();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_jid_expect("a_account", "a_local@a_domain");

    expect_cons_show("Updated jid for account a_account: a_local@a_domain");

    expect_cons_show_calls(2);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_jid_sets_resource(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_jid();
    mock_accounts_set_resource();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "jid", "a_local@a_domain/a_resource", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show_calls(1);

    accounts_set_resource_expect("a_account", "a_resource");

    expect_cons_show("Updated resource for account a_account: a_resource");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_server_sets_server(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_server();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "server", "a_server", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_server_expect("a_account", "a_server");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_server_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_server();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "server", "a_server", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated server for account a_account: a_server");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_resource_sets_resource(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_resource();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_resource_expect("a_account", "a_resource");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_resource_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_resource();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "resource", "a_resource", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated resource for account a_account: a_resource");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_password_sets_password(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_password();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "password", "a_password", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_password_expect("a_account", "a_password");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_password_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_password();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "password", "a_password", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated password for account a_account");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_muc_sets_muc(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_muc_service();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "muc", "a_muc", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_muc_service_expect("a_account", "a_muc");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_muc_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_muc_service();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "muc", "a_muc", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated muc service for account a_account: a_muc");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_nick_sets_nick(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_muc_nick();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_muc_nick_expect("a_account", "a_nick");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_nick_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_muc_nick();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "nick", "a_nick", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated muc nick for account a_account: a_nick");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_status_shows_message_when_invalid_status(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_login_presence();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "status", "bad_status", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Invalid status: bad_status");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_status_sets_status_when_valid(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_login_presence();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "status", "away", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_login_presence_expect("a_account", "away");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_status_sets_status_when_last(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_login_presence();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "status", "last", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_login_presence_expect("a_account", "last");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_status_shows_message_when_set_valid(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_login_presence();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "status", "away", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated login status for account a_account: away");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_status_shows_message_when_set_last(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_login_presence();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "status", "last", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Updated login status for account a_account: last");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_invalid_presence_string_priority_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "blah", "10", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Invalid property: blah");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_last_priority_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "last", "10", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Invalid property: last");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_online_priority_sets_preference(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "10", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_priority_online_expect("a_account", 10);

    mock_connection_status(JABBER_DISCONNECTED);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_chat_priority_sets_preference(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "chat", "10", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_priority_chat_expect("a_account", 10);

    mock_connection_status(JABBER_DISCONNECTED);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_away_priority_sets_preference(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "away", "10", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_priority_away_expect("a_account", 10);

    mock_connection_status(JABBER_DISCONNECTED);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_xa_priority_sets_preference(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "xa", "10", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_priority_xa_expect("a_account", 10);

    mock_connection_status(JABBER_DISCONNECTED);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_dnd_priority_sets_preference(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    mock_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "dnd", "10", NULL };

    accounts_account_exists_return(TRUE);

    accounts_set_priority_dnd_expect("a_account", 10);

    mock_connection_status(JABBER_DISCONNECTED);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_online_priority_shows_message(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    stub_accounts_set_priorities();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "10", NULL };

    accounts_account_exists_return(TRUE);

    mock_connection_status(JABBER_DISCONNECTED);

    expect_cons_show("Updated online priority for account a_account: 10");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_priority_too_low_shows_message(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "-150", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Value -150 out of range. Must be in -128..127.");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_priority_too_high_shows_message(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "150", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Value 150 out of range. Must be in -128..127.");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_priority_when_not_number_shows_message(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "abc", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Could not convert \"abc\" to a number.");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_priority_when_empty_shows_message(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Could not convert \"\" to a number.");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state)
{
    stub_cons_show();
    stub_accounts_set_priorities();
    mock_accounts_get_last_presence();
    mock_presence_update();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "set", "a_account", "online", "10", NULL };

    accounts_account_exists_return(TRUE);

    mock_connection_status(JABBER_CONNECTED);
    mock_connection_account_name("a_account");

    accounts_get_last_presence_return(RESOURCE_ONLINE);

    mock_connection_presence_message("Free to chat");

    presence_update_expect(RESOURCE_ONLINE, "Free to chat", 0);

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_clear_shows_usage_when_no_args(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "clear", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_clear_shows_usage_when_one_arg(void **state)
{
    mock_cons_show();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    help->usage = "some usage";
    gchar *args[] = { "clear", "a_account", NULL };

    expect_cons_show("Usage: some usage");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_clear_checks_account_exists(void **state)
{
    stub_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "clear", "a_account", "a_property", NULL };

    accounts_account_exists_expect("a_account");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_clear_shows_message_when_account_doesnt_exist(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "clear", "a_account", "a_property", NULL };

    accounts_account_exists_return(FALSE);

    expect_cons_show("Account a_account doesn't exist");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);
}

void cmd_account_clear_shows_message_when_invalid_property(void **state)
{
    mock_cons_show();
    mock_accounts_account_exists();
    CommandHelp *help = malloc(sizeof(CommandHelp));
    gchar *args[] = { "clear", "a_account", "badproperty", NULL };

    accounts_account_exists_return(TRUE);

    expect_cons_show("Invalid property: badproperty");
    expect_cons_show("");

    gboolean result = cmd_account(args, *help);
    assert_true(result);

    free(help);

}