1: %%%----------------------------------------------------------------------
    2: %%% File    : carboncopy_proper_tests_SUITE.erl
    3: %%% Author  : Shambhu Prasad <shambhuprasad58@gmail.com>
    4: %%% Purpose : Tests for mod_carboncopy.erl based on Proper API
    5: %%% Created : 15 July 2014 by Shambhu Prasad <shambhuprasad58@gmail.com>
    6: %%%-------------------------------------------------------------------
    7: 
    8: -module(carboncopy_proper_tests_SUITE).
    9: -compile([export_all, nowarn_export_all]).
   10: 
   11: -include_lib("common_test/include/ct.hrl").
   12: -include_lib("proper/include/proper.hrl").
   13: -include_lib("eunit/include/eunit.hrl").
   14: -include_lib("exml/include/exml.hrl").
   15: 
   16: -import(xmlel_gen, [xmlel/3]).
   17: 
   18: all() ->
   19:     [{group, mod_message_carbons_proper_tests}].
   20: 
   21: all_tests() ->
   22:     [
   23:      private_message_test,
   24:      no_copy_type_test,
   25:      empty_message_test,
   26:      received_type_test,
   27:      sent_message_test,
   28:      simple_badarg_test,
   29:      simple_chat_message_test,
   30:      has_chat_state_notifications_test,
   31:      has_delivery_receipts_test,
   32:      is_muc_invitation_test,
   33:      is_direct_invitation_test
   34:     ].
   35: 
   36: groups() ->
   37:     [{mod_message_carbons_proper_tests, [parallel], all_tests()}].
   38: 
   39: private_message_test(_) ->
   40:     property(private_message_test, ?FORALL(Msg, private_carbon_message(),
   41:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   42: 
   43: no_copy_type_test(_) ->
   44:     property(no_copy_type_test, ?FORALL(Msg, no_copy_message(),
   45:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   46: 
   47: empty_message_test(_) ->
   48:     property(empty_message_test, ?FORALL(Msg, non_chat_message(),
   49:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   50: 
   51: received_type_test(_) ->
   52:     property(received_type_test, ?FORALL(Msg, received_message(),
   53:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   54: 
   55: sent_message_test(_) ->
   56:     property(sent_message_test, ?FORALL(Msg, sent_message(),
   57:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   58: 
   59: simple_badarg_test(_) ->
   60:     property(simple_badarg_test, ?FORALL(Msg, badarg_message(),
   61:           false == mod_carboncopy:should_forward(Msg, alice(), received))).
   62: 
   63: simple_chat_message_test(_) ->
   64:     property(simple_chat_message_test, ?FORALL(Msg, simple_chat_message(),
   65:           true == mod_carboncopy:should_forward(Msg, alice(), received))).
   66: 
   67: has_chat_state_notifications_test(_) ->
   68:     property(has_chat_state_notifications_test, ?FORALL(Msg, chat_state_notification(),
   69:           true == mod_carboncopy:should_forward(Msg, alice(), received))).
   70: 
   71: has_delivery_receipts_test(_) ->
   72:     property(has_delivery_receipts_test, ?FORALL(Msg, delivery_receipt(),
   73:           true == mod_carboncopy:should_forward(Msg, alice(), received))).
   74: 
   75: is_muc_invitation_test(_) ->
   76:     property(is_muc_invitation_test, ?FORALL(Msg, muc_invitation(),
   77:           true == mod_carboncopy:should_forward(Msg, alice(), received))).
   78: 
   79: is_direct_invitation_test(_) ->
   80:     property(is_direct_invitation_test, ?FORALL(Msg, direct_invitation(),
   81:           true == mod_carboncopy:should_forward(Msg, alice(), received))).
   82: 
   83: property(Name, Prop) ->
   84:     Props = proper:conjunction([{Name, Prop}]),
   85:     true = proper:quickcheck(Props, [verbose, long_result, {numtests, 50}]).
   86: 
   87: alice() ->
   88:     jid:make_noprep(<<"alice">>, <<"localhost">>, <<>>).
   89: 
   90: %%
   91: %% Generators
   92: %%
   93: 
   94: non_chat_message() ->
   95:     xmlel("message", [], []).
   96: 
   97: private_carbon_message() ->
   98:     xmlel("message",
   99:           [{<<"type">>, <<"chat">>}],
  100:           [xmlel("private", [{<<"xmlns">>, <<"urn:xmpp:carbons:2">>}], [])]).
  101: 
  102: no_copy_message() ->
  103:     xmlel("message",
  104:           [{<<"type">>, <<"chat">>}],
  105:           [xmlel("no-copy", [{<<"xmlns">>, <<"urn:xmpp:hints">>}], [])]).
  106: 
  107: received_message() ->
  108:     xmlel("message",
  109:           [{<<"type">>, <<"chat">>}],
  110:           [xmlel("received", [{<<"xmlns">>, <<"urn:xmpp:carbons:2">>}], [])]).
  111: 
  112: sent_message() ->
  113:     xmlel("message",
  114:           [{<<"type">>, <<"chat">>}],
  115:           [xmlel("sent", [{<<"xmlns">>, <<"urn:xmpp:carbons:2">>}], [])]).
  116: 
  117: simple_chat_message() ->
  118:     xmlel("message", [{<<"type">>, <<"chat">>}], []).
  119: 
  120: chat_state_notification() ->
  121:     xmlel("message",
  122:           [{<<"type">>, <<"chat">>}],
  123:           [xmlel("someelement", [{<<"xmlns">>, <<"http://jabber.org/protocol/chatstates">>}], [])]).
  124: 
  125: delivery_receipt() ->
  126:     xmlel("message",
  127:           [{<<"type">>, <<"chat">>}],
  128:           [xmlel("received", [{<<"xmlns">>, <<"urn:xmpp:receipts">>}], [])]).
  129: 
  130: muc_invitation() ->
  131:     xmlel("message",
  132:           [{<<"type">>, <<"chat">>}],
  133:           [xmlel("x", [{<<"xmlns">>, <<"jabber:x:conference">>}],
  134:                  [xmlel("invite", [<<"from">>], [<<"alice@localhost">>])])]).
  135: 
  136: direct_invitation() ->
  137:     xmlel("message",
  138:           [{<<"type">>, <<"chat">>}],
  139:           [xmlel("x", [{<<"xmlns">>, <<"jabber:x:conference">>}], [])]).
  140: 
  141: badarg_message() ->
  142:     xmlel("message", [{<<"type">>, <<"123">>}],[]).