Title: [159668] trunk/Tools
Revision
159668
Author
[email protected]
Date
2013-11-21 19:01:55 -0800 (Thu, 21 Nov 2013)

Log Message

webkitdirs::checkForArgumentAndRemoveFromArrayRef() removed wrong element
https://bugs.webkit.org/show_bug.cgi?id=124676

Patch by Nick Diego Yamane <[email protected]> on 2013-11-21
Reviewed by Daniel Bates.

checkForArgumentAndRemoveFromArrayRef functions was removing wrong
elements when there were more then one occurrence of that argument.
E.g: Checking for 'a' in {a, b, a, c}, the resulting array would be
{b, a}, when it should be {b, c}.

* Scripts/webkitdirs.pm:
(checkForArgumentAndRemoveFromArrayRef): bugfix mentioned above.
* Scripts/webkitperl/webkitdirs_unittest/checkForArgumentAndRemoveFromArrayRef.pl:
Added; Unit tests for webkitdirs::checkForArgumentAndRemoveFromArrayRef function.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (159667 => 159668)


--- trunk/Tools/ChangeLog	2013-11-22 03:01:26 UTC (rev 159667)
+++ trunk/Tools/ChangeLog	2013-11-22 03:01:55 UTC (rev 159668)
@@ -1,3 +1,20 @@
+2013-11-21  Nick Diego Yamane  <[email protected]>
+
+        webkitdirs::checkForArgumentAndRemoveFromArrayRef() removed wrong element
+        https://bugs.webkit.org/show_bug.cgi?id=124676
+
+        Reviewed by Daniel Bates.
+
+        checkForArgumentAndRemoveFromArrayRef functions was removing wrong
+        elements when there were more then one occurrence of that argument.
+        E.g: Checking for 'a' in {a, b, a, c}, the resulting array would be
+        {b, a}, when it should be {b, c}.
+
+        * Scripts/webkitdirs.pm:
+        (checkForArgumentAndRemoveFromArrayRef): bugfix mentioned above.
+        * Scripts/webkitperl/webkitdirs_unittest/checkForArgumentAndRemoveFromArrayRef.pl:
+        Added; Unit tests for webkitdirs::checkForArgumentAndRemoveFromArrayRef function.
+
 2013-11-21  Ryosuke Niwa  <[email protected]>
 
         Update build-webkit after r159550.

Modified: trunk/Tools/Scripts/webkitdirs.pm (159667 => 159668)


--- trunk/Tools/Scripts/webkitdirs.pm	2013-11-22 03:01:26 UTC (rev 159667)
+++ trunk/Tools/Scripts/webkitdirs.pm	2013-11-22 03:01:55 UTC (rev 159668)
@@ -876,8 +876,9 @@
 {
     my ($argToCheck, $arrayRef) = @_;
     my @indicesToRemove = findMatchingArguments($argToCheck, $arrayRef);
+    my $removeOffset = 0;
     foreach my $index (@indicesToRemove) {
-        splice(@$arrayRef, $index, 1);
+        splice(@$arrayRef, $index - $removeOffset++, 1);
     }
     return scalar @indicesToRemove > 0;
 }

Added: trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/checkForArgumentAndRemoveFromArrayRef.pl (0 => 159668)


--- trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/checkForArgumentAndRemoveFromArrayRef.pl	                        (rev 0)
+++ trunk/Tools/Scripts/webkitperl/webkitdirs_unittest/checkForArgumentAndRemoveFromArrayRef.pl	2013-11-22 03:01:55 UTC (rev 159668)
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+#
+# Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Unit tests of webkitdirs::checkForArgumentAndRemoveFromArrayRef
+use strict;
+use warnings;
+use Test::More;
+use webkitdirs;
+
+my @testCases = (
+{
+    argToCheck => "anything",
+    args => [],
+    expectedArgs => [],
+    expectedReturn => 0,
+    description => "Empty array"
+},
+{
+    argToCheck => "not-found",
+    args => ["a","b","c"],
+    expectedArgs => ["a","b","c"],
+    expectedReturn => 0,
+    description => "Not found"
+},
+{
+    argToCheck => "b",
+    args => ["a","b","c"],
+    expectedArgs => ["a","c"],
+    expectedReturn => 1,
+    description => "One occurrence"
+},
+{
+    argToCheck => "a",
+    args => ["a","b","a","c","a","x","a"],
+    expectedArgs => ["b","c","x"],
+    expectedReturn => 1,
+    description => "More than one occurrence"
+}
+);
+
+plan(tests => 2 * @testCases);
+
+foreach my $testCase (@testCases) {
+    my $result = checkForArgumentAndRemoveFromArrayRef($testCase->{argToCheck}, $testCase->{args});
+    ok($result == $testCase->{expectedReturn}, "checkForArgumentAndRemoveFromArrayRef: $testCase->{description} - result");
+    is_deeply($testCase->{args}, $testCase->{expectedArgs}, "checkForArgumentAndRemoveFromArrayRef: $testCase->{description} - array state");
+}
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to