Skip to content

Commit f957206

Browse files
Fix compiler warnings and cppcheck
1 parent 495ea7d commit f957206

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

Framework/NexusCpp/test/napi_test_cpp.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static std::string relativePathOf(const std::string &filenamestr) {
3333
}
3434
}
3535

36-
static int writeTest(const string &filename, NXaccess create_code) {
36+
static void writeTest(const string &filename, NXaccess create_code) {
3737
NeXus::File file(filename, create_code);
3838
// create group
3939
file.makeGroup("entry", "NXentry", true);
@@ -55,21 +55,21 @@ static int writeTest(const string &filename, NXaccess create_code) {
5555

5656
// 1d uint8 array
5757
vector<uint8_t> i1_array;
58-
for (size_t i = 0; i < 4; i++) {
58+
for (uint8_t i = 0; i < 4; i++) {
5959
i1_array.push_back(static_cast<uint8_t>(i + 1));
6060
}
6161
file.writeData("i1_data", i1_array);
6262

6363
// 1d int16 array
6464
vector<int16_t> i2_array;
65-
for (size_t i = 0; i < 4; i++) {
66-
i2_array.push_back(1000 * (i + 1));
65+
for (int16_t i = 0; i < 4; i++) {
66+
i2_array.push_back(static_cast<int16_t>(1000 * (i + 1)));
6767
}
6868
file.writeData("i2_data", i2_array);
6969

7070
// 1d int32 data
7171
vector<int32_t> i4_array;
72-
for (size_t i = 0; i < 4; i++) {
72+
for (int32_t i = 0; i < 4; i++) {
7373
i4_array.push_back(1000000 * (i + 1));
7474
}
7575
file.writeData("i4_data", i4_array);
@@ -204,8 +204,6 @@ static int writeTest(const string &filename, NXaccess create_code) {
204204
file.makeLink(glink);
205205
file.makeNamedLink("renLinkGroup", glink);
206206
file.makeNamedLink("renLinkData", link);
207-
208-
return 0;
209207
}
210208

211209
template <typename NumT> string toString(const vector<NumT> &data) {
@@ -469,10 +467,10 @@ int testLoadPath(const string &filename) {
469467
}
470468
}
471469

472-
int testExternal(const string &fileext, NXaccess create_code) {
473-
string filename("nxext_cpp" + fileext);
474-
string exturl1("nxfile://data/dmc01" + fileext + "#entry1");
475-
string exturl2("nxfile://data/dmc02" + fileext + "#entry1");
470+
void testExternal(const string &fileext, NXaccess create_code) {
471+
const string filename("nxext_cpp" + fileext);
472+
const string exturl1("nxfile://data/dmc01" + fileext + "#entry1");
473+
const string exturl2("nxfile://data/dmc02" + fileext + "#entry1");
476474

477475
// create the external link
478476
NeXus::File fileout(filename, create_code);
@@ -492,8 +490,6 @@ int testExternal(const string &fileext, NXaccess create_code) {
492490
cout << "Second file time: " << filein.getStrData() << endl;
493491
filein.openPath("/");
494492
cout << "entry1 external URL = " << filein.isExternalGroup("entry1", "NXentry") << endl;
495-
496-
return 0;
497493
}
498494

499495
int testTypeMap(const std::string &fname) {
@@ -538,9 +534,11 @@ int main(int argc, char **argv) {
538534
extfile_ext = ".hdf";
539535
}
540536

541-
if (int result = writeTest(filename, nx_creation_code)) {
542-
cout << "writeTest failed" << endl;
543-
return result;
537+
try {
538+
writeTest(filename, nx_creation_code);
539+
} catch (const std::runtime_error &e) {
540+
cout << "writeTest failed:\n" << e.what() << endl;
541+
return 1;
544542
}
545543
if ((argc >= 2) && !strcmp(argv[1], "-q")) {
546544
return 0; //
@@ -559,9 +557,11 @@ int main(int argc, char **argv) {
559557
}
560558

561559
// try external linking
562-
if (int result = testExternal(extfile_ext, nx_creation_code)) {
563-
cout << "testExternal failed" << endl;
564-
return result;
560+
try {
561+
testExternal(extfile_ext, nx_creation_code);
562+
} catch (const std::runtime_error &e) {
563+
cout << "testExternal failed:\n" << e.what() << endl;
564+
return 1;
565565
}
566566

567567
// test of typemap generation

0 commit comments

Comments
 (0)