2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // Unit tests for npnacl_plugin.so
36 #include "bindings/npapi.h"
37 #include "bindings/npruntime.h"
38 #include "nphostapi.h"
42 void* GetSymbolHandle(const char* name
) {
43 void* sym_handle
= dlsym(dl_handle
, name
);
44 char* error_string
= dlerror();
45 if (!sym_handle
|| error_string
) {
46 fprintf(stderr
, "Couldn't get symbol %s: %s\n", name
, error_string
);
52 bool TestMIMEDescription() {
53 typedef char* (*FP
)();
54 FP func
= reinterpret_cast<FP
>(GetSymbolHandle("NP_GetMIMEDescription"));
58 char* mime_string
= (*func
)();
60 fprintf(stderr
, "ERROR: NP_GetMIMEDescriptor returned no string\n");
66 bool TestInitialize() {
67 typedef NPError (*FP
)(NPNetscapeFuncs
*, NPPluginFuncs
*);
68 FP func
= reinterpret_cast<FP
>(GetSymbolHandle("NP_Initialize"));
72 NPNetscapeFuncs browser_funcs
;
73 NPPluginFuncs plugin_funcs
;
74 browser_funcs
.version
= (NP_VERSION_MAJOR
<< 8) | NP_VERSION_MINOR
;
75 browser_funcs
.size
= sizeof(NPNetscapeFuncs
);
76 if (NPERR_NO_ERROR
!= (*func
)(&browser_funcs
, &plugin_funcs
)) {
77 fprintf(stderr
, "ERROR: NP_Initialize returned error\n");
83 bool TestEntryPoints() {
84 typedef NPError (*FP
)(NPPluginFuncs
*);
85 FP func
= reinterpret_cast<FP
>(GetSymbolHandle("NP_GetEntryPoints"));
89 NPPluginFuncs plugin_funcs
;
90 if (NPERR_NO_ERROR
!= (*func
)(&plugin_funcs
)) {
91 fprintf(stderr
, "ERROR: NP_GetEntryPoints returned error\n");
98 typedef NPError (*FP
)(void);
99 FP func
= reinterpret_cast<FP
>(GetSymbolHandle("NP_Shutdown"));
103 if (NPERR_NO_ERROR
!= (*func
)()) {
104 fprintf(stderr
, "ERROR: NP_Shutdown returned error\n");
110 int main(int argc
, char** argv
) {
112 fprintf(stderr
, "Usage: %s <soname>\n", argv
[0]);
115 // Test opening the .so
116 dl_handle
= dlopen(argv
[1], RTLD_NOW
);
118 fprintf(stderr
, "Couldn't open: %s\n", dlerror());
123 (TestMIMEDescription() &&
128 // Test closing the .so
129 if (dlclose(dl_handle
)) {
130 fprintf(stderr
, "Couldn't close: %s\n", dlerror());