testexecfw/symbianunittestfw/tsrc/eunit_to_symbianunit.pl
author Johnson Ma <johnson.ma@nokia.com>
Mon, 29 Mar 2010 14:46:27 +0800
changeset 1 bbd31066657e
parent 0 3e07fef1e154
permissions -rw-r--r--
publish symbianunittest v1.1.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     1
#
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     3
# All rights reserved.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     8
#
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     9
# Initial Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    11
#
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    12
# Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    13
#
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    14
# Description: 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    15
#
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    16
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    17
#!/usr/bin/perl
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    18
use strict;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    19
use warnings;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    20
use Getopt::Long;
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    21
#use Cwd 'abs_path';
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    22
use Cwd;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    23
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
# Main
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
my $root_dir = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
GetOptions("dir=s" => \$root_dir);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
if ($root_dir eq "") {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
    $root_dir = ".";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
}
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    31
convert_cpp_in_directory($root_dir);
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
convert_files_in_directory($root_dir);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
print "Conversion completed.\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    35
sub convert_cpp_in_directory {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    36
    my $dir_name = shift;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    37
    print "Opening directory: " . $dir_name . "\n";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    38
    opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    39
    chdir($dir_name);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    40
    my @sourcefiles = readdir(DIR);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    41
    foreach (@sourcefiles) {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    42
        if ( $_ =~ /.cpp$/i ) {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    43
            # make the file writable (0666 is in linux/unix terms rw-)
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    44
            chmod(0666,$_);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    45
            print "Converting: ";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    46
            print $_;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    47
            my $converted_file_content = "";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    48
            if (/.cpp$/ ) {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    49
                $converted_file_content = convert_source_file_content($_);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    50
            }
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    51
	    open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n");
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    52
	    print $result_file_handle $converted_file_content;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    53
	    close $result_file_handle;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    54
            print ". Done\n";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    55
        }
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    56
        elsif ( /\./ ) {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    57
            # Other types of files
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    58
        }
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    59
        else {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    60
            # Directories    
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    61
            convert_cpp_in_directory($_);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    62
            chdir(".."); # After recursion change back to the current directory
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    63
        }
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    64
    }
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    65
    closedir DIR;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    66
}
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    67
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    68
sub convert_files_in_directory {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
    my $dir_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
    print "Opening directory: " . $dir_name . "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
    opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
    chdir($dir_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
    my @sourcefiles = readdir(DIR);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
    foreach (@sourcefiles) {
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    75
        if ( $_ =~ /.h$/i || $_ =~ /.mmp$/i || $_ =~ /.def$/i) {
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
            # make the file writable (0666 is in linux/unix terms rw-)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
            chmod(0666,$_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    78
            print "Converting: ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
            print $_;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
            my $converted_file_content = "";
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    81
            if (/.h$/) {
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
                $converted_file_content = convert_source_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
            elsif (/.mmp$/) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    85
                $converted_file_content = convert_mmp_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    86
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    87
            else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
                $converted_file_content = convert_def_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
            }
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    90
	    open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n");
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    91
	    print $result_file_handle $converted_file_content;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
    92
	    close $result_file_handle;
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
            print ". Done\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    94
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    95
        elsif ( /\./ ) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    96
            # Other types of files
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    97
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    98
        else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    99
            # Directories    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   100
            convert_files_in_directory($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   101
            chdir(".."); # After recursion change back to the current directory
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   102
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   103
    }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   104
    closedir DIR;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   105
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   106
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   107
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   108
sub convert_source_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   109
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   110
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   111
    my $file_content = read_file_content_into_string($file_name);
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   112
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   113
    #check if this source include a separate test table header file
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   114
    #in that case, we need to insert the test table content from header first
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   115
    if ($file_content =~ m/\#include\s*\"(.*)testtable\.h\"/) {
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   116
	    my $curpath = cwd; 
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   117
            my $table_file_name = $curpath . "/../inc/" . $1 . "testtable.h";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   118
	    print "\n    try to merge header file at: " . $table_file_name . "\n";
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   119
            my $tabledef = read_file_content_into_string($table_file_name);
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   120
	    #remove copyright and other comments
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   121
            $tabledef =~ s/\/\/.*|\/\*[\s\S]*?\*\///g;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   122
            $tabledef =~ s/#include\s*\".*\"//g;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   123
            $file_content =~ s/\#include\s*\".*testtable\.h\"/$tabledef/g;  
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   124
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   125
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   126
    }
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   127
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   128
    # Convert the EUnit test table to SymbianUnit tests and move it to the constructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   129
    my $symbianunit_constructor_content = "BASE_CONSTRUCT";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   130
    my $converted_test_table = convert_eunit_test_table($file_content);
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   131
    #print "converted test table: " . $converted_test_table . "\n";
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   132
    $symbianunit_constructor_content .= $converted_test_table;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   133
    $file_content =~ s/CEUnitTestSuiteClass::ConstructL\(.*\)\;/$symbianunit_constructor_content/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   134
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   135
    # Remove the EUnit test table
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   136
    $file_content =~ s/EUNIT_BEGIN_TEST_TABLE(.*)EUNIT_END_TEST_TABLE//ms;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   137
    $file_content =~ s/\/\/  TEST TABLE//ms;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   138
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   139
    # Do rest of the conversions
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   140
    $file_content =~ s/#include <eunitmacros.h>/#include <symbianunittestmacros.h>/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   141
    $file_content =~ s/#include <ceunittestsuiteclass.h>/#include <symbianunittest.h>/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   142
    $file_content =~ s/#include <ceunittestsuite.h>/#include <symbianunittestsuite.h>/gi;
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   143
    $file_content =~ s/#include <eunitdecorators.h>//gi;
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   144
    $file_content =~ s/CEUnitTestSuiteClass/CSymbianUnitTest/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   145
    $file_content =~ s/CEUnitTestSuite/CSymbianUnitTestSuite/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   146
    $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g;  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   147
    $file_content =~ s/EUNIT_DECLARE_TEST_TABLE;//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   148
    $file_content =~ s/EUNIT_ASSERT_SPECIFIC_LEAVE/SUT_ASSERT_LEAVE_WITH/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   149
    $file_content =~ s/EUNIT_ASSERT_LEAVE/SUT_ASSERT_LEAVE/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   150
    $file_content =~ s/EUNIT_ASSERT_EQUALS/SUT_ASSERT_EQUALS/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   151
    $file_content =~ s/EUNIT_ASSERT_NO_LEAVE//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   152
    $file_content =~ s/EUNIT_ASSERT/SUT_ASSERT/g;
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   153
    $file_content =~ s/EUNIT_ASSERT_DESC/SUT_ASSERT_DESC/g;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   154
    $file_content =~ s/EUNIT_ASSERT_EQUALS_DESC/SUT_ASSERT_EQUALS_DESC/g;
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   155
    $file_content =~ s/EUNIT_PRINT/\/\/EUNIT_PRINT/g;
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   156
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   157
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   158
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   159
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   160
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   161
sub convert_mmp_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   162
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   163
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   164
    my $file_content = read_file_content_into_string($file_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   165
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   166
    $file_content =~ s/eunit.lib/symbianunittestfw.lib/gi;
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   167
    $file_content =~ s/eunitutil.lib//gi;
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   168
    $file_content =~ s/\/epoc32\/include\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi;
1
bbd31066657e publish symbianunittest v1.1.0
Johnson Ma <johnson.ma@nokia.com>
parents: 0
diff changeset
   169
    $file_content =~ s/\/epoc32\/include\/platform\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi;
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   170
    $file_content =~ s/TARGETPATH(.*)\/DigiaEUnit\/Tests//gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   171
    $file_content =~ s/UID(.*)0x1000af5a/MACRO SYMBIAN_UNIT_TEST\nUID 0x20022E76/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   172
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   173
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   174
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   175
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   176
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   177
sub convert_def_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   178
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   179
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   180
    my $file_content = read_file_content_into_string($file_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   181
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   182
    $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   183
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   184
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   185
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   186
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   187
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   188
sub read_file_content_into_string {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   189
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   190
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   191
    open(my $src_file_handle, "<", $file_name) or die("\nFile not found!\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   192
    my @file_content_array = <$src_file_handle>;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   193
    my $file_content = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   194
    foreach (@file_content_array) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   195
        $file_content .= $_;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   196
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   197
    close $src_file_handle;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   198
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   199
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   200
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   201
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   202
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   203
sub convert_eunit_test_table {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   204
    my $file_content = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   205
    my $converted_test_table = "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   206
    if ($file_content =~ /EUNIT_BEGIN_TEST_TABLE(.*)EUNIT_END_TEST_TABLE/ms) {  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   207
        my $test_table_content = $1;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   208
        my @test_list = split(/EUNIT_TEST/, $test_table_content);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   209
        shift @test_list; # Remove the test table parameters before the first test
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   210
        foreach (@test_list) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   211
            if ($_ =~ /\((.*)\)/ms) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   212
                $converted_test_table .= "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   213
                $converted_test_table .= convert_eunit_test_entry($1);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   214
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   215
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   216
    }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   217
    return $converted_test_table;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   218
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   219
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   220
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   221
sub convert_eunit_test_entry {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   222
    # Parameters for EUNIT_TEST:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   223
    # text1, text2, text3, text4, setupFunc, runFunc, teardownFunc
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   224
    my $eunit_test_parameters = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   225
    # Remove whitespaces, tabs and line breaks
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   226
    $eunit_test_parameters =~ s/\s//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   227
    my @test_parameter_array = split(/,/, $eunit_test_parameters);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   228
    my $result = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   229
    if (@test_parameter_array == 7) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   230
        if ($test_parameter_array[4] ne "SetupL" || 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   231
            $test_parameter_array[6] ne "Teardown") {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   232
            # Non-default setup or teardown used
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   233
            $result = "    ADD_SUT_WITH_SETUP_AND_TEARDOWN( ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   234
            $result .= $test_parameter_array[4];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   235
            $result .= ", ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   236
            $result .= $test_parameter_array[5];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   237
            $result .= ", ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   238
            $result .= $test_parameter_array[6];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   239
            $result .= " )";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   240
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   241
        else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   242
            $result = "    ADD_SUT( ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   243
            $result .= $test_parameter_array[5];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   244
            $result .= " )";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   245
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   246
    }   
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   247
    return $result;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   248
}