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

Side by Side Diff: tests/manifest_file/irt_manifest_file_test.cc

Issue 7605029: Extend IRT with nacl_irt_resource_open interface (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 4 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
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 //
8 // Test for resource open before PPAPI initialization.
9 //
10
11 #include <stdio.h>
12 #include <string.h>
13
14 #include <string>
15
16 #include "native_client/src/shared/ppapi_proxy/ppruntime.h"
17 #include "native_client/src/untrusted/irt/irt.h"
18 #include "native_client/src/untrusted/nacl/nacl_irt.h"
19
20 #include "ppapi/cpp/instance.h"
21 #include "ppapi/cpp/module.h"
22 #include "ppapi/cpp/var.h"
23
24 std::string str;
25
26 void load_manifest(TYPE_nacl_irt_query *query_func) {
27 struct nacl_irt_resource_open nacl_irt_resource_open;
28 if (sizeof(nacl_irt_resource_open) !=
29 (*query_func)(
30 NACL_IRT_RESOURCE_OPEN_v0_0,
31 &nacl_irt_resource_open,
32 sizeof(nacl_irt_resource_open))) {
33 str = "irt manifest api not found";
34 return;
35 }
36 int desc;
37 int error;
38 error = nacl_irt_resource_open.open_resource("files/test_file", &desc);
39 if (0 != error) {
40 str = "Can't open file";
41 printf("Can't open file, error=%d", error);
42 return;
43 }
44
45 str = "File Contents:\n";
46
47 FILE *iob = fdopen(desc, "r");
48 char buffer[4096];
49 while (fgets(buffer, sizeof buffer, iob) != NULL) {
50 // NB: fgets does not discard the newline nor any carriage return
51 // character before that.
52 //
53 // Note that CR LF is the default end-of-line style for Windows.
54 // Furthermore, when the test_file (input data, which happens to
55 // be the nmf file) is initially created in a change list, the
56 // patch is sent to our try bots as text. This means that when
57 // the file arrives, it has CR LF endings instead of the original
58 // LF line endings. Since the expected or golden data is
59 // (manually) encoded in the HTML file's JavaScript, there will be
60 // a mismatch. After submission, the svn property svn:eol-style
61 // will be set to LF, so a clean check out should have LF and not
62 // CR LF endings, and the tests will pass without CR removal.
63 // However -- and there's always a however in long discourses --
64 // if the nmf file is edited, say, because the test is being
65 // modified, and the modification is being done on a Windows
66 // machine, then it is likely that the editor used by the
67 // programmer will convert the file to CR LF endings. Which,
68 // unfortunatly, implies that the test will mysteriously fail
69 // again.
70 //
71 // To defend against such nonsense, we weaken the test slighty,
72 // and just strip the CR if it is present.
73 int len = strlen(buffer);
74 if (len >= 2 && buffer[len-1] == '\n' && buffer[len-2] == '\r') {
75 buffer[len-2] = '\n';
76 buffer[len-1] = '\0';
77 }
78 str += buffer;
79 }
80 printf("file loaded: %s\n", str.c_str());
81 fclose(iob); // closed desc
82 return;
83 }
84
85 class TestInstance : public pp::Instance {
86 public:
87 explicit TestInstance(PP_Instance instance) : pp::Instance(instance) {}
88 virtual ~TestInstance() {}
89 virtual void HandleMessage(const pp::Var& var_message) {
90 if (!var_message.is_string()) {
91 return;
92 }
93 if (var_message.AsString() != "hello") {
94 return;
95 }
96 pp::Var reply = pp::Var(str);
97 PostMessage(reply);
98 }
99 };
100
101 class TestModule : public pp::Module {
102 public:
103 TestModule() : pp::Module() {}
104 virtual ~TestModule() {}
105
106 virtual pp::Instance* CreateInstance(PP_Instance instance) {
107 return new TestInstance(instance);
108 }
109 };
110
111 namespace pp {
112 Module* CreateModule() {
113 return new TestModule();
114 }
115 }
116
117 int main() {
118 load_manifest(&__nacl_irt_query);
119 return PpapiPluginMain();
120 }
121
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698