diff --git a/Array.cc b/Array.cc index c837369a9..36b3a6e9c 100644 --- a/Array.cc +++ b/Array.cc @@ -994,7 +994,7 @@ void Array::print_decl(FILE *out, string space, bool print_semi, bool constraint constrained, and FALSE otherwise. */ void Array::print_decl(ostream &out, string space, bool print_semi, bool constraint_info, bool constrained, - bool is_root_grp, bool array_member) { + bool is_root_grp, bool) { if (constrained && !send_p()) return; diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e8389453..6d27adcb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,7 @@ set(DAP4_ONLY_SRC D4ParserSax2.cc D4BaseTypeFactory.cc D4Dimensions.cc D4EnumDefs.cc D4Group.cc DMR.cc D4Attributes.cc D4Enum.cc chunked_ostream.cc chunked_istream.cc D4Sequence.cc D4Maps.cc D4Opaque.cc D4AsyncUtil.cc D4RValue.cc D4FilterClause.cc + diagnostic_suppression.h ) set(CLIENT_SRC RCReader.cc Connect.cc D4Connect.cc util_mit.cc) diff --git a/D4Enum.cc b/D4Enum.cc index 969c78b87..fe4ecb673 100644 --- a/D4Enum.cc +++ b/D4Enum.cc @@ -87,7 +87,7 @@ void D4Enum::m_duplicate(const D4Enum &src) { * * @param attr AttrTable pointer, ignored by this method. */ -std::vector *D4Enum::transform_to_dap2(AttrTable *, bool show_shared_dims) { +std::vector *D4Enum::transform_to_dap2(AttrTable *, bool) { BaseType *btp; DBG(cerr << __func__ << "() - BEGIN" << endl;); diff --git a/D4Opaque.cc b/D4Opaque.cc index b0465bea7..24f9e3d98 100644 --- a/D4Opaque.cc +++ b/D4Opaque.cc @@ -116,11 +116,7 @@ bool D4Opaque::set_value(const dods_opaque &value) { @return The value. */ D4Opaque::dods_opaque D4Opaque::value() const { return d_buf; } -std::vector *D4Opaque::transform_to_dap2(AttrTable *, bool show_shared_dims) { - - DBG(cerr << __func__ << "() - Transform not implemented DAP4 Opaque type." << endl;); - return NULL; -} +std::vector *D4Opaque::transform_to_dap2(AttrTable *, bool) { return nullptr; } void D4Opaque::print_val(ostream &out, string space, bool print_decl_p, bool is_root_grp) { if (print_decl_p) diff --git a/D4Sequence.cc b/D4Sequence.cc index 4874bf532..8e0c9c097 100644 --- a/D4Sequence.cc +++ b/D4Sequence.cc @@ -453,7 +453,7 @@ void D4Sequence::print_val_by_rows(ostream &out, string space, bool print_decl_p out << ";\n"; } -void D4Sequence::print_val(ostream &out, string space, bool print_decl_p, bool is_root_grp) { +void D4Sequence::print_val(ostream &out, string space, bool print_decl_p, bool) { DBG(cerr << name() << " isa " << type_name() << endl); print_val_by_rows(out, space, print_decl_p, false); diff --git a/Int64.cc b/Int64.cc index 56f84f73e..ba715add4 100644 --- a/Int64.cc +++ b/Int64.cc @@ -51,13 +51,6 @@ #include "UInt64.h" #include "Url.h" -#if 0 -#include "Array.h" -#include "Grid.h" -#include "Sequence.h" -#include "Structure.h" -#endif - #include "D4StreamMarshaller.h" #include "D4StreamUnMarshaller.h" #include "DMR.h" @@ -211,20 +204,7 @@ bool Int64::d4_ops(BaseType *b, int op) { * * @return A pointer to the transformed variable */ -std::vector *Int64::transform_to_dap2(AttrTable *, bool show_shared_dims) { -#if 0 - BaseType *dest = this->ptr_duplicate(); - // convert the d4 attributes to a dap2 attribute table. - AttrTable *attrs = this->attributes()->get_AttrTable(); - attrs->set_name(name()); - dest->set_attr_table(*attrs); - dest->set_is_dap4(false); - // attrs->print(cerr,"",true); - return dest; -#endif - - return NULL; -} +std::vector *Int64::transform_to_dap2(AttrTable *, bool) { return nullptr; } /** * When send_p() is true a description of the instance is added to the inventory and true is returned. diff --git a/Int8.cc b/Int8.cc index ed6e21d27..397e97dc6 100644 --- a/Int8.cc +++ b/Int8.cc @@ -187,7 +187,7 @@ bool Int8::d4_ops(BaseType *b, int op) { * * @return A pointer to the transformed variable */ -std::vector *Int8::transform_to_dap2(AttrTable *parent_attr_table, bool show_shared_dims) { +std::vector *Int8::transform_to_dap2(AttrTable *parent_attr_table, bool) { vector *vec = BaseType::transform_to_dap2(parent_attr_table); if (vec->size() != 1) { ostringstream oss; diff --git a/Makefile.am b/Makefile.am index 505889977..8fcb6bc3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -202,7 +202,7 @@ DAP_HDR = AttrTable.h DAS.h DDS.h DataDDS.h DDXParserSAX2.h \ Grid.h UInt32.h Int16.h UInt16.h Float32.h BaseTypeFactory.h \ ObjectType.h EncodingType.h SignalHandler.h Error.h \ InternalErr.h util.h escaping.h parser.h debug.h dods-limits.h \ - dods-datatypes.h Type.h \ + dods-datatypes.h Type.h diagnostic_suppression.h \ util_mit.h expr.h Clause.h RValue.h ConstraintEvaluator.h \ ce_parser.h DapIndent.h DapObj.h XDRFileMarshaller.h \ Marshaller.h UnMarshaller.h XDRFileUnMarshaller.h \ diff --git a/Sequence.cc b/Sequence.cc index 6c0ad09e8..241313fdc 100644 --- a/Sequence.cc +++ b/Sequence.cc @@ -1109,11 +1109,11 @@ void Sequence::print_val_by_rows(ostream &out, string space, bool print_decl_p, out << ";\n"; } -void Sequence::print_val(FILE *out, string space, bool print_decl_p, bool is_root_grp) { +void Sequence::print_val(FILE *out, string space, bool print_decl_p, bool) { print_val_by_rows(out, space, print_decl_p, false); } -void Sequence::print_val(ostream &out, string space, bool print_decl_p, bool is_root_grp) { +void Sequence::print_val(ostream &out, string space, bool print_decl_p, bool) { print_val_by_rows(out, space, print_decl_p, false); } diff --git a/Sequence.h b/Sequence.h index 7dc81b516..ed491e505 100644 --- a/Sequence.h +++ b/Sequence.h @@ -218,12 +218,12 @@ class Sequence : public Constructor { sequence_values_stack_t &sequence_values_stack); public: - Sequence(const string &n); + explicit Sequence(const string &n); Sequence(const string &n, const string &d); Sequence(const Sequence &rhs); - virtual ~Sequence(); + ~Sequence() override; Sequence &operator=(const Sequence &rhs); diff --git a/UInt32.cc b/UInt32.cc index 716480562..97b62dc3f 100644 --- a/UInt32.cc +++ b/UInt32.cc @@ -199,7 +199,7 @@ bool UInt32::ops(BaseType *b, int op) { // Since the read method is virtual and implemented outside // libdap++ if we cannot read the data that is the problem // of the user or of whoever wrote the surrogate library - // implemeting read therefore it is an internal error. + // implementing read, therefore, it is an internal error. throw InternalErr(__FILE__, __LINE__, "This value was not read!"); } @@ -209,7 +209,7 @@ bool UInt32::ops(BaseType *b, int op) { // Since the read method is virtual and implemented outside // libdap++ if we cannot read the data that is the problem // of the user or of whoever wrote the surrogate library - // implemeting read therefore it is an internal error. + // implementing read, therefore, it is an internal error. throw InternalErr(__FILE__, __LINE__, "This value was not read!"); } diff --git a/UInt64.cc b/UInt64.cc index 608c105c2..17092ee7e 100644 --- a/UInt64.cc +++ b/UInt64.cc @@ -218,21 +218,7 @@ bool UInt64::d4_ops(BaseType *b, int op) { * * @return A pointer to the transformed variable */ -std::vector *UInt64::transform_to_dap2(AttrTable *, bool show_shared_dims) { - -#if 0 - BaseType *dest = this->ptr_duplicate(); - // convert the d4 attributes to a dap2 attribute table. - AttrTable *attrs = this->attributes()->get_AttrTable(); - attrs->set_name(name()); - dest->set_attr_table(*attrs); - dest->set_is_dap4(false); - // attrs->print(cerr,"",true); - return dest; -#endif - - return NULL; -} +std::vector *UInt64::transform_to_dap2(AttrTable *, bool) { return nullptr; } /** * When send_p() is true a description of the instance is added to the inventory and true is returned. diff --git a/XDRUtils.cc b/XDRUtils.cc index 848af9a25..f225025b1 100644 --- a/XDRUtils.cc +++ b/XDRUtils.cc @@ -35,6 +35,7 @@ #include "Str.h" #include "XDRUtils.h" #include "debug.h" +#include "diagnostic_suppression.h" using namespace libdap; @@ -135,7 +136,7 @@ namespace libdap { @return A C function used to encode data in the XDR format. */ xdrproc_t XDRUtils::xdr_coder(const Type &t) { - switch (t) { + A_cast_function_type_mismatch switch (t) { case dods_int16_c: return reinterpret_cast(XDR_INT16); case dods_uint16_c: @@ -148,6 +149,7 @@ xdrproc_t XDRUtils::xdr_coder(const Type &t) { return reinterpret_cast(XDR_FLOAT32); case dods_float64_c: return reinterpret_cast(XDR_FLOAT64); + case dods_byte_c: case dods_str_c: case dods_url_c: @@ -158,8 +160,7 @@ xdrproc_t XDRUtils::xdr_coder(const Type &t) { default: break; } - - return NULL; + A_Pop return nullptr; } } // namespace libdap diff --git a/diagnostic_suppression.h b/diagnostic_suppression.h new file mode 100644 index 000000000..1c7a31dc9 --- /dev/null +++ b/diagnostic_suppression.h @@ -0,0 +1,27 @@ +// +// Created by James Gallagher on 1/26/26. +// + +#ifndef LIBDAP_DIAGNOSTIC_SUPPRESSION_H +#define LIBDAP_DIAGNOSTIC_SUPPRESSION_H + +// Define a macro for convenience. To keep things simple, use a macro for +// each kind of warning. There should be few uses of this. jhrg 1/26/26 +// +// Based on https://nelkinda.com/blog/suppress-warnings-in-gcc-and-clang/ + +#ifdef __GNUC__ + +#define A_cast_function_type_mismatch \ + _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wcast-function-type-mismatch\"") + +#define A_Pop _Pragma("GCC diagnostic pop") + +#else +// Define them empty for other compilers (e.g., MSVC) if needed + +#define A_IgnoreUnused +#define A_Pop +#endif + +#endif // LIBDAP_DIAGNOSTIC_SUPPRESSION_H diff --git a/unit-tests/MarshallerTest.cc b/unit-tests/MarshallerTest.cc index 05d0c3593..1946b7dd8 100644 --- a/unit-tests/MarshallerTest.cc +++ b/unit-tests/MarshallerTest.cc @@ -1,24 +1,19 @@ -#include -#include -#include -#include -#include -#include #include "config.h" #ifdef HAVE_UNISTD_H #include #endif -#include -#include - -// #define DODS_DEBUG 1 -#include +#include // Needed for Linux #include #include +#include +#include +#include +#include + #include "TestArray.h" #include "TestByte.h" #include "TestFloat32.h" @@ -44,7 +39,6 @@ #include "debug.h" #include "run_tests_cppunit.h" -#include "test_config.h" int test_variable_sleep_interval = 0; // Used in Test* classes for testing timeouts. @@ -102,53 +96,47 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_TEST(array_stream_put_vector_thread_test_4); CPPUNIT_TEST(array_stream_put_vector_thread_test_5); -#if 1 CPPUNIT_TEST(array_stream_serialize_part_thread_test); CPPUNIT_TEST(array_stream_serialize_part_thread_test_2); CPPUNIT_TEST(array_stream_serialize_part_thread_test_3); -#endif CPPUNIT_TEST_SUITE_END(); - TestByte *b; - TestInt16 *i16; - TestInt32 *i32; - TestUInt16 *ui16; - TestUInt32 *ui32; - TestFloat32 *f32; - TestFloat64 *f64; - TestStr *str; - TestUrl *url; + TestByte *b = nullptr; + TestInt16 *i16 = nullptr; + TestInt32 *i32 = nullptr; + TestUInt16 *ui16 = nullptr; + TestUInt32 *ui32 = nullptr; + TestFloat32 *f32 = nullptr; + TestFloat64 *f64 = nullptr; + TestStr *str = nullptr; + TestUrl *url = nullptr; vector db; - TestByte *ab; - TestArray *arr; + TestByte *ab = nullptr; + TestArray *arr = nullptr; vector d_f32; - TestFloat32 *a_f32; - TestArray *arr_f32; + TestFloat32 *a_f32 = nullptr; + TestArray *arr_f32 = nullptr; vector d_f64; - TestFloat64 *a_f64; - TestArray *arr_f64; + TestFloat64 *a_f64 = nullptr; + TestArray *arr_f64 = nullptr; - TestStructure *s; + TestStructure *s = nullptr; ConstraintEvaluator eval; TestTypeFactory ttf; DataDDS dds; string str_value, str2_value; - string url_value; + string url_value{"http://dcz.gso.uri.edu/avhrr-archive/archive.html"}; public: - MarshallerTest() - : b(0), i16(0), i32(0), ui16(0), ui32(0), f32(0), f64(0), str(0), url(0), ab(0), arr(0), a_f32(0), arr_f32(0), - a_f64(0), arr_f64(0), s(0), dds(&ttf, "dds") { - url_value = "http://dcz.gso.uri.edu/avhrr-archive/archive.html"; - } + MarshallerTest() : dds(&ttf, "dds") {} - void setUp() { + void setUp() override { b = new TestByte("byte"); b->read(); @@ -225,41 +213,41 @@ class MarshallerTest : public CppUnit::TestFixture { s->set_send_p(true); } - void tearDown() { + void tearDown() override { delete b; - b = 0; + b = nullptr; delete i16; - i16 = 0; + i16 = nullptr; delete i32; - i32 = 0; + i32 = nullptr; delete ui16; - ui16 = 0; + ui16 = nullptr; delete ui32; - ui32 = 0; + ui32 = nullptr; delete f32; - f32 = 0; + f32 = nullptr; delete f64; - f64 = 0; + f64 = nullptr; delete str; - str = 0; + str = nullptr; delete url; - url = 0; + url = nullptr; delete ab; - ab = 0; + ab = nullptr; delete arr; - arr = 0; + arr = nullptr; delete a_f32; - ab = 0; + ab = nullptr; delete arr_f32; - arr_f32 = 0; + arr_f32 = nullptr; delete a_f64; - ab = 0; + ab = nullptr; delete arr_f64; - arr_f64 = 0; + arr_f64 = nullptr; delete s; - s = 0; + s = nullptr; } void simple_types_file_serialize_test() { @@ -355,11 +343,11 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(farr.length() == arr->length()); - dods_byte fdb[farr.length() * sizeof(dods_byte)]; - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + vector fdb(farr.length() * sizeof(dods_byte)); + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); } catch (Error &e) { - string err = "failed:" + e.get_error_message(); + const string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); } } @@ -408,13 +396,13 @@ class MarshallerTest : public CppUnit::TestFixture { BaseType *bt = fs.var("fsab"); CPPUNIT_ASSERT(bt); - Array *fsarr_p = dynamic_cast(bt); + auto *fsarr_p = dynamic_cast(bt); CPPUNIT_ASSERT(fsarr_p); - dods_byte fdb[fsarr_p->length() * sizeof(dods_byte)]; - fsarr_p->value(fdb); + vector fdb(fsarr_p->length() * sizeof(dods_byte)); + fsarr_p->value(fdb.data()); CPPUNIT_ASSERT(fsarr_p->length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), fsarr_p->length() * sizeof(dods_byte))); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), fsarr_p->length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); @@ -475,9 +463,11 @@ class MarshallerTest : public CppUnit::TestFixture { // Check the values in the array CPPUNIT_ASSERT(tg.get_array()->length() == arr->length()); - dods_byte fdb[tg.get_array()->length() * sizeof(dods_byte)]; - tg.get_array()->value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), tg.get_array()->length() * sizeof(dods_byte))); + vector fdb(tg.get_array()->length() * sizeof(dods_byte)); + ; + tg.get_array()->value(fdb.data()); + CPPUNIT_ASSERT( + !memcmp((void *)fdb.data(), (void *)db.data(), tg.get_array()->length() * sizeof(dods_byte))); // Should test the map values here, but skip that for now... } catch (Error &e) { @@ -516,7 +506,8 @@ class MarshallerTest : public CppUnit::TestFixture { FILE *ff = fopen("seq_test.file", "r"); XDRFileUnMarshaller um(ff); - dods_byte fdb[arr->length() * sizeof(dods_byte)]; + vector fdb(arr->length() * sizeof(dods_byte)); + ; TestSequence seq("seq"); seq.add_var(f64); @@ -536,16 +527,16 @@ class MarshallerTest : public CppUnit::TestFixture { BaseTypeRow *row = seq.row_value(i); CPPUNIT_ASSERT(row); CPPUNIT_ASSERT(row->size() == 3); - Float64 *f64_p = dynamic_cast((*row)[0]); + auto *f64_p = dynamic_cast((*row)[0]); CPPUNIT_ASSERT(f64_p); CPPUNIT_ASSERT(f64_p->value() == f64->value()); - Array *arr_p = dynamic_cast((*row)[1]); + auto *arr_p = dynamic_cast((*row)[1]); CPPUNIT_ASSERT(arr_p); - arr_p->value(fdb); + arr_p->value(fdb.data()); CPPUNIT_ASSERT(arr_p->length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), arr_p->length() * sizeof(dods_byte))); - Sequence *seq_p = dynamic_cast((*row)[2]); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), arr_p->length() * sizeof(dods_byte))); + auto *seq_p = dynamic_cast((*row)[2]); CPPUNIT_ASSERT(seq_p); unsigned int num_rows_sub = seq_p->number_of_rows(); CPPUNIT_ASSERT(num_rows == 4); @@ -553,10 +544,10 @@ class MarshallerTest : public CppUnit::TestFixture { BaseTypeRow *row_sub = seq_p->row_value(j); CPPUNIT_ASSERT(row_sub); CPPUNIT_ASSERT(row_sub->size() == 2); - UInt16 *ui16_p = dynamic_cast((*row_sub)[0]); + auto *ui16_p = dynamic_cast((*row_sub)[0]); CPPUNIT_ASSERT(ui16_p); CPPUNIT_ASSERT(ui16_p->value() == ui16->value()); - Url *url_p = dynamic_cast((*row_sub)[1]); + auto url_p = dynamic_cast((*row_sub)[1]); CPPUNIT_ASSERT(url_p); CPPUNIT_ASSERT(url_p->value() == url->value()); } @@ -599,13 +590,8 @@ class MarshallerTest : public CppUnit::TestFixture { void simple_types_stream_deserialize_test() { try { -#if 0 - ifstream strm( "st_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("st_test.strm", "r"); XDRFileUnMarshaller um(sf); -#endif Byte fb("fb"); fb.deserialize(um, &dds, false); CPPUNIT_ASSERT(fb.value() == b->value()); @@ -662,13 +648,8 @@ class MarshallerTest : public CppUnit::TestFixture { void array_stream_deserialize_test() { try { -#if 0 - ifstream strm( "a_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("a_test.strm", "r"); XDRFileUnMarshaller um(sf); -#endif TestByte fab("ab"); TestArray farr("arr", &fab); farr.append_dim(5, "dim1"); @@ -677,9 +658,10 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(farr.length() == arr->length()); - dods_byte fdb[arr->length() * sizeof(dods_byte)]; - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + vector fdb(arr->length() * sizeof(dods_byte)); + ; + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); @@ -819,13 +801,8 @@ class MarshallerTest : public CppUnit::TestFixture { void array_f32_stream_deserialize_test() { try { -#if 0 - ifstream strm( "a_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("a_f32_test.file", "r"); XDRFileUnMarshaller um(sf); -#endif TestFloat32 fa_f32("a_f32"); TestArray farr("arr_f32", &fa_f32); farr.append_dim(5, "dim1"); @@ -904,13 +881,8 @@ class MarshallerTest : public CppUnit::TestFixture { void array_f64_stream_deserialize_test() { try { -#if 0 - ifstream strm( "a_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("a_f64_test.file", "r"); XDRFileUnMarshaller um(sf); -#endif TestFloat64 fa_f64("a_f64"); TestArray farr("arr_f64", &fa_f64); farr.append_dim(5, "dim1"); @@ -988,13 +960,8 @@ class MarshallerTest : public CppUnit::TestFixture { void structure_stream_deserialize_test() { try { -#if 0 - ifstream strm( "struct_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("struct_test.strm", "r"); XDRFileUnMarshaller um(sf); -#endif TestStructure fs("fs"); TestInt32 fsi32("fsi32"); fs.add_var(&fsi32); @@ -1014,19 +981,19 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(fsi32_p); CPPUNIT_ASSERT(fsi32_p->value() == i32->value()); - Str *fsstr_p = dynamic_cast(fs.var("fsstr")); + auto fsstr_p = dynamic_cast(fs.var("fsstr")); CPPUNIT_ASSERT(fsstr_p); DBG(cerr << "fsstr_p->value(): " << fsstr_p->value() << endl); CPPUNIT_ASSERT(fsstr_p->value().find("Silly test string:") != string::npos); BaseType *bt = fs.var("fsab"); CPPUNIT_ASSERT(bt); - Array *fsarr_p = dynamic_cast(bt); + auto *fsarr_p = dynamic_cast(bt); CPPUNIT_ASSERT(fsarr_p); CPPUNIT_ASSERT(fsarr_p->length() == arr->length()); - dods_byte fdb[fsarr_p->length() * sizeof(dods_byte)]; - fsarr_p->value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), fsarr_p->length() * sizeof(dods_byte))); + vector fdb(fsarr_p->length() * sizeof(dods_byte)); + fsarr_p->value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), fsarr_p->length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); @@ -1065,13 +1032,8 @@ class MarshallerTest : public CppUnit::TestFixture { void grid_stream_deserialize_test() { try { -#if 0 - ifstream strm( "g_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("g_test.strm", "r"); XDRFileUnMarshaller um(sf); -#endif TestGrid tg("grid1"); TestArray arr2("arr2", ab); arr2.append_dim(5, "dim1"); @@ -1091,9 +1053,11 @@ class MarshallerTest : public CppUnit::TestFixture { // Check the values in the array CPPUNIT_ASSERT(tg.get_array()->length() == arr->length()); - dods_byte fdb[tg.get_array()->length() * sizeof(dods_byte)]; - tg.get_array()->value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), tg.get_array()->length() * sizeof(dods_byte))); + vector fdb(tg.get_array()->length() * sizeof(dods_byte)); + ; + tg.get_array()->value(fdb.data()); + CPPUNIT_ASSERT( + !memcmp((void *)fdb.data(), (void *)db.data(), tg.get_array()->length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); @@ -1126,14 +1090,10 @@ class MarshallerTest : public CppUnit::TestFixture { void sequence_stream_deserialize_test() { try { -#if 0 - ifstream strm( "seq_test.strm", ios::in ); - XDRStreamUnMarshaller um( strm ); -#else FILE *sf = fopen("seq_test.strm", "r"); XDRFileUnMarshaller um(sf); -#endif - dods_byte fdb[arr->length() * sizeof(dods_byte)]; + vector fdb(arr->length() * sizeof(dods_byte)); + ; TestSequence seq("seq"); seq.add_var(f64); @@ -1155,15 +1115,15 @@ class MarshallerTest : public CppUnit::TestFixture { BaseTypeRow *row = seq.row_value(i); CPPUNIT_ASSERT(row); CPPUNIT_ASSERT(row->size() == 3); - Float64 *f64_p = dynamic_cast((*row)[0]); + auto *f64_p = dynamic_cast((*row)[0]); CPPUNIT_ASSERT(f64_p); CPPUNIT_ASSERT(f64_p->value() == f64->value()); - Array *arr_p = dynamic_cast((*row)[1]); + auto *arr_p = dynamic_cast((*row)[1]); CPPUNIT_ASSERT(arr_p); - arr_p->value(fdb); + arr_p->value(fdb.data()); CPPUNIT_ASSERT(arr_p->length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), arr_p->length() * sizeof(dods_byte))); - Sequence *seq_p = dynamic_cast((*row)[2]); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), arr_p->length() * sizeof(dods_byte))); + auto *seq_p = dynamic_cast((*row)[2]); CPPUNIT_ASSERT(seq_p); unsigned int num_rows_sub = seq_p->number_of_rows(); CPPUNIT_ASSERT(num_rows == 4); @@ -1171,10 +1131,10 @@ class MarshallerTest : public CppUnit::TestFixture { BaseTypeRow *row_sub = seq_p->row_value(j); CPPUNIT_ASSERT(row_sub); CPPUNIT_ASSERT(row_sub->size() == 2); - UInt16 *ui16_p = dynamic_cast((*row_sub)[0]); + const auto *ui16_p = dynamic_cast((*row_sub)[0]); CPPUNIT_ASSERT(ui16_p); CPPUNIT_ASSERT(ui16_p->value() == ui16->value()); - Url *url_p = dynamic_cast((*row_sub)[1]); + const auto url_p = dynamic_cast((*row_sub)[1]); CPPUNIT_ASSERT(url_p); CPPUNIT_ASSERT(url_p->value() == url->value()); } @@ -1263,22 +1223,23 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(farr.length() == arr->length()); - dods_byte fdb[arr->length() * sizeof(dods_byte)]; - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + vector fdb(arr->length() * sizeof(dods_byte)); + ; + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); // now get three more arrays of the same size farr.deserialize(um, &dds, false); - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); farr.deserialize(um, &dds, false); - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); farr.deserialize(um, &dds, false); - farr.value(fdb); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db.data(), farr.length() * sizeof(dods_byte))); + farr.value(fdb.data()); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); @@ -1352,7 +1313,7 @@ class MarshallerTest : public CppUnit::TestFixture { throw InternalErr(__FILE__, __LINE__, "Implemented for numeric simple types only"); } } catch (Error &e) { - string err = "failed:" + e.get_error_message(); + const string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); } @@ -1402,14 +1363,14 @@ class MarshallerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT(farr.length() == arr->length()); - dods_float32 fd_32[arr->length() * sizeof(dods_float32)]; - farr.value(fd_32); - CPPUNIT_ASSERT(!memcmp((void *)fd_32, (void *)d_f32.data(), farr.length() * sizeof(dods_float32))); + vector fd_32(arr->length() * sizeof(dods_float32)); + farr.value(fd_32.data()); + CPPUNIT_ASSERT(!memcmp((void *)fd_32.data(), (void *)d_f32.data(), farr.length() * sizeof(dods_float32))); // now get three more arrays of the same size farr.deserialize(um, &dds, false); - farr.value(fd_32); - CPPUNIT_ASSERT(!memcmp((void *)fd_32, (void *)d_f32.data(), farr.length() * sizeof(dods_byte))); + farr.value(fd_32.data()); + CPPUNIT_ASSERT(!memcmp((void *)fd_32.data(), (void *)d_f32.data(), farr.length() * sizeof(dods_byte))); } catch (Error &e) { string err = "failed:" + e.get_error_message(); CPPUNIT_FAIL(err.c_str()); diff --git a/unit-tests/RCReaderTest.cc b/unit-tests/RCReaderTest.cc index e74477197..755cc7bd4 100644 --- a/unit-tests/RCReaderTest.cc +++ b/unit-tests/RCReaderTest.cc @@ -22,28 +22,25 @@ // // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. +#include "config.h" + #include -#include -#include "config.h" #ifdef HAVE_UNISTD_H #include #endif -#include -#include - +#include // Needed for Linux #include #include #include #include #include -#include // #define DODS_DEBUG #include "RCReader.h" -#include "debug.h" + #include "run_tests_cppunit.h" #include "test_config.h" @@ -55,16 +52,14 @@ static char dods_conf_ev[1024] = ""; namespace libdap { class RCReaderTest : public TestFixture { -private: RCReader *rcr; -protected: public: RCReaderTest() : rcr(RCReader::instance()) {} - void setUp() {} + void setUp() override {} - void tearDown() {} + void tearDown() override {} /** Put values in an environment variable. This should be used only * for the env var 'DODS_CONF' and should never pass in values longer @@ -74,7 +69,7 @@ class RCReaderTest : public TestFixture { * so any value passed in from the heap that might be freed or from the * stack that could be popped will cause a memory access error. */ - void my_putenv(const string &value) { + static void my_putenv(const string &value) { strncpy(dods_conf_ev, value.c_str(), 1024); ; putenv(dods_conf_ev); @@ -100,12 +95,12 @@ class RCReaderTest : public TestFixture { void check_env_var_test1() { my_putenv("DODS_CONF="); - CPPUNIT_ASSERT(rcr->check_env_var("DODS_CONF") == ""); + CPPUNIT_ASSERT(rcr->check_env_var("DODS_CONF").empty()); } void check_env_var_test2() { my_putenv("DODS_CONF=Nothing_sensible"); - CPPUNIT_ASSERT(rcr->check_env_var("DODS_CONF") == ""); + CPPUNIT_ASSERT(rcr->check_env_var("DODS_CONF").empty()); } void check_env_var_test3() { @@ -142,7 +137,7 @@ class RCReaderTest : public TestFixture { // Create the file. string rc = string(cwd) + string("/.dodsrc"); CPPUNIT_ASSERT(rcr->check_env_var("DODS_CONF") == rc); - struct stat stat_info; + struct stat stat_info {}; CPPUNIT_ASSERT(stat(rc.c_str(), &stat_info) == 0 && S_ISREG(stat_info.st_mode)); remove(rc.c_str()); } @@ -155,7 +150,7 @@ class RCReaderTest : public TestFixture { if (*home.rbegin() != '/') home += "/"; - RCReader *reader = RCReader::instance(); + const RCReader *reader = RCReader::instance(); rcr->loadRC(); CPPUNIT_ASSERT(reader->d_rc_file_path == home + string(".dodsrc")); DBG(cerr << "Cache root: " << reader->get_dods_cache_root() << endl); @@ -225,21 +220,20 @@ class RCReaderTest : public TestFixture { CPPUNIT_ASSERT(reader->get_proxy_server_host() == "proxy.local.org"); CPPUNIT_ASSERT(reader->get_proxy_server_port() == 80); - CPPUNIT_ASSERT(reader->get_proxy_server_userpw() == ""); + CPPUNIT_ASSERT(reader->get_proxy_server_userpw().empty()); } void proxy_test3() { - string rc = (string) "DODS_CONF=" + TEST_SRC_DIR + "/rcreader-testsuite/test3.rc"; + const string rc = static_cast("DODS_CONF=") + TEST_SRC_DIR + "/rcreader-testsuite/test3.rc"; DBG(cerr << "rc: " << rc << endl); my_putenv(rc); try { - RCReader *reader = RCReader::instance(); rcr->loadRC(); CPPUNIT_ASSERT(!"initialize_instance() should throw Error."); } catch (const Error &e) { DBG(cerr << e.get_error_message() << endl); - CPPUNIT_ASSERT(e.get_error_message() != ""); + CPPUNIT_ASSERT(!e.get_error_message().empty()); } } @@ -249,7 +243,7 @@ class RCReaderTest : public TestFixture { my_putenv(rc); try { - RCReader *reader = RCReader::instance(); + const RCReader *reader = RCReader::instance(); rcr->loadRC(); DBG(cerr << "RC path: " << reader->d_rc_file_path << endl); CPPUNIT_ASSERT(reader->d_rc_file_path == (string)TEST_SRC_DIR + "/rcreader-testsuite/test4.rc"); @@ -264,7 +258,7 @@ class RCReaderTest : public TestFixture { CPPUNIT_ASSERT(reader->get_proxy_server_userpw() == "jimg:test"); } catch (Error &e) { DBG(cerr << e.get_error_message() << endl); - CPPUNIT_ASSERT(e.get_error_message() != ""); + CPPUNIT_ASSERT(!e.get_error_message().empty()); } } @@ -289,14 +283,14 @@ class RCReaderTest : public TestFixture { CPPUNIT_ASSERT(reader->get_proxy_server_userpw() == "jimg:test"); } catch (Error &e) { DBG(cerr << e.get_error_message() << endl); - CPPUNIT_ASSERT(e.get_error_message() != ""); + CPPUNIT_ASSERT(!e.get_error_message().empty()); } } // This simple test checks to see that the VALIDATE_SSL parameter is // read correctly. void validate_ssl_test() { - string rc = (string) "DODS_CONF=" + TEST_SRC_DIR + "/rcreader-testsuite/dodssrc_ssl_1"; + string rc = static_cast("DODS_CONF=") + TEST_SRC_DIR + "/rcreader-testsuite/dodssrc_ssl_1"; DBG(cerr << "rc: " << rc << endl); my_putenv(rc); @@ -312,7 +306,7 @@ class RCReaderTest : public TestFixture { // string object) because the code casts away the const-ness of the // char* returned by c_str() and putenv does odd stuff with it. There's // nothing good about using env vars... - rc = (string) "DODS_CONF=" + TEST_SRC_DIR + "/rcreader-testsuite/dodssrc_ssl_2"; + rc = static_cast("DODS_CONF=") + TEST_SRC_DIR + "/rcreader-testsuite/dodssrc_ssl_2"; DBG(cerr << "rc: " << rc << endl); my_putenv(rc); diff --git a/unit-tests/marshT.cc b/unit-tests/marshT.cc index 5f2529563..3a9614b7b 100644 --- a/unit-tests/marshT.cc +++ b/unit-tests/marshT.cc @@ -1,16 +1,11 @@ -#include -#include -#include -#include -#include -#include #include "config.h" + #ifdef HAVE_UNISTD_H #include #endif -#include +#include // Needed for Linux #include #include @@ -33,10 +28,12 @@ #include "XDRFileUnMarshaller.h" #include "XDRStreamMarshaller.h" -#include "debug.h" +#include +#include +#include +#include #include "run_tests_cppunit.h" -#include "test_config.h" using std::cerr; using std::cout; @@ -74,9 +71,9 @@ class marshT : public CppUnit::TestFixture { public: marshT() = default; - ~marshT() = default; + ~marshT() override = default; - void setUp() { + void setUp() override { b = new TestByte("b"); i16 = new TestInt16("i16"); i32 = new TestInt32("i32"); @@ -127,33 +124,33 @@ class marshT : public CppUnit::TestFixture { s->read(); } - void tearDown() { + void tearDown() override { delete b; - b = 0; + b = nullptr; delete i16; - i16 = 0; + i16 = nullptr; delete i32; - i32 = 0; + i32 = nullptr; delete ui16; - ui16 = 0; + ui16 = nullptr; delete ui32; - ui32 = 0; + ui32 = nullptr; delete f32; - f32 = 0; + f32 = nullptr; delete f64; - f64 = 0; + f64 = nullptr; delete str; - str = 0; + str = nullptr; delete url; - url = 0; + url = nullptr; delete ab; - ab = 0; + ab = nullptr; delete arr; - arr = 0; + arr = nullptr; delete s; - s = 0; + s = nullptr; delete seq; delete seq2; } @@ -173,7 +170,7 @@ class marshT : public CppUnit::TestFixture { DBG(cerr << "serializing using XDRFileMarshaller" << endl); - BaseType *bt = static_cast(b); + auto *bt = static_cast(b); FILE *f = fopen("test.file", "w"); CPPUNIT_ASSERT_THROW(bt->BaseType::serialize(eval, dds, fm, false), InternalErr); fclose(f); @@ -273,14 +270,14 @@ class marshT : public CppUnit::TestFixture { BaseType *bt = fs.var("fsab"); CPPUNIT_ASSERT(bt); - Array *fsarr_p = dynamic_cast(bt); + auto *fsarr_p = dynamic_cast(bt); CPPUNIT_ASSERT(fsarr_p); - dods_byte fdb[fsarr_p->length() * sizeof(dods_byte)]; - dods_byte db[arr->length() * sizeof(dods_byte)]; - fsarr_p->value(fdb); - arr->value(db); + vector fdb(fsarr_p->length() * sizeof(dods_byte)); + vector db(fsarr_p->length() * sizeof(dods_byte)); + fsarr_p->value(fdb.data()); + arr->value(db.data()); CPPUNIT_ASSERT(fsarr_p->length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db, fsarr_p->length() * sizeof(dods_byte))); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), fsarr_p->length() * sizeof(dods_byte))); DBG(cerr << " file array" << endl); TestByte fab("ab"); @@ -288,9 +285,9 @@ class marshT : public CppUnit::TestFixture { farr.append_dim(5, "dim1"); farr.append_dim(3, "dim2"); farr.deserialize(um, &dds, false); - farr.value(fdb); + farr.value(fdb.data()); CPPUNIT_ASSERT(farr.length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db, farr.length() * sizeof(dods_byte))); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), farr.length() * sizeof(dods_byte))); TestSequence fseq("fseq"); fseq.add_var(f64); @@ -309,15 +306,15 @@ class marshT : public CppUnit::TestFixture { BaseTypeRow *row = fseq.row_value(i); CPPUNIT_ASSERT(row); CPPUNIT_ASSERT(row->size() == 3); - Float64 *f64_p = dynamic_cast((*row)[0]); + auto *f64_p = dynamic_cast((*row)[0]); CPPUNIT_ASSERT(f64_p); CPPUNIT_ASSERT(f64_p->value() == f64->value()); - Array *arr_p = dynamic_cast((*row)[1]); + auto *arr_p = dynamic_cast((*row)[1]); CPPUNIT_ASSERT(arr_p); - arr_p->value(fdb); + arr_p->value(fdb.data()); CPPUNIT_ASSERT(arr_p->length() == arr->length()); - CPPUNIT_ASSERT(!memcmp((void *)fdb, (void *)db, arr_p->length() * sizeof(dods_byte))); - Sequence *seq_p = dynamic_cast((*row)[2]); + CPPUNIT_ASSERT(!memcmp((void *)fdb.data(), (void *)db.data(), arr_p->length() * sizeof(dods_byte))); + auto *seq_p = dynamic_cast((*row)[2]); CPPUNIT_ASSERT(seq_p); unsigned int num_rows_sub = seq_p->number_of_rows(); CPPUNIT_ASSERT(num_rows == 4); @@ -325,10 +322,10 @@ class marshT : public CppUnit::TestFixture { BaseTypeRow *row_sub = seq_p->row_value(j); CPPUNIT_ASSERT(row_sub); CPPUNIT_ASSERT(row_sub->size() == 2); - UInt16 *ui16_p = dynamic_cast((*row_sub)[0]); + auto *ui16_p = dynamic_cast((*row_sub)[0]); CPPUNIT_ASSERT(ui16_p); CPPUNIT_ASSERT(ui16_p->value() == ui16->value()); - Url *url_p = dynamic_cast((*row_sub)[1]); + auto *url_p = dynamic_cast((*row_sub)[1]); CPPUNIT_ASSERT(url_p); CPPUNIT_ASSERT(url_p->value() == url->value()); }