summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
Diffstat (limited to 'c++')
-rwxr-xr-xc++/examples/testexamples.sh68
-rw-r--r--c++/src/H5Attribute.cpp30
-rw-r--r--c++/src/H5PropList.cpp34
-rw-r--r--c++/test/ttypes.cpp5
-rw-r--r--c++/test/tvlstr.cpp1
5 files changed, 98 insertions, 40 deletions
diff --git a/c++/examples/testexamples.sh b/c++/examples/testexamples.sh
new file mode 100755
index 0000000..2b6cc1b
--- /dev/null
+++ b/c++/examples/testexamples.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# Copyright by The HDF Group.
+# Copyright by the Board of Trustees of the University of Illinois.
+# All rights reserved.
+#
+# This file is part of HDF5. The full HDF5 copyright notice, including
+# terms governing use, modification, and redistribution, is contained in
+# the files COPYING and Copyright.html. COPYING can be found at the root
+# of the source code distribution tree; Copyright.html can be found at the
+# root level of an installed copy of the electronic HDF5 document set and
+# is linked from the top-level documents page. It can also be found at
+# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
+# access to either file, you may request a copy from help@hdfgroup.org.
+
+CMP='cmp -s'
+DIFF='diff -c'
+
+nerrors=0
+verbose=yes
+
+# The build (current) directory might be different than the source directory.
+if test -z "$srcdir"; then
+ srcdir=.
+fi
+
+actual=sample.out
+expect=$srcdir/expected.out
+
+# Print a line-line message left justified in a field of 70 characters
+# beginning with the word "Testing".
+TESTING()
+{
+ SPACES=" "
+ echo "Testing $* $SPACES" |cut -c1-70 |tr -d '\012'
+}
+
+TESTING C++ Examples
+
+(
+ ./create
+ ./readdata
+ ./writedata
+ ./compound
+ ./extend_ds
+ ./chunks
+ ./h5group
+) > $actual
+
+if $CMP $expect $actual; then
+ echo " PASSED"
+else
+ echo "*FAILED*"
+ echo " Expected result differs from actual result"
+ nerrors="`expr $nerrors + 1`"
+ test yes = "$verbose" && $DIFF $expect $actual | sed 's/^/ /'
+fi
+
+# Clean up output file
+if test -z "$HDF5_NOCLEANUP"; then
+ rm -f $actual
+fi
+
+if test $nerrors -eq 0 ; then
+ echo "All tests passed."
+fi
+
+exit $nerrors
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 043dc4d..1bca691 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -131,36 +131,22 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
///\exception H5::AttributeIException
// Programmer Binh-Minh Ribler - Apr, 2003
// Modification
-// Mar 2008
-// Corrected a misunderstanding that H5Aread would allocate
-// space for the buffer. Obtained the attribute size and
-// allocated memory properly. - BMR
+// 2006/12/9 - H5Aread allocates memory for character string
+// buffer with malloc, therefore, no allocation here,
+// but HDfree is needed. - BMR
//--------------------------------------------------------------------------
void Attribute::read( const DataType& mem_type, H5std_string& strg ) const
{
- // Get the attribute size and allocate temporary C-string for C API
- hsize_t attr_size = H5Aget_storage_size(id);
- if (attr_size <= 0)
- {
- throw AttributeIException("Attribute::read", "Unable to get attribute size before reading");
- }
- char* strg_C = new char [attr_size+1];
- if (strg_C == NULL)
- {
- throw AttributeIException("Attribute::read", "Unable to allocate buffer to read the attribute");
- }
+ char* strg_C; // temporary C-string for C API
- // Call C API to get the attribute data, a string of chars
- herr_t ret_value = H5Aread(id, mem_type.getId(), &strg_C);
+ // call C API to get the attribute string of chars
+ herr_t ret_value = H5Aread( id, mem_type.getId(), &strg_C);
if( ret_value < 0 )
{
throw AttributeIException("Attribute::read", "H5Aread failed");
}
-
- // Get 'string' from the C char* and release resource
- strg_C[attr_size] = '\0';
- strg = strg_C;
- delete []strg_C;
+ strg = strg_C; // get 'string' from the C char*
+ HDfree(strg_C);
}
//--------------------------------------------------------------------------
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 76bc089..136fb3b 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -25,7 +25,6 @@
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
-#include "H5private.h" // for HDfree
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -158,7 +157,7 @@ void PropList::copyProp(PropList& dest, const char *name) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param dest - IN: Destination property list or class
-///\param name - IN: Name of the property to copy - \c H5std_string
+///\param name - IN: Name of the property to copy - \c std::string
// Programmer Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
void PropList::copyProp( PropList& dest, const H5std_string& name ) const
@@ -195,7 +194,7 @@ void PropList::copyProp( PropList& dest, PropList& src, const char *name ) const
/// accepts. - Obsolete
///\param dest - IN: Destination property list or class
///\param src - IN: Source property list or class
-///\param name - IN: Name of the property to copy - \c H5std_string
+///\param name - IN: Name of the property to copy - \c std::string
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name ) const
@@ -274,7 +273,7 @@ bool PropList::propExist(const char* name ) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to check for - \c H5std_string
+///\param name - IN: Name of property to check for - \c std::string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
bool PropList::propExist(const H5std_string& name ) const
@@ -327,7 +326,7 @@ void PropList::getProperty(const char* name, void* value) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param name - IN: Name of property to query - \c char pointer
-///\return The property that is a \c H5std_string.
+///\return The property that is a \c std::string.
///\exception H5::PropListIException
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -344,7 +343,7 @@ H5std_string PropList::getProperty(const char* name) const
}
// Return propety value as a string after deleting temp C-string
- H5std_string prop_strg(prop_strg_C);
+ H5std_string prop_strg = H5std_string(prop_strg_C);
delete []prop_strg_C;
return (prop_strg);
}
@@ -353,7 +352,7 @@ H5std_string PropList::getProperty(const char* name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c H5std_string
+///\param name - IN: Name of property to query - \c std::string
///\param value - OUT: Pointer to the buffer for the property value
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -366,8 +365,8 @@ void PropList::getProperty(const H5std_string& name, void* value) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c H5std_string
-///\return The property that is a \c H5std_string.
+///\param name - IN: Name of property to query - \c std::string
+///\return The property that is a \c std::string.
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
H5std_string PropList::getProperty(const H5std_string& name) const
@@ -403,7 +402,7 @@ size_t PropList::getPropSize(const char *name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c H5std_string
+///\param name - IN: Name of property to query - \c std::string
///
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -422,13 +421,12 @@ size_t PropList::getPropSize(const H5std_string& name) const
H5std_string PropList::getClassName() const
{
char* temp_str;
- temp_str = H5Pget_class_name(id); // this API specified that temp_str must
- // be freed.
+ temp_str = H5Pget_class_name(id);
if (temp_str != NULL)
{
- H5std_string class_name(temp_str);
- HDfree(temp_str);
+ H5std_string class_name = H5std_string(temp_str);
+ free(temp_str);
return(class_name);
}
else
@@ -491,7 +489,7 @@ void PropList::setProperty(const char* name, const char* charptr) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param name - IN: Name of property to set - \c char pointer
-///\param strg - IN: Value for the property is a \c H5std_string
+///\param strg - IN: Value for the property is a \c std::string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void PropList::setProperty(const char* name, H5std_string& strg) const
@@ -504,7 +502,7 @@ void PropList::setProperty(const char* name, H5std_string& strg) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to set - \c H5std_string
+///\param name - IN: Name of property to set - \c std::string
///\param value - IN: Void pointer to the value for the property
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -518,7 +516,7 @@ void PropList::setProperty(const H5std_string& name, void* value) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to set - \c H5std_string
+///\param name - IN: Name of property to set - \c std::string
///\param strg - IN: Value for the property is a \c std::string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -571,7 +569,7 @@ void PropList::removeProp(const char *name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to remove - \c H5std_string
+///\param name - IN: Name of property to remove - \c std::string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void PropList::removeProp(const H5std_string& name) const
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index 557f400..ac468c4 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -144,6 +144,8 @@ static void test_classes()
*/
static void test_copy()
{
+ hid_t a_copy;
+ herr_t status;
SUBTEST("DataType::copy() and DataType::operator=");
try {
@@ -211,6 +213,7 @@ static void test_query()
long c;
double d;
} s_type_t;
+ char filename[1024];
short enum_val;
// Output message about test being performed
@@ -385,9 +388,11 @@ static void test_transient ()
const H5std_string filename2("dtypes2.h5");
static void test_named ()
{
+ herr_t status;
static hsize_t ds_size[2] = {10, 20};
hsize_t i;
unsigned attr_data[10][20];
+ char filename[1024];
SUBTEST("Named datatypes");
try {
diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp
index 007ab10..469e861 100644
--- a/c++/test/tvlstr.cpp
+++ b/c++/test/tvlstr.cpp
@@ -527,6 +527,7 @@ static void test_compact_vlstring()
*-------------------------------------------------------------------------
*/
// String for testing attributes
+static const char *string_att = "This is the string for the attribute";
static char *string_att_write=NULL;
// Info for a string attribute