OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // WebKitTools/DumpRenderTree/ImageDiff.m | 6 // WebKitTools/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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 false, &png_encoding); | 313 false, &png_encoding); |
314 if (file_util::WriteFile(UTF8ToWide(out_file), | 314 if (file_util::WriteFile(UTF8ToWide(out_file), |
315 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) | 315 reinterpret_cast<char*>(&png_encoding.front()), png_encoding.size()) < 0) |
316 return kStatusError; | 316 return kStatusError; |
317 | 317 |
318 return kStatusDifferent; | 318 return kStatusDifferent; |
319 } | 319 } |
320 | 320 |
321 int main(int argc, const char* argv[]) { | 321 int main(int argc, const char* argv[]) { |
322 base::EnableTerminationOnHeapCorruption(); | 322 base::EnableTerminationOnHeapCorruption(); |
323 // TODO(estade): why does using the default constructor (command line | 323 CommandLine::Init(argc, argv); |
324 // singleton) cause an exception when run in debug mode? | 324 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
325 #if defined(OS_WIN) | |
326 CommandLine parsed_command_line(::GetCommandLine()); | |
327 #elif defined(OS_POSIX) | |
328 CommandLine parsed_command_line(argc, argv); | |
329 #endif | |
330 if (parsed_command_line.HasSwitch(kOptionPollStdin)) { | 325 if (parsed_command_line.HasSwitch(kOptionPollStdin)) { |
331 // Watch stdin for filenames. | 326 // Watch stdin for filenames. |
332 std::string stdin_buffer; | 327 std::string stdin_buffer; |
333 std::string filename1_buffer; | 328 std::string filename1_buffer; |
334 bool have_filename1 = false; | 329 bool have_filename1 = false; |
335 while (std::getline(std::cin, stdin_buffer)) { | 330 while (std::getline(std::cin, stdin_buffer)) { |
336 if (stdin_buffer.empty()) | 331 if (stdin_buffer.empty()) |
337 continue; | 332 continue; |
338 | 333 |
339 if (have_filename1) { | 334 if (have_filename1) { |
340 // CompareImages writes results to stdout unless an error occurred. | 335 // CompareImages writes results to stdout unless an error occurred. |
341 if (CompareImages(filename1_buffer.c_str(), stdin_buffer.c_str()) == | 336 if (CompareImages(filename1_buffer.c_str(), stdin_buffer.c_str()) == |
342 kStatusError) | 337 kStatusError) |
343 printf("error\n"); | 338 printf("error\n"); |
344 fflush(stdout); | 339 fflush(stdout); |
345 have_filename1 = false; | 340 have_filename1 = false; |
346 } else { | 341 } else { |
347 // Save the first filename in another buffer and wait for the second | 342 // Save the first filename in another buffer and wait for the second |
348 // filename to arrive via stdin. | 343 // filename to arrive via stdin. |
349 filename1_buffer = stdin_buffer; | 344 filename1_buffer = stdin_buffer; |
350 have_filename1 = true; | 345 have_filename1 = true; |
351 } | 346 } |
352 } | 347 } |
353 return 0; | 348 return 0; |
354 } | 349 } |
355 | 350 |
| 351 std::vector<std::wstring> values = parsed_command_line.GetLooseValues(); |
356 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) { | 352 if (parsed_command_line.HasSwitch(kOptionGenerateDiff)) { |
357 if (3 == parsed_command_line.GetLooseValueCount()) { | 353 if (values.size() == 3) { |
358 CommandLine::LooseValueIterator iter = | 354 return DiffImages(WideToUTF8(values[0]).c_str(), |
359 parsed_command_line.GetLooseValuesBegin(); | 355 WideToUTF8(values[1]).c_str(), |
360 return DiffImages(WideToUTF8(*iter).c_str(), | 356 WideToUTF8(values[2]).c_str()); |
361 WideToUTF8(*(iter + 1)).c_str(), | |
362 WideToUTF8(*(iter + 2)).c_str()); | |
363 } | 357 } |
364 } else if (2 == parsed_command_line.GetLooseValueCount()) { | 358 } else if (values.size() == 2) { |
365 return CompareImages(argv[1], argv[2]); | 359 return CompareImages(argv[1], argv[2]); |
366 } | 360 } |
367 | 361 |
368 PrintHelp(); | 362 PrintHelp(); |
369 return kStatusError; | 363 return kStatusError; |
370 } | 364 } |
OLD | NEW |