4
%% Copyright Ericsson AB 2010-2011. 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
20
%%%-------------------------------------------------------------------
21
%%% File: ct_misc_1_SUITE
24
%%% Test misc things in Common Test suites.
26
%%% The suites used for the test are located in the data directory.
27
%%%-------------------------------------------------------------------
28
-module(ct_misc_1_SUITE).
32
-include_lib("common_test/include/ct.hrl").
33
-include_lib("test_server/include/test_server_line.hrl").
34
-include_lib("common_test/include/ct_event.hrl").
36
-define(eh, ct_test_support_eh).
38
%%--------------------------------------------------------------------
39
%% TEST SERVER CALLBACK FUNCTIONS
40
%%--------------------------------------------------------------------
42
%%--------------------------------------------------------------------
43
%% Description: Since Common Test starts another Test Server
44
%% instance, the tests need to be performed on a separate node (or
45
%% there will be clashes with logging processes etc).
46
%%--------------------------------------------------------------------
47
init_per_suite(Config) ->
48
Config1 = ct_test_support:init_per_suite(Config),
51
end_per_suite(Config) ->
52
ct_test_support:end_per_suite(Config).
54
init_per_testcase(TestCase, Config) ->
55
ct_test_support:init_per_testcase(TestCase, Config).
57
end_per_testcase(TestCase, Config) ->
58
ct_test_support:end_per_testcase(TestCase, Config).
60
suite() -> [{ct_hooks,[ts_install_cth]}].
63
[beam_me_up, {group,parse_table}].
66
[{parse_table,[parallel],
67
[parse_table_empty, parse_table_single,
68
parse_table_multiline_row,
69
parse_table_one_column_multiline,
70
parse_table_one_column_simple]}].
72
init_per_group(_GroupName, Config) ->
75
end_per_group(_GroupName, Config) ->
78
%%--------------------------------------------------------------------
80
%%--------------------------------------------------------------------
82
%%%-----------------------------------------------------------------
84
beam_me_up(Config) when is_list(Config) ->
85
DataDir = ?config(data_dir, Config),
86
CTNode = ?config(ct_node, Config),
88
%% Path = rpc:call(CTNode, code, get_path, []),
89
%% [_ | Parts] = lists:reverse(filename:split(DataDir)),
90
%% TSDir = filename:join(lists:reverse(Parts)),
91
%% true = rpc:call(CTNode, code, del_path, [TSDir]),
93
Mods = [beam_1_SUITE, beam_2_SUITE],
94
Suites = [atom_to_list(M) || M <- Mods],
95
[{error,_} = rpc:call(CTNode, code, load_file, [M]) || M <- Mods],
97
code:add_path(DataDir),
99
[compile:file(filename:join(DataDir,F),
100
[verbose,report_errors,
101
report_warnings,binary]) || F <- Suites],
103
[{module,_} = rpc:call(CTNode, code, load_binary,
104
[Mod, atom_to_list(Mod), Bin]) ||
105
{ok,Mod,Bin} <- CRes],
107
{Opts,ERPid} = setup([{suite,Suites},{auto_compile,false}], Config),
109
ok = ct_test_support:run(ct, run_test, [Opts], Config),
110
Events = ct_test_support:get_events(ERPid, Config),
112
ct_test_support:log_events(beam_me_up,
113
reformat(Events, ?eh),
114
?config(priv_dir, Config)),
116
TestEvents = events_to_check(beam_me_up, 1),
117
ok = ct_test_support:verify_events(TestEvents, Events, Config).
119
parse_table_empty(Config) when is_list(Config) ->
121
String = ["+----+-------+---------+---------+----------+------+--------+",
122
"| id | col11 | col2222 | col3333 | col4 | col5 | col6666 |",
123
"+----+-------+---------+---------+----------+------+--------+",
124
"+----+-------+---------+---------+----------+------+--------+",
125
"Query Done: 0 records selected"],
127
{{"id","col11","col2222","col3333","col4","col5","col6666"},[]} =
128
ct:parse_table(String).
131
parse_table_single(Config) when is_list(Config) ->
133
String = ["+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+",
134
"| id | col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 |",
135
"+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+",
136
"| 0 | 0 | -1407231560 | -256 | -1407231489 | 1500 | 1 | 1 | 1 |",
137
"+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+"
138
"Query Done: 1 record selected"],
140
{{"id","col1","col2","col3","col4","col5","col6","col7","col8"},
141
[{"0","0","-1407231560","-256","-1407231489", "1500","1","1","1"}]} =
142
ct:parse_table(String).
144
parse_table_multiline_row(Config) when is_list(Config) ->
146
String = ["+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+",
147
"| id | col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 |",
148
"+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+",
149
"| 0 | 0 | Free test string",
152
"| -256 | -1407231489 | 1500 | 1 | 1 | 1 |",
153
"+------+--------+--------------+------------+------------------+---------+--------+---------+-----------+"
154
"Query Done: 1 record selected"],
156
{{"id","col1","col2","col3","col4","col5","col6","col7","col8"},
157
[{"0","0","Free test string\n on more lines\nthan one\n",
158
"-256","-1407231489", "1500","1","1","1"}]} =
159
ct:parse_table(String).
161
parse_table_one_column_simple(Config) when is_list(Config) ->
163
String = ["|test|","|test value|"],
165
{{"test"},[{"test value"}]} = ct:parse_table(String).
167
parse_table_one_column_multiline(Config) when is_list(Config) ->
168
String = ["|test|","|test","value|"],
170
{{"test"},[{"test\nvalue"}]} = ct:parse_table(String).
172
%%%-----------------------------------------------------------------
174
%%%-----------------------------------------------------------------
176
setup(Test, Config) ->
177
Opts0 = ct_test_support:get_opts(Config),
178
Level = ?config(trace_level, Config),
179
EvHArgs = [{cbm,ct_test_support},{trace_level,Level}],
180
Opts = Opts0 ++ [{event_handler,{?eh,EvHArgs}}|Test],
181
ERPid = ct_test_support:start_event_receiver(Config),
184
reformat(Events, EH) ->
185
ct_test_support:reformat(Events, EH).
186
%reformat(Events, _EH) ->
189
%%%-----------------------------------------------------------------
191
%%%-----------------------------------------------------------------
192
events_to_check(Test) ->
193
%% 2 tests (ct:run_test + script_start) is default
194
events_to_check(Test, 2).
196
events_to_check(_, 0) ->
198
events_to_check(Test, N) ->
199
test_events(Test) ++ events_to_check(Test, N-1).
201
test_events(beam_me_up) ->
203
{?eh,start_logging,{'DEF','RUNDIR'}},
204
{?eh,test_start,{'DEF',{'START_TIME','LOGDIR'}}},
205
{?eh,start_info,{2,2,4}},
206
{?eh,tc_start,{beam_1_SUITE,init_per_suite}},
207
{?eh,tc_done,{beam_1_SUITE,init_per_suite,ok}},
208
{?eh,tc_start,{beam_1_SUITE,tc1}},
209
{?eh,tc_done,{beam_1_SUITE,tc1,ok}},
210
{?eh,test_stats,{1,0,{0,0}}},
211
{?eh,tc_start,{beam_1_SUITE,tc2}},
212
{?eh,tc_done,{beam_1_SUITE,tc2,{failed,{error,'tc2 failed'}}}},
213
{?eh,test_stats,{1,1,{0,0}}},
214
{?eh,tc_start,{beam_1_SUITE,end_per_suite}},
215
{?eh,tc_done,{beam_1_SUITE,end_per_suite,ok}},
216
{?eh,tc_start,{beam_2_SUITE,init_per_suite}},
217
{?eh,tc_done,{beam_2_SUITE,init_per_suite,ok}},
218
{?eh,tc_start,{beam_2_SUITE,tc1}},
219
{?eh,tc_done,{beam_2_SUITE,tc1,ok}},
220
{?eh,test_stats,{2,1,{0,0}}},
221
{?eh,tc_start,{beam_2_SUITE,tc2}},
222
{?eh,tc_done,{beam_2_SUITE,tc2,{failed,{error,'tc2 failed'}}}},
223
{?eh,test_stats,{2,2,{0,0}}},
224
{?eh,tc_start,{beam_2_SUITE,end_per_suite}},
225
{?eh,tc_done,{beam_2_SUITE,end_per_suite,ok}},
226
{?eh,test_done,{'DEF','STOP_TIME'}},
227
{?eh,stop_logging,[]}