1#!/usr/bin/perl -w 2# 3# Copyright (C) Research in Motion Limited 2010. All Rights Reserved. 4# Copyright (C) 2010 Chris Jerdonek (chris.jerdonek@gmail.com) 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: 9# 10# * Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# * Redistributions in binary form must reproduce the above 13# copyright notice, this list of conditions and the following disclaimer 14# in the documentation and/or other materials provided with the 15# distribution. 16# * Neither the name of Apple Computer, Inc. ("Apple") nor the names of 17# its contributors may be used to endorse or promote products derived 18# from this software without specific prior written permission. 19# 20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32# Unit tests of parseSvnDiffProperties(). 33 34use strict; 35use warnings; 36 37use Test::More; 38use VCSUtils; 39 40my @testCaseHashRefs = ( 41#### 42# Simple test cases 43## 44{ 45 # New test 46 diffName => "simple: add svn:executable", 47 inputText => <<'END', 48Property changes on: FileA 49___________________________________________________________________ 50Added: svn:executable 51 + * 52END 53 expectedReturn => [ 54{ 55 propertyPath => "FileA", 56 executableBitDelta => 1, 57}, 58undef], 59 expectedNextLine => undef, 60}, 61{ 62 # New test 63 diffName => "simple: add svn:mergeinfo", 64 inputText => <<'END', 65Property changes on: Makefile 66___________________________________________________________________ 67Added: svn:mergeinfo 68 Merged /trunk/Makefile:r33020 69END 70 expectedReturn => [ 71{ 72 propertyPath => "Makefile", 73}, 74undef], 75 expectedNextLine => undef, 76}, 77{ 78 # New test 79 diffName => "simple: delete svn:mergeinfo", 80 inputText => <<'END', 81Property changes on: Makefile 82___________________________________________________________________ 83Deleted: svn:mergeinfo 84 Reverse-merged /trunk/Makefile:r33020 85END 86 expectedReturn => [ 87{ 88 propertyPath => "Makefile", 89}, 90undef], 91 expectedNextLine => undef, 92}, 93{ 94 # New test 95 diffName => "simple: modified svn:mergeinfo", 96 inputText => <<'END', 97Property changes on: Makefile 98___________________________________________________________________ 99Modified: svn:mergeinfo 100 Reverse-merged /trunk/Makefile:r33020 101 Merged /trunk/Makefile:r41697 102END 103 expectedReturn => [ 104{ 105 propertyPath => "Makefile", 106}, 107undef], 108 expectedNextLine => undef, 109}, 110{ 111 # New test 112 diffName => "simple: delete svn:executable", 113 inputText => <<'END', 114Property changes on: FileA 115___________________________________________________________________ 116Deleted: svn:executable 117 - * 118END 119 expectedReturn => [ 120{ 121 propertyPath => "FileA", 122 executableBitDelta => -1, 123}, 124undef], 125 expectedNextLine => undef, 126}, 127{ 128 # New test 129 diffName => "simple: delete svn:executable using SVN 1.4 syntax", 130 inputText => <<'END', 131Property changes on: FileA 132___________________________________________________________________ 133Name: svn:executable 134 - * 135END 136 expectedReturn => [ 137{ 138 propertyPath => "FileA", 139 executableBitDelta => -1, 140}, 141undef], 142 expectedNextLine => undef, 143}, 144#### 145# Property value followed by empty line and start of next diff 146## 147{ 148 # New test 149 diffName => "add svn:executable, followed by empty line and start of next diff", 150 inputText => <<'END', 151Property changes on: FileA 152___________________________________________________________________ 153Added: svn:executable 154 + * 155 156Index: Makefile.shared 157END 158 expectedReturn => [ 159{ 160 propertyPath => "FileA", 161 executableBitDelta => 1, 162}, 163"\n"], 164 expectedNextLine => "Index: Makefile.shared\n", 165}, 166{ 167 # New test 168 diffName => "add svn:executable, followed by empty line and start of next property diff", 169 inputText => <<'END', 170Property changes on: FileA 171___________________________________________________________________ 172Added: svn:executable 173 + * 174 175Property changes on: Makefile.shared 176END 177 expectedReturn => [ 178{ 179 propertyPath => "FileA", 180 executableBitDelta => 1, 181}, 182"\n"], 183 expectedNextLine => "Property changes on: Makefile.shared\n", 184}, 185#### 186# Property value followed by empty line and start of the binary contents 187## 188{ 189 # New test 190 diffName => "add svn:executable, followed by empty line and start of binary contents", 191 inputText => <<'END', 192Property changes on: FileA 193___________________________________________________________________ 194Added: svn:executable 195 + * 196 197Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 198END 199 expectedReturn => [ 200{ 201 propertyPath => "FileA", 202 executableBitDelta => 1, 203}, 204"\n"], 205 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n", 206}, 207{ 208 # New test 209 diffName => "custom property followed by svn:executable, empty line and start of binary contents", 210 inputText => <<'END', 211Property changes on: FileA 212___________________________________________________________________ 213Added: documentation 214 + This is an example sentence. 215Added: svn:executable 216 + * 217 218Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 219END 220 expectedReturn => [ 221{ 222 propertyPath => "FileA", 223 executableBitDelta => 1, 224}, 225"\n"], 226 expectedNextLine => "Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA==\n", 227}, 228#### 229# Successive properties 230## 231{ 232 # New test 233 diffName => "svn:executable followed by custom property", 234 inputText => <<'END', 235Property changes on: FileA 236___________________________________________________________________ 237Added: svn:executable 238 + * 239Added: documentation 240 + This is an example sentence. 241END 242 expectedReturn => [ 243{ 244 propertyPath => "FileA", 245 executableBitDelta => 1, 246}, 247undef], 248 expectedNextLine => undef, 249}, 250{ 251 # New test 252 diffName => "custom property followed by svn:executable", 253 inputText => <<'END', 254Property changes on: FileA 255___________________________________________________________________ 256Added: documentation 257 + This is an example sentence. 258Added: svn:executable 259 + * 260END 261 expectedReturn => [ 262{ 263 propertyPath => "FileA", 264 executableBitDelta => 1, 265}, 266undef], 267 expectedNextLine => undef, 268}, 269#### 270# Successive properties followed by empty line and start of next diff 271## 272{ 273 # New test 274 diffName => "custom property followed by svn:executable, empty line and start of next property diff", 275 inputText => <<'END', 276Property changes on: FileA 277___________________________________________________________________ 278Added: documentation 279 + This is an example sentence. 280Added: svn:executable 281 + * 282 283Property changes on: Makefile.shared 284END 285 expectedReturn => [ 286{ 287 propertyPath => "FileA", 288 executableBitDelta => 1, 289}, 290"\n"], 291 expectedNextLine => "Property changes on: Makefile.shared\n", 292}, 293{ 294 # New test 295 diffName => "custom property followed by svn:executable, empty line and start of next index diff", 296 inputText => <<'END', 297Property changes on: FileA 298___________________________________________________________________ 299Added: documentation 300 + This is an example sentence. 301Added: svn:executable 302 + * 303 304Index: Makefile.shared 305END 306 expectedReturn => [ 307{ 308 propertyPath => "FileA", 309 executableBitDelta => 1, 310}, 311"\n"], 312 expectedNextLine => "Index: Makefile.shared\n", 313}, 314#### 315# Custom properties 316## 317# FIXME: We do not support anything other than the svn:executable property. 318# We should add support for handling other properties. 319{ 320 # New test 321 diffName => "simple: custom property", 322 inputText => <<'END', 323Property changes on: FileA 324___________________________________________________________________ 325Name: documentation 326 + This is an example sentence. 327END 328 expectedReturn => [ 329{ 330 propertyPath => "FileA", 331}, 332undef], 333 expectedNextLine => undef, 334}, 335{ 336 # New test 337 diffName => "custom property followed by custom property", 338 inputText => <<'END', 339Property changes on: FileA 340___________________________________________________________________ 341Added: copyright 342 + Copyright (C) Research in Motion Limited 2010. All Rights Reserved. 343Added: documentation 344 + This is an example sentence. 345END 346 expectedReturn => [ 347{ 348 propertyPath => "FileA", 349}, 350undef], 351 expectedNextLine => undef, 352}, 353#### 354# Malformed property diffs 355## 356# We shouldn't encounter such diffs in practice. 357{ 358 # New test 359 diffName => "svn:executable followed by custom property and svn:executable", 360 inputText => <<'END', 361Property changes on: FileA 362___________________________________________________________________ 363Added: svn:executable 364 + * 365Added: documentation 366 + This is an example sentence. 367Deleted: svn:executable 368 - * 369END 370 expectedReturn => [ 371{ 372 propertyPath => "FileA", 373 executableBitDelta => -1, 374}, 375undef], 376 expectedNextLine => undef, 377}, 378); 379 380my $testCasesCount = @testCaseHashRefs; 381plan(tests => 2 * $testCasesCount); # Total number of assertions. 382 383foreach my $testCase (@testCaseHashRefs) { 384 my $testNameStart = "parseSvnDiffProperties(): $testCase->{diffName}: comparing"; 385 386 my $fileHandle; 387 open($fileHandle, "<", \$testCase->{inputText}); 388 my $line = <$fileHandle>; 389 390 my @got = VCSUtils::parseSvnDiffProperties($fileHandle, $line); 391 my $expectedReturn = $testCase->{expectedReturn}; 392 393 is_deeply(\@got, $expectedReturn, "$testNameStart return value."); 394 395 my $gotNextLine = <$fileHandle>; 396 is($gotNextLine, $testCase->{expectedNextLine}, "$testNameStart next read line."); 397} 398