Finish globalOverloads: made sure overloaded global functions actually work, including within namespaces.
commit
6384e4d336
|
|
@ -17,7 +17,8 @@ using namespace std;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack) {
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const StrVec& ns_stack) {
|
||||||
this->verbose_ = verbose;
|
this->verbose_ = verbose;
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->argLists.push_back(args);
|
this->argLists.push_back(args);
|
||||||
|
|
@ -26,16 +27,16 @@ void GlobalFunction::addOverload(bool verbose, const std::string& name,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::matlab_proxy(const std::string& toolboxPath, const std::string& wrapperName,
|
void GlobalFunction::matlab_proxy(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const {
|
FileWriter& file, std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
// cluster overloads with same namespace
|
// cluster overloads with same namespace
|
||||||
// create new GlobalFunction structures around namespaces - same namespaces and names are overloads
|
// create new GlobalFunction structures around namespaces - same namespaces and names are overloads
|
||||||
// map of namespace to global function
|
// map of namespace to global function
|
||||||
typedef map<string, GlobalFunction> GlobalFunctionMap;
|
typedef map<string, GlobalFunction> GlobalFunctionMap;
|
||||||
GlobalFunctionMap grouped_functions;
|
GlobalFunctionMap grouped_functions;
|
||||||
for (size_t i=0; i<namespaces.size(); ++i) {
|
for (size_t i = 0; i < namespaces.size(); ++i) {
|
||||||
StrVec ns = namespaces.at(i);
|
StrVec ns = namespaces.at(i);
|
||||||
string str_ns = qualifiedName("", ns, "");
|
string str_ns = qualifiedName("", ns, "");
|
||||||
ReturnValue ret = returnVals.at(i);
|
ReturnValue ret = returnVals.at(i);
|
||||||
|
|
@ -51,16 +52,17 @@ void GlobalFunction::matlab_proxy(const std::string& toolboxPath, const std::str
|
||||||
|
|
||||||
size_t lastcheck = grouped_functions.size();
|
size_t lastcheck = grouped_functions.size();
|
||||||
BOOST_FOREACH(const GlobalFunctionMap::value_type& p, grouped_functions) {
|
BOOST_FOREACH(const GlobalFunctionMap::value_type& p, grouped_functions) {
|
||||||
p.second.generateSingleFunction(toolboxPath, wrapperName, typeAttributes, wrapperFile, functionNames);
|
p.second.generateSingleFunction(toolboxPath, wrapperName, typeAttributes,
|
||||||
|
file, functionNames);
|
||||||
if (--lastcheck != 0)
|
if (--lastcheck != 0)
|
||||||
wrapperFile.oss << endl;
|
file.oss << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, const std::string& wrapperName,
|
void GlobalFunction::generateSingleFunction(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const {
|
FileWriter& file, std::vector<std::string>& functionNames) const {
|
||||||
|
|
||||||
// create the folder for the namespace
|
// create the folder for the namespace
|
||||||
const StrVec& ns = namespaces.front();
|
const StrVec& ns = namespaces.front();
|
||||||
|
|
@ -68,79 +70,68 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
|
|
||||||
// open destination mfunctionFileName
|
// open destination mfunctionFileName
|
||||||
string mfunctionFileName = toolboxPath;
|
string mfunctionFileName = toolboxPath;
|
||||||
if(!ns.empty())
|
if (!ns.empty())
|
||||||
mfunctionFileName += "/+" + wrap::qualifiedName("/+", ns);
|
mfunctionFileName += "/+" + wrap::qualifiedName("/+", ns);
|
||||||
mfunctionFileName += "/" + name + ".m";
|
mfunctionFileName += "/" + name + ".m";
|
||||||
FileWriter mfunctionFile(mfunctionFileName, verbose_, "%");
|
FileWriter mfunctionFile(mfunctionFileName, verbose_, "%");
|
||||||
|
|
||||||
// get the name of actual matlab object
|
// get the name of actual matlab object
|
||||||
const string
|
const string matlabQualName = qualifiedName(".", ns, name), matlabUniqueName =
|
||||||
matlabQualName = qualifiedName(".", ns, name),
|
qualifiedName("", ns, name), cppName = qualifiedName("::", ns, name);
|
||||||
matlabUniqueName = qualifiedName("", ns, name),
|
|
||||||
cppName = qualifiedName("::", ns, name);
|
|
||||||
|
|
||||||
mfunctionFile.oss << "function varargout = " << name << "(varargin)\n";
|
mfunctionFile.oss << "function varargout = " << name << "(varargin)\n";
|
||||||
|
|
||||||
for(size_t overload = 0; overload < argLists.size(); ++overload) {
|
for (size_t overload = 0; overload < argLists.size(); ++overload) {
|
||||||
const ArgumentList& args = argLists[overload];
|
const ArgumentList& args = argLists[overload];
|
||||||
const ReturnValue& returnVal = returnVals[overload];
|
const ReturnValue& returnVal = returnVals[overload];
|
||||||
size_t nrArgs = args.size();
|
|
||||||
|
|
||||||
const int id = functionNames.size();
|
const int id = functionNames.size();
|
||||||
|
|
||||||
// Output proxy matlab code
|
// Output proxy matlab code
|
||||||
|
mfunctionFile.oss << " " << (overload == 0 ? "" : "else");
|
||||||
// check for number of arguments...
|
argLists[overload].emit_conditional_call(mfunctionFile,
|
||||||
mfunctionFile.oss << (overload==0?"":"else") << "if length(varargin) == " << nrArgs;
|
returnVals[overload], wrapperName, id, true); // true omits "this"
|
||||||
if (nrArgs>0) mfunctionFile.oss << " && ";
|
|
||||||
// ...and their types
|
|
||||||
bool first = true;
|
|
||||||
for(size_t i=0;i<nrArgs;i++) {
|
|
||||||
if (!first) mfunctionFile.oss << " && ";
|
|
||||||
mfunctionFile.oss << "isa(varargin{" << i+1 << "},'" << args[i].matlabClass(".") << "')";
|
|
||||||
first=false;
|
|
||||||
}
|
|
||||||
mfunctionFile.oss << "\n";
|
|
||||||
|
|
||||||
// output call to C++ wrapper
|
|
||||||
mfunctionFile.oss << " ";
|
|
||||||
returnVal.emit_matlab(mfunctionFile);
|
|
||||||
mfunctionFile.oss << wrapperName << "(" << id << ", varargin{:});\n";
|
|
||||||
|
|
||||||
// Output C++ wrapper code
|
// Output C++ wrapper code
|
||||||
|
|
||||||
const string wrapFunctionName = matlabUniqueName + "_" + boost::lexical_cast<string>(id);
|
const string wrapFunctionName = matlabUniqueName + "_"
|
||||||
|
+ boost::lexical_cast<string>(id);
|
||||||
|
|
||||||
// call
|
// call
|
||||||
wrapperFile.oss << "void " << wrapFunctionName << "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
file.oss << "void " << wrapFunctionName
|
||||||
|
<< "(int nargout, mxArray *out[], int nargin, const mxArray *in[])\n";
|
||||||
// start
|
// start
|
||||||
wrapperFile.oss << "{\n";
|
file.oss << "{\n";
|
||||||
|
|
||||||
returnVal.wrapTypeUnwrap(wrapperFile);
|
returnVal.wrapTypeUnwrap(file);
|
||||||
|
|
||||||
// check arguments
|
// check arguments
|
||||||
// NOTE: for static functions, there is no object passed
|
// NOTE: for static functions, there is no object passed
|
||||||
wrapperFile.oss << " checkArguments(\"" << matlabUniqueName << "\",nargout,nargin," << args.size() << ");\n";
|
file.oss << " checkArguments(\"" << matlabUniqueName
|
||||||
|
<< "\",nargout,nargin," << args.size() << ");\n";
|
||||||
|
|
||||||
// unwrap arguments, see Argument.cpp
|
// unwrap arguments, see Argument.cpp
|
||||||
args.matlab_unwrap(wrapperFile,0); // We start at 0 because there is no self object
|
args.matlab_unwrap(file, 0); // We start at 0 because there is no self object
|
||||||
|
|
||||||
// call method with default type and wrap result
|
// call method with default type and wrap result
|
||||||
if (returnVal.type1!="void")
|
if (returnVal.type1 != "void")
|
||||||
returnVal.wrap_result(cppName+"("+args.names()+")", wrapperFile, typeAttributes);
|
returnVal.wrap_result(cppName + "(" + args.names() + ")", file,
|
||||||
|
typeAttributes);
|
||||||
else
|
else
|
||||||
wrapperFile.oss << cppName+"("+args.names()+");\n";
|
file.oss << cppName + "(" + args.names() + ");\n";
|
||||||
|
|
||||||
// finish
|
// finish
|
||||||
wrapperFile.oss << "}\n";
|
file.oss << "}\n";
|
||||||
|
|
||||||
// Add to function list
|
// Add to function list
|
||||||
functionNames.push_back(wrapFunctionName);
|
functionNames.push_back(wrapFunctionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
mfunctionFile.oss << "else\n";
|
mfunctionFile.oss << " else\n";
|
||||||
mfunctionFile.oss << " error('Arguments do not match any overload of function " << matlabQualName << "');" << endl;
|
mfunctionFile.oss
|
||||||
mfunctionFile.oss << "end" << endl;
|
<< " error('Arguments do not match any overload of function "
|
||||||
|
<< matlabQualName << "');" << endl;
|
||||||
|
mfunctionFile.oss << " end" << endl;
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
mfunctionFile.emit(true);
|
mfunctionFile.emit(true);
|
||||||
|
|
@ -148,9 +139,5 @@ void GlobalFunction::generateSingleFunction(const std::string& toolboxPath, cons
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,37 +22,38 @@ struct GlobalFunction {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
// each overload, regardless of namespace
|
// each overload, regardless of namespace
|
||||||
std::vector<ArgumentList> argLists; ///< arugments for each overload
|
std::vector<ArgumentList> argLists; ///< arugments for each overload
|
||||||
std::vector<ReturnValue> returnVals; ///< returnVals for each overload
|
std::vector<ReturnValue> returnVals; ///< returnVals for each overload
|
||||||
std::vector<StrVec> namespaces; ///< Stack of namespaces
|
std::vector<StrVec> namespaces; ///< Stack of namespaces
|
||||||
|
|
||||||
// Constructor only used in Module
|
// Constructor only used in Module
|
||||||
GlobalFunction(bool verbose = true) : verbose_(verbose) {}
|
GlobalFunction(bool verbose = true) :
|
||||||
|
verbose_(verbose) {
|
||||||
|
}
|
||||||
|
|
||||||
// Used to reconstruct
|
// Used to reconstruct
|
||||||
GlobalFunction(const std::string& name_, bool verbose = true)
|
GlobalFunction(const std::string& name_, bool verbose = true) :
|
||||||
: verbose_(verbose), name(name_) {}
|
verbose_(verbose), name(name_) {
|
||||||
|
}
|
||||||
|
|
||||||
// adds an overloaded version of this function
|
// adds an overloaded version of this function
|
||||||
void addOverload(bool verbose, const std::string& name,
|
void addOverload(bool verbose, const std::string& name,
|
||||||
const ArgumentList& args, const ReturnValue& retVal, const StrVec& ns_stack);
|
const ArgumentList& args, const ReturnValue& retVal,
|
||||||
|
const StrVec& ns_stack);
|
||||||
|
|
||||||
// codegen function called from Module to build the cpp and matlab versions of the function
|
// codegen function called from Module to build the cpp and matlab versions of the function
|
||||||
void matlab_proxy(const std::string& toolboxPath, const std::string& wrapperName,
|
void matlab_proxy(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const;
|
FileWriter& file, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Creates a single global function - all in same namespace
|
// Creates a single global function - all in same namespace
|
||||||
void generateSingleFunction(const std::string& toolboxPath, const std::string& wrapperName,
|
void generateSingleFunction(const std::string& toolboxPath,
|
||||||
const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile,
|
const std::string& wrapperName, const TypeAttributesTable& typeAttributes,
|
||||||
std::vector<std::string>& functionNames) const;
|
FileWriter& file, std::vector<std::string>& functionNames) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // \namespace wrap
|
} // \namespace wrap
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
function varargout = aGlobalFunction(varargin)
|
function varargout = aGlobalFunction(varargin)
|
||||||
if length(varargin) == 0
|
if length(varargin) == 0
|
||||||
varargout{1} = geometry_wrapper(42, varargin{:});
|
varargout{1} = geometry_wrapper(42, varargin{:});
|
||||||
else
|
else
|
||||||
error('Arguments do not match any overload of function aGlobalFunction');
|
error('Arguments do not match any overload of function aGlobalFunction');
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -502,6 +502,19 @@ void aGlobalFunction_42(int nargout, mxArray *out[], int nargin, const mxArray *
|
||||||
checkArguments("aGlobalFunction",nargout,nargin,0);
|
checkArguments("aGlobalFunction",nargout,nargin,0);
|
||||||
out[0] = wrap< Vector >(aGlobalFunction());
|
out[0] = wrap< Vector >(aGlobalFunction());
|
||||||
}
|
}
|
||||||
|
void overloadedGlobalFunction_43(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
checkArguments("overloadedGlobalFunction",nargout,nargin,1);
|
||||||
|
int a = unwrap< int >(in[0]);
|
||||||
|
out[0] = wrap< Vector >(overloadedGlobalFunction(a));
|
||||||
|
}
|
||||||
|
void overloadedGlobalFunction_44(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
checkArguments("overloadedGlobalFunction",nargout,nargin,2);
|
||||||
|
int a = unwrap< int >(in[0]);
|
||||||
|
double b = unwrap< double >(in[1]);
|
||||||
|
out[0] = wrap< Vector >(overloadedGlobalFunction(a,b));
|
||||||
|
}
|
||||||
|
|
||||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
{
|
{
|
||||||
|
|
@ -643,6 +656,12 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
case 42:
|
case 42:
|
||||||
aGlobalFunction_42(nargout, out, nargin-1, in+1);
|
aGlobalFunction_42(nargout, out, nargin-1, in+1);
|
||||||
break;
|
break;
|
||||||
|
case 43:
|
||||||
|
overloadedGlobalFunction_43(nargout, out, nargin-1, in+1);
|
||||||
|
break;
|
||||||
|
case 44:
|
||||||
|
overloadedGlobalFunction_44(nargout, out, nargin-1, in+1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch(const std::exception& e) {
|
} catch(const std::exception& e) {
|
||||||
mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
|
mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
function varargout = overloadedGlobalFunction(varargin)
|
||||||
|
if length(varargin) == 1 && isa(varargin{1},'numeric')
|
||||||
|
varargout{1} = geometry_wrapper(43, varargin{:});
|
||||||
|
elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double')
|
||||||
|
varargout{1} = geometry_wrapper(44, varargin{:});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of function overloadedGlobalFunction');
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
function varargout = overloadedGlobalFunction(varargin)
|
||||||
|
if length(varargin) == 1 && isa(varargin{1},'ns1.ClassA')
|
||||||
|
varargout{1} = testNamespaces_wrapper(24, varargin{:});
|
||||||
|
elseif length(varargin) == 2 && isa(varargin{1},'ns1.ClassA') && isa(varargin{2},'double')
|
||||||
|
varargout{1} = testNamespaces_wrapper(25, varargin{:});
|
||||||
|
else
|
||||||
|
error('Arguments do not match any overload of function ns2.overloadedGlobalFunction');
|
||||||
|
end
|
||||||
|
|
@ -342,6 +342,21 @@ void ns2aGlobalFunction_23(int nargout, mxArray *out[], int nargin, const mxArra
|
||||||
checkArguments("ns2aGlobalFunction",nargout,nargin,0);
|
checkArguments("ns2aGlobalFunction",nargout,nargin,0);
|
||||||
out[0] = wrap< Vector >(ns2::aGlobalFunction());
|
out[0] = wrap< Vector >(ns2::aGlobalFunction());
|
||||||
}
|
}
|
||||||
|
void ns2overloadedGlobalFunction_24(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
typedef boost::shared_ptr<ns1::ClassA> SharedClassA;
|
||||||
|
checkArguments("ns2overloadedGlobalFunction",nargout,nargin,1);
|
||||||
|
ns1::ClassA& a = *unwrap_shared_ptr< ns1::ClassA >(in[0], "ptr_ns1ClassA");
|
||||||
|
out[0] = wrap_shared_ptr(SharedClassA(new ns1::ClassA(ns2::overloadedGlobalFunction(a))),"ns1.ClassA", false);
|
||||||
|
}
|
||||||
|
void ns2overloadedGlobalFunction_25(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
|
{
|
||||||
|
typedef boost::shared_ptr<ns1::ClassA> SharedClassA;
|
||||||
|
checkArguments("ns2overloadedGlobalFunction",nargout,nargin,2);
|
||||||
|
ns1::ClassA& a = *unwrap_shared_ptr< ns1::ClassA >(in[0], "ptr_ns1ClassA");
|
||||||
|
double b = unwrap< double >(in[1]);
|
||||||
|
out[0] = wrap_shared_ptr(SharedClassA(new ns1::ClassA(ns2::overloadedGlobalFunction(a,b))),"ns1.ClassA", false);
|
||||||
|
}
|
||||||
|
|
||||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
{
|
{
|
||||||
|
|
@ -426,6 +441,12 @@ void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||||
case 23:
|
case 23:
|
||||||
ns2aGlobalFunction_23(nargout, out, nargin-1, in+1);
|
ns2aGlobalFunction_23(nargout, out, nargin-1, in+1);
|
||||||
break;
|
break;
|
||||||
|
case 24:
|
||||||
|
ns2overloadedGlobalFunction_24(nargout, out, nargin-1, in+1);
|
||||||
|
break;
|
||||||
|
case 25:
|
||||||
|
ns2overloadedGlobalFunction_25(nargout, out, nargin-1, in+1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch(const std::exception& e) {
|
} catch(const std::exception& e) {
|
||||||
mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
|
mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,10 @@ class Test {
|
||||||
|
|
||||||
Vector aGlobalFunction();
|
Vector aGlobalFunction();
|
||||||
|
|
||||||
|
// An overloaded global function
|
||||||
|
Vector overloadedGlobalFunction(int a);
|
||||||
|
Vector overloadedGlobalFunction(int a, double b);
|
||||||
|
|
||||||
// comments at the end!
|
// comments at the end!
|
||||||
|
|
||||||
// even more comments at the end!
|
// even more comments at the end!
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,10 @@ class ClassC {
|
||||||
// separate namespace global function, same name
|
// separate namespace global function, same name
|
||||||
Vector aGlobalFunction();
|
Vector aGlobalFunction();
|
||||||
|
|
||||||
|
// An overloaded global function
|
||||||
|
ns1::ClassA overloadedGlobalFunction(const ns1::ClassA& a);
|
||||||
|
ns1::ClassA overloadedGlobalFunction(const ns1::ClassA& a, double b);
|
||||||
|
|
||||||
} //\namespace ns2
|
} //\namespace ns2
|
||||||
|
|
||||||
class ClassD {
|
class ClassD {
|
||||||
|
|
|
||||||
|
|
@ -15,16 +15,18 @@
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
#include <wrap/utilities.h>
|
||||||
|
#include <wrap/Module.h>
|
||||||
|
|
||||||
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
|
||||||
|
#include <boost/assign/std/vector.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/assign/std/vector.hpp>
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <CppUnitLite/TestHarness.h>
|
|
||||||
|
|
||||||
#include <wrap/utilities.h>
|
|
||||||
#include <wrap/Module.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
@ -305,8 +307,8 @@ TEST( wrap, parse_geometry ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// evaluate global functions
|
// evaluate global functions
|
||||||
// Vector aGlobalFunction();
|
// Vector aGlobalFunction();
|
||||||
LONGS_EQUAL(1, module.global_functions.size());
|
LONGS_EQUAL(2, module.global_functions.size());
|
||||||
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
|
|
@ -380,7 +382,7 @@ TEST( wrap, parse_namespaces ) {
|
||||||
// evaluate global functions
|
// evaluate global functions
|
||||||
// Vector ns1::aGlobalFunction();
|
// Vector ns1::aGlobalFunction();
|
||||||
// Vector ns2::aGlobalFunction();
|
// Vector ns2::aGlobalFunction();
|
||||||
LONGS_EQUAL(1, module.global_functions.size());
|
LONGS_EQUAL(2, module.global_functions.size());
|
||||||
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
CHECK(module.global_functions.find("aGlobalFunction") != module.global_functions.end());
|
||||||
{
|
{
|
||||||
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
GlobalFunction gfunc = module.global_functions.at("aGlobalFunction");
|
||||||
|
|
@ -415,13 +417,17 @@ TEST( wrap, matlab_code_namespaces ) {
|
||||||
module.matlab_code("actual_namespaces", headerPath);
|
module.matlab_code("actual_namespaces", headerPath);
|
||||||
|
|
||||||
|
|
||||||
EXPECT(files_equal(exp_path + "ClassD.m" , act_path + "ClassD.m" ));
|
EXPECT(files_equal(exp_path + "ClassD.m", act_path + "ClassD.m" ));
|
||||||
EXPECT(files_equal(exp_path + "+ns1/ClassA.m" , act_path + "+ns1/ClassA.m" ));
|
EXPECT(files_equal(exp_path + "+ns1/ClassA.m", act_path + "+ns1/ClassA.m" ));
|
||||||
EXPECT(files_equal(exp_path + "+ns1/ClassB.m" , act_path + "+ns1/ClassB.m" ));
|
EXPECT(files_equal(exp_path + "+ns1/ClassB.m", act_path + "+ns1/ClassB.m" ));
|
||||||
EXPECT(files_equal(exp_path + "+ns2/ClassA.m" , act_path + "+ns2/ClassA.m" ));
|
EXPECT(files_equal(exp_path + "+ns2/ClassA.m", act_path + "+ns2/ClassA.m" ));
|
||||||
EXPECT(files_equal(exp_path + "+ns2/ClassC.m" , act_path + "+ns2/ClassC.m" ));
|
EXPECT(files_equal(exp_path + "+ns2/ClassC.m", act_path + "+ns2/ClassC.m" ));
|
||||||
EXPECT(files_equal(exp_path + "+ns2/+ns3/ClassB.m" , act_path + "+ns2/+ns3/ClassB.m" ));
|
EXPECT(
|
||||||
EXPECT(files_equal(exp_path + "testNamespaces_wrapper.cpp" , act_path + "testNamespaces_wrapper.cpp" ));
|
files_equal(exp_path + "+ns2/overloadedGlobalFunction.m", exp_path + "+ns2/overloadedGlobalFunction.m" ));
|
||||||
|
EXPECT(
|
||||||
|
files_equal(exp_path + "+ns2/+ns3/ClassB.m", act_path + "+ns2/+ns3/ClassB.m" ));
|
||||||
|
EXPECT(
|
||||||
|
files_equal(exp_path + "testNamespaces_wrapper.cpp", act_path + "testNamespaces_wrapper.cpp" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
@ -445,6 +451,7 @@ TEST( wrap, matlab_code_geometry ) {
|
||||||
EXPECT(files_equal(epath + "Point3.m" , apath + "Point3.m" ));
|
EXPECT(files_equal(epath + "Point3.m" , apath + "Point3.m" ));
|
||||||
EXPECT(files_equal(epath + "Test.m" , apath + "Test.m" ));
|
EXPECT(files_equal(epath + "Test.m" , apath + "Test.m" ));
|
||||||
EXPECT(files_equal(epath + "aGlobalFunction.m" , apath + "aGlobalFunction.m" ));
|
EXPECT(files_equal(epath + "aGlobalFunction.m" , apath + "aGlobalFunction.m" ));
|
||||||
|
EXPECT(files_equal(epath + "overloadedGlobalFunction.m" , apath + "overloadedGlobalFunction.m" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,11 @@ bool files_equal(const string& expected, const string& actual, bool skipheader)
|
||||||
string actual_contents = file_contents(actual, skipheader);
|
string actual_contents = file_contents(actual, skipheader);
|
||||||
bool equal = actual_contents == expected_contents;
|
bool equal = actual_contents == expected_contents;
|
||||||
if (!equal) {
|
if (!equal) {
|
||||||
|
cerr << "<<< DIFF OUTPUT (if none, white-space differences only):\n";
|
||||||
stringstream command;
|
stringstream command;
|
||||||
command << "diff " << expected << " " << actual << endl;
|
command << "diff --ignore-all-space " << expected << " " << actual << endl;
|
||||||
system(command.str().c_str());
|
system(command.str().c_str());
|
||||||
|
cerr << ">>>\n";
|
||||||
}
|
}
|
||||||
return equal;
|
return equal;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue