sbsv1/abld/test/featurevariantmap/test.pl
author jjkang
Fri, 25 Jun 2010 17:29:25 +0800
changeset 599 fa7a3cc6effd
permissions -rw-r--r--
Add sbsv1 to new structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
# unit tests for featurevariantmap.pm
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
use strict;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
use Test;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
use File::Basename;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
use File::Spec;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
use lib "../../e32util";	# run from e32toolp/test/featuervariantmap
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
use lib "../e32util";		# run from e32toolp/test
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
use featurevariantmap;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
use File::Copy;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
use Digest::MD5;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
# how many tests do we plan to run?
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
BEGIN { plan tests => 56 }
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
# where is the test data
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
my $dir = File::Spec->rel2abs(dirname($0));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
print "# running in $dir\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
# Copy the features lists needed for this test to the right place
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
mkdir("$ENV{EPOCROOT}epoc32/include/variant/featurelists/");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
unlink "$ENV{EPOCROOT}epoc32/include/variant/featurelists/featnames.txt";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
copy("$dir/featnames.txt", "$ENV{EPOCROOT}epoc32/include/variant/featurelists/featnames.txt");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
# tests for Find                                                              #
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
# we wont find a non-existent file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
ok(featurevariantmap->Find("non-existant-file", "myvar"), "");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
# we will find a real file (with no vmap)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
ok(featurevariantmap->Find("$dir/fred.dll", "myvar"), "$dir/fred.dll");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
# we wont find a non-existent feature variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
print "# expect an ERROR from this test\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
ok(featurevariantmap->Find("$dir/john.dll", "not-a-variant"), "");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
# we will find a real feature variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
ok(featurevariantmap->Find("$dir/john.dll", "myvar"),
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
   "$dir/john.12345678901234567890123456789012.dll");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
# the feature variant name should not depend on case
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
ok(featurevariantmap->Find("$dir/john.dll", "MyVar"),
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
   "$dir/john.12345678901234567890123456789012.dll");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
# tests for Save                                                              #
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
# create a .vmap from scratch
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
unlink("$dir/tony.dll.vmap"); 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
ok(! featurevariantmap->Save("$dir/tony.dll", 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
     "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a_phone", "features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
# add to an existing .vmap file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
ok(! featurevariantmap->Save("$dir/tony.dll", 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
     "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "b_phone", "features_for_b1"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
ok(check("$dir/tony.dll.vmap", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","b_phone","features_for_b1"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
# change an entry in an existing .vmap file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
ok(! featurevariantmap->Save("$dir/tony.dll", 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
     "babababababababababababababababa", "b_phone", "features_for_b2"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
ok(check("$dir/tony.dll.vmap", "babababababababababababababababa","b_phone","features_for_b2"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
# change with one case and check with another
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
ok(! featurevariantmap->Save("$dir/tony.dll", 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
     "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba", "B_PhOnE", "features_for_b3"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
ok(check("$dir/tony.dll.vmap", "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba","b_phone","features_for_b3"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
# add an entry and a hint to an existing .vmap file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
my @hints = ("FEATUREVARIANT");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
ok(! featurevariantmap->Save("$dir/tony.dll", 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
     "cccccccccccccccccccccccccccccccc", "c_phone", "features_for_c", \@hints));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
ok(check("$dir/tony.dll.vmap", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","a_phone","features_for_a"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
ok(check("$dir/tony.dll.vmap", "abbbbbbbbbbbbbbbbbbbbbbbbbbbbbba","b_phone","features_for_b3"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
ok(check("$dir/tony.dll.vmap", "cccccccccccccccccccccccccccccccc","c_phone","features_for_c"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
ok(check("$dir/tony.dll.vmap", "FEATUREVARIANT"));
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
# tests for Hash                                                              #
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
# test the hash key for an invalid feature variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
my @src = ("$dir/a.cpp", "$dir/b.cpp");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
my %var = ('NAME' => 'something', 'VALID' => 0);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
ok(featurevariantmap->Hash(\@src, \%var), "");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
ok(featurevariantmap->HashAndFeatures(\@src, \%var), "");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
# test the hash key for a valid feature variant with missing headers
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
$var{'VALID'} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
ok(featurevariantmap->Hash(\@src, \%var), qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
# test the hash key for a working feature variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
$var{'BUILD_INCLUDES'} = ["$dir/inc_jack"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
my $h1 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
ok($h1, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=undefined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
# test the hash key for a different working feature variant
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
$var{'BUILD_INCLUDES'} = ["$dir/inc_noel", "$dir/inc_fake"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
my $h2 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
ok($h2, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
ok($h1 ne $h2);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,NOEL=undefined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
# test the hash key for a working feature variant with a pre-include
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
$var{'PREINCLUDE'} = "$dir/jack.hrh";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
$var{'BUILD_INCLUDES'} = ["$dir/inc_jack"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
my $h3 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
ok($h3, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
ok($h3 ne $h2);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
ok($h3 ne $h1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
# test that we get the same hash value when we should (jack2.hrh ~ jack.hrh)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
$var{'PREINCLUDE'} = "$dir/jack2.hrh";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
my $h3a = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
ok($h3a, $h3);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,JACK=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
# test the hash key for a different working feature variant with a pre-include
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
$var{'PREINCLUDE'} = "$dir/noel.hrh";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
$var{'BUILD_INCLUDES'} = ["$dir/inc_noel"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
my $h4 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
ok($h4, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
ok($h4 ne $h3);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
ok($h4 ne $h2);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
ok($h4 ne $h1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=undefined,BDEF=undefined,NOEL=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
# test the hash key for a different working feature variant with extra macros
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
$var{'PREINCLUDE'} = "$dir/noel.hrh";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
$var{'BUILD_INCLUDES'} = ["$dir/inc_noel"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
$var{'MACROS'} = ["ADEF"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
my $h5 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
ok($h5, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
ok($h5 ne $h4);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
ok($h5 ne $h3);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
ok($h5 ne $h2);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
ok($h5 ne $h1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=undefined,NOEL=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
$var{'MACROS'} = ["ADEF", "BDEF"];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
my $h6 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
ok($h6, qr/^[0-9a-f]{32}$/);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
ok($h6 ne $h5);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
ok($h6 ne $h4);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
ok($h6 ne $h3);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
ok($h6 ne $h2);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
ok($h6 ne $h1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=\'1\',NOEL=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
# test verbose mode
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
$featurevariantmap::verbose = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
print "# this test is verbose\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
my $h7 = featurevariantmap->Hash(\@src, \%var);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
ok($h7, $h6);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
print "# this test is verbose\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
ok(CompareHashAndFeatures(featurevariantmap->HashAndFeatures(\@src, \%var)), 'ADEF=\'1\',BDEF=\'1\',NOEL=defined');
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
# END OF TESTS                                                                #
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
###############################################################################
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
# utility functions
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
sub check
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
	my $file = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
	my $arg1 = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
	my $arg2 = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
	my $feat = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
	if ($arg2)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
		return checkHash($file, $arg1, $arg2, $feat);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
	return checkHint($file, $arg1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
sub checkHash
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
	my $file = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
	my $hash = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
	my $name = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
	my $feat = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
	open(FILE, $file) or return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
	my $hit = 0;	# found hash with the right name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
	my $bad = 0;	# found hash with the wrong name
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
	while (<FILE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
		if (/^$hash\s+(\w+)\s+$feat$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
			if (uc($1) eq uc($name))
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
				$hit = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
			else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
				$bad = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
	close(FILE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
	return ($hit && !$bad);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
sub checkHint
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
	my $file = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
	my $hint = shift;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
	open(FILE, $file) or return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
	while (<FILE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
		if (/^$hint\s*$/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
			close(FILE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
			return 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
	close(FILE);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
	return 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
# Check hash and feature list matches
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
sub CompareHashAndFeatures
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   259
	return if !$_[0] || !$_[1];
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   260
	return $_[1] if $_[0] eq Digest::MD5::md5_hex($_[1]);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   261
}