Skip to content

Commit 5bee649

Browse files
Add test for unlimited arrays
1 parent c0c5057 commit 5bee649

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

Framework/NexusCpp/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ add_test(NAME "${TEST_PREFIX}-Cpp-HDF4-test" COMMAND napi_test_cpp-hdf4)
107107
# if (WIN32) set_property(TEST "${TEST_PREFIX}-Cpp-HDF4-test" APPEND PROPERTY ENVIRONMENT "PATH=${TESTSPATH}")
108108
# endif(WIN32)
109109

110+
# #### test for unlimited dimensions
111+
add_executable(napi_test_nxunlimited EXCLUDE_FROM_ALL test/test_nxunlimited.c)
112+
target_link_libraries(napi_test_nxunlimited NexusCpp)
113+
add_test(NAME "${TEST_PREFIX}-C-test-nxunlimited" COMMAND napi_test_nxunlimited)
114+
115+
# TODO figure out correct check
116+
117+
# if (WIN32) set_property(TEST "NAPI-C-test-nxunlimited" APPEND PROPERTY ENVIRONMENT "PATH=${TESTSPATH}") endif(WIN32)
118+
110119
# #### leak tests
111120

112-
add_executable(napi_leak_test1 test/leak_test1.c)
121+
add_executable(napi_leak_test1 EXCLUDE_FROM_ALL test/leak_test1.c)
113122
target_link_libraries(napi_leak_test1 NexusCpp)
114123
add_test(NAME "${TEST_PREFIX}-C-leak-test-1" COMMAND napi_leak_test1)
115124

@@ -143,6 +152,7 @@ add_custom_target(
143152
napi_test_hdf4
144153
napi_attra_test_hdf4
145154
napi_test_cpp-hdf4
155+
napi_test_nxunlimited
146156
napi_leak_test1
147157
napi_leak_test2
148158
napi_leak_test3
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*---------------------------------------------------------------------------
2+
NeXus - Neutron & X-ray Common Data Format
3+
4+
Test program for C API
5+
6+
Copyright (C) 1997-2009 Freddie Akeroyd
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation; either
11+
version 2 of the License, or (at your option) any later version.
12+
13+
This library is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
Lesser General Public License for more details.
17+
18+
You should have received a copy of the GNU Lesser General Public
19+
License along with this library; if not, write to the Free Software
20+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
22+
For further information, see <http://www.nexusformat.org>
23+
24+
$Id: napi_test.c 1178 2009-01-21 12:28:55Z Freddie Akeroyd $
25+
26+
----------------------------------------------------------------------------*/
27+
#include "MantidNexusCpp/napi.h"
28+
#include "MantidNexusCpp/napiconfig.h"
29+
#include <stdio.h>
30+
#include <stdlib.h>
31+
#include <string.h>
32+
#include <time.h>
33+
34+
#define DATA_SIZE 200000
35+
36+
int test_unlimited(int file_type, const char *filename) {
37+
static double d[DATA_SIZE];
38+
int dims[2] = {NX_UNLIMITED, DATA_SIZE};
39+
int i, slab_start[2], slab_size[2];
40+
NXhandle file_id = NULL;
41+
remove(filename);
42+
NXopen(filename, file_type, &file_id);
43+
NXmakegroup(file_id, "entry1", "NXentry");
44+
NXopengroup(file_id, "entry1", "NXentry");
45+
NXmakedata(file_id, "data", NX_FLOAT64, 2, dims);
46+
NXopendata(file_id, "data");
47+
slab_start[1] = 0;
48+
slab_size[0] = 1;
49+
slab_size[1] = DATA_SIZE;
50+
51+
for (i = 0; i < 2; i++) {
52+
slab_start[0] = i;
53+
NXputslab(file_id, d, slab_start, slab_size);
54+
}
55+
56+
NXclosedata(file_id);
57+
NXclosegroup(file_id);
58+
NXclose(&file_id);
59+
return 0;
60+
}
61+
62+
int main(int argc, char *argv[]) {
63+
time_t tim;
64+
#ifdef WITH_HDF4
65+
printf("Testing HDF4\n");
66+
time(&tim);
67+
test_unlimited(NXACC_CREATE4, "test_unlimited.nx4");
68+
printf("Took %u seconds\n", (unsigned)(time(NULL) - tim));
69+
#endif
70+
71+
#ifdef WITH_HDF5
72+
printf("Testing HDF5\n");
73+
time(&tim);
74+
test_unlimited(NXACC_CREATE5, "test_unlimited.nx5");
75+
printf("Took %u seconds\n", (unsigned)(time(NULL) - tim));
76+
#endif
77+
return 0;
78+
}

0 commit comments

Comments
 (0)