Home | History | Annotate | Download | only in VCSUtils_unittest
      1 #!/usr/bin/perl -w
      2 #
      3 # Copyright (C) 2010 Chris Jerdonek (cjerdonek (at] webkit.org)
      4 # Copyright (C) 2010 Research In Motion Limited. All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1.  Redistributions of source code must retain the above copyright
     10 #     notice, this list of conditions and the following disclaimer.
     11 # 2.  Redistributions in binary form must reproduce the above copyright
     12 #     notice, this list of conditions and the following disclaimer in the
     13 #     documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
     16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
     19 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     22 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25 
     26 # Unit tests for setChangeLogDateAndReviewer(fixChangeLogPatch()).
     27 
     28 use strict;
     29 use warnings;
     30 
     31 use Test::More;
     32 use VCSUtils;
     33 
     34 my @testCaseHashRefs = (
     35 {
     36     testName => "New entry inserted earlier in the file, but after an entry with the same author and date, patch applied a day later.",
     37     reviewer => "Sue",
     38     epochTime => 1273414321,
     39     patch => <<'END',
     40 --- ChangeLog
     41 +++ ChangeLog
     42 @@ -70,6 +70,14 @@
     43  
     44  2010-05-08  Alice  <alice@email.address>
     45  
     46 +        Reviewed by NOBODY (OOPS!).
     47 +
     48 +        Changed some more code on 2010-05-08.
     49 +
     50 +        * File:
     51 +
     52 +2010-05-08  Alice  <alice@email.address>
     53 +
     54          Reviewed by Ray.
     55  
     56          Changed some code on 2010-05-08.
     57 END
     58     expectedReturn => <<'END',
     59 --- ChangeLog
     60 +++ ChangeLog
     61 @@ -1,3 +1,11 @@
     62 +2010-05-09  Alice  <alice@email.address>
     63 +
     64 +        Reviewed by Sue.
     65 +
     66 +        Changed some more code on 2010-05-08.
     67 +
     68 +        * File:
     69 +
     70  2010-05-08  Alice  <alice@email.address>
     71  
     72          Reviewed by Ray.
     73 END
     74 },
     75 );
     76 
     77 my $testCasesCount = @testCaseHashRefs;
     78 plan(tests => 1 * $testCasesCount); # Total number of assertions.
     79 
     80 foreach my $testCase (@testCaseHashRefs) {
     81     my $testNameStart = "setChangeLogDateAndReviewer(fixChangeLogPatch()): $testCase->{testName}: comparing";
     82 
     83     my $patch = $testCase->{patch};
     84     my $reviewer = $testCase->{reviewer};
     85     my $epochTime = $testCase->{epochTime};
     86 
     87     my $fixedChangeLog = VCSUtils::fixChangeLogPatch($patch);
     88     my $got = VCSUtils::setChangeLogDateAndReviewer($fixedChangeLog->{patch}, $reviewer, $epochTime);
     89     my $expectedReturn = $testCase->{expectedReturn};
     90 
     91     is($got, $expectedReturn, "$testNameStart return value.");
     92 }
     93