source: trunk/test/leak_test3.cxx @ 1822

Revision 942, 2.0 KB checked in by Freddie Akeroyd, 5 years ago (diff)

Merge in changes from r892 to r941 (4.0.0 release) on the 4.0 branch
to the main trunk. Refs #78.

Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <sstream>
4#include <unistd.h>
5#include <napi.h>
6
7#define PSZ(s) (s).c_str()
8
9using namespace std;
10
11const int nFiles = 10;
12const int nEntry = 2;
13const int nData = 2;
14int array_dims[2] = {512, 512};
15const char szFile[] = "leak_test.nxs";
16const int iBinarySize = 512*512;
17int aiBinaryData[iBinarySize];
18
19int main ()
20{
21  int i, iFile, iEntry, iData, iNXdata;
22 
23  for(i=0; i < iBinarySize; i++)
24  {
25        aiBinaryData[i] = rand();
26  }     
27  for( iFile = 0; iFile < nFiles; iFile++ )
28  {
29    printf("file %d\n", iFile);
30       
31    NXhandle fileid;
32    NXlink aLink;
33    if( NXopen(szFile, NXACC_CREATE5, &fileid ) != NX_OK) return 1;
34    for( iEntry = 0; iEntry < nEntry; iEntry++ )
35    {
36      ostringstream oss;
37      oss << "entry_" << iEntry;
38      if (NXmakegroup (fileid, PSZ(oss.str()), "NXentry") != NX_OK) return 1;
39      if (NXopengroup (fileid, PSZ(oss.str()), "NXentry") != NX_OK) return 1;
40      for( iNXdata = 0; iNXdata < nData; iNXdata++ )
41      {
42        ostringstream oss;
43        oss << "data_" << iNXdata;
44        if (NXmakegroup (fileid, PSZ(oss.str()), "NXdata") != NX_OK) return 1;
45        if (NXopengroup (fileid, PSZ(oss.str()), "NXdata") != NX_OK) return 1;
46        NXgetgroupID(fileid, &aLink);
47        for( iData = 0; iData < nData; iData++ )
48        {
49          ostringstream oss;
50          oss << "i2_data_" << iData;
51          if (NXcompmakedata (fileid, PSZ(oss.str()), NX_INT16, 2, array_dims, NX_COMP_LZW, array_dims) != NX_OK)
52//          if (NXmakedata (fileid, PSZ(oss.str()), NX_INT16, 2, array_dims) != NX_OK)
53                return 1;
54          if (NXopendata (fileid, PSZ(oss.str())) != NX_OK) return 1;
55            if (NXputdata (fileid, aiBinaryData) != NX_OK) return 1;
56          if (NXclosedata (fileid) != NX_OK) return 1;
57        }
58        if (NXclosegroup (fileid) != NX_OK) return 1;
59      }
60      if (NXclosegroup (fileid) != NX_OK) return 1;
61    }
62    if (NXclose (&fileid) != NX_OK) return 1;
63
64    // Delete file
65    remove(szFile);
66  }
67
68  printf("done...\n");
69  _exit(EXIT_FAILURE);
70}
71
72
Note: See TracBrowser for help on using the repository browser.