testexecfw/symbianunittestfw/tsrc/eunit_to_symbianunit.pl
author Johnson Ma <johnson.ma@nokia.com>
Mon, 08 Mar 2010 15:03:44 +0800
changeset 0 3e07fef1e154
child 1 bbd31066657e
permissions -rw-r--r--
Initial EPL Contribution
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;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    21
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    22
# Main
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    23
my $root_dir = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
GetOptions("dir=s" => \$root_dir);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
if ($root_dir eq "") {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
    $root_dir = ".";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
convert_files_in_directory($root_dir);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
print "Conversion completed.\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    31
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
sub convert_files_in_directory {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
    my $dir_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
    print "Opening directory: " . $dir_name . "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    35
    opendir(DIR, $dir_name) || die "Cannot open directory " . $dir_name;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    36
    chdir($dir_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    37
    my @sourcefiles = readdir(DIR);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    38
    foreach (@sourcefiles) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    39
        if ( $_ =~ /.cpp$/i || $_ =~ /.h$/i || $_ =~ /.mmp$/i || $_ =~ /.def$/i) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    40
            # make the file writable (0666 is in linux/unix terms rw-)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    41
            chmod(0666,$_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    42
            print "Converting: ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    43
            print $_;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    44
            my $converted_file_content = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    45
            if (/.cpp$/ || /.h$/) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    46
                $converted_file_content = convert_source_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    47
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    48
            elsif (/.mmp$/) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    49
                $converted_file_content = convert_mmp_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    50
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    51
            else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    52
                $converted_file_content = convert_def_file_content($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    53
            }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    54
            open(my $result_file_handle, ">", $_) or die(". Writing " . $_ . " failed!\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    55
            print $result_file_handle $converted_file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    56
            close $result_file_handle;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    57
            print ". Done\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    58
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    59
        elsif ( /\./ ) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    60
            # Other types of files
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    61
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    62
        else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    63
            # Directories    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    64
            convert_files_in_directory($_);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    65
            chdir(".."); # After recursion change back to the current directory
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    66
        }
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
    closedir DIR;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
sub convert_source_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    75
    my $file_content = read_file_content_into_string($file_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
    # 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
    78
    my $symbianunit_constructor_content = "BASE_CONSTRUCT";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
    my $converted_test_table = convert_eunit_test_table($file_content);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
    $symbianunit_constructor_content .= $converted_test_table;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    81
    $file_content =~ s/CEUnitTestSuiteClass::ConstructL\(.*\)\;/$symbianunit_constructor_content/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
    # Remove the EUnit test table
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
    $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
    85
    $file_content =~ s/\/\/  TEST TABLE//ms;
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
    # Do rest of the conversions
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
    $file_content =~ s/#include <eunitmacros.h>/#include <symbianunittestmacros.h>/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
    $file_content =~ s/#include <ceunittestsuiteclass.h>/#include <symbianunittest.h>/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    90
    $file_content =~ s/#include <ceunittestsuite.h>/#include <symbianunittestsuite.h>/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    91
    $file_content =~ s/CEUnitTestSuiteClass/CSymbianUnitTest/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    92
    $file_content =~ s/CEUnitTestSuite/CSymbianUnitTestSuite/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
    $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g;  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    94
    $file_content =~ s/EUNIT_DECLARE_TEST_TABLE;//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    95
    $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
    96
    $file_content =~ s/EUNIT_ASSERT_LEAVE/SUT_ASSERT_LEAVE/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    97
    $file_content =~ s/EUNIT_ASSERT_EQUALS/SUT_ASSERT_EQUALS/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    98
    $file_content =~ s/EUNIT_ASSERT_NO_LEAVE//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    99
    $file_content =~ s/EUNIT_ASSERT/SUT_ASSERT/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   100
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   101
    return $file_content;
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
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   105
sub convert_mmp_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   106
    my $file_name = shift;
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
    my $file_content = read_file_content_into_string($file_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   109
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   110
    $file_content =~ s/eunit.lib/symbianunittestfw.lib/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   111
    $file_content =~ s/\/epoc32\/include\/Digia\/EUnit/\/epoc32\/include\/symbianunittest/gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   112
    $file_content =~ s/TARGETPATH(.*)\/DigiaEUnit\/Tests//gi;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   113
    $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
   114
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   115
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   116
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   117
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   118
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   119
sub convert_def_file_content {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   120
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   121
    
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   122
    my $file_content = read_file_content_into_string($file_name);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   123
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   124
    $file_content =~ s/MEUnitTest/MSymbianUnitTestInterface/g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   125
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   126
    return $file_content;
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
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   129
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   130
sub read_file_content_into_string {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   131
    my $file_name = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   132
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   133
    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
   134
    my @file_content_array = <$src_file_handle>;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   135
    my $file_content = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   136
    foreach (@file_content_array) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   137
        $file_content .= $_;
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
    close $src_file_handle;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   140
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   141
    return $file_content;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   142
}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   143
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   144
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   145
sub convert_eunit_test_table {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   146
    my $file_content = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   147
    my $converted_test_table = "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   148
    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
   149
        my $test_table_content = $1;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   150
        my @test_list = split(/EUNIT_TEST/, $test_table_content);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   151
        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
   152
        foreach (@test_list) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   153
            if ($_ =~ /\((.*)\)/ms) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   154
                $converted_test_table .= "\n";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   155
                $converted_test_table .= convert_eunit_test_entry($1);
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
        }
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
    return $converted_test_table;
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
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   162
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   163
sub convert_eunit_test_entry {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   164
    # Parameters for EUNIT_TEST:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   165
    # text1, text2, text3, text4, setupFunc, runFunc, teardownFunc
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   166
    my $eunit_test_parameters = shift;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   167
    # Remove whitespaces, tabs and line breaks
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   168
    $eunit_test_parameters =~ s/\s//g;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   169
    my @test_parameter_array = split(/,/, $eunit_test_parameters);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   170
    my $result = "";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   171
    if (@test_parameter_array == 7) {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   172
        if ($test_parameter_array[4] ne "SetupL" || 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   173
            $test_parameter_array[6] ne "Teardown") {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   174
            # Non-default setup or teardown used
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   175
            $result = "    ADD_SUT_WITH_SETUP_AND_TEARDOWN( ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   176
            $result .= $test_parameter_array[4];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   177
            $result .= ", ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   178
            $result .= $test_parameter_array[5];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   179
            $result .= ", ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   180
            $result .= $test_parameter_array[6];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   181
            $result .= " )";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   182
        }
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   183
        else {
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   184
            $result = "    ADD_SUT( ";
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   185
            $result .= $test_parameter_array[5];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   186
            $result .= " )";
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
    }   
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   189
    return $result;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   190
}