1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%%-------------------------------------------------------------------
%%% File : wx_basic_SUITE.erl
%%% Author : Dan Gudmundsson <[email protected]>
%%% Description : Basic SUITE, some simple tests to show that the basics
%%% are working.
%%% Created : 3 Nov 2008 by Dan Gudmundsson <[email protected]>
%%%-------------------------------------------------------------------
-module(wx_basic_SUITE).
-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]).
-compile(export_all).
-include("wx_test_lib.hrl").
%% Initialization functions.
init_per_suite(Config) ->
wx_test_lib:init_per_suite(Config).
end_per_suite(Config) ->
wx_test_lib:end_per_suite(Config).
init_per_testcase(Func,Config) ->
wx_test_lib:init_per_testcase(Func,Config).
end_per_testcase(Func,Config) ->
wx_test_lib:end_per_testcase(Func,Config).
%% SUITE specification
suite() -> [{suite_callbacks,[ts_install_scb]}].
all() ->
[create_window, several_apps, wx_api, wx_misc,
data_types].
groups() ->
[].
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
%% The test cases
%% create and test creating a window
create_window(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
create_window(Config) ->
Wx = ?mr(wx_ref, wx:new()),
Frame = ?mt(wxFrame, wxFrame:new(Wx, 1, "Hello World")),
timer:sleep(1000),
?m(true,wxWindow:show(Frame, [])),
wx_test_lib:wx_destroy(Frame, Config).
%% create several windows from independent processes
%% to simulate several applications and test creating a window
several_apps(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
several_apps(Config) ->
Parent = self(),
Pids = [spawn_link(fun() -> several_apps(Parent, N, Config) end)
|| N <- lists:seq(1,4)],
process_flag(trap_exit,true),
?m_multi_receive([{complete,Pid} || Pid <- Pids]),
case wx_test_lib:user_available(Config) of
true ->
receive {'EXIT',_,foo} -> ok end;
false ->
ok
end.
several_apps(Parent, N, Config) ->
Wx = ?mr(wx_ref, wx:new()),
Frame = ?mt(wxFrame, wxFrame:new(Wx, 1, "Hello World No:" ++
integer_to_list(N))),
create_menus(Frame),
wxFrame:connect(Frame,size),
?m(true,wxWindow:show(Frame, [])),
receive
#wx{obj=Frame, event=#wxSize{}} ->
Parent ! {complete, self()}
end,
wx_test_lib:wx_destroy(Frame, Config),
exit(foo).
%% Test the wx.erl api functionality.
wx_api(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
wx_api(Config) ->
Wx = ?mr(wx_ref, wx:new()),
?m(true, wx:is_null(Wx)),
Null = ?mr(wx_ref, wx:null()),
?m(true, wx:is_null(Null)),
Frame = ?mt(wxFrame, wxFrame:new(Wx, 1, "WX API: " ++ unicode:characters_to_list("������"))),
?m(false, wx:is_null(Frame)),
?m(wxFrame, wx:getObjectType(Frame)),
Env = ?mr(wx_env, wx:get_env()),
%% Test some error cases
erase(wx_env),
?m({'EXIT', {{wxe,unknown_port},_}},wxWindow:show(Frame, [])),
?m({'EXIT', {{wxe,unknown_port},_}},wx:debug(2)),
?m(ok,wx:set_env(Env)),
?m(ok,wx:debug(1)),
?m(ok,wx:debug(2)),
?m(ok,wx:debug(0)),
?m(ok,wx:debug(none)),
?m(ok,wx:debug(verbose)),
?m(ok,wx:debug(trace)),
Mem = ?mr(wx_mem, wx:create_memory(10)),
?m(true, is_binary(wx:get_memory_bin(Mem))),
?mt(foo, wx:typeCast(Frame, foo)),
RecBatch = fun() ->
wx:batch(fun() -> create_menus(Frame) end)
end,
?m(batch_ret, wx:batch(fun() -> RecBatch(), batch_ret end)),
?m(ok, wx:foreach(fun(A) -> true = lists:member(A,[1,2,3,4,5]) end,
lists:seq(1,5))),
?m([2,3,4,5,6], wx:map(fun(A) -> A+1 end, lists:seq(1,5))),
?m({5,15}, wx:foldl(fun(A,{_,Acc}) -> {A,A+Acc} end, {0,0},
lists:seq(1,5))),
?m({1,15}, wx:foldr(fun(A,{_,Acc}) -> {A,A+Acc} end, {0,0},
lists:seq(1,5))),
?m(ok,wx:debug(none)),
?m(ball, wx:batch(fun() -> throw(ball), batch_ret end)),
?m({'EXIT', door}, wx:batch(fun() -> exit(door), batch_ret end)),
?m({'EXIT',{message,_ST}},
wx:batch(fun() -> erlang:error(message), batch_ret end)),
?m({'EXIT',_},wxWindow:show(wx:null(), [])),
?m(true,wxWindow:show(Frame, [])),
Temp = ?mt(wxButton, wxButton:new(Frame, -1)),
?m(ok,wxButton:setLabel(Temp, "Testing")),
?m(ok,wxButton:destroy(Temp)),
?m({'EXIT',_},wxButton:getLabel(Temp)),
case wx_test_lib:user_available(Config) of
true ->
%% Hmm popup doesn't return until mouse is pressed.
Menu = wxMenu:new(),
wxMenu:append(Menu, 0, "Press", []),
wxMenu:append(Menu, 1, "Me", []),
?m(true, wxWindow:popupMenu(Frame, Menu)),
%% This didn't work for a while
?m(true, wx:batch(fun() ->
wxMenu:append(Menu, 2, "AGAIN", []),
wxWindow:popupMenu(Frame, Menu)
end)),
ok;
_ ->
ignore
end,
%% dbg:tracer(),
%% {_, _Port, Server, _Dbg} = wx:get_env(),
%% dbg:p(Server, [m, call]),
%% dbg:p(new, [m, call]),
%% dbg:tpl(wxe_server,'_', [{'_', [], [{return_trace}]}]),
wx_test_lib:wx_destroy(Frame,Config).
create_menus(Frame) ->
MenuBar = ?mt(wxMenuBar, wxMenuBar:new()),
File = ?mt(wxMenu, wxMenu:new([])),
Help = ?mt(wxMenu, wxMenu:new([])),
?mt(wxMenuItem, wxMenu:append(Help, ?wxID_ABOUT, "&About", [])),
?mt(wxMenuItem, wxMenu:append(Help, ?wxID_HELP, "&Help", [])),
?mt(wxMenuItem, wxMenu:append(File, ?wxID_EXIT, "Exit", [])),
?m(ok,wxFrame:connect(Frame, command_menu_selected)),
?m(true, wxMenuBar:append(MenuBar, File, "&File")),
?m(true, wxMenuBar:append(MenuBar, Help, "&Help")),
?m(ok, wxFrame:setMenuBar(Frame,MenuBar)).
%% Test the wx_misc.erl api functionality.
wx_misc(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
wx_misc(Config) ->
wx:new([{debug, trace}]),
put(wx_test_verbose, true),
?m(ok, wx_misc:bell()),
?m(true, length(wx_misc:getUserId()) > 0),
?m(true, is_list(wx_misc:getEmailAddress())),
Home = ?m([_|_], wx_misc:getHomeDir()),
?m(true, filelib:is_dir(Home)),
?m(true, length(wx_misc:getOsDescription()) > 0),
IsLitte = case <<1:32/native>> of
<<1:8, 0:24>> -> true;
<<0:24,1:16>> -> false
end,
?m(IsLitte, wx_misc:isPlatformLittleEndian()),
?m(true, is_boolean(wx_misc:isPlatform64Bit())),
?mr(wxMouseState, wx_misc:getMouseState()),
?m({_,_}, wx_misc:getMousePosition()),
%% Don't hold home down when testing :-)
?m(false, wx_misc:getKeyState(?WXK_HOME)),
%% wx:shutdown() %% How do you test this?
case os:type() of
{win32, _} -> %% These hangs when running automatic tests
skip; %% through ssh on windows. Works otherwise
_ ->
wx_misc:shell([{command,"echo TESTING close the popup shell"}])
end,
case wx_test_lib:user_available(Config) of
true ->
wx_misc:shell();
false ->
%% Don't want to spawn a shell if no user
skip %% is available
end,
?m(false, wx_misc:isBusy()),
?m(ok, wx_misc:beginBusyCursor([])),
?m(true, wx_misc:isBusy()),
?m(ok, wx_misc:endBusyCursor()),
%%?m(true, is_boolean(wx_misc:setDetectableAutoRepeat(true)),
Curr = wx_misc:getCurrentId(),
?m(true, is_integer(Curr)),
NewId = wx_misc:newId(),
?m(ok, wx_misc:registerId(NewId+1)),
?m(true, (NewId+1) /= wx_misc:newId()),
wx:destroy().
%% Check that all the data_types works in communication
%% between erlang and c++ thread.
data_types(TestInfo) when is_atom(TestInfo) -> wx_test_lib:tc_info(TestInfo);
data_types(_Config) ->
Wx = ?mr(wx_ref, wx:new()),
Frame = wxFrame:new(Wx, 1, "Data Types"),
CDC = wxClientDC:new(Frame),
%% From wx.erl
%% The following classes are implemented directly as erlang types: <br />
%% wxPoint={x,y},wxSize={w,h},wxRect={x,y,w,h},wxColour={r,g,b [,a]},wxString=[integer],
%% wxGBPosition={r,c},wxGBSpan={rs,cs},wxGridCellCoords={r,c}.
%% Strings
?m("Data Types", wxFrame:getTitle(Frame)),
%% Doubles
?m(ok, wxDC:setUserScale(CDC, 123.45, 234.67)),
?m({123.45,234.67}, wxDC:getUserScale(CDC)),
%% Colors input is 3 or 4 tuple, returns are 4 tuples
?m(ok, wxDC:setTextForeground(CDC, {100,10,1})),
?m({100,10,1,255}, wxDC:getTextForeground(CDC)),
?m(ok, wxDC:setTextForeground(CDC, {100,10,1,43})),
?m({100,10,1,43}, wxDC:getTextForeground(CDC)),
%% Bool
?m(ok, wxDC:setAxisOrientation(CDC, true, false)),
?m(true, is_boolean(wxDC:isOk(CDC))),
%% wxCoord
?m(true, is_integer(wxDC:maxX(CDC))),
%% wxSize
?m({_,_}, wxWindow:getSize(Frame)),
%% DateTime
DateTime = calendar:now_to_datetime(erlang:now()),
io:format("DateTime ~p ~n",[DateTime]),
Cal = ?mt(wxCalendarCtrl, wxCalendarCtrl:new(Frame, ?wxID_ANY, [{date,DateTime}])),
?m(DateTime, wxCalendarCtrl:getDate(Cal)),
?m(true, is_boolean(wxCalendarCtrl:setDate(Cal,DateTime))),
?m(DateTime, wxCalendarCtrl:getDate(Cal)),
wxClientDC:destroy(CDC),
%%wx_test_lib:wx_destroy(Frame,Config).
wx:destroy().
|