<commit_before>%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(nc_SUITE).


-include_lib("common_test/include/ct.hrl").

-define(VERSION_MAGIC,       131).

-define(ATOM_EXT,            100).
-define(REFERENCE_EXT,       101).
-define(PORT_EXT,            102).
-define(PID_EXT,             103).
-define(NEW_REFERENCE_EXT,   114).
-define(ATOM_UTF8_EXT,       118).
-define(SMALL_ATOM_UTF8_EXT, 119).
-define(NEW_PID_EXT,         $X).
-define(NEW_PORT_EXT,        $Y).
-define(NEWER_REFERENCE_EXT, $Z).


-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
	 init_per_suite/1,
	 end_per_suite/1,
	 init_per_testcase/2,
	 end_per_testcase/2]).

-export([pid_roundtrip/1,
	 port_roundtrip/1,
	 ref_roundtrip/1,
	 new_float/1,
	 old_stuff/1,
	 binary_roundtrip/1,
	 decompress_roundtrip/1,
	 compress_roundtrip/1,
	 integer_roundtrip/1,
	 fun_roundtrip/1,
	 lists_roundtrip/1,
	 lists_roundtrip_2/1,
	 lists_iterator/1,
	 unicode/1,
	 unicode_list_to_string/1,
	 unicode_string_to_list/1,
	 utf8_atom/1,
	 utf8_pid/1,
	 utf8_port/1,
	 utf8_ref/1,
	 connect/1]).


%% Top of cases

suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    [pid_roundtrip, port_roundtrip, ref_roundtrip,
     new_float, old_stuff, binary_roundtrip,
     decompress_roundtrip, compress_roundtrip,
     integer_roundtrip, fun_roundtrip, lists_roundtrip,
     lists_roundtrip_2, lists_iterator, unicode,
     unicode_list_to_string, unicode_string_to_list,
     utf8_atom, utf8_pid, utf8_port, utf8_ref,
     connect].

groups() -> 
    [].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.

init_per_suite(Config) when is_list(Config) ->
    case case code:priv_dir(jinterface) of
	     {error,bad_name} -> false;
	     P -> filelib:is_dir(P) end of
	true ->
	    jitu:init_all(Config);
	false ->
	    {skip,"No jinterface application"}
    end.

end_per_suite(Config) ->
    jitu:finish_all(Config).



%% Add/remove watchdog before/after each test case.
%%
init_per_testcase(Case, Config) ->
    T = case atom_to_list(Case) of
	    "unicode"++_ -> 240;
	    _ -> 120
	end,
    WatchDog = test_server:timetrap(test_server:seconds(T)),
    [{watchdog, WatchDog}| Config].

end_per_testcase(_Case, Config) ->
    jitu:kill_all_jnodes(),
    WatchDog = ?config(watchdog, Config),
    test_server:timetrap_cancel(WatchDog).


%%
%% Test cases
%%

pid_roundtrip(doc) -> [];
pid_roundtrip(suite) -> [];
pid_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemPids = [mk_pid({gurka@sallad, Cr}, Num, Ser)
	       || Cr <- [1,2,3,4,16#adec0ded],
		  {Num, Ser} <- [{4711,4711},{32767, 8191}]],
    do_echo([self(),
	     mk_pid(ThisNode, 4711, 4711),
	     mk_pid(ThisNode, 32767, 8191)
	     | RemPids],
	    Config).

fun_roundtrip(doc) -> [];
fun_roundtrip(suite) -> [];
fun_roundtrip(Config) when is_list(Config)->
    do_echo([fun(A, B) -> A + B end,
	     fun(A) -> lists:reverse(A) end,
	     fun() -> ok end,
	     fun fun_roundtrip/1,
             fun ?MODULE:fun_roundtrip/1],
	    Config).

port_roundtrip(doc) -> [];
port_roundtrip(suite) -> [];
port_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemPorts = [mk_port({gurka@sallad, Cr}, Num)
		|| Cr <- [1,2,3,4,16#adec0ded],
		   Num <- [4711, 268435455]],
    do_echo([hd(erlang:ports()),
	     mk_port(ThisNode, 4711),
	     mk_port(ThisNode, 268435455)
	     | RemPorts],
	    Config).

ref_roundtrip(doc) -> [];
ref_roundtrip(suite) -> [];
ref_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemRefs = [mk_ref({gurka@sallad, Cr}, Words)
	       || Cr <- [1,2,3,4,16#adec0ded],
		  Words <- [[4711],
			    [4711, 4711, 4711],
			    [262143, 4294967295, 4294967295]]],
    do_echo([make_ref(),
	     mk_ref(ThisNode, [4711]),
	     mk_ref(ThisNode, [4711, 4711, 4711]),
	     mk_ref(ThisNode, [262143, 4294967295, 4294967295])
	     | RemRefs],
	    Config).

new_float(doc) -> [];
new_float(suite) -> [];<commit_msg>Test huge refs against jinterface<commit_after>%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2018. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(nc_SUITE).


-include_lib("common_test/include/ct.hrl").

-define(VERSION_MAGIC,       131).

-define(ATOM_EXT,            100).
-define(REFERENCE_EXT,       101).
-define(PORT_EXT,            102).
-define(PID_EXT,             103).
-define(NEW_REFERENCE_EXT,   114).
-define(ATOM_UTF8_EXT,       118).
-define(SMALL_ATOM_UTF8_EXT, 119).
-define(NEW_PID_EXT,         $X).
-define(NEW_PORT_EXT,        $Y).
-define(NEWER_REFERENCE_EXT, $Z).


-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
	 init_per_suite/1,
	 end_per_suite/1,
	 init_per_testcase/2,
	 end_per_testcase/2]).

-export([pid_roundtrip/1,
	 port_roundtrip/1,
	 ref_roundtrip/1,
	 new_float/1,
	 old_stuff/1,
	 binary_roundtrip/1,
	 decompress_roundtrip/1,
	 compress_roundtrip/1,
	 integer_roundtrip/1,
	 fun_roundtrip/1,
	 lists_roundtrip/1,
	 lists_roundtrip_2/1,
	 lists_iterator/1,
	 unicode/1,
	 unicode_list_to_string/1,
	 unicode_string_to_list/1,
	 utf8_atom/1,
	 utf8_pid/1,
	 utf8_port/1,
	 utf8_ref/1,
	 connect/1]).


%% Top of cases

suite() -> [{ct_hooks,[ts_install_cth]}].

all() -> 
    [pid_roundtrip, port_roundtrip, ref_roundtrip,
     new_float, old_stuff, binary_roundtrip,
     decompress_roundtrip, compress_roundtrip,
     integer_roundtrip, fun_roundtrip, lists_roundtrip,
     lists_roundtrip_2, lists_iterator, unicode,
     unicode_list_to_string, unicode_string_to_list,
     utf8_atom, utf8_pid, utf8_port, utf8_ref,
     connect].

groups() -> 
    [].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, Config) ->
    Config.

init_per_suite(Config) when is_list(Config) ->
    case case code:priv_dir(jinterface) of
	     {error,bad_name} -> false;
	     P -> filelib:is_dir(P) end of
	true ->
	    jitu:init_all(Config);
	false ->
	    {skip,"No jinterface application"}
    end.

end_per_suite(Config) ->
    jitu:finish_all(Config).



%% Add/remove watchdog before/after each test case.
%%
init_per_testcase(Case, Config) ->
    T = case atom_to_list(Case) of
	    "unicode"++_ -> 240;
	    _ -> 120
	end,
    WatchDog = test_server:timetrap(test_server:seconds(T)),
    [{watchdog, WatchDog}| Config].

end_per_testcase(_Case, Config) ->
    jitu:kill_all_jnodes(),
    WatchDog = ?config(watchdog, Config),
    test_server:timetrap_cancel(WatchDog).


%%
%% Test cases
%%

pid_roundtrip(doc) -> [];
pid_roundtrip(suite) -> [];
pid_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemPids = [mk_pid({gurka@sallad, Cr}, Num, Ser)
	       || Cr <- [1,2,3,4,16#adec0ded],
		  {Num, Ser} <- [{4711,4711},{32767, 8191}]],
    do_echo([self(),
	     mk_pid(ThisNode, 4711, 4711),
	     mk_pid(ThisNode, 32767, 8191)
	     | RemPids],
	    Config).

fun_roundtrip(doc) -> [];
fun_roundtrip(suite) -> [];
fun_roundtrip(Config) when is_list(Config)->
    do_echo([fun(A, B) -> A + B end,
	     fun(A) -> lists:reverse(A) end,
	     fun() -> ok end,
	     fun fun_roundtrip/1,
             fun ?MODULE:fun_roundtrip/1],
	    Config).

port_roundtrip(doc) -> [];
port_roundtrip(suite) -> [];
port_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemPorts = [mk_port({gurka@sallad, Cr}, Num)
		|| Cr <- [1,2,3,4,16#adec0ded],
		   Num <- [4711, 268435455]],
    do_echo([hd(erlang:ports()),
	     mk_port(ThisNode, 4711),
	     mk_port(ThisNode, 268435455)
	     | RemPorts],
	    Config).

ref_roundtrip(doc) -> [];
ref_roundtrip(suite) -> [];
ref_roundtrip(Config) when is_list(Config)->
    ThisNode = {node(), erlang:system_info(creation)},
    RemRefs = [mk_ref({gurka@sallad, Cr}, Words)
	       || Cr <- [1,2,3,4,16#adec0ded],
		  Words <- [[4711],
			    [4711, 4711, 4711],
			    [262143, 4294967295, 4294967295],
                            [262143, 4294967295, 4294967294, 4294967293, 4294967292]]],
    do_echo([make_ref(),
	     mk_ref(ThisNode, [4711]),
	     mk_ref(ThisNode, [4711, 4711, 4711]),
	     mk_ref(ThisNode, [262143, 4294967295, 4294967295])
	     | RemRefs],
	    Config).

new_float(doc) -> [];
new_float(suite) -> [];
{'fraction_non_alphanumeric': 0.15005257623554152, 'fraction_numerical': 0.057623554153522605, 'mean_word_length': 3.568203650336215, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915333', 'n_tokens_mistral': 4034, 'n_tokens_neox': 3487, 'n_words': 679}