Newer
Older
% This file is a part of the CaosDB Project.
%
% Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
% Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end
% Only tests which don't need a connection to a server.
function test_local()
% default connection
c1 = Caosdb();
% class with explicit connection
assertEqual(c2.connection, "local-caosdb-admin");
% Only get the local versions.
version = caosdb_exec("--version");
assertEqual(version(1:21), "v0.1 (libcaosdb v0.0.");
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
% Test if conversion between Entity objects and mxArray structures works.
function test_entity_conversion()
% set plain Octave properties
p1 = Property();
p1.id = "P1_id";
p1.name = "Prop 1";
p1.description = "";
p1.importance = "somewhat";
p1.datatype = "DOUBLE";
p1.unit = "Mt";
p1.value = [];
p2 = Property();
p2.id = "P2_id";
p2.name = "Prop 2";
p2.description = "";
p2.importance = "very";
p2.datatype = "BOOLEAN";
p2.value = 1;
par = Parent();
par.id = "-1";
par.name = "Parent 1";
par.description = "self-inheritance";
e = Entity();
e.role = "Record";
e.id = "-1";
e.name = "Test Record";
% merge objects
e.set_properties({p1, p2});
e.set_parents({par});
% convert forwards and backwards
e_struct = e.to_struct();
e_clone = Entity(e_struct);
assertEqual(e_clone.id, e.id);
assertEqual(numel(e.get_parents()), 1);
assertEqual(numel(e.get_properties()), 2);