2 Unit tests for Matlab wrap program
3 Author: Matthew Sklar, Varun Agrawal
14 sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
21 Test the Matlab wrapper
28 self.
TEST_DIR = osp.dirname(osp.realpath(__file__))
37 template_file = osp.join(self.
TEST_DIR,
"..",
"gtwrap",
38 "matlab_wrapper",
"matlab_wrapper.tpl")
39 if not osp.exists(template_file):
40 with open(template_file,
'w', encoding=
"UTF-8")
as tpl:
41 tpl.write(
"#include <gtwrap/matlab.h>\n#include <map>\n")
48 Compute the comparison between the expected and actual file,
49 and assert if diff is zero.
52 success = filecmp.cmp(actual, expected)
55 os.system(f
"diff {actual} {expected}")
56 self.assertTrue(success, f
"Mismatch for file {file}")
60 Check generation of matlab geometry wrapper.
61 python3 wrap/matlab_wrapper.py --src wrap/tests/geometry.h
62 --module_name geometry --out wrap/tests/actual-matlab
68 top_module_namespace=[
'gtsam'],
70 use_boost_serialization=
True)
74 files = [
'+gtsam/Point2.m',
'+gtsam/Point3.m',
'geometry_wrapper.cpp']
83 """Test interface file with function info."""
87 module_name=
'functions',
88 top_module_namespace=[
'gtsam'],
95 'functions_wrapper.cpp',
98 'MultiTemplatedFunctionDoubleSize_tDouble.m',
99 'MultiTemplatedFunctionStringSize_tDouble.m',
100 'overloadedGlobalFunction.m',
101 'TemplatedFunctionRot3.m',
104 'DefaultFuncString.m',
105 'DefaultFuncVector.m',
115 """Test interface file with only class info."""
120 top_module_namespace=[
'gtsam'],
130 'MultipleTemplatesIntDouble.m',
131 'MultipleTemplatesIntFloat.m',
132 'MyFactorPosePoint2.m',
135 'PrimitiveRefDouble.m',
137 'ForwardKinematics.m',
145 """Test interface file with only enum info."""
150 top_module_namespace=[
'gtsam'],
160 '+gtsam/VerbosityLM.m',
161 '+gtsam/+MCU/Avengers.m',
162 '+gtsam/+MCU/GotG.m',
163 '+gtsam/+OptimizerGaussNewtonParams/Verbosity.m',
171 """Test interface file with template info."""
175 module_name=
'template',
176 top_module_namespace=[
'gtsam'],
183 'template_wrapper.cpp',
'ScopedTemplateResult.m',
184 'TemplatedConstructor.m'
192 """Test interface file with class inheritance definitions."""
196 module_name=
'inheritance',
197 top_module_namespace=[
'gtsam'],
203 'inheritance_wrapper.cpp',
205 'MyTemplateMatrix.m',
206 'MyTemplatePoint2.m',
207 'ForwardKinematicsFactor.m',
216 Test interface file with full namespace definition.
221 module_name=
'namespaces',
222 top_module_namespace=[
'gtsam'],
229 'namespaces_wrapper.cpp',
230 '+ns1/aGlobalFunction.m',
233 '+ns2/+ns3/ClassB.m',
234 '+ns2/aGlobalFunction.m',
237 '+ns2/overloadedGlobalFunction.m',
248 Tests for some unique, non-trivial features.
253 module_name=
'special_cases',
254 top_module_namespace=[
'gtsam'],
260 'special_cases_wrapper.cpp',
261 '+gtsam/GeneralSFMFactorCal3Bundler.m',
262 '+gtsam/NonlinearFactorGraph.m',
263 '+gtsam/PinholeCameraCal3Bundler.m',
273 Test for when multiple interface files are specified.
279 module_name=
'multiple_files',
280 top_module_namespace=[
'gtsam'],
287 'multiple_files_wrapper.cpp',
298 if __name__ ==
'__main__':