emqtt -> emqttd

This commit is contained in:
Ery Lee 2015-03-12 21:16:20 +08:00
parent 43e1b7e966
commit 399d9e08dc
4 changed files with 36 additions and 37 deletions

View File

@ -20,11 +20,11 @@
%%% SOFTWARE. %%% SOFTWARE.
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
%%% @doc %%% @doc
%%% emqtt_opts_tests. %%% emqttd_opts_tests.
%%% %%%
%%% @end %%% @end
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
-module(emqtt_opts_tests). -module(emqttd_opts_tests).
-ifdef(TEST). -ifdef(TEST).
@ -39,7 +39,7 @@
]). ]).
merge_test() -> merge_test() ->
Opts = emqtt_opts:merge(?SOCKOPTS, [raw, Opts = emqttd_opts:merge(?SOCKOPTS, [raw,
{backlog, 1024}, {backlog, 1024},
{nodelay, false}, {nodelay, false},
{max_clients, 1024}, {max_clients, 1024},

View File

@ -20,20 +20,20 @@
%%% SOFTWARE. %%% SOFTWARE.
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
%%% @doc %%% @doc
%%% emqtt_parser tests. %%% emqttd_parser tests.
%%% %%%
%%% @end %%% @end
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
-module(emqtt_parser_tests). -module(emqttd_parser_tests).
-include("emqtt_packet.hrl"). -include("emqttd_packet.hrl").
-ifdef(TEST). -ifdef(TEST).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
parse_connect_test() -> parse_connect_test() ->
State = emqtt_parser:init(), State = emqttd_parser:init([]),
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined) %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
V31ConnBin = <<16,37,0,6,77,81,73,115,100,112,3,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>, V31ConnBin = <<16,37,0,6,77,81,73,115,100,112,3,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
?assertMatch({ok, #mqtt_packet{ ?assertMatch({ok, #mqtt_packet{
@ -45,7 +45,7 @@ parse_connect_test() ->
proto_name = <<"MQIsdp">>, proto_name = <<"MQIsdp">>,
client_id = <<"mosqpub/10451-iMac.loca">>, client_id = <<"mosqpub/10451-iMac.loca">>,
clean_sess = true, clean_sess = true,
keep_alive = 60}}, <<>>}, emqtt_parser:parse(V31ConnBin, State)), keep_alive = 60}}, <<>>}, emqttd_parser:parse(V31ConnBin, State)),
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined) %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10451-iMac.loca, ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60, Username=undefined, Password=undefined)
V311ConnBin = <<16,35,0,4,77,81,84,84,4,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>, V311ConnBin = <<16,35,0,4,77,81,84,84,4,2,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,49,45,105,77,97,99,46,108,111,99,97>>,
?assertMatch({ok, #mqtt_packet{ ?assertMatch({ok, #mqtt_packet{
@ -57,7 +57,7 @@ parse_connect_test() ->
proto_name = <<"MQTT">>, proto_name = <<"MQTT">>,
client_id = <<"mosqpub/10451-iMac.loca">>, client_id = <<"mosqpub/10451-iMac.loca">>,
clean_sess = true, clean_sess = true,
keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnBin, State)), keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnBin, State)),
%% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60) %% CONNECT(Qos=0, Retain=false, Dup=false, ClientId="", ProtoName=MQTT, ProtoVsn=4, CleanSess=true, KeepAlive=60)
V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>, V311ConnWithoutClientId = <<16,12,0,4,77,81,84,84,4,2,0,60,0,0>>,
@ -70,7 +70,7 @@ parse_connect_test() ->
proto_name = <<"MQTT">>, proto_name = <<"MQTT">>,
client_id = <<>>, client_id = <<>>,
clean_sess = true, clean_sess = true,
keep_alive = 60 } }, <<>>}, emqtt_parser:parse(V311ConnWithoutClientId, State)), keep_alive = 60 } }, <<>>}, emqttd_parser:parse(V311ConnWithoutClientId, State)),
%%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg)) %%CONNECT(Qos=0, Retain=false, Dup=false, ClientId=mosqpub/10452-iMac.loca, ProtoName=MQIsdp, ProtoVsn=3, CleanSess=true, KeepAlive=60, Username=test, Password=******, Will(Qos=1, Retain=false, Topic=/will, Msg=willmsg))
ConnBinWithWill = <<16,67,0,6,77,81,73,115,100,112,3,206,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,50,45,105,77,97,99,46,108,111,99,97,0,5,47,119,105,108,108,0,7,119,105,108,108,109,115,103,0,4,116,101,115,116,0,6,112,117,98,108,105,99>>, ConnBinWithWill = <<16,67,0,6,77,81,73,115,100,112,3,206,0,60,0,23,109,111,115,113,112,117,98,47,49,48,52,53,50,45,105,77,97,99,46,108,111,99,97,0,5,47,119,105,108,108,0,7,119,105,108,108,109,115,103,0,4,116,101,115,116,0,6,112,117,98,108,105,99>>,
?assertMatch({ok, #mqtt_packet{ ?assertMatch({ok, #mqtt_packet{
@ -90,11 +90,11 @@ parse_connect_test() ->
will_msg = <<"willmsg">> , will_msg = <<"willmsg">> ,
username = <<"test">>, username = <<"test">>,
password = <<"public">>}}, password = <<"public">>}},
<<>> }, emqtt_parser:parse(ConnBinWithWill, State)), <<>> }, emqttd_parser:parse(ConnBinWithWill, State)),
ok. ok.
parse_publish_test() -> parse_publish_test() ->
State = emqtt_parser:init(), State = emqttd_parser:init([]),
%%PUBLISH(Qos=1, Retain=false, Dup=false, TopicName=a/b/c, PacketId=1, Payload=<<"hahah">>) %%PUBLISH(Qos=1, Retain=false, Dup=false, TopicName=a/b/c, PacketId=1, Payload=<<"hahah">>)
PubBin = <<50,14,0,5,97,47,98,47,99,0,1,104,97,104,97,104>>, PubBin = <<50,14,0,5,97,47,98,47,99,0,1,104,97,104,97,104>>,
?assertMatch({ok, #mqtt_packet{ ?assertMatch({ok, #mqtt_packet{
@ -104,7 +104,7 @@ parse_publish_test() ->
retain = false}, retain = false},
variable = #mqtt_packet_publish{topic_name = <<"a/b/c">>, variable = #mqtt_packet_publish{topic_name = <<"a/b/c">>,
packet_id = 1}, packet_id = 1},
payload = <<"hahah">> }, <<>>}, emqtt_parser:parse(PubBin, State)), payload = <<"hahah">> }, <<>>}, emqttd_parser:parse(PubBin, State)),
%PUBLISH(Qos=0, Retain=false, Dup=false, TopicName=xxx/yyy, PacketId=undefined, Payload=<<"hello">>) %PUBLISH(Qos=0, Retain=false, Dup=false, TopicName=xxx/yyy, PacketId=undefined, Payload=<<"hello">>)
%DISCONNECT(Qos=0, Retain=false, Dup=false) %DISCONNECT(Qos=0, Retain=false, Dup=false)
@ -116,13 +116,13 @@ parse_publish_test() ->
retain = false}, retain = false},
variable = #mqtt_packet_publish{topic_name = <<"xxx/yyy">>, variable = #mqtt_packet_publish{topic_name = <<"xxx/yyy">>,
packet_id = undefined}, packet_id = undefined},
payload = <<"hello">> }, <<224,0>>}, emqtt_parser:parse(PubBin1, State)), payload = <<"hello">> }, <<224,0>>}, emqttd_parser:parse(PubBin1, State)),
?assertMatch({ok, #mqtt_packet{ ?assertMatch({ok, #mqtt_packet{
header = #mqtt_packet_header{type = ?DISCONNECT, header = #mqtt_packet_header{type = ?DISCONNECT,
dup = false, dup = false,
qos = 0, qos = 0,
retain = false} retain = false}
}, <<>>}, emqtt_parser:parse(<<224, 0>>, State)). }, <<>>}, emqttd_parser:parse(<<224, 0>>, State)).
parse_puback_test() -> parse_puback_test() ->
%%PUBACK(Qos=0, Retain=false, Dup=false, PacketId=1) %%PUBACK(Qos=0, Retain=false, Dup=false, PacketId=1)
@ -132,7 +132,7 @@ parse_puback_test() ->
dup = false, dup = false,
qos = 0, qos = 0,
retain = false } retain = false }
}, <<>>}, emqtt_parser:parse(PubAckBin, emqtt_parser:init())), }, <<>>}, emqttd_parser:parse(PubAckBin, emqttd_parser:init([]))),
ok. ok.
parse_subscribe_test() -> parse_subscribe_test() ->
@ -149,7 +149,7 @@ parse_disconnect_test() ->
dup = false, dup = false,
qos = 0, qos = 0,
retain = false} retain = false}
}, <<>>}, emqtt_parser:parse(Bin, emqtt_parser:init())). }, <<>>}, emqttd_parser:parse(Bin, emqttd_parser:init([]))).
-endif. -endif.

View File

@ -20,57 +20,57 @@
%%% SOFTWARE. %%% SOFTWARE.
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
%%% @doc %%% @doc
%%% emqtt_serialiser tests. %%% emqttd_serialiser tests.
%%% %%%
%%% @end %%% @end
%%%----------------------------------------------------------------------------- %%%-----------------------------------------------------------------------------
-module(emqtt_serialiser_tests). -module(emqttd_serialiser_tests).
-include("emqtt_packet.hrl"). -include("emqttd_packet.hrl").
-ifdef(TEST). -ifdef(TEST).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
serialise_connect_test() -> serialise_connect_test() ->
emqtt_serialiser:serialise(?CONNECT_PACKET(#mqtt_packet_connect{})). emqttd_serialiser:serialise(?CONNECT_PACKET(#mqtt_packet_connect{})).
serialise_connack_test() -> serialise_connack_test() ->
ConnAck = #mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK}, ConnAck = #mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK},
variable = #mqtt_packet_connack{ack_flags = 0, return_code = 0}}, variable = #mqtt_packet_connack{ack_flags = 0, return_code = 0}},
?assertEqual(<<32,2,0,0>>, emqtt_serialiser:serialise(ConnAck)). ?assertEqual(<<32,2,0,0>>, emqttd_serialiser:serialise(ConnAck)).
serialise_publish_test() -> serialise_publish_test() ->
emqtt_serialiser:serialise(?PUBLISH_PACKET(?QOS_0, <<"Topic">>, undefined, <<"Payload">>)), emqttd_serialiser:serialise(?PUBLISH_PACKET(?QOS_0, <<"Topic">>, undefined, <<"Payload">>)),
emqtt_serialiser:serialise(?PUBLISH_PACKET(?QOS_1, <<"Topic">>, 938, <<"Payload">>)). emqttd_serialiser:serialise(?PUBLISH_PACKET(?QOS_1, <<"Topic">>, 938, <<"Payload">>)).
serialise_puback_test() -> serialise_puback_test() ->
emqtt_serialiser:serialise(?PUBACK_PACKET(?PUBACK, 10384)). emqttd_serialiser:serialise(?PUBACK_PACKET(?PUBACK, 10384)).
serialise_pubrel_test() -> serialise_pubrel_test() ->
emqtt_serialiser:serialise(?PUBREL_PACKET(10384)). emqttd_serialiser:serialise(?PUBREL_PACKET(10384)).
serialise_subscribe_test() -> serialise_subscribe_test() ->
TopicTable = [{<<"TopicQos0">>, ?QOS_0}, {<<"TopicQos1">>, ?QOS_1}, {<<"TopicQos2">>, ?QOS_2}], TopicTable = [{<<"TopicQos0">>, ?QOS_0}, {<<"TopicQos1">>, ?QOS_1}, {<<"TopicQos2">>, ?QOS_2}],
emqtt_serialiser:serialise(?SUBSCRIBE_PACKET(10, TopicTable)). emqttd_serialiser:serialise(?SUBSCRIBE_PACKET(10, TopicTable)).
serialise_suback_test() -> serialise_suback_test() ->
emqtt_serialiser:serialise(?SUBACK_PACKET(10, [?QOS_0, ?QOS_1, 128])). emqttd_serialiser:serialise(?SUBACK_PACKET(10, [?QOS_0, ?QOS_1, 128])).
serialise_unsubscribe_test() -> serialise_unsubscribe_test() ->
emqtt_serialiser:serialise(?UNSUBSCRIBE_PACKET(10, [<<"Topic1">>, <<"Topic2">>])). emqttd_serialiser:serialise(?UNSUBSCRIBE_PACKET(10, [<<"Topic1">>, <<"Topic2">>])).
serialise_unsuback_test() -> serialise_unsuback_test() ->
emqtt_serialiser:serialise(?UNSUBACK_PACKET(10)). emqttd_serialiser:serialise(?UNSUBACK_PACKET(10)).
serialise_pingreq_test() -> serialise_pingreq_test() ->
emqtt_serialiser:serialise(?PACKET(?PINGREQ)). emqttd_serialiser:serialise(?PACKET(?PINGREQ)).
serialise_pingresp_test() -> serialise_pingresp_test() ->
emqtt_serialiser:serialise(?PACKET(?PINGRESP)). emqttd_serialiser:serialise(?PACKET(?PINGRESP)).
serialise_disconnect_test() -> serialise_disconnect_test() ->
emqtt_serialiser:serialise(?PACKET(?DISCONNECT)). emqttd_serialiser:serialise(?PACKET(?DISCONNECT)).
-endif. -endif.

View File

@ -19,12 +19,11 @@
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE %% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
%% SOFTWARE. %% SOFTWARE.
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
-module(emqttd_topic_tests).
-module(emqtt_topic_tests). -include("emqttd_topic.hrl").
-include("emqtt_topic.hrl"). -import(emqttd_topic, [validate/1, type/1, match/2, triples/1, words/1]).
-import(emqtt_topic, [validate/1, type/1, match/2, triples/1, words/1]).
-ifdef(TEST). -ifdef(TEST).