OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 // | 7 // |
8 // Post-message based test for simple rpc based access to name services. | 8 // Post-message based test for simple rpc based access to name services. |
9 // | 9 // |
10 | 10 |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 "files/test_file", O_RDONLY, | 543 "files/test_file", O_RDONLY, |
544 &status, &desc)) { | 544 &status, &desc)) { |
545 sb->Printf("manifest lookup RPC failed\n"); | 545 sb->Printf("manifest lookup RPC failed\n"); |
546 NaClSrpcDtor(&manifest_channel); | 546 NaClSrpcDtor(&manifest_channel); |
547 return; | 547 return; |
548 } | 548 } |
549 | 549 |
550 sb->DiscardOutput(); | 550 sb->DiscardOutput(); |
551 sb->Printf("File Contents:\n"); | 551 sb->Printf("File Contents:\n"); |
552 | 552 |
553 FILE *iob = fdopen(desc, "r"); | |
554 char buffer[4096]; | 553 char buffer[4096]; |
555 while (fgets(buffer, sizeof buffer, iob) != NULL) { | 554 int len; |
| 555 while ((len = read(desc, buffer, sizeof buffer - 1)) > 0) { |
556 // NB: fgets does not discard the newline nor any carriage return | 556 // NB: fgets does not discard the newline nor any carriage return |
557 // character before that. | 557 // character before that. |
558 // | 558 // |
559 // Note that CR LF is the default end-of-line style for Windows. | 559 // Note that CR LF is the default end-of-line style for Windows. |
560 // Furthermore, when the test_file (input data, which happens to | 560 // Furthermore, when the test_file (input data, which happens to |
561 // be the nmf file) is initially created in a change list, the | 561 // be the nmf file) is initially created in a change list, the |
562 // patch is sent to our try bots as text. This means that when | 562 // patch is sent to our try bots as text. This means that when |
563 // the file arrives, it has CR LF endings instead of the original | 563 // the file arrives, it has CR LF endings instead of the original |
564 // LF line endings. Since the expected or golden data is | 564 // LF line endings. Since the expected or golden data is |
565 // (manually) encoded in the HTML file's JavaScript, there will be | 565 // (manually) encoded in the HTML file's JavaScript, there will be |
566 // a mismatch. After submission, the svn property svn:eol-style | 566 // a mismatch. After submission, the svn property svn:eol-style |
567 // will be set to LF, so a clean check out should have LF and not | 567 // will be set to LF, so a clean check out should have LF and not |
568 // CR LF endings, and the tests will pass without CR removal. | 568 // CR LF endings, and the tests will pass without CR removal. |
569 // However -- and there's always a however in long discourses -- | 569 // However -- and there's always a however in long discourses -- |
570 // if the nmf file is edited, say, because the test is being | 570 // if the nmf file is edited, say, because the test is being |
571 // modified, and the modification is being done on a Windows | 571 // modified, and the modification is being done on a Windows |
572 // machine, then it is likely that the editor used by the | 572 // machine, then it is likely that the editor used by the |
573 // programmer will convert the file to CR LF endings. Which, | 573 // programmer will convert the file to CR LF endings. Which, |
574 // unfortunatly, implies that the test will mysteriously fail | 574 // unfortunatly, implies that the test will mysteriously fail |
575 // again. | 575 // again. |
576 // | 576 // |
577 // To defend against such nonsense, we weaken the test slighty, | 577 // To defend against such nonsense, we weaken the test slighty, |
578 // and just strip the CR if it is present. | 578 // and just strip the CR if it is present. |
579 int len = strlen(buffer); | |
580 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') { | 579 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') { |
581 buffer[len-2] = '\n'; | 580 buffer[len-2] = '\n'; |
582 buffer[len-1] = '\0'; | 581 buffer[len-1] = '\0'; |
583 } | 582 } |
| 583 // Null terminate. |
| 584 buffer[len] = 0; |
584 sb->Printf("%s", buffer); | 585 sb->Printf("%s", buffer); |
585 } | 586 } |
586 fclose(iob); // closed desc | |
587 NaClSrpcDtor(&manifest_channel); | 587 NaClSrpcDtor(&manifest_channel); |
588 return; | 588 return; |
589 } | 589 } |
590 | 590 |
591 // HandleMessage gets invoked when postMessage is called on the DOM | 591 // HandleMessage gets invoked when postMessage is called on the DOM |
592 // element associated with this plugin instance. In this case, if we | 592 // element associated with this plugin instance. In this case, if we |
593 // are given a string, we'll post a message back to JavaScript with a | 593 // are given a string, we'll post a message back to JavaScript with a |
594 // reply -- essentially treating this as a string-based RPC. | 594 // reply -- essentially treating this as a string-based RPC. |
595 void MyInstance::HandleMessage(const pp::Var& message) { | 595 void MyInstance::HandleMessage(const pp::Var& message) { |
596 if (message.is_string()) { | 596 if (message.is_string()) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 | 660 |
661 namespace pp { | 661 namespace pp { |
662 | 662 |
663 // Factory function for your specialization of the Module object. | 663 // Factory function for your specialization of the Module object. |
664 Module* CreateModule() { | 664 Module* CreateModule() { |
665 fprintf(stderr, "CreateModule invoked\n"); fflush(NULL); | 665 fprintf(stderr, "CreateModule invoked\n"); fflush(NULL); |
666 return new MyModule(); | 666 return new MyModule(); |
667 } | 667 } |
668 | 668 |
669 } // namespace pp | 669 } // namespace pp |
OLD | NEW |