annotate quick-test.cpp @ 73:8db927152497
Simple test script (and associated fixes) for the JS code
author |
Chris Cannam <c.cannam@qmul.ac.uk> |
date |
Wed, 24 Aug 2016 10:50:40 +0100 |
parents |
4f16ceb503c4 |
children |
2a4685f230ac |
rev |
line source |
c@71
|
1
|
c@71
|
2 #include <iostream>
|
c@71
|
3 #include <dlfcn.h>
|
c@71
|
4
|
c@71
|
5 using namespace std;
|
c@71
|
6
|
c@71
|
7 int main(int argc, char **argv)
|
c@71
|
8 {
|
c@71
|
9 string example = "./example.so";
|
c@71
|
10
|
c@71
|
11 void *lib = dlopen(example.c_str(), RTLD_LAZY | RTLD_LOCAL);
|
c@71
|
12 if (!lib) {
|
c@71
|
13 cerr << "failed to open " + example + ": " << dlerror() << endl;
|
c@71
|
14 return 1;
|
c@71
|
15 }
|
c@71
|
16
|
c@71
|
17 typedef const char *(*RequestFn)(const char *);
|
c@71
|
18 RequestFn reqFn = (RequestFn)dlsym(lib, "vampipeRequestJson");
|
c@71
|
19 if (!reqFn) {
|
c@71
|
20 cerr << "failed to find request function in " +
|
c@71
|
21 example + ": " << dlerror() << endl;
|
c@71
|
22 return 1;
|
c@71
|
23 }
|
c@71
|
24
|
c@71
|
25 typedef void (*FreeFn)(const char *);
|
c@71
|
26 FreeFn freeFn = (FreeFn)dlsym(lib, "vampipeFreeJson");
|
c@71
|
27 if (!freeFn) {
|
c@71
|
28 cerr << "failed to find free function in " +
|
c@71
|
29 example + ": " << dlerror() << endl;
|
c@71
|
30 return 1;
|
c@71
|
31 }
|
c@71
|
32
|
c@71
|
33 string listRequest = "{\"type\": \"list\"}";
|
c@71
|
34 const char *listResponse = reqFn(listRequest.c_str());
|
c@71
|
35 cout << listResponse << endl;
|
c@71
|
36 freeFn(listResponse);
|
c@73
|
37
|
c@73
|
38 string loadRequest = "{\"type\":\"load\",\"content\": {\"pluginKey\":\"vamp-example-plugins:zerocrossing\",\"inputSampleRate\":44100,\"adapterFlags\":[\"AdaptAllSafe\"]}}";
|
c@73
|
39 const char *loadResponse = reqFn(loadRequest.c_str());
|
c@73
|
40 cout << loadResponse << endl;
|
c@73
|
41 freeFn(loadResponse);
|
c@71
|
42 }
|
c@71
|
43
|