Merge "[Cherry-pick] Refactor WrapShape classes to BasicShape" into tizen_2.1
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / generate_test_file
1 #!/usr/bin/perl
2
3 # A script which generates a template test file using the macros available from
4 # utc_webkit2_ewk.h. The template file is generated in the same directory where this script is located.
5 #
6 # Execution:
7 #     ./generate_test_file <function-name> [<number-of-positive-tests>] [<number-of-negative-tests>]
8 #
9 # Parameters:       <function-name> - the core name of the tested function (e.g., ewk_init)
10 #           <number-of-positive-tests> - how many positive tests to generate (default 1)
11 #           <number-of-negative-tests> - how many negative tests to generate (default 1)
12 # Example:
13 # If you type the following command:
14 #     ./generate_test_file ewk_my_favourite_functionality
15 #
16 # The script will generate file named 'utc_webkit2_ewk_my_favourite_functionality_func.c'
17 # and will fill its body with template content (1 positive and 1 negative test).
18 # Places to be checked/modified are marked with 'TODO'.
19 #
20 # Author: Michal Roj <m.roj@samsung.com>
21 # Date: 2012-02-20
22
23
24 use Time::localtime;
25 use Cwd 'abs_path';
26 use File::Basename;
27
28 if(@ARGV eq 0) { die("Too few arguments"); }
29
30 $script_name = $0;
31 $pos_tests = 1;
32 $neg_tests = 1;
33
34 if(@ARGV > 1) {
35    $pos_tests = $ARGV[1];
36 }
37 if(@ARGV > 2) {
38    $neg_tests = $ARGV[2];
39 }
40
41 $dirname = dirname(abs_path($script_name));
42
43 $fun_name = $ARGV[0];
44 $file_name = "utc_webkit2_${fun_name}_func.c";
45
46 if(-f $file_name) { die("File $file_name exists!"); }
47
48 open(OUTFILE, ">${dirname}/${file_name}");
49
50 # generate generic header
51
52 $generic_header = <<HEADEND;
53 /*
54  * WebKit2 EFL
55  *
56  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
57  *
58  * This library is free software; you can redistribute it and/or modify it under
59  * the terms of the GNU Lesser General Public License as published by the
60  * Free Software Foundation; either version 2.1 of the License, or (at your option)
61  * any later version.
62  *
63  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
64  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
65  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
66  * License for more details.
67  *
68  * You should have received a copy of the GNU Lesser General Public License
69  * along with this library; if not, write to the Free Software Foundation, Inc., 51
70  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
71  *
72  */
73
74 HEADEND
75
76 # generate user/test-specific header
77
78 $user_name = `git config --global --get user.name`;
79 chomp($user_name);
80 $user_email = `git config --global --get user.email`;
81 chomp($user_email);
82 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
83 $year+=1900;
84 $mon+=1;
85 if($mon < 10) {
86     $mon_string = "0${mon}";
87 } else {
88     $mon_string = "${mon}";
89 }
90
91 if($mday < 10) {
92     $mday_string = "0${mday}";
93 } else {
94     $mday_string = "${mday}";
95 }
96
97 $date_string = "${year}-${mon_string}-${mday_string}";
98
99
100 $specific_header = <<HEADEND;
101 /**
102  * \@file $file_name
103  * \@author $user_name <${user_email}>
104  * \@date ${date_string}
105  * \@brief Tests EWK function ${fun_name}()
106  */
107
108 HEADEND
109
110 # generate init section for $pos_tests positive and $neg_tests negative test functions
111
112 $init_section = <<INITEND;
113 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */
114 #define TESTED_FUN_NAME ${fun_name}
115 #define POSITIVE_TEST_FUN_NUM ${pos_tests}
116 #define NEGATIVE_TEST_FUN_NUM ${neg_tests}
117
118 #include "utc_webkit2_ewk.h"
119
120 INITEND
121
122 # generate empty positive and empty negative test
123
124 $template_functions = "";
125 for($i=1; $i<=$pos_tests; $i++) {
126
127 $template_functions = $template_functions . <<ENDTEMPLATE;
128
129 /**
130  * \@brief Tests if (... TODO: add description of this test ...)
131  */
132 POS_TEST_FUN($i)
133 {
134     /* TODO: this code should use ${fun_name} and check its behaviour.
135     Results should be reported using one of utc_ macros */
136 }
137 ENDTEMPLATE
138 }
139
140 for($i=1; $i<=$neg_tests; $i++) {
141
142 $template_functions = $template_functions . <<ENDTEMPLATE;
143
144 /**
145  * \@brief Tests if (... TODO: add description of this test ...)
146  */
147 NEG_TEST_FUN($i)
148 {
149     /* TODO: this code should use ${fun_name} and check its behaviour.
150     Results should be reported using one of utc_ macros */
151 }
152 ENDTEMPLATE
153 }
154
155 # generate default startup/cleanup functions
156
157 $startup_cleanup = <<ENDDEFAULT;
158 /* Startup and cleanup functions */
159 static void startup(void)
160 {
161     utc_webkit2_ewk_test_init();
162 }
163
164 static void cleanup(void)
165 {
166     utc_webkit2_ewk_test_end();
167 }
168 ENDDEFAULT
169
170 print OUTFILE $generic_header, $specific_header, $init_section, $startup_cleanup, $template_functions;
171
172 close(OUTFILE);
173
174 print "File ${file_name} with ${pos_tests} positive tests and ${neg_tests} negative tests successfully generated.\n";
175 print "Don't forget adding the generated file to Makefile and tslist.\n";