Commit 59ad5d28 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Add failure case for manifest file testing.

Currently we only have testing for success case of the
manifest file. This CL adds a test case for testing when
a file resource is not found, and an entry is not found in
the manifest.

BUG=370895
TEST=Ran browser_tests --gtest_filter=*IrtManifestFile and trybots.

Review URL: https://codereview.chromium.org/303683005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273813 0039d316-1c4b-4281-b951-d872f2087c98
parent 465c9750
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "native_client/src/untrusted/irt/irt.h" #include "native_client/src/untrusted/irt/irt.h"
#include "native_client/src/untrusted/nacl/nacl_irt.h" #include "native_client/src/untrusted/nacl/nacl_irt.h"
...@@ -20,30 +21,30 @@ ...@@ -20,30 +21,30 @@
#include "ppapi/cpp/instance.h" #include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h" #include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h" #include "ppapi/cpp/var.h"
#include "ppapi/cpp/var_array.h"
#include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
std::string str;
void load_manifest(TYPE_nacl_irt_query *query_func) { std::vector<std::string> result;
std::string LoadManifestSuccess(TYPE_nacl_irt_query *query_func) {
struct nacl_irt_resource_open nacl_irt_resource_open; struct nacl_irt_resource_open nacl_irt_resource_open;
if (sizeof(nacl_irt_resource_open) != if (sizeof(nacl_irt_resource_open) !=
(*query_func)( (*query_func)(
NACL_IRT_RESOURCE_OPEN_v0_1, NACL_IRT_RESOURCE_OPEN_v0_1,
&nacl_irt_resource_open, &nacl_irt_resource_open,
sizeof(nacl_irt_resource_open))) { sizeof(nacl_irt_resource_open))) {
str = "irt manifest api not found"; return "irt manifest api not found";
return;
} }
int desc; int desc;
int error; int error;
error = nacl_irt_resource_open.open_resource("test_file", &desc); error = nacl_irt_resource_open.open_resource("test_file", &desc);
if (0 != error) { if (0 != error) {
str = "Can't open file";
printf("Can't open file, error=%d", error); printf("Can't open file, error=%d", error);
return; return "Can't open file";
} }
str = "File Contents:\n"; std::string str;
char buffer[4096]; char buffer[4096];
int len; int len;
...@@ -80,8 +81,63 @@ void load_manifest(TYPE_nacl_irt_query *query_func) { ...@@ -80,8 +81,63 @@ void load_manifest(TYPE_nacl_irt_query *query_func) {
buffer[len] = 0; buffer[len] = 0;
str += buffer; str += buffer;
} }
printf("file loaded: %s\n", str.c_str());
return; if (str != "Test File Content") {
printf("Wrong file content: \"%s\"\n", str.c_str());
return "Wrong file content: " + str;
}
return "Pass";
}
std::string LoadManifestNonExistentEntry(
TYPE_nacl_irt_query *query_func) {
struct nacl_irt_resource_open nacl_irt_resource_open;
if (sizeof(nacl_irt_resource_open) !=
(*query_func)(
NACL_IRT_RESOURCE_OPEN_v0_1,
&nacl_irt_resource_open,
sizeof(nacl_irt_resource_open))) {
return "irt manifest api not found";
}
int desc;
int error = nacl_irt_resource_open.open_resource("non_existent_entry", &desc);
// We expect ENOENT here, as it does not exist.
if (error != ENOENT) {
printf("Unexpected error code: %d\n", error);
char buf[80];
snprintf(buf, sizeof(buf), "open_resource() result: %d", error);
return std::string(buf);
}
return "Pass";
}
std::string LoadManifestNonExistentFile(
TYPE_nacl_irt_query *query_func) {
struct nacl_irt_resource_open nacl_irt_resource_open;
if (sizeof(nacl_irt_resource_open) !=
(*query_func)(
NACL_IRT_RESOURCE_OPEN_v0_1,
&nacl_irt_resource_open,
sizeof(nacl_irt_resource_open))) {
return "irt manifest api not found";
}
int desc;
int error = nacl_irt_resource_open.open_resource("dummy_test_file", &desc);
// We expect ENOENT here, as it does not exist.
if (error != ENOENT) {
printf("Unexpected error code: %d\n", error);
char buf[80];
snprintf(buf, sizeof(buf), "open_resource() result: %d", error);
return std::string(buf);
}
return "Pass";
} }
class TestInstance : public pp::Instance { class TestInstance : public pp::Instance {
...@@ -95,7 +151,10 @@ class TestInstance : public pp::Instance { ...@@ -95,7 +151,10 @@ class TestInstance : public pp::Instance {
if (var_message.AsString() != "hello") { if (var_message.AsString() != "hello") {
return; return;
} }
pp::Var reply = pp::Var(str); pp::VarArray reply = pp::VarArray();
for (size_t i = 0; i < result.size(); ++i) {
reply.Set(i, pp::Var(result[i]));
}
PostMessage(reply); PostMessage(reply);
} }
}; };
...@@ -117,7 +176,8 @@ Module* CreateModule() { ...@@ -117,7 +176,8 @@ Module* CreateModule() {
} }
int main() { int main() {
load_manifest(&__nacl_irt_query); result.push_back(LoadManifestSuccess(&__nacl_irt_query));
result.push_back(LoadManifestNonExistentEntry(&__nacl_irt_query));
result.push_back(LoadManifestNonExistentFile(&__nacl_irt_query));
return PpapiPluginMain(); return PpapiPluginMain();
} }
...@@ -40,7 +40,8 @@ function setupTests(tester, plugin) { ...@@ -40,7 +40,8 @@ function setupTests(tester, plugin) {
tester.addAsyncTest('Test_00_Init', function(status) { tester.addAsyncTest('Test_00_Init', function(status) {
plugin.addEventListener('message', function(message_event) { plugin.addEventListener('message', function(message_event) {
this.removeEventListener('message', arguments.callee, false); this.removeEventListener('message', arguments.callee, false);
var golden = 'File Contents:\nTest File Content'; // When a test succeeds, 'Pass' is returned. We have now three test cases.
var golden = ['Pass', 'Pass', 'Pass'];
status.assertEqual(message_event.data, golden); status.assertEqual(message_event.data, golden);
status.pass(); status.pass();
}, false); }, false);
......
...@@ -644,6 +644,9 @@ ...@@ -644,6 +644,9 @@
'create_nmf_args_portable': [ 'create_nmf_args_portable': [
'-xtest_file:test_file.txt', '-xtest_file:test_file.txt',
'-xnmf says hello world:test_file.txt', '-xnmf says hello world:test_file.txt',
# There is no dummy_test_file.txt file intentionally. This is just for
# a test case where there is a manifest entry, but no actual file.
'-xdummy_test_file:dummy_test_file.txt',
], ],
'test_files': [ 'test_files': [
'manifest_file/irt_manifest_file_test.html', 'manifest_file/irt_manifest_file_test.html',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment