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 (at] 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 34 use strict; 35 use warnings; 36 37 use Test::More; 38 use VCSUtils; 39 40 my @testCaseHashRefs = ( 41 #### 42 # Simple test cases 43 ## 44 { 45 # New test 46 diffName => "simple: add svn:executable", 47 inputText => <<'END', 48 Property changes on: FileA 49 ___________________________________________________________________ 50 Added: svn:executable 51 + * 52 END 53 expectedReturn => [ 54 { 55 propertyPath => "FileA", 56 executableBitDelta => 1, 57 }, 58 undef], 59 expectedNextLine => undef, 60 }, 61 { 62 # New test 63 diffName => "simple: add svn:mergeinfo", 64 inputText => <<'END', 65 Property changes on: Makefile 66 ___________________________________________________________________ 67 Added: svn:mergeinfo 68 Merged /trunk/Makefile:r33020 69 END 70 expectedReturn => [ 71 { 72 propertyPath => "Makefile", 73 }, 74 undef], 75 expectedNextLine => undef, 76 }, 77 { 78 # New test 79 diffName => "simple: delete svn:mergeinfo", 80 inputText => <<'END', 81 Property changes on: Makefile 82 ___________________________________________________________________ 83 Deleted: svn:mergeinfo 84 Reverse-merged /trunk/Makefile:r33020 85 END 86 expectedReturn => [ 87 { 88 propertyPath => "Makefile", 89 }, 90 undef], 91 expectedNextLine => undef, 92 }, 93 { 94 # New test 95 diffName => "simple: modified svn:mergeinfo", 96 inputText => <<'END', 97 Property changes on: Makefile 98 ___________________________________________________________________ 99 Modified: svn:mergeinfo 100 Reverse-merged /trunk/Makefile:r33020 101 Merged /trunk/Makefile:r41697 102 END 103 expectedReturn => [ 104 { 105 propertyPath => "Makefile", 106 }, 107 undef], 108 expectedNextLine => undef, 109 }, 110 { 111 # New test 112 diffName => "simple: delete svn:executable", 113 inputText => <<'END', 114 Property changes on: FileA 115 ___________________________________________________________________ 116 Deleted: svn:executable 117 - * 118 END 119 expectedReturn => [ 120 { 121 propertyPath => "FileA", 122 executableBitDelta => -1, 123 }, 124 undef], 125 expectedNextLine => undef, 126 }, 127 { 128 # New test 129 diffName => "simple: delete svn:executable using SVN 1.4 syntax", 130 inputText => <<'END', 131 Property changes on: FileA 132 ___________________________________________________________________ 133 Name: svn:executable 134 - * 135 END 136 expectedReturn => [ 137 { 138 propertyPath => "FileA", 139 executableBitDelta => -1, 140 }, 141 undef], 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', 151 Property changes on: FileA 152 ___________________________________________________________________ 153 Added: svn:executable 154 + * 155 156 Index: Makefile.shared 157 END 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', 170 Property changes on: FileA 171 ___________________________________________________________________ 172 Added: svn:executable 173 + * 174 175 Property changes on: Makefile.shared 176 END 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', 192 Property changes on: FileA 193 ___________________________________________________________________ 194 Added: svn:executable 195 + * 196 197 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 198 END 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', 211 Property changes on: FileA 212 ___________________________________________________________________ 213 Added: documentation 214 + This is an example sentence. 215 Added: svn:executable 216 + * 217 218 Q1dTBx0AAAB42itg4GlgYJjGwMDDyODMxMDw34GBgQEAJPQDJA== 219 END 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', 235 Property changes on: FileA 236 ___________________________________________________________________ 237 Added: svn:executable 238 + * 239 Added: documentation 240 + This is an example sentence. 241 END 242 expectedReturn => [ 243 { 244 propertyPath => "FileA", 245 executableBitDelta => 1, 246 }, 247 undef], 248 expectedNextLine => undef, 249 }, 250 { 251 # New test 252 diffName => "custom property followed by svn:executable", 253 inputText => <<'END', 254 Property changes on: FileA 255 ___________________________________________________________________ 256 Added: documentation 257 + This is an example sentence. 258 Added: svn:executable 259 + * 260 END 261 expectedReturn => [ 262 { 263 propertyPath => "FileA", 264 executableBitDelta => 1, 265 }, 266 undef], 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', 276 Property changes on: FileA 277 ___________________________________________________________________ 278 Added: documentation 279 + This is an example sentence. 280 Added: svn:executable 281 + * 282 283 Property changes on: Makefile.shared 284 END 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', 297 Property changes on: FileA 298 ___________________________________________________________________ 299 Added: documentation 300 + This is an example sentence. 301 Added: svn:executable 302 + * 303 304 Index: Makefile.shared 305 END 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', 323 Property changes on: FileA 324 ___________________________________________________________________ 325 Name: documentation 326 + This is an example sentence. 327 END 328 expectedReturn => [ 329 { 330 propertyPath => "FileA", 331 }, 332 undef], 333 expectedNextLine => undef, 334 }, 335 { 336 # New test 337 diffName => "custom property followed by custom property", 338 inputText => <<'END', 339 Property changes on: FileA 340 ___________________________________________________________________ 341 Added: copyright 342 + Copyright (C) Research in Motion Limited 2010. All Rights Reserved. 343 Added: documentation 344 + This is an example sentence. 345 END 346 expectedReturn => [ 347 { 348 propertyPath => "FileA", 349 }, 350 undef], 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', 361 Property changes on: FileA 362 ___________________________________________________________________ 363 Added: svn:executable 364 + * 365 Added: documentation 366 + This is an example sentence. 367 Deleted: svn:executable 368 - * 369 END 370 expectedReturn => [ 371 { 372 propertyPath => "FileA", 373 executableBitDelta => -1, 374 }, 375 undef], 376 expectedNextLine => undef, 377 }, 378 ); 379 380 my $testCasesCount = @testCaseHashRefs; 381 plan(tests => 2 * $testCasesCount); # Total number of assertions. 382 383 foreach 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