1#!/usr/bin/perl -w
2#
3# Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1.  Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10# 2.  Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
18# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25# Unit tests of setChangeLogDateAndReviewer().
26
27use strict;
28use warnings;
29
30use Test::More;
31use VCSUtils;
32
33my @testCaseHashRefs = (
34{
35    testName => "reviewer defined and \"NOBODY (OOPS!)\" in leading junk",
36    reviewer => "John Doe",
37    epochTime => 1273414321,
38    patch => <<'END',
39Subject: [PATCH]
40
41Reviewed by NOBODY (OOPS!).
42
43diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
44--- a/WebCore/ChangeLog
45+++ b/WebCore/ChangeLog
46@@ -1,3 +1,15 @@
47+2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
48+
49+        Reviewed by NOBODY (OOPS!).
50+
51 2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
52
53         Reviewed by Jane Doe.
54END
55    expectedReturn => <<'END',
56Subject: [PATCH]
57
58Reviewed by NOBODY (OOPS!).
59
60diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
61--- a/WebCore/ChangeLog
62+++ b/WebCore/ChangeLog
63@@ -1,3 +1,15 @@
64+2010-05-09  Chris Jerdonek  <cjerdonek@webkit.org>
65+
66+        Reviewed by John Doe.
67+
68 2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
69
70         Reviewed by Jane Doe.
71END
72},
73{
74    testName => "reviewer not defined and \"NOBODY (OOPS!)\" in leading junk",
75    reviewer => undef,
76    epochTime => 1273414321,
77    patch => <<'END',
78Subject: [PATCH]
79
80Reviewed by NOBODY (OOPS!).
81
82diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
83--- a/WebCore/ChangeLog
84+++ b/WebCore/ChangeLog
85@@ -1,3 +1,15 @@
86+2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
87+
88+        Reviewed by NOBODY (OOPS!).
89+
90 2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
91
92         Reviewed by Jane Doe.
93END
94    expectedReturn => <<'END',
95Subject: [PATCH]
96
97Reviewed by NOBODY (OOPS!).
98
99diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
100--- a/WebCore/ChangeLog
101+++ b/WebCore/ChangeLog
102@@ -1,3 +1,15 @@
103+2010-05-09  Chris Jerdonek  <cjerdonek@webkit.org>
104+
105+        Reviewed by NOBODY (OOPS!).
106+
107 2010-05-08  Chris Jerdonek  <cjerdonek@webkit.org>
108
109         Reviewed by Jane Doe.
110END
111},
112);
113
114my $testCasesCount = @testCaseHashRefs;
115plan(tests => 1 * $testCasesCount); # Total number of assertions.
116
117foreach my $testCase (@testCaseHashRefs) {
118    my $testNameStart = "setChangeLogDateAndReviewer(): $testCase->{testName}: comparing";
119
120    my $patch = $testCase->{patch};
121    my $reviewer = $testCase->{reviewer};
122    my $epochTime = $testCase->{epochTime};
123
124    my $got = VCSUtils::setChangeLogDateAndReviewer($patch, $reviewer, $epochTime);
125    my $expectedReturn = $testCase->{expectedReturn};
126
127    is($got, $expectedReturn, "$testNameStart return value.");
128}
129