| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file input format is based loosely on | 5 // This file input format is based loosely on |
| 6 // Tools/DumpRenderTree/ImageDiff.m | 6 // Tools/DumpRenderTree/ImageDiff.m |
| 7 | 7 |
| 8 // The exact format of this tool's output to stdout is important, to match | 8 // The exact format of this tool's output to stdout is important, to match |
| 9 // what the run-webkit-tests script expects. | 9 // what the run-webkit-tests script expects. |
| 10 | 10 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 base::FilePath FilePathFromASCII(const std::string& str) { | 398 base::FilePath FilePathFromASCII(const std::string& str) { |
| 399 #if defined(OS_WIN) | 399 #if defined(OS_WIN) |
| 400 return base::FilePath(base::ASCIIToUTF16(str)); | 400 return base::FilePath(base::ASCIIToUTF16(str)); |
| 401 #else | 401 #else |
| 402 return base::FilePath(str); | 402 return base::FilePath(str); |
| 403 #endif | 403 #endif |
| 404 } | 404 } |
| 405 | 405 |
| 406 int main(int argc, const char* argv[]) { | 406 int main(int argc, const char* argv[]) { |
| 407 base::EnableTerminationOnHeapCorruption(); | 407 base::EnableTerminationOnHeapCorruption(); |
| 408 CommandLine::Init(argc, argv); | 408 base::CommandLine::Init(argc, argv); |
| 409 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 409 const base::CommandLine& parsed_command_line = |
| 410 *base::CommandLine::ForCurrentProcess(); |
| 410 bool histograms = parsed_command_line.HasSwitch(kOptionCompareHistograms); | 411 bool histograms = parsed_command_line.HasSwitch(kOptionCompareHistograms); |
| 411 if (parsed_command_line.HasSwitch(kOptionPollStdin)) { | 412 if (parsed_command_line.HasSwitch(kOptionPollStdin)) { |
| 412 // Watch stdin for filenames. | 413 // Watch stdin for filenames. |
| 413 std::string stdin_buffer; | 414 std::string stdin_buffer; |
| 414 base::FilePath filename1; | 415 base::FilePath filename1; |
| 415 while (std::getline(std::cin, stdin_buffer)) { | 416 while (std::getline(std::cin, stdin_buffer)) { |
| 416 if (stdin_buffer.empty()) | 417 if (stdin_buffer.empty()) |
| 417 continue; | 418 continue; |
| 418 | 419 |
| 419 if (!filename1.empty()) { | 420 if (!filename1.empty()) { |
| 420 // CompareImages writes results to stdout unless an error occurred. | 421 // CompareImages writes results to stdout unless an error occurred. |
| 421 base::FilePath filename2 = FilePathFromASCII(stdin_buffer); | 422 base::FilePath filename2 = FilePathFromASCII(stdin_buffer); |
| 422 if (CompareImages(filename1, filename2, histograms) == kStatusError) | 423 if (CompareImages(filename1, filename2, histograms) == kStatusError) |
| 423 printf("error\n"); | 424 printf("error\n"); |
| 424 fflush(stdout); | 425 fflush(stdout); |
| 425 filename1 = base::FilePath(); | 426 filename1 = base::FilePath(); |
| 426 } else { | 427 } else { |
| 427 // Save the first filename in another buffer and wait for the second | 428 // Save the first filename in another buffer and wait for the second |
| 428 // filename to arrive via stdin. | 429 // filename to arrive via stdin. |
| 429 filename1 = FilePathFromASCII(stdin_buffer); | 430 filename1 = FilePathFromASCII(stdin_buffer); |
| 430 } | 431 } |
| 431 } | 432 } |
| 432 return 0; | 433 return 0; |
| 433 } | 434 } |
| 434 | 435 |
| 435 const CommandLine::StringVector& args = parsed_command_line.GetArgs(); | 436 const base::CommandLine::StringVector& args = parsed_command_line.GetArgs(); |
| 436 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) { | 437 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) { |
| 437 if (args.size() == 3) { | 438 if (args.size() == 3) { |
| 438 return DiffImages(base::FilePath(args[0]), | 439 return DiffImages(base::FilePath(args[0]), |
| 439 base::FilePath(args[1]), | 440 base::FilePath(args[1]), |
| 440 base::FilePath(args[2])); | 441 base::FilePath(args[2])); |
| 441 } | 442 } |
| 442 } else if (args.size() == 2) { | 443 } else if (args.size() == 2) { |
| 443 return CompareImages( | 444 return CompareImages( |
| 444 base::FilePath(args[0]), base::FilePath(args[1]), histograms); | 445 base::FilePath(args[0]), base::FilePath(args[1]), histograms); |
| 445 } | 446 } |
| 446 | 447 |
| 447 PrintHelp(); | 448 PrintHelp(); |
| 448 return kStatusError; | 449 return kStatusError; |
| 449 } | 450 } |
| OLD | NEW |