OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2011 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 // Test for resource open before PPAPI initialization. | 8 // Test for resource open before PPAPI initialization. |
9 // | 9 // |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 int error; | 38 int error; |
39 error = nacl_irt_resource_open.open_resource("test_file", &desc); | 39 error = nacl_irt_resource_open.open_resource("test_file", &desc); |
40 if (0 != error) { | 40 if (0 != error) { |
41 str = "Can't open file"; | 41 str = "Can't open file"; |
42 printf("Can't open file, error=%d", error); | 42 printf("Can't open file, error=%d", error); |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 str = "File Contents:\n"; | 46 str = "File Contents:\n"; |
47 | 47 |
48 FILE *iob = fdopen(desc, "r"); | |
49 char buffer[4096]; | 48 char buffer[4096]; |
50 while (fgets(buffer, sizeof buffer, iob) != NULL) { | 49 int len; |
| 50 while ((len = read(desc, buffer, sizeof buffer - 1)) > 0) { |
51 // NB: fgets does not discard the newline nor any carriage return | 51 // NB: fgets does not discard the newline nor any carriage return |
52 // character before that. | 52 // character before that. |
53 // | 53 // |
54 // Note that CR LF is the default end-of-line style for Windows. | 54 // Note that CR LF is the default end-of-line style for Windows. |
55 // Furthermore, when the test_file (input data, which happens to | 55 // Furthermore, when the test_file (input data, which happens to |
56 // be the nmf file) is initially created in a change list, the | 56 // be the nmf file) is initially created in a change list, the |
57 // patch is sent to our try bots as text. This means that when | 57 // patch is sent to our try bots as text. This means that when |
58 // the file arrives, it has CR LF endings instead of the original | 58 // the file arrives, it has CR LF endings instead of the original |
59 // LF line endings. Since the expected or golden data is | 59 // LF line endings. Since the expected or golden data is |
60 // (manually) encoded in the HTML file's JavaScript, there will be | 60 // (manually) encoded in the HTML file's JavaScript, there will be |
61 // a mismatch. After submission, the svn property svn:eol-style | 61 // a mismatch. After submission, the svn property svn:eol-style |
62 // will be set to LF, so a clean check out should have LF and not | 62 // will be set to LF, so a clean check out should have LF and not |
63 // CR LF endings, and the tests will pass without CR removal. | 63 // CR LF endings, and the tests will pass without CR removal. |
64 // However -- and there's always a however in long discourses -- | 64 // However -- and there's always a however in long discourses -- |
65 // if the nmf file is edited, say, because the test is being | 65 // if the nmf file is edited, say, because the test is being |
66 // modified, and the modification is being done on a Windows | 66 // modified, and the modification is being done on a Windows |
67 // machine, then it is likely that the editor used by the | 67 // machine, then it is likely that the editor used by the |
68 // programmer will convert the file to CR LF endings. Which, | 68 // programmer will convert the file to CR LF endings. Which, |
69 // unfortunatly, implies that the test will mysteriously fail | 69 // unfortunatly, implies that the test will mysteriously fail |
70 // again. | 70 // again. |
71 // | 71 // |
72 // To defend against such nonsense, we weaken the test slighty, | 72 // To defend against such nonsense, we weaken the test slighty, |
73 // and just strip the CR if it is present. | 73 // and just strip the CR if it is present. |
74 int len = strlen(buffer); | 74 int len = strlen(buffer); |
75 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') { | 75 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') { |
76 buffer[len-2] = '\n'; | 76 buffer[len-2] = '\n'; |
77 buffer[len-1] = '\0'; | 77 buffer[len-1] = '\0'; |
78 } | 78 } |
| 79 // Null terminate. |
| 80 buffer[len] = 0; |
79 str += buffer; | 81 str += buffer; |
80 } | 82 } |
81 printf("file loaded: %s\n", str.c_str()); | 83 printf("file loaded: %s\n", str.c_str()); |
82 fclose(iob); // closed desc | |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
86 class TestInstance : public pp::Instance { | 87 class TestInstance : public pp::Instance { |
87 public: | 88 public: |
88 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {} | 89 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {} |
89 virtual ~TestInstance() {} | 90 virtual ~TestInstance() {} |
90 virtual void HandleMessage(const pp::Var& var_message) { | 91 virtual void HandleMessage(const pp::Var& var_message) { |
91 if (!var_message.is_string()) { | 92 if (!var_message.is_string()) { |
92 return; | 93 return; |
(...skipping 20 matching lines...) Expand all Loading... |
113 Module* CreateModule() { | 114 Module* CreateModule() { |
114 return new TestModule(); | 115 return new TestModule(); |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
118 int main() { | 119 int main() { |
119 load_manifest(&__nacl_irt_query); | 120 load_manifest(&__nacl_irt_query); |
120 return PpapiPluginMain(); | 121 return PpapiPluginMain(); |
121 } | 122 } |
122 | 123 |
OLD | NEW |