16 |
16 |
17 #!/usr/bin/perl |
17 #!/usr/bin/perl |
18 use strict; |
18 use strict; |
19 use warnings; |
19 use warnings; |
20 use Getopt::Long; |
20 use Getopt::Long; |
|
21 #use Cwd 'abs_path'; |
|
22 use Cwd; |
|
23 |
21 |
24 |
22 # Main |
25 # Main |
23 my $root_dir = ""; |
26 my $root_dir = ""; |
24 GetOptions("dir=s" => \$root_dir); |
27 GetOptions("dir=s" => \$root_dir); |
25 if ($root_dir eq "") { |
28 if ($root_dir eq "") { |
26 $root_dir = "."; |
29 $root_dir = "."; |
27 } |
30 } |
|
31 convert_cpp_in_directory($root_dir); |
28 convert_files_in_directory($root_dir); |
32 convert_files_in_directory($root_dir); |
29 print "Conversion completed.\n"; |
33 print "Conversion completed.\n"; |
30 |
34 |
|
35 sub convert_cpp_in_directory { |
|
36 my $dir_name = shift; |
|
37 print "Opening directory: " . $dir_name . "\n"; |
|
38 opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name; |
|
39 chdir($dir_name); |
|
40 my @sourcefiles = readdir(DIR); |
|
41 foreach (@sourcefiles) { |
|
42 if ( $_ =~ /.cpp$/i ) { |
|
43 # make the file writable (0666 is in linux/unix terms rw-) |
|
44 chmod(0666,$_); |
|
45 print "Converting: "; |
|
46 print $_; |
|
47 my $converted_file_content = ""; |
|
48 if (/.cpp$/ ) { |
|
49 $converted_file_content = convert_source_file_content($_); |
|
50 } |
|
51 open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n"); |
|
52 print $result_file_handle $converted_file_content; |
|
53 close $result_file_handle; |
|
54 print ". Done\n"; |
|
55 } |
|
56 elsif ( /\./ ) { |
|
57 # Other types of files |
|
58 } |
|
59 else { |
|
60 # Directories |
|
61 convert_cpp_in_directory($_); |
|
62 chdir(".."); # After recursion change back to the current directory |
|
63 } |
|
64 } |
|
65 closedir DIR; |
|
66 } |
31 |
67 |
32 sub convert_files_in_directory { |
68 sub convert_files_in_directory { |
33 my $dir_name = shift; |
69 my $dir_name = shift; |
34 print "Opening directory: " . $dir_name . "\n"; |
70 print "Opening directory: " . $dir_name . "\n"; |
35 opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name; |
71 opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name; |
36 chdir($dir_name); |
72 chdir($dir_name); |
37 my @sourcefiles = readdir(DIR); |
73 my @sourcefiles = readdir(DIR); |
38 foreach (@sourcefiles) { |
74 foreach (@sourcefiles) { |
39 if ( $_ =~ /.cpp$/i || $_ =~ /.h$/i || $_ =~ /.mmp$/i || $_ =~ /.def$/i) { |
75 if ( $_ =~ /.h$/i || $_ =~ /.mmp$/i || $_ =~ /.def$/i) { |
40 # make the file writable (0666 is in linux/unix terms rw-) |
76 # make the file writable (0666 is in linux/unix terms rw-) |
41 chmod(0666,$_); |
77 chmod(0666,$_); |
42 print "Converting: "; |
78 print "Converting: "; |
43 print $_; |
79 print $_; |
44 my $converted_file_content = ""; |
80 my $converted_file_content = ""; |
45 if (/.cpp$/ || /.h$/) { |
81 if (/.h$/) { |
46 $converted_file_content = convert_source_file_content($_); |
82 $converted_file_content = convert_source_file_content($_); |
47 } |
83 } |
48 elsif (/.mmp$/) { |
84 elsif (/.mmp$/) { |
49 $converted_file_content = convert_mmp_file_content($_); |
85 $converted_file_content = convert_mmp_file_content($_); |
50 } |
86 } |
51 else { |
87 else { |
52 $converted_file_content = convert_def_file_content($_); |
88 $converted_file_content = convert_def_file_content($_); |
53 } |
89 } |
54 open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n"); |
90 open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n"); |
55 print $result_file_handle $converted_file_content; |
91 print $result_file_handle $converted_file_content; |
56 close $result_file_handle; |
92 close $result_file_handle; |
57 print ". Done\n"; |
93 print ". Done\n"; |
58 } |
94 } |
59 elsif ( /\./ ) { |
95 elsif ( /\./ ) { |
60 # Other types of files |
96 # Other types of files |
61 } |
97 } |
71 |
107 |
72 sub convert_source_file_content { |
108 sub convert_source_file_content { |
73 my $file_name = shift; |
109 my $file_name = shift; |
74 |
110 |
75 my $file_content = read_file_content_into_string($file_name); |
111 my $file_content = read_file_content_into_string($file_name); |
|
112 |
|
113 #check if this source include a separate test table header file |
|
114 #in that case, we need to insert the test table content from header first |
|
115 if ($file_content =~ m/\#include\s*\"(.*)testtable\.h\"/) { |
|
116 my $curpath = cwd; |
|
117 my $table_file_name = $curpath . "/../inc/" . $1 . "testtable.h"; |
|
118 print "\n try to merge header file at: " . $table_file_name . "\n"; |
|
119 my $tabledef = read_file_content_into_string($table_file_name); |
|
120 #remove copyright and other comments |
|
121 $tabledef =~ s/\/\/.*|\/\*[\s\S]*?\*\///g; |
|
122 $tabledef =~ s/#include\s*\".*\"//g; |
|
123 $file_content =~ s/\#include\s*\".*testtable\.h\"/$tabledef/g; |
|
124 |
|
125 |
|
126 } |
76 |
127 |
77 # Convert the EUnit test table to SymbianUnit tests and move it to the constructor |
128 # Convert the EUnit test table to SymbianUnit tests and move it to the constructor |
78 my $symbianunit_constructor_content = "BASE_CONSTRUCT"; |
129 my $symbianunit_constructor_content = "BASE_CONSTRUCT"; |
79 my $converted_test_table = convert_eunit_test_table($file_content); |
130 my $converted_test_table = convert_eunit_test_table($file_content); |
|
131 #print "converted test table: " . $converted_test_table . "\n"; |
80 $symbianunit_constructor_content .= $converted_test_table; |
132 $symbianunit_constructor_content .= $converted_test_table; |
81 $file_content =~ s/CEUnitTestSuiteClass::ConstructL\(.*\)\;/$symbianunit_constructor_content/g; |
133 $file_content =~ s/CEUnitTestSuiteClass::ConstructL\(.*\)\;/$symbianunit_constructor_content/g; |
82 |
134 |
83 # Remove the EUnit test table |
135 # Remove the EUnit test table |
84 $file_content =~ s/EUNIT_BEGIN_TEST_TABLE(.*)EUNIT_END_TEST_TABLE//ms; |
136 $file_content =~ s/EUNIT_BEGIN_TEST_TABLE(.*)EUNIT_END_TEST_TABLE//ms; |
86 |
138 |
87 # Do rest of the conversions |
139 # Do rest of the conversions |
88 $file_content =~ s/#include <eunitmacros.h>/#include <symbianunittestmacros.h>/gi; |
140 $file_content =~ s/#include <eunitmacros.h>/#include <symbianunittestmacros.h>/gi; |
89 $file_content =~ s/#include <ceunittestsuiteclass.h>/#include <symbianunittest.h>/gi; |
141 $file_content =~ s/#include <ceunittestsuiteclass.h>/#include <symbianunittest.h>/gi; |
90 $file_content =~ s/#include <ceunittestsuite.h>/#include <symbianunittestsuite.h>/gi; |
142 $file_content =~ s/#include <ceunittestsuite.h>/#include <symbianunittestsuite.h>/gi; |
|
143 $file_content =~ s/#include <eunitdecorators.h>//gi; |
91 $file_content =~ s/CEUnitTestSuiteClass/CSymbianUnitTest/g; |
144 $file_content =~ s/CEUnitTestSuiteClass/CSymbianUnitTest/g; |
92 $file_content =~ s/CEUnitTestSuite/CSymbianUnitTestSuite/g; |
145 $file_content =~ s/CEUnitTestSuite/CSymbianUnitTestSuite/g; |
93 $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g; |
146 $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g; |
94 $file_content =~ s/EUNIT_DECLARE_TEST_TABLE;//g; |
147 $file_content =~ s/EUNIT_DECLARE_TEST_TABLE;//g; |
95 $file_content =~ s/EUNIT_ASSERT_SPECIFIC_LEAVE/SUT_ASSERT_LEAVE_WITH/g; |
148 $file_content =~ s/EUNIT_ASSERT_SPECIFIC_LEAVE/SUT_ASSERT_LEAVE_WITH/g; |
96 $file_content =~ s/EUNIT_ASSERT_LEAVE/SUT_ASSERT_LEAVE/g; |
149 $file_content =~ s/EUNIT_ASSERT_LEAVE/SUT_ASSERT_LEAVE/g; |
97 $file_content =~ s/EUNIT_ASSERT_EQUALS/SUT_ASSERT_EQUALS/g; |
150 $file_content =~ s/EUNIT_ASSERT_EQUALS/SUT_ASSERT_EQUALS/g; |
98 $file_content =~ s/EUNIT_ASSERT_NO_LEAVE//g; |
151 $file_content =~ s/EUNIT_ASSERT_NO_LEAVE//g; |
99 $file_content =~ s/EUNIT_ASSERT/SUT_ASSERT/g; |
152 $file_content =~ s/EUNIT_ASSERT/SUT_ASSERT/g; |
|
153 $file_content =~ s/EUNIT_ASSERT_DESC/SUT_ASSERT_DESC/g; |
|
154 $file_content =~ s/EUNIT_ASSERT_EQUALS_DESC/SUT_ASSERT_EQUALS_DESC/g; |
|
155 $file_content =~ s/EUNIT_PRINT/\/\/EUNIT_PRINT/g; |
100 |
156 |
101 return $file_content; |
157 return $file_content; |
102 } |
158 } |
103 |
159 |
104 |
160 |
106 my $file_name = shift; |
162 my $file_name = shift; |
107 |
163 |
108 my $file_content = read_file_content_into_string($file_name); |
164 my $file_content = read_file_content_into_string($file_name); |
109 |
165 |
110 $file_content =~ s/eunit.lib/symbianunittestfw.lib/gi; |
166 $file_content =~ s/eunit.lib/symbianunittestfw.lib/gi; |
|
167 $file_content =~ s/eunitutil.lib//gi; |
111 $file_content =~ s/\/epoc32\/include\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi; |
168 $file_content =~ s/\/epoc32\/include\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi; |
|
169 $file_content =~ s/\/epoc32\/include\/platform\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi; |
112 $file_content =~ s/TARGETPATH(.*)\/DigiaEUnit\/Tests//gi; |
170 $file_content =~ s/TARGETPATH(.*)\/DigiaEUnit\/Tests//gi; |
113 $file_content =~ s/UID(.*)0x1000af5a/MACRO SYMBIAN_UNIT_TEST\nUID 0x20022E76/gi; |
171 $file_content =~ s/UID(.*)0x1000af5a/MACRO SYMBIAN_UNIT_TEST\nUID 0x20022E76/gi; |
114 |
172 |
115 return $file_content; |
173 return $file_content; |
116 } |
174 } |