execm test driver: use to test rcldoc.py
This commit is contained in:
parent
28be1152ef
commit
9bb428aa3b
1 changed files with 84 additions and 76 deletions
|
@ -1071,22 +1071,25 @@ void ReExec::reexec()
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "cancelcheck.h"
|
#include "cancelcheck.h"
|
||||||
#include "execmd.h"
|
#include "execmd.h"
|
||||||
#include "smallut.h"
|
#include "smallut.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// Testing with rclaudio: use an mp3 as parameter
|
// Testing with rclaudio: use an mp3 as parameter
|
||||||
static const string tstcmd("/usr/share/recoll/filters/rclaudio");
|
static const string tstcmd("/home/dockes/projets/fulltext/win-recoll/src/filters/rcldoc.py");
|
||||||
static const string mimetype("audio/mpeg");
|
static const string mimetype("text/html");
|
||||||
bool exercise_mhexecm(const string& filename)
|
bool exercise_mhexecm(vector<string>& files)
|
||||||
{
|
{
|
||||||
ExecCmd cmd;
|
ExecCmd cmd;
|
||||||
|
|
||||||
|
@ -1097,77 +1100,81 @@ bool exercise_mhexecm(const string& filename)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build request message
|
for (vector<string>::const_iterator it = files.begin();
|
||||||
ostringstream obuf;
|
it != files.end(); it++) {
|
||||||
obuf << "FileName: " << filename.length() << "\n" << filename;
|
// Build request message
|
||||||
obuf << "Mimetype: " << mimetype.length() << "\n" << mimetype;
|
ostringstream obuf;
|
||||||
// Bogus parameter should be skipped by filter
|
obuf << "Filename: " << (*it).length() << "\n" << (*it);
|
||||||
obuf << "BogusParam: " << string("bogus").length() << "\n" << "bogus";
|
obuf << "Mimetype: " << mimetype.length() << "\n" << mimetype;
|
||||||
obuf << "\n";
|
// Bogus parameter should be skipped by filter
|
||||||
cerr << "SENDING: [" << obuf.str() << "]\n";
|
obuf << "BogusParam: " << string("bogus").length() << "\n" << "bogus";
|
||||||
// Send it
|
obuf << "\n";
|
||||||
if (cmd.send(obuf.str()) < 0) {
|
cerr << "SENDING: [" << obuf.str() << "]\n";
|
||||||
// The real code calls zapchild here, but we don't need it as
|
// Send it
|
||||||
// this will be handled by ~ExecCmd
|
if (cmd.send(obuf.str()) < 0) {
|
||||||
//cmd.zapChild();
|
// The real code calls zapchild here, but we don't need it as
|
||||||
cerr << "send error\n";
|
// this will be handled by ~ExecCmd
|
||||||
return false;
|
//cmd.zapChild();
|
||||||
|
cerr << "send error\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read answer
|
||||||
|
for (int loop=0;;loop++) {
|
||||||
|
string name, data;
|
||||||
|
|
||||||
|
// Code from mh_execm.cpp: readDataElement
|
||||||
|
string ibuf;
|
||||||
|
// Read name and length
|
||||||
|
if (cmd.getline(ibuf) <= 0) {
|
||||||
|
cerr << "getline error\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Empty line (end of message)
|
||||||
|
if (!ibuf.compare("\n")) {
|
||||||
|
cerr << "Got empty line\n";
|
||||||
|
name.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters will sometimes abort before entering the real
|
||||||
|
// protocol, ie if a module can't be loaded. Check the
|
||||||
|
// special filter error first word:
|
||||||
|
if (ibuf.find("RECFILTERROR ") == 0) {
|
||||||
|
cerr << "Got RECFILTERROR\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're expecting something like Name: len\n
|
||||||
|
vector<string> tokens;
|
||||||
|
stringToTokens(ibuf, tokens);
|
||||||
|
if (tokens.size() != 2) {
|
||||||
|
cerr << "bad line in filter output: [" << ibuf << "]\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vector<string>::iterator it = tokens.begin();
|
||||||
|
name = *it++;
|
||||||
|
string& slen = *it;
|
||||||
|
int len;
|
||||||
|
if (sscanf(slen.c_str(), "%d", &len) != 1) {
|
||||||
|
cerr << "bad line in filter output (no len): [" <<
|
||||||
|
ibuf << "]\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Read element data
|
||||||
|
data.erase();
|
||||||
|
if (len > 0 && cmd.receive(data, len) != len) {
|
||||||
|
cerr << "MHExecMultiple: expected " << len <<
|
||||||
|
" bytes of data, got " << data.length() << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty element: end of message
|
||||||
|
if (name.empty())
|
||||||
|
break;
|
||||||
|
cerr << "Got name: [" << name << "] data [" << data << "]\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read answer
|
|
||||||
for (int loop=0;;loop++) {
|
|
||||||
string name, data;
|
|
||||||
|
|
||||||
// Code from mh_execm.cpp: readDataElement
|
|
||||||
string ibuf;
|
|
||||||
// Read name and length
|
|
||||||
if (cmd.getline(ibuf) <= 0) {
|
|
||||||
cerr << "getline error\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Empty line (end of message)
|
|
||||||
if (!ibuf.compare("\n")) {
|
|
||||||
cerr << "Got empty line\n";
|
|
||||||
name.clear();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filters will sometimes abort before entering the real protocol, ie if
|
|
||||||
// a module can't be loaded. Check the special filter error first word:
|
|
||||||
if (ibuf.find("RECFILTERROR ") == 0) {
|
|
||||||
cerr << "Got RECFILTERROR\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're expecting something like Name: len\n
|
|
||||||
vector<string> tokens;
|
|
||||||
stringToTokens(ibuf, tokens);
|
|
||||||
if (tokens.size() != 2) {
|
|
||||||
cerr << "bad line in filter output: [" << ibuf << "]\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
vector<string>::iterator it = tokens.begin();
|
|
||||||
name = *it++;
|
|
||||||
string& slen = *it;
|
|
||||||
int len;
|
|
||||||
if (sscanf(slen.c_str(), "%d", &len) != 1) {
|
|
||||||
cerr << "bad line in filter output (no len): [" << ibuf << "]\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Read element data
|
|
||||||
data.erase();
|
|
||||||
if (len > 0 && cmd.receive(data, len) != len) {
|
|
||||||
cerr << "MHExecMultiple: expected " << len <<
|
|
||||||
" bytes of data, got " << data.length() << endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Empty element: end of message
|
|
||||||
if (name.empty())
|
|
||||||
break;
|
|
||||||
cerr << "Got name: [" << name << "] data [" << data << "]\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1227,7 +1234,7 @@ static char usage [] =
|
||||||
"trexecmd [-c|-r] cmd [arg1 arg2 ...]\n"
|
"trexecmd [-c|-r] cmd [arg1 arg2 ...]\n"
|
||||||
" -c : test cancellation (ie: trexecmd -c sleep 1000)\n"
|
" -c : test cancellation (ie: trexecmd -c sleep 1000)\n"
|
||||||
" -r : test reexec\n"
|
" -r : test reexec\n"
|
||||||
" -m <path to mp3 file>: test execm: needs installed and working rclaudio/mutagen\n"
|
" -m <file.doc> [...]: test execm:\n"
|
||||||
"trexecmd -w cmd : do the which thing\n"
|
"trexecmd -w cmd : do the which thing\n"
|
||||||
;
|
;
|
||||||
static void Usage(void)
|
static void Usage(void)
|
||||||
|
@ -1303,7 +1310,8 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op_flags & OPT_m) {
|
if (op_flags & OPT_m) {
|
||||||
return exercise_mhexecm(arg1) ? 0 : 1;
|
l.insert(l.begin(), arg1);
|
||||||
|
return exercise_mhexecm(l) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////
|
//////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue