diff options
Diffstat (limited to 'lib/wx/test')
-rw-r--r-- | lib/wx/test/Makefile | 3 | ||||
-rw-r--r-- | lib/wx/test/wx_app_SUITE.erl | 7 | ||||
-rw-r--r-- | lib/wx/test/wx_basic_SUITE.erl | 163 | ||||
-rw-r--r-- | lib/wx/test/wx_class_SUITE.erl | 8 | ||||
-rw-r--r-- | lib/wx/test/wx_event_SUITE.erl | 9 | ||||
-rw-r--r-- | lib/wx/test/wx_obj_test.erl | 7 | ||||
-rw-r--r-- | lib/wx/test/wx_oc_object.erl | 44 | ||||
-rw-r--r-- | lib/wx/test/wx_opengl_SUITE.erl | 2 | ||||
-rw-r--r-- | lib/wx/test/wx_test_lib.erl | 13 | ||||
-rw-r--r-- | lib/wx/test/wx_xtra_SUITE.erl | 3 | ||||
-rw-r--r-- | lib/wx/test/wxt.erl | 32 |
11 files changed, 244 insertions, 47 deletions
diff --git a/lib/wx/test/Makefile b/lib/wx/test/Makefile index 9a78307be1..2eaf2f8ae5 100644 --- a/lib/wx/test/Makefile +++ b/lib/wx/test/Makefile @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 2008-2016. All Rights Reserved. +# Copyright Ericsson AB 2008-2017. 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. @@ -29,6 +29,7 @@ APPDIR = $(shell dirname $(PWD)) ERL_COMPILE_FLAGS = -pa $(APPDIR)/ebin Mods = wxt wx_test_lib wx_obj_test \ + wx_oc_object \ wx_app_SUITE \ wx_basic_SUITE \ wx_event_SUITE \ diff --git a/lib/wx/test/wx_app_SUITE.erl b/lib/wx/test/wx_app_SUITE.erl index 3fd5bf689d..a5202d8448 100644 --- a/lib/wx/test/wx_app_SUITE.erl +++ b/lib/wx/test/wx_app_SUITE.erl @@ -24,7 +24,12 @@ %%---------------------------------------------------------------------- -module(wx_app_SUITE). --compile(export_all). +-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([t/0, t/1, fields/1, modules/1, exportall/1, app_depend/1, + undef_funcs/0, undef_funcs/1, appup/1]). -include("wx_test_lib.hrl"). -include_lib("common_test/include/ct.hrl"). diff --git a/lib/wx/test/wx_basic_SUITE.erl b/lib/wx/test/wx_basic_SUITE.erl index 6a2528780e..ad03a378de 100644 --- a/lib/wx/test/wx_basic_SUITE.erl +++ b/lib/wx/test/wx_basic_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2008-2016. All Rights Reserved. +%% Copyright Ericsson AB 2008-2017. 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. @@ -28,7 +28,11 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). --compile(export_all). +-export([silent_start/1, create_window/1, several_apps/1, wx_api/1, wx_misc/1, + data_types/1, wx_object/1, undef_in_handle_info/1, undef_in_terminate/1, + undef_handle_event/1, undef_handle_call/1, undef_handle_cast/1, undef_handle_info/1, + undef_code_change/1, undef_terminate1/1, undef_terminate2/1 + ]). -include("wx_test_lib.hrl"). @@ -49,10 +53,13 @@ suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap,{minutes,2}}]. all() -> [silent_start, create_window, several_apps, wx_api, wx_misc, - data_types, wx_object]. + data_types, wx_object, {group, undef_callbacks}, + undef_in_handle_info, undef_in_terminate]. groups() -> - []. + [{undef_callbacks, [], + [undef_handle_event, undef_handle_call, undef_handle_cast, undef_handle_info, + undef_code_change, undef_terminate1, undef_terminate2]}]. init_per_group(_GroupName, Config) -> Config. @@ -426,6 +433,154 @@ wx_object(Config) -> catch wx:destroy(), ok. +%% Test that the server crashes correctly if the handle_event callback is +%% not exported in the callback module +undef_handle_event(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_handle_event(_Config) -> + wx:new(), + {_, _, _, Pid} = wx_object:start(wx_oc_object, [], []), + MRef = monitor(process, Pid), + %% Mock a call to handle_event + Pid ! {wx, a, b, c, d}, + ok = receive + {'DOWN', MRef, process, Pid, + {undef, [{wx_oc_object, handle_event, _, _}|_]}} -> + ok + after 5000 -> + ct:fail(should_crash) + end. + +%% Test that the server crashes correctly if the handle_call callback is +%% not exported in the callback module +undef_handle_call(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_handle_call(_Config) -> + wx:new(), + Frame = wx_object:start(wx_oc_object, [], []), + try + wx_object:call(Frame, call_msg), + ct:fail(should_crash) + catch error:{{undef, [{wx_oc_object,handle_call, _, _}|_]}, + {wx_object,call,_}} -> + ok + end. + +%% Test that the server crashes correctly if the handle_cast callback is +%% not exported in the callback module +undef_handle_cast(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_handle_cast(_Config) -> + wx:new(), + {_, _, _, Pid} = Frame = wx_object:start(wx_oc_object, [], []), + MRef = monitor(process, Pid), + wx_object:cast(Frame, cast_msg), + ok = receive + {'DOWN', MRef, process, Pid, + {undef, [{wx_oc_object, handle_cast, _, _}|_]}} -> + ok + after 5000 -> + ct:fail(should_crash) + end. + +%% Test the default implementation of handle_info if the callback module +%% does not export it +undef_handle_info(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_handle_info(_Config) -> + wx:new(), + {_, _, _, Pid} = wx_object:start(wx_oc_object, [], []), + MRef = monitor(process, Pid), + Pid ! test, + receive + {'DOWN', MRef, process, Pid, _} -> + ct:fail(should_not_crash) + after 500 -> + ok + end, + ok = wx_object:stop(Pid). + +%% Test the server crashes correctly if called and the code_change callback is +%% not exported in the callback module +undef_code_change(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_code_change(_Config) -> + wx:new(), + {_, _, _, Pid} = wx_object:start(wx_oc_object, [], []), + sys:suspend(Pid), + sys:replace_state(Pid, fun([P, S, M, T]) -> [P, {new, S}, M, T] end), + {error, {'EXIT', {undef, [{wx_oc_object,code_change, [_, _, _], _}|_]}}} + = sys:change_code(Pid, wx_oc_object, old_vsn, []), + ok = sys:resume(Pid), + ok = wx_object:stop(Pid). + +%% Test the default implementation of terminate if the callback module +%% does not export it +undef_terminate1(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_terminate1(_Config) -> + ok = terminate([], normal). + +%% Test the default implementation of terminate if the callback module +%% does not export it +undef_terminate2(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_terminate2(_Config) -> + ok = terminate([{error, test}, infinity], {error, test}). + +terminate(ArgsTl, Reason) -> + wx:new(), + {_, _, _, Pid} = wx_object:start(wx_oc_object, [], []), + MRef = monitor(process, Pid), + ok = apply(wx_object, stop, [Pid|ArgsTl]), + receive + {'DOWN', MRef, process, Pid, Reason} -> + ok + after 1000 -> + ct:fail(failed) + end. + +%% Test that the server crashes correctly if the handle_info callback is +%% calling an undefined function +undef_in_handle_info(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_in_handle_info(_Config) -> + wx:new(), + Init = ui_init_fun(), + {_, _, _, Pid} = wx_object:start(wx_obj_test, + [{parent, self()}, {init, Init}], []), + unlink(Pid), + MRef = monitor(process, Pid), + Pid ! {call_undef_fun, {wx_obj_test, handle_info}}, + receive + {'DOWN', MRef, process, Pid, + {undef, [{wx_obj_test, handle_info, _, _}|_]}} -> + ok + after 1000 -> + ct:fail(failed) + end, + ok. + +%% Test that the server crashes correctly if the terminate callback is +%% calling an undefined function +undef_in_terminate(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo); +undef_in_terminate(_Config) -> + wx:new(), + Init = ui_init_fun(), + Frame = wx_object:start(wx_obj_test, + [{parent, self()}, {init, Init}, + {terminate, {wx_obj_test, terminate}}], []), + try + wx_object:stop(Frame), + ct:fail(should_crash) + catch error:{{undef, [{wx_obj_test, terminate, _, _}|_]}, _} -> + ok + end. + +ui_init_fun() -> + Init = fun() -> + Frame0 = wxFrame:new(wx:null(), ?wxID_ANY, "Test wx_object", [{size, {500, 400}}]), + Frame = wx_object:set_pid(Frame0, self()), + Sz = wxBoxSizer:new(?wxHORIZONTAL), + Panel = wxPanel:new(Frame), + wxSizer:add(Sz, Panel, [{flag, ?wxEXPAND}, {proportion, 1}]), + wxWindow:show(Frame), + {Frame, {Frame, Panel}} + end, + Init. + check_events(Msgs) -> check_events(Msgs, 0,0). diff --git a/lib/wx/test/wx_class_SUITE.erl b/lib/wx/test/wx_class_SUITE.erl index 0a3c4659bf..6d314ab8fc 100644 --- a/lib/wx/test/wx_class_SUITE.erl +++ b/lib/wx/test/wx_class_SUITE.erl @@ -29,7 +29,10 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). --compile(export_all). +-export([calendarCtrl/1, treeCtrl/1, notebook/1, staticBoxSizer/1, + clipboard/1, helpFrame/1, htmlWindow/1, listCtrlSort/1, listCtrlVirtual/1, + radioBox/1, systemSettings/1, taskBarIcon/1, toolbar/1, popup/1, modal/1, + textCtrl/1, locale/1]). -include("wx_test_lib.hrl"). @@ -51,7 +54,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap,{minutes,2}}]. all() -> [calendarCtrl, treeCtrl, notebook, staticBoxSizer, clipboard, helpFrame, htmlWindow, listCtrlSort, listCtrlVirtual, - radioBox, systemSettings, taskBarIcon, toolbar, popup, modal]. + radioBox, systemSettings, taskBarIcon, toolbar, popup, modal, + textCtrl, locale]. groups() -> []. diff --git a/lib/wx/test/wx_event_SUITE.erl b/lib/wx/test/wx_event_SUITE.erl index 6512cedaf2..a564f89e58 100644 --- a/lib/wx/test/wx_event_SUITE.erl +++ b/lib/wx/test/wx_event_SUITE.erl @@ -27,7 +27,10 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). --compile(export_all). +-export([connect/1, disconnect/1, disconnect_cb/1, connect_msg_20/1, connect_cb_20/1, + mouse_on_grid/1, spin_event/1, connect_in_callback/1, recursive/1, + dialog/1, char_events/1, callback_clean/1, handler_clean/1 + ]). -include("wx_test_lib.hrl"). @@ -49,7 +52,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap,{minutes,2}}]. all() -> [connect, disconnect, disconnect_cb, connect_msg_20, connect_cb_20, mouse_on_grid, spin_event, connect_in_callback, recursive, - dialog, char_events, callback_clean + dialog, char_events, callback_clean, handler_clean ]. groups() -> @@ -577,6 +580,7 @@ handler_clean(_Config) -> Frame1 = wx_obj_test:start([{init, Init}]), ?mt(wxFrame, Frame1), wxWindow:show(Frame1), + timer:sleep(500), ?m([_|_], lists:sort(wx_test_lib:flush())), ?m(ok, wx_obj_test:stop(Frame1)), ?m([{terminate,normal}], lists:sort(wx_test_lib:flush())), @@ -584,6 +588,7 @@ handler_clean(_Config) -> Terminate = fun({Frame,_}) -> wxWindow:destroy(Frame) end, Frame2 = wx_obj_test:start([{init, Init}, {terminate, Terminate}]), wxWindow:show(Frame2), + timer:sleep(500), ?m([_|_], lists:sort(wx_test_lib:flush())), ?m(ok, wx_obj_test:stop(Frame2)), ?m([{terminate,normal}], lists:sort(wx_test_lib:flush())), diff --git a/lib/wx/test/wx_obj_test.erl b/lib/wx/test/wx_obj_test.erl index 23142e28b2..65ecb4f50d 100644 --- a/lib/wx/test/wx_obj_test.erl +++ b/lib/wx/test/wx_obj_test.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2011-2016. All Rights Reserved. +%% Copyright Ericsson AB 2011-2017. 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. @@ -79,6 +79,9 @@ handle_cast(What, State = #state{parent=Pid}) -> Pid ! {cast, What}, {noreply, State}. +handle_info({call_undef_fun, {Mod, Fun}}, State) -> + Mod:Fun(), + {noreply, State}; handle_info(What, State = #state{parent=Pid}) -> Pid ! {info, What}, {noreply, State}. @@ -87,6 +90,8 @@ terminate(What, #state{parent=Pid, opts=Opts, user_state=US}) -> case proplists:get_value(terminate, Opts) of undefined -> ok; + {Mod, Fun} -> + Mod:Fun(); Terminate -> Terminate(US) end, diff --git a/lib/wx/test/wx_oc_object.erl b/lib/wx/test/wx_oc_object.erl new file mode 100644 index 0000000000..bc9b7d48d0 --- /dev/null +++ b/lib/wx/test/wx_oc_object.erl @@ -0,0 +1,44 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2017. 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(wx_oc_object). +-include_lib("wx/include/wx.hrl"). + +%%-behaviour(wx_object). %% commented out avoid warnings + +%% wx_object callbacks +-export([init/1]). + +-record(state, {}). + +init([]) -> + Init = fun() -> + Frame0 = wxFrame:new(wx:null(), ?wxID_ANY, "Test wx_object", [{size, {500, 400}}]), + Frame = wx_object:set_pid(Frame0, self()), + Sz = wxBoxSizer:new(?wxHORIZONTAL), + Panel = wxPanel:new(Frame), + wxSizer:add(Sz, Panel, [{flag, ?wxEXPAND}, {proportion, 1}]), + wxWindow:show(Frame), + {Frame, {Frame, Panel}} + end, + {Obj, _UserState} = Init(), + {Obj, #state{}}; +init([Init]) -> + {Obj, _UserState} = Init(), + {Obj, #state{}}. diff --git a/lib/wx/test/wx_opengl_SUITE.erl b/lib/wx/test/wx_opengl_SUITE.erl index 3de9209fae..19ea731dfb 100644 --- a/lib/wx/test/wx_opengl_SUITE.erl +++ b/lib/wx/test/wx_opengl_SUITE.erl @@ -27,7 +27,7 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). --compile(export_all). +-export([canvas/1, glu_tesselation/1]). -include("wx_test_lib.hrl"). -include_lib("wx/include/gl.hrl"). diff --git a/lib/wx/test/wx_test_lib.erl b/lib/wx/test/wx_test_lib.erl index 9f26b8cb9d..af508ff490 100644 --- a/lib/wx/test/wx_test_lib.erl +++ b/lib/wx/test/wx_test_lib.erl @@ -24,7 +24,10 @@ %%% Created : 30 Oct 2008 by Dan Gudmundsson <[email protected]> %%%------------------------------------------------------------------- -module(wx_test_lib). --compile(export_all). +-export([init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). +-export([tc_info/1, log/2, log/4, verbose/4, error/4, + flush/0, pick_msg/0, user_available/1, wx_destroy/2, wx_close/2, wait_for_close/0, + run_test/2, run_test/3, test_case_evaluator/3]). -include("wx_test_lib.hrl"). @@ -182,11 +185,15 @@ run_test([], _Config) -> []. run_test(Module, all, Config) -> All = [{Module, Test} || Test <- Module:all()], run_test(All, Config); +run_test(Module, {group, Group}, Config) -> + {_, _, TCs} = lists:keyfind(Group, 1, Module:groups()), + All = [{Module, Test} || Test <- TCs], + run_test(All, Config); + run_test(Module, TestCase, Config) -> log("Eval test case: ~w~n", [{Module, TestCase}]), Sec = timer:seconds(1) * 1000, - {T, Res} = - timer:tc(?MODULE, eval_test_case, [Module, TestCase, Config]), + {T, Res} = timer:tc(fun() -> eval_test_case(Module, TestCase, Config) end), log("Tested ~w in ~w sec~n", [TestCase, T div Sec]), {T div Sec, Res}. diff --git a/lib/wx/test/wx_xtra_SUITE.erl b/lib/wx/test/wx_xtra_SUITE.erl index c6268a7f46..486843ec63 100644 --- a/lib/wx/test/wx_xtra_SUITE.erl +++ b/lib/wx/test/wx_xtra_SUITE.erl @@ -28,7 +28,8 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, end_per_testcase/2]). --compile(export_all). +-export([destroy_app/1, multiple_add_in_sizer/1, app_dies/1, + menu_item_debug/1]). -include("wx_test_lib.hrl"). diff --git a/lib/wx/test/wxt.erl b/lib/wx/test/wxt.erl index 265cd5c981..2b380606d5 100644 --- a/lib/wx/test/wxt.erl +++ b/lib/wx/test/wxt.erl @@ -20,7 +20,7 @@ %% Description : Shortcuts for running tests with wx internal test_server %%------------------------------------------------------------------- -module(wxt). --compile(export_all). +-export([t/0, t/1, t/2, user/0, user/1,user/2]). %% Modules or suites can be shortcuts i.e. basic expands to wx_basic_SUITE. %% @@ -83,36 +83,6 @@ alias(Suite) when is_atom(Suite) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -config_fname() -> - "wx_test_case_config". - -%% Read default config file -read_config() -> - Fname = config_fname(), - wx_test_lib:log("Consulting file ~s...~n", [Fname]), - case file:consult(Fname) of - {ok, Config} -> - wx_test_lib:log("Read config ~w~n", [Config]), - Config; - _Error -> - Config = wx_test_lib:default_config(), - wx_test_lib:log("<>WARNING<> Using default config: ~w~n", [Config]), - Config - end. - -%% Write new default config file -write_config(Config) when is_list(Config) -> - Fname = config_fname(), - {ok, Fd} = file:open(Fname, write), - write_list(Fd, Config), - file:close(Fd). - -write_list(Fd, [H | T]) -> - ok = io:format(Fd, "~p.~n",[H]), - write_list(Fd, T); -write_list(_, []) -> - ok. - test_case_fname() -> "wx_test_case_info". |