4
%% Copyright Ericsson AB 2009. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
18
%%%-------------------------------------------------------------------
19
%%% File : wx_basic_SUITE.erl
20
%%% Author : Dan Gudmundsson <dan.gudmundsson@ericsson.com>
21
%%% Description : Basic SUITE, some simple tests to show that the basics
23
%%% Created : 3 Nov 2008 by Dan Gudmundsson <dan.gudmundsson@ericsson.com>
24
%%%-------------------------------------------------------------------
25
-module(wx_xtra_SUITE).
26
-export([all/0, init_per_suite/1, end_per_suite/1,
27
init_per_testcase/2, fin_per_testcase/2, end_per_testcase/2]).
31
-include("wx_test_lib.hrl").
33
%% Initialization functions.
34
init_per_suite(Config) ->
35
wx_test_lib:init_per_suite(Config).
37
end_per_suite(Config) ->
38
wx_test_lib:end_per_suite(Config).
40
init_per_testcase(Func,Config) ->
41
wx_test_lib:init_per_testcase(Func,Config).
42
end_per_testcase(Func,Config) ->
43
wx_test_lib:end_per_testcase(Func,Config).
44
fin_per_testcase(Func,Config) -> %% For test_server
45
wx_test_lib:end_per_testcase(Func,Config).
47
%% SUITE specification
53
multiple_add_in_sizer,
59
%% Verify that everything is handled on the queue first
60
%% before wx:destroy is called.
61
destroy_app(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
62
destroy_app(_Config) ->
63
%% This is timing releated but we test a couple of times
65
?m(ok, destroy_app_test(15)).
67
destroy_app_test(N) when N > 0 ->
68
Wx = ?mr(wx_ref, wx:new()),
69
Frame = wxFrame:new(Wx, 1, "Destroy"),
70
?m(ok, wxFrame:destroy(Frame)),
74
after 150 -> destroy_app_test(N-1)
76
destroy_app_test(_) ->
83
%% This should work, and does but not when run automaticly on windows
84
%% for some strange reason (it just hangs), run it last.
85
app_dies(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
88
Die = (Die0*2) + ?LINE,
91
Frame = wxFrame:new(Wx, 1, ?MODULE_STRING ++ integer_to_list(?LINE)),
93
wxFrame:createStatusBar(Frame, []),
95
Win=wxWindow:new(Frame, ?wxID_ANY),
97
_Pen = wxPen:new({0,0,0}, [{width, 3}]),
99
_Font = wxFont:new(10, ?wxSWISS, ?wxNORMAL, ?wxNORMAL,[]),
101
wxWindow:connect(Win, key_up),
103
wxWindow:connect(Win, key_up, [{callback, fun(_,_) -> callback end}]),
107
DC0 = wxClientDC:new(Win),
109
DC = wxBufferedDC:new(DC0),
111
_Size = wxWindow:getSize(Win),
112
oops(Die,?LINE), %% redraw(DC, Size, G),
113
wxBufferedDC:destroy(DC),
115
wxClientDC:destroy(DC0),
118
process_flag(trap_exit,true),
119
app_dies2(Tester, 1),
122
app_dies2(Test, N) ->
123
spawn_link(fun() -> Test(N) end),
125
{'EXIT', _, {oops, last}} -> ok;
126
{'EXIT', _, {oops, _}} -> app_dies2(Test, N+1)
129
oops(Die, Line) when (Die =:= last) orelse (Die =< Line) ->
131
?log(" Exits at line ~p~n",[Line]),
136
%% This have happend often enough that I have special code to handle
137
%% this user error (i.e. using the a window twice in an sizer).
138
multiple_add_in_sizer(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
139
multiple_add_in_sizer(Config) ->
141
Frame = wxFrame:new(Wx, -1, "Button Fix"),
142
wxFrame:connect(Frame, close_window),
144
FramePanel = wxPanel:new(Frame),
145
Sizer = wxBoxSizer:new(?wxVERTICAL),
146
wxPanel:setSizer(FramePanel, Sizer),
147
wxSizer:setSizeHints(Sizer, Frame),
149
Panel = wxPanel:new(FramePanel),
150
Button = wxButton:new(Panel, -1, [{label, "Centre Me!"}]),
152
PanelSizer = wxBoxSizer:new(?wxVERTICAL),
154
%%%%%%%%%%% THIS CALL CRASHES BEAM AT DESTROY TIME %%%%%%%%%%%%%
155
wxPanel:setSizer(Panel, PanelSizer),
156
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
ButtonSizer = wxBoxSizer:new(?wxVERTICAL),
160
SizerFlags = wxSizerFlags:new(),
161
wxSizerFlags:align(SizerFlags, ?wxALIGN_CENTRE),
163
wxSizer:add(ButtonSizer, Button, SizerFlags), %% no tricks
165
wxSizerFlags:expand(SizerFlags), %
166
wxSizer:add(PanelSizer, ButtonSizer, SizerFlags),
168
%% PanelSizer is added to a size twice
169
wxSizer:add(Sizer, PanelSizer, SizerFlags),
171
wxFrame:setSize(Frame, 400, 300),
172
io:format("Panel ~p PSizer ~p ~n",[Panel, PanelSizer]),
174
wxWindow:show(Frame),
175
wx_test_lib:wx_destroy(Frame, Config).