Skip to content

Commit b40f43a

Browse files
committed
Merge branch 'master' of github.com:msgpack/msgpack-erlang
2 parents eed86b7 + 784390c commit b40f43a

File tree

6 files changed

+154
-0
lines changed

6 files changed

+154
-0
lines changed

.eqc_ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{build, "./rebar3 compile eqc"}.
2+
{test_path, "./_build/eqc/lib/msgpack/ebin"}.
3+
{test_path, "./_build/eqc/lib/msgpack"}.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ ebin/*.app
55
deps
66
*.so
77
_build
8+
.rebar3

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: erlang
22
sudo: false
3+
install: echo rebar3
34
script: make check-all
45
notifications:
56
email: false

EQC_CI_LICENCE.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This file is an agreement between Quviq AB ("Quviq"), Sven Hultins
2+
Gata 9, Gothenburg, Sweden, and the committers to the github
3+
repository in which the file appears ("the owner"). By placing this
4+
file in a github repository, the owner agrees to the terms below.
5+
6+
The purpose of the agreement is to enable Quviq AB to provide a
7+
continuous integration service to the owner, whereby the code in the
8+
repository ("the source code") is tested using Quviq's test tools, and
9+
the test results are made available on the web. The test results
10+
include test output, generated test cases, and a copy of the source
11+
code in the repository annotated with coverage information ("the test
12+
results").
13+
14+
The owner agrees that Quviq may run the tests in the source code and
15+
display the test results on the web, without obligation.
16+
17+
The owner warrants that running the tests in the source code and
18+
displaying the test results on the web violates no laws, licences or other
19+
agreements. In the event of such a violation, the owner accepts full
20+
responsibility.
21+
22+
The owner warrants that the source code is not malicious, and will not
23+
mount an attack on either Quviq's server or any other server--for
24+
example by taking part in a denial of service attack, or by attempting
25+
to send unsolicited emails.
26+
27+
The owner warrants that the source code does not attempt to reverse
28+
engineer Quviq's code.
29+
30+
Quviq reserves the right to exclude repositories that break this
31+
agreement from its continuous integration service.
32+
33+
Any dispute arising from the use of Quviq's service will be resolved
34+
under Swedish law.

eqc/msgpack_eqc.erl

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
%%
2+
%% MessagePack for Erlang
3+
%%
4+
%% Copyright (C) 2009-2014 UENISHI Kota
5+
%%
6+
%% Licensed under the Apache License, Version 2.0 (the "License");
7+
%% you may not use this file except in compliance with the License.
8+
%% You may obtain a copy of the License at
9+
%%
10+
%% http://www.apache.org/licenses/LICENSE-2.0
11+
%%
12+
%% Unless required by applicable law or agreed to in writing, software
13+
%% distributed under the License is distributed on an "AS IS" BASIS,
14+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
%% See the License for the specific language governing permissions and
16+
%% limitations under the License.
17+
%%
18+
19+
-module(msgpack_eqc).
20+
21+
22+
-ifdef(TEST).
23+
-ifdef(EQC).
24+
25+
-compile(export_all).
26+
-include_lib("eqc/include/eqc.hrl").
27+
-include_lib("eunit/include/eunit.hrl").
28+
29+
-define(NUMTESTS, 16).
30+
-define(QC_OUT(P),
31+
eqc:on_output(fun(Str, Args) ->
32+
io:format(user, Str, Args) end, P)).
33+
-define(_assertProp(S),
34+
{timeout, ?NUMTESTS * 10,
35+
?_assert(quickcheck(numtests(?NUMTESTS, ?QC_OUT(S))))}).
36+
37+
eqc_test_() ->
38+
{inparallel,
39+
[
40+
?_assertProp(prop_msgpack()),
41+
?_assertProp(prop_msgpack([{format, jiffy}])),
42+
?_assertProp(prop_msgpack([{format, jsx}]))
43+
]}.
44+
45+
prop_msgpack() ->
46+
?FORALL(Obj, msgpack_object(),
47+
begin
48+
{ok, Obj} =:= msgpack:unpack(msgpack:pack(Obj))
49+
end).
50+
51+
prop_msgpack(Options) ->
52+
?FORALL(Obj, msgpack_object(),
53+
begin
54+
{ok, Obj} =:= msgpack:unpack(msgpack:pack(Obj, Options), Options)
55+
end).
56+
57+
msgpack_object() ->
58+
oneof(container_types() ++ primitive_types()).
59+
60+
container_types() ->
61+
[ fix_array(), array16() ].
62+
%% TODO: add map
63+
64+
primitive_types() ->
65+
[null(),
66+
positive_fixnum(), negative_fixnum(),
67+
int8(), int16(), int32(), int64(),
68+
uint8(), uint16(), uint32(), uint64(),
69+
eqc_gen:real(), eqc_gen:bool(),
70+
fix_raw(), raw16(), raw32()
71+
].
72+
%% fix_raw(), raw16(), raw32()]).
73+
74+
positive_fixnum() -> choose(0, 127).
75+
negative_fixnum() -> choose(-32, -1).
76+
77+
int8() -> choose(-16#80, 16#7F).
78+
int16() -> oneof([choose(-16#8000, -16#81),
79+
choose(16#80, 16#7FFF)]).
80+
int32() -> oneof([choose(-16#80000000, -16#8001),
81+
choose(16#10000, 16#7FFFFFFF)]).
82+
int64() -> oneof([choose(-16#8000000000000000, -16#80000001),
83+
choose(16#100000000, 16#7FFFFFFFFFFFFFFF)]).
84+
85+
uint8() -> choose(0, 16#FF).
86+
uint16() -> choose(16#100, 16#FFFF).
87+
uint32() -> choose(16#10000, 16#FFFFFFFF).
88+
uint64() -> choose(16#100000000, 16#FFFFFFFFFFFFFFFF).
89+
90+
null() -> null.
91+
92+
fix_raw() ->
93+
?LET(Integer, choose(0, 31),
94+
?LET(Binary, binary(Integer), Binary)).
95+
96+
raw16() ->
97+
?LET(Integer, uint16(),
98+
?LET(Binary, binary(Integer), Binary)).
99+
100+
raw32() ->
101+
?LET(Binary, binary(65537), Binary).
102+
103+
fix_array() ->
104+
eqc_gen:resize(16, eqc_gen:list(oneof(primitive_types()))).
105+
106+
array16() ->
107+
eqc_gen:resize(128, eqc_gen:list(oneof(primitive_types()))).
108+
109+
-endif.
110+
-endif.

rebar.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{require_otp_vsn, "17|18"}.
22

33
{erl_opts, [fail_on_warning, debug_info, warn_untyped_record]}.
4+
%%, {parse_transform, eqc_cover}]}.
5+
46
{xref_checks, [undefined_function_calls]}.
57
{cover_enabled, true}.
68
{cover_print_enabled, false}.
@@ -11,6 +13,9 @@
1113
"src/msgpack_ext.erl"
1214
]}.
1315

16+
{plugins, [
17+
{rebar3_eqc, ".*", {git, "https://github.com/kellymclaughlin/rebar3-eqc-plugin.git", {tag, "0.0.8"}}}
18+
]}.
1419

1520
%% {port_sources, ["c_src/*.c"]}.
1621
%% {port_env, [

0 commit comments

Comments
 (0)