Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-octaveinttest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-octaveinttest
Commits
44c0129b
Commit
44c0129b
authored
Sep 1, 2021
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Test for file handling.
parent
63b97043
Branches
Branches containing commit
No related tags found
1 merge request
!3
ENH: Full functionality
Pipeline
#12889
failed
Sep 1, 2021
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/Run_Test.m
+3
-2
3 additions, 2 deletions
test/Run_Test.m
test/cleanup.m
+10
-1
10 additions, 1 deletion
test/cleanup.m
test/test_files.m
+103
-0
103 additions, 0 deletions
test/test_files.m
with
116 additions
and
3 deletions
test/Run_Test.m
+
3
−
2
View file @
44c0129b
...
@@ -19,8 +19,9 @@
...
@@ -19,8 +19,9 @@
pkg
load
caosdb
;
pkg
load
caosdb
;
all_tests
=
true
;
all_tests
=
true
;
all_tests
&=
moxunit_runtests
(
"-verbose"
,
"test_query_retrieve.m"
);
% all_tests &= moxunit_runtests("-verbose", "test_query_retrieve.m");
all_tests
&=
moxunit_runtests
(
"-verbose"
,
"test_transaction.m"
);
% all_tests &= moxunit_runtests("-verbose", "test_transaction.m");
all_tests
&=
moxunit_runtests
(
"-verbose"
,
"test_files.m"
);
if
not
(
all_tests
)
if
not
(
all_tests
)
exit
(
1
);
exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
test/cleanup.m
+
10
−
1
View file @
44c0129b
...
@@ -18,8 +18,17 @@
...
@@ -18,8 +18,17 @@
%% Clean up CaosDB (remove everything with ID > 99)
%% Clean up CaosDB (remove everything with ID > 99)
function
cleanup
()
function
cleanup
()
% if nargin < 1
% filenames = {}
% end
c
=
Caosdb
();
c
=
Caosdb
();
ids
=
caosdb_get_ids
(
c
.
query
(
'FIND ENTITY WITH ID > 99'
));
ids
=
caosdb_get_ids
(
c
.
query
(
'FIND ENTITY WITH ID > 99'
));
result
=
c
.
delete_by_id
(
ids
);
result
=
c
.
delete_by_id
(
ids
);
% disp(result)
%
% If FILENAMES is given, it must be a cell string array with filenames to delete.
% for filename = filenames
% filename = filename{1};
% fsdelete(filename) % TODO
% end
end
end
This diff is collapsed.
Click to expand it.
test/test_files.m
0 → 100644
+
103
−
0
View file @
44c0129b
% 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/>.
%% The main function which intitializes the tests.
function
test_suite
=
test_files
()
try
% assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions
=
localfunctions
();
catch
% no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite
;
end
% Create files with nearly random content.
function
filenames
=
create_testfiles
(
n
)
seed
=
20210831
;
rand
(
"state"
,
seed
);
filenames
=
{};
for
i
=
[
1
:
n
]
[
fid
,
filename
,
msg
]
=
mkstemp
(
"testfile_XXXXXX"
,
true
);
if
fid
==
-
1
error
([
"Error while creating temporary file:\n "
,
msg
]);
end
data
=
rand
([
10
,
10
]);
save
(
filename
,
"data"
);
end
end
function
test_insert_file
()
cleanup
();
filenames
=
create_testfiles
(
1
);
c
=
Caosdb
();
% Create file
F1
=
Entity
();
F1
.
role
=
"FILE"
;
F1
.
name
=
"file_1"
;
F1
.
filepath
=
"testfile1.xyz"
;
F1
.
localpath
=
filenames
{
1
};
% upload file
insert
=
c
.
insert
({
F1
});
assertFalse
(
insert
.
has_errors
(),
print_messages
(
insert
.
get_errors
(),
"error"
));
assertFalse
(
insert
.
has_warnings
(),
print_messages
(
insert
.
get_warnings
(),
"warning"
));
assertFalse
(
insert
.
has_infos
(),
print_messages
(
insert
.
get_infos
(),
"info"
));
assertEqual
(
numel
(
insert
),
1
);
F1_id
=
insert
{
1
}
.
id
;
% query for file
q_result
=
c
.
query
([
"COUNT FILE WHICH IS STORED AT '"
,
F1
.
filepath
,
"'"
]);
assertEqual
(
q_result
,
1
);
% download file and compare
[
fid
,
outfilename_1
,
msg
]
=
mkstemp
(
"testfile_out_XXXXXX"
,
true
);
if
fid
==
-
1
error
([
"Error while creating temporary file:\n "
,
msg
]);
end
c
.
retrieve_file_by_id
(
F1_id
,
outfilename_1
);
fid_orig
=
fopen
(
filenames
{
1
},
"r"
);
fid_retr
=
fopen
(
outfilename_1
,
"r"
);
[
data_orig
,
count_orig
]
=
fread
(
fid_orig
,
Inf
,
"*uint8"
);
count_retr
=
count_orig
+
1
;
% try to read up to one byte more
[
data_retr
,
count_retr
]
=
fread
(
fid_retr
,
count_retr
,
"*uint8"
);
fclose
(
fid_orig
);
fclose
(
fid_retr
);
assertEqual
(
count_retr
,
count_orig
);
assertEqual
(
data_orig
,
data_retr
);
cleanup
();
end
% Utility functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% print the messages into a cell
function
result
=
print_messages
(
message_cell
,
log_name
)
result
=
""
;
if
nargin
>
1
&&
~
isempty
(
log_name
)
result
=
[
"[ "
,
log_name
,
" ] "
];
end
for
msg
=
message_cell
msg
=
msg
{
1
};
result
=
[
result
,
"\n "
,
msg
.
str
()];
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment