Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: chrome/test/data/nacl/manifest_file/irt_manifest_file_test.cc

Issue 303683005: Add failure case for manifest file testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 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
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <string.h> 12 #include <string.h>
13 13
14 #include <sstream>
14 #include <string> 15 #include <string>
15 #include <sstream> 16 #include <vector>
16 17
17 #include "native_client/src/untrusted/irt/irt.h" 18 #include "native_client/src/untrusted/irt/irt.h"
18 #include "native_client/src/untrusted/nacl/nacl_irt.h" 19 #include "native_client/src/untrusted/nacl/nacl_irt.h"
19 20
20 #include "ppapi/cpp/instance.h" 21 #include "ppapi/cpp/instance.h"
21 #include "ppapi/cpp/module.h" 22 #include "ppapi/cpp/module.h"
22 #include "ppapi/cpp/var.h" 23 #include "ppapi/cpp/var.h"
24 #include "ppapi/cpp/var_array.h"
23 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" 25 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
24 26
25 std::string str;
26 27
27 void load_manifest(TYPE_nacl_irt_query *query_func) { 28 std::vector<std::string> result;
29
30 std::string LoadManifestSuccess(TYPE_nacl_irt_query *query_func) {
28 struct nacl_irt_resource_open nacl_irt_resource_open; 31 struct nacl_irt_resource_open nacl_irt_resource_open;
29 if (sizeof(nacl_irt_resource_open) != 32 if (sizeof(nacl_irt_resource_open) !=
30 (*query_func)( 33 (*query_func)(
31 NACL_IRT_RESOURCE_OPEN_v0_1, 34 NACL_IRT_RESOURCE_OPEN_v0_1,
32 &nacl_irt_resource_open, 35 &nacl_irt_resource_open,
33 sizeof(nacl_irt_resource_open))) { 36 sizeof(nacl_irt_resource_open))) {
34 str = "irt manifest api not found"; 37 return "irt manifest api not found";
35 return;
36 } 38 }
37 int desc; 39 int desc;
38 int error; 40 int error;
39 error = nacl_irt_resource_open.open_resource("test_file", &desc); 41 error = nacl_irt_resource_open.open_resource("test_file", &desc);
40 if (0 != error) { 42 if (0 != error) {
41 str = "Can't open file";
42 printf("Can't open file, error=%d", error); 43 printf("Can't open file, error=%d", error);
43 return; 44 return "Can't open file";
44 } 45 }
45 46
46 str = "File Contents:\n"; 47 std::string str = "File Contents:\n";
47 48
48 char buffer[4096]; 49 char buffer[4096];
49 int len; 50 int len;
50 while ((len = read(desc, buffer, sizeof buffer - 1)) > 0) { 51 while ((len = read(desc, buffer, sizeof buffer - 1)) > 0) {
51 // NB: fgets does not discard the newline nor any carriage return 52 // NB: fgets does not discard the newline nor any carriage return
52 // character before that. 53 // character before that.
53 // 54 //
54 // Note that CR LF is the default end-of-line style for Windows. 55 // Note that CR LF is the default end-of-line style for Windows.
55 // Furthermore, when the test_file (input data, which happens to 56 // Furthermore, when the test_file (input data, which happens to
56 // be the nmf file) is initially created in a change list, the 57 // be the nmf file) is initially created in a change list, the
(...skipping 17 matching lines...) Expand all
74 int len = strlen(buffer); 75 int len = strlen(buffer);
75 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') { 76 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') {
76 buffer[len-2] = '\n'; 77 buffer[len-2] = '\n';
77 buffer[len-1] = '\0'; 78 buffer[len-1] = '\0';
78 } 79 }
79 // Null terminate. 80 // Null terminate.
80 buffer[len] = 0; 81 buffer[len] = 0;
81 str += buffer; 82 str += buffer;
82 } 83 }
83 printf("file loaded: %s\n", str.c_str()); 84 printf("file loaded: %s\n", str.c_str());
84 return; 85 return str;
86 }
87
88 std::string LoadManifestNonExistentEntry(
89 TYPE_nacl_irt_query *query_func) {
90 struct nacl_irt_resource_open nacl_irt_resource_open;
91 if (sizeof(nacl_irt_resource_open) !=
92 (*query_func)(
93 NACL_IRT_RESOURCE_OPEN_v0_1,
94 &nacl_irt_resource_open,
95 sizeof(nacl_irt_resource_open))) {
96 return "irt manifest api not found";
97 }
98
99 int desc;
100 int error = nacl_irt_resource_open.open_resource("non_existent_entry", &desc);
101 char buf[80];
102 snprintf(buf, sizeof(buf), "open_resource() result: %d", error);
Mark Seaborn 2014/05/29 16:55:48 Rather than always formatting the numeric errno me
hidehiko 2014/05/30 04:49:58 Done.
103 return std::string(buf);
104 }
105
106 std::string LoadManifestNonExistentFile(
107 TYPE_nacl_irt_query *query_func) {
108 struct nacl_irt_resource_open nacl_irt_resource_open;
109 if (sizeof(nacl_irt_resource_open) !=
110 (*query_func)(
111 NACL_IRT_RESOURCE_OPEN_v0_1,
112 &nacl_irt_resource_open,
113 sizeof(nacl_irt_resource_open))) {
114 return "irt manifest api not found";
115 }
116
117 int desc;
118 int error = nacl_irt_resource_open.open_resource("dummy_test_file", &desc);
119 char buf[80];
120 snprintf(buf, sizeof(buf), "open_resource() result: %d", error);
Mark Seaborn 2014/05/29 16:55:48 Same here
hidehiko 2014/05/30 04:49:58 Done.
121 return std::string(buf);
85 } 122 }
86 123
87 class TestInstance : public pp::Instance { 124 class TestInstance : public pp::Instance {
88 public: 125 public:
89 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {} 126 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {}
90 virtual ~TestInstance() {} 127 virtual ~TestInstance() {}
91 virtual void HandleMessage(const pp::Var& var_message) { 128 virtual void HandleMessage(const pp::Var& var_message) {
92 if (!var_message.is_string()) { 129 if (!var_message.is_string()) {
93 return; 130 return;
94 } 131 }
95 if (var_message.AsString() != "hello") { 132 if (var_message.AsString() != "hello") {
96 return; 133 return;
97 } 134 }
98 pp::Var reply = pp::Var(str); 135 pp::VarArray reply = pp::VarArray();
136 for (size_t i = 0; i < result.size(); ++i) {
137 reply.Set(i, pp::Var(result[i]));
138 }
99 PostMessage(reply); 139 PostMessage(reply);
100 } 140 }
101 }; 141 };
102 142
103 class TestModule : public pp::Module { 143 class TestModule : public pp::Module {
104 public: 144 public:
105 TestModule() : pp::Module() {} 145 TestModule() : pp::Module() {}
106 virtual ~TestModule() {} 146 virtual ~TestModule() {}
107 147
108 virtual pp::Instance* CreateInstance(PP_Instance instance) { 148 virtual pp::Instance* CreateInstance(PP_Instance instance) {
109 return new TestInstance(instance); 149 return new TestInstance(instance);
110 } 150 }
111 }; 151 };
112 152
113 namespace pp { 153 namespace pp {
114 Module* CreateModule() { 154 Module* CreateModule() {
115 return new TestModule(); 155 return new TestModule();
116 } 156 }
117 } 157 }
118 158
119 int main() { 159 int main() {
120 load_manifest(&__nacl_irt_query); 160 result.push_back(LoadManifestSuccess(&__nacl_irt_query));
161 result.push_back(LoadManifestNonExistentEntry(&__nacl_irt_query));
162 result.push_back(LoadManifestNonExistentFile(&__nacl_irt_query));
121 return PpapiPluginMain(); 163 return PpapiPluginMain();
122 } 164 }
123
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698