Skip to content
Snippets Groups Projects
Commit f7de2550 authored by William F Godoy's avatar William F Godoy
Browse files

Initial implementation of Attributes with Tests

Refactored IO, Variable class due to common functionality
parent 857cdfc4
No related branches found
No related tags found
1 merge request!228Attribute template core class implementation
Showing
with 681 additions and 40 deletions
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#------------------------------------------------------------------------------# #------------------------------------------------------------------------------#
add_library(adios2 add_library(adios2
core/Attribute.cpp core/Attribute.tcc
core/AttributeBase.cpp
core/ADIOS.cpp core/ADIOS.cpp
core/Engine.cpp core/Engine.cpp
core/IO.cpp core/IO.tcc core/IO.cpp core/IO.tcc
......
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* Attribute.cpp : needed for template separation using Attribute.tcc
*
* Created on: Aug 3, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "Attribute.h"
#include "Attribute.tcc"
namespace adios2
{
} // end namespace adios2
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See * Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details. * accompanying file Copyright.txt for details.
* *
* Attribute.h : template class * Attribute.h : template class that defines typed attributes
* *
* Created on: Aug 1, 2017 * Created on: Aug 1, 2017
* Author: William F Godoy godoywf@ornl.gov * Author: William F Godoy godoywf@ornl.gov
...@@ -45,4 +45,4 @@ public: ...@@ -45,4 +45,4 @@ public:
} // end namespace adios2 } // end namespace adios2
#endif /* SOURCE_ADIOS2_CORE_ATTRIBUTE_H_ */ #endif /* ADIOS2_CORE_ATTRIBUTE_H_ */
...@@ -31,7 +31,7 @@ namespace adios2 ...@@ -31,7 +31,7 @@ namespace adios2
\ \
template <> \ template <> \
Attribute<T>::Attribute(const std::string &name, const T &value) \ Attribute<T>::Attribute(const std::string &name, const T &value) \
: AttributeBase(name, GetType<T>(), 1), m_DataValue() \ : AttributeBase(name, GetType<T>(), 1), m_DataValue(value) \
{ \ { \
} }
...@@ -39,3 +39,5 @@ ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_type) ...@@ -39,3 +39,5 @@ ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_type)
#undef declare_type #undef declare_type
} // end namespace adios2 } // end namespace adios2
#endif /* ADIOS2_CORE_ATTRIBUTE_TCC_ */
...@@ -11,6 +11,13 @@ ...@@ -11,6 +11,13 @@
#ifndef ADIOS2_CORE_ATTRIBUTEBASE_H_ #ifndef ADIOS2_CORE_ATTRIBUTEBASE_H_
#define ADIOS2_CORE_ATTRIBUTEBASE_H_ #define ADIOS2_CORE_ATTRIBUTEBASE_H_
/// \cond EXCLUDE_FROM_DOXYGEN
#include <string>
/// \endcond
#include "adios2/ADIOSConfig.h"
#include "adios2/ADIOSTypes.h"
namespace adios2 namespace adios2
{ {
......
...@@ -287,11 +287,22 @@ void IO::CheckTransportType(const std::string type) const ...@@ -287,11 +287,22 @@ void IO::CheckTransportType(const std::string type) const
// Explicitly instantiate the necessary public template implementations // Explicitly instantiate the necessary public template implementations
#define define_template_instantiation(T) \ #define define_template_instantiation(T) \
template Variable<T> &IO::DefineVariable<T>( \ template Variable<T> &IO::DefineVariable<T>(const std::string &, \
const std::string &, const Dims, const Dims, const Dims, const bool); \ const Dims &, const Dims &, \
const Dims &, const bool); \
template Variable<T> &IO::GetVariable<T>(const std::string &); template Variable<T> &IO::GetVariable<T>(const std::string &);
ADIOS2_FOREACH_TYPE_1ARG(define_template_instantiation) ADIOS2_FOREACH_TYPE_1ARG(define_template_instantiation)
#undef define_template_instatiation #undef define_template_instatiation
#define declare_template_instantiation(T) \
template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const T *, const size_t); \
template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const T &); \
template Attribute<T> &IO::GetAttribute(const std::string &);
ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end namespace adios } // end namespace adios
...@@ -118,8 +118,8 @@ public: ...@@ -118,8 +118,8 @@ public:
* @return reference to Variable object * @return reference to Variable object
*/ */
template <class T> template <class T>
Variable<T> &DefineVariable(const std::string &name, const Dims shape = {}, Variable<T> &DefineVariable(const std::string &name, const Dims &shape = {},
const Dims start = {}, const Dims count = {}, const Dims &start = {}, const Dims &count = {},
const bool constantShape = false); const bool constantShape = false);
/** /**
...@@ -136,13 +136,14 @@ public: ...@@ -136,13 +136,14 @@ public:
*/ */
template <class T> template <class T>
VariableCompound & VariableCompound &DefineVariableCompound(const std::string &name,
DefineVariableCompound(const std::string &name, const Dims shape = Dims{}, const Dims &shape = Dims{},
const Dims start = Dims{}, const Dims count = Dims{}, const Dims &start = Dims{},
const bool constantShape = false); const Dims &count = Dims{},
const bool constantShape = false);
/** /**
* Define attribute from contiguous data array * Define attribute from contiguous data array owned by an application
* @param name must be unique for the IO object * @param name must be unique for the IO object
* @param array pointer to user data * @param array pointer to user data
* @param elements number of data elements * @param elements number of data elements
...@@ -153,7 +154,7 @@ public: ...@@ -153,7 +154,7 @@ public:
const size_t elements); const size_t elements);
/** /**
* Define attribute from a single variable * Define attribute from a single variable making a copy
* @param name must be unique for the IO object * @param name must be unique for the IO object
* @param value single data value * @param value single data value
* @return reference to internal Attribute * @return reference to internal Attribute
...@@ -340,8 +341,8 @@ private: ...@@ -340,8 +341,8 @@ private:
// Explicit declaration of the public template methods // Explicit declaration of the public template methods
#define declare_template_instantiation(T) \ #define declare_template_instantiation(T) \
extern template Variable<T> &IO::DefineVariable<T>( \ extern template Variable<T> &IO::DefineVariable<T>( \
const std::string &name, const Dims, const Dims, const Dims, \ const std::string &, const Dims &, const Dims &, const Dims &, \
const bool constantShape); \ const bool); \
extern template Variable<T> &IO::GetVariable<T>(const std::string &name); extern template Variable<T> &IO::GetVariable<T>(const std::string &name);
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
...@@ -349,14 +350,15 @@ ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation) ...@@ -349,14 +350,15 @@ ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#define declare_template_instantiation(T) \ #define declare_template_instantiation(T) \
extern template Attribute<T> &IO::DefineAttribute<T>( \ extern template Attribute<T> &IO::DefineAttribute<T>( \
const std::string &name, const T *array, const size_t elements); \ const std::string &, const T *, const size_t); \
extern template Attribute<T> &IO::DefineAttribute<T>( \ extern template Attribute<T> &IO::DefineAttribute<T>(const std::string &, \
const std::string &name, const T &value); const T &); \
extern template Attribute<T> &IO::GetAttribute(const std::string &);
ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation) ADIOS2_FOREACH_ATTRIBUTE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation #undef declare_template_instantiation
} // end namespace adios } // end namespace adios2
#include "adios2/core/IO.inl" #include "adios2/core/IO.inl"
......
...@@ -21,10 +21,10 @@ namespace adios2 ...@@ -21,10 +21,10 @@ namespace adios2
{ {
template <class T> template <class T>
VariableCompound &IO::DefineVariableCompound(const std::string &name, VariableCompound &
const Dims shape, const Dims start, IO::DefineVariableCompound(const std::string &name, const Dims &shape,
const Dims count, const Dims &start, const Dims &count,
const bool constantShape) const bool constantShape)
{ {
if (m_DebugMode) if (m_DebugMode)
{ {
......
...@@ -26,8 +26,8 @@ namespace adios2 ...@@ -26,8 +26,8 @@ namespace adios2
{ {
template <class T> template <class T>
Variable<T> &IO::DefineVariable(const std::string &name, const Dims shape, Variable<T> &IO::DefineVariable(const std::string &name, const Dims &shape,
const Dims start, const Dims count, const Dims &start, const Dims &count,
const bool constantShape) const bool constantShape)
{ {
if (m_DebugMode) if (m_DebugMode)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See * Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details. * accompanying file Copyright.txt for details.
* *
* Variable.cpp needed for template separation using Variable.tcc * Variable.cpp : needed for template separation using Variable.tcc
* *
* Created on: Jun 8, 2017 * Created on: Jun 8, 2017
* Author: William F Godoy godoywf@ornl.gov * Author: William F Godoy godoywf@ornl.gov
...@@ -14,4 +14,4 @@ ...@@ -14,4 +14,4 @@
namespace adios2 namespace adios2
{ {
} // end namespace adios } // end namespace adios2
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include <vector> #include <vector>
/// \endcond /// \endcond
#include "adios2/ADIOSMacros.h"
#include "adios2/core/Transform.h"
#include "adios2/core/VariableBase.h" #include "adios2/core/VariableBase.h"
namespace adios2 namespace adios2
...@@ -50,8 +48,8 @@ public: ...@@ -50,8 +48,8 @@ public:
* @param constantShape * @param constantShape
* @param debugMode * @param debugMode
*/ */
Variable<T>(const std::string &name, const Dims shape, const Dims start, Variable<T>(const std::string &name, const Dims &shape, const Dims &start,
const Dims count, const bool constantShape, const Dims &count, const bool constantShape,
const bool debugMode); const bool debugMode);
~Variable<T>() = default; ~Variable<T>() = default;
......
...@@ -22,8 +22,8 @@ namespace adios2 ...@@ -22,8 +22,8 @@ namespace adios2
#define declare_type(T) \ #define declare_type(T) \
\ \
template <> \ template <> \
Variable<T>::Variable(const std::string &name, const Dims shape, \ Variable<T>::Variable(const std::string &name, const Dims &shape, \
const Dims start, const Dims count, \ const Dims &start, const Dims &count, \
const bool constantShape, const bool debugMode) \ const bool constantShape, const bool debugMode) \
: VariableBase(name, GetType<T>(), sizeof(T), shape, start, count, \ : VariableBase(name, GetType<T>(), sizeof(T), shape, start, count, \
constantShape, debugMode) \ constantShape, debugMode) \
......
...@@ -21,8 +21,8 @@ namespace adios2 ...@@ -21,8 +21,8 @@ namespace adios2
{ {
VariableBase::VariableBase(const std::string &name, const std::string type, VariableBase::VariableBase(const std::string &name, const std::string type,
const size_t elementSize, const Dims shape, const size_t elementSize, const Dims &shape,
const Dims start, const Dims count, const Dims &start, const Dims &count,
const bool constantDims, const bool debugMode) const bool constantDims, const bool debugMode)
: m_Name(name), m_Type(type), m_ElementSize(elementSize), m_Shape(shape), : m_Name(name), m_Type(type), m_ElementSize(elementSize), m_Shape(shape),
m_Start(start), m_Count(count), m_ConstantDims(constantDims), m_Start(start), m_Count(count), m_ConstantDims(constantDims),
...@@ -41,7 +41,7 @@ size_t VariableBase::TotalSize() const noexcept ...@@ -41,7 +41,7 @@ size_t VariableBase::TotalSize() const noexcept
return GetTotalSize(m_Count); return GetTotalSize(m_Count);
} }
void VariableBase::SetSelection(const Dims start, const Dims count) void VariableBase::SetSelection(const Dims &start, const Dims &count)
{ {
if (m_DebugMode) if (m_DebugMode)
{ {
......
...@@ -63,8 +63,8 @@ public: ...@@ -63,8 +63,8 @@ public:
unsigned int m_AvailableSteps = 1; unsigned int m_AvailableSteps = 1;
VariableBase(const std::string &name, const std::string type, VariableBase(const std::string &name, const std::string type,
const size_t elementSize, const Dims shape, const Dims start, const size_t elementSize, const Dims &shape, const Dims &start,
const Dims count, const bool constantShape, const Dims &count, const bool constantShape,
const bool debugMode); const bool debugMode);
virtual ~VariableBase() = default; virtual ~VariableBase() = default;
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
size_t TotalSize() const noexcept; size_t TotalSize() const noexcept;
/** Set the local dimension and global offset of the variable */ /** Set the local dimension and global offset of the variable */
void SetSelection(const Dims start, const Dims count); void SetSelection(const Dims &start, const Dims &count);
/** Overloaded version of SetSelection using a SelectionBoundingBox */ /** Overloaded version of SetSelection using a SelectionBoundingBox */
void SetSelection(const SelectionBoundingBox &selection); void SetSelection(const SelectionBoundingBox &selection);
......
...@@ -27,6 +27,13 @@ inline std::string GetType<void>() noexcept ...@@ -27,6 +27,13 @@ inline std::string GetType<void>() noexcept
{ {
return "unknown"; return "unknown";
} }
template <>
inline std::string GetType<std::string>() noexcept
{
return "string";
}
template <> template <>
inline std::string GetType<char>() noexcept inline std::string GetType<char>() noexcept
{ {
......
...@@ -9,5 +9,9 @@ target_link_libraries(TestADIOSInterfaceWrite adios2 gtest gtest_main) ...@@ -9,5 +9,9 @@ target_link_libraries(TestADIOSInterfaceWrite adios2 gtest gtest_main)
add_executable(TestADIOSDefineVariable TestADIOSDefineVariable.cpp) add_executable(TestADIOSDefineVariable TestADIOSDefineVariable.cpp)
target_link_libraries(TestADIOSDefineVariable adios2 gtest gtest_main) target_link_libraries(TestADIOSDefineVariable adios2 gtest gtest_main)
add_executable(TestADIOSDefineAttribute TestADIOSDefineAttribute.cpp)
target_link_libraries(TestADIOSDefineAttribute adios2 gtest gtest_main)
gtest_add_tests(TARGET TestADIOSInterfaceWrite) gtest_add_tests(TARGET TestADIOSInterfaceWrite)
gtest_add_tests(TARGET TestADIOSDefineVariable) gtest_add_tests(TARGET TestADIOSDefineVariable)
\ No newline at end of file gtest_add_tests(TARGET TestADIOSDefineAttribute)
\ No newline at end of file
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <adios2.h>
#include <gtest/gtest.h>
class ADIOSDefineAttributeTest : public ::testing::Test
{
public:
ADIOSDefineAttributeTest() : adios(true), io(adios.DeclareIO("TestIO")) {}
protected:
// virtual void SetUp() { }
// virtual void TearDown() { }
adios2::ADIOS adios;
adios2::IO &io;
};
TEST_F(ADIOSDefineAttributeTest, DefineAttributeNameException)
{
auto &attributeString1 =
io.DefineAttribute<std::string>("attributeString", "-1");
EXPECT_THROW(auto &attributeString2 =
io.DefineAttribute<std::string>("attributeString", "0"),
std::invalid_argument);
EXPECT_THROW(auto &attributeString2 =
io.GetAttribute<std::string>("NoExistingAttribute"),
std::invalid_argument);
EXPECT_NO_THROW(auto &attributeString3 =
io.GetAttribute<std::string>("attributeString"));
}
TEST_F(ADIOSDefineAttributeTest, DefineAttributeTypeByValue)
{
// Define ADIOS global value
auto &attributeString =
io.DefineAttribute<std::string>("attributeString", "-1");
auto &attributeChar = io.DefineAttribute<char>("attributeChar", '0');
auto &attributeUChar =
io.DefineAttribute<unsigned char>("attributeUChar", '1');
auto &attributeShort = io.DefineAttribute<short>("attributeShort", 2);
auto &attributeUShort =
io.DefineAttribute<unsigned short>("attributeUShort", 3);
auto &attributeInt = io.DefineAttribute<int>("attributeInt", 4);
auto &attributeUInt = io.DefineAttribute<unsigned int>("attributeUInt", 5);
auto &attributeLInt = io.DefineAttribute<long int>("attributeLInt", 6);
auto &attributeULInt =
io.DefineAttribute<unsigned long int>("attributeULInt", 7);
auto &attributeLLInt =
io.DefineAttribute<long long int>("attributeLLInt", 8);
auto &attributeULLInt =
io.DefineAttribute<unsigned long long int>("attributeULLInt", 9);
auto &attributeFloat = io.DefineAttribute<float>("attributeFloat", 10);
auto &attributeDouble = io.DefineAttribute<double>("attributeDouble", 11);
auto &attributeLDouble =
io.DefineAttribute<long double>("attributeLDouble", 12);
// Verify the return type is as expected
::testing::StaticAssertTypeEq<decltype(attributeString),
adios2::Attribute<std::string> &>();
::testing::StaticAssertTypeEq<decltype(attributeChar),
adios2::Attribute<char> &>();
::testing::StaticAssertTypeEq<decltype(attributeUChar),
adios2::Attribute<unsigned char> &>();
::testing::StaticAssertTypeEq<decltype(attributeShort),
adios2::Attribute<short> &>();
::testing::StaticAssertTypeEq<decltype(attributeUShort),
adios2::Attribute<unsigned short> &>();
::testing::StaticAssertTypeEq<decltype(attributeInt),
adios2::Attribute<int> &>();
::testing::StaticAssertTypeEq<decltype(attributeUInt),
adios2::Attribute<unsigned int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLInt),
adios2::Attribute<long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeULInt),
adios2::Attribute<unsigned long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLLInt),
adios2::Attribute<long long int> &>();
::testing::StaticAssertTypeEq<
decltype(attributeULLInt),
adios2::Attribute<unsigned long long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeFloat),
adios2::Attribute<float> &>();
::testing::StaticAssertTypeEq<decltype(attributeDouble),
adios2::Attribute<double> &>();
::testing::StaticAssertTypeEq<decltype(attributeLDouble),
adios2::Attribute<long double> &>();
// Verify the members are correct
ASSERT_EQ(attributeString.m_DataArray, nullptr);
EXPECT_EQ(attributeString.m_Name, "attributeString");
EXPECT_EQ(attributeString.m_DataValue, "-1");
EXPECT_EQ(attributeString.m_Elements, 1);
EXPECT_EQ(attributeString.m_Type, "string");
ASSERT_EQ(attributeChar.m_DataArray, nullptr);
EXPECT_EQ(attributeChar.m_Name, "attributeChar");
EXPECT_EQ(attributeChar.m_DataValue, '0');
EXPECT_EQ(attributeChar.m_Elements, 1);
EXPECT_EQ(attributeChar.m_Type, "char");
ASSERT_EQ(attributeUChar.m_DataArray, nullptr);
EXPECT_EQ(attributeUChar.m_Name, "attributeUChar");
EXPECT_EQ(attributeUChar.m_DataValue, '1');
EXPECT_EQ(attributeUChar.m_Elements, 1);
EXPECT_EQ(attributeUChar.m_Type, "unsigned char");
ASSERT_EQ(attributeShort.m_DataArray, nullptr);
EXPECT_EQ(attributeShort.m_Name, "attributeShort");
EXPECT_EQ(attributeShort.m_DataValue, 2);
EXPECT_EQ(attributeShort.m_Elements, 1);
EXPECT_EQ(attributeShort.m_Type, "short");
ASSERT_EQ(attributeUShort.m_DataArray, nullptr);
EXPECT_EQ(attributeUShort.m_Name, "attributeUShort");
EXPECT_EQ(attributeUShort.m_DataValue, 3);
EXPECT_EQ(attributeUShort.m_Elements, 1);
EXPECT_EQ(attributeUShort.m_Type, "unsigned short");
ASSERT_EQ(attributeInt.m_DataArray, nullptr);
EXPECT_EQ(attributeInt.m_Name, "attributeInt");
EXPECT_EQ(attributeInt.m_DataValue, 4);
EXPECT_EQ(attributeInt.m_Elements, 1);
EXPECT_EQ(attributeInt.m_Type, "int");
ASSERT_EQ(attributeUInt.m_DataArray, nullptr);
EXPECT_EQ(attributeUInt.m_Name, "attributeUInt");
EXPECT_EQ(attributeUInt.m_DataValue, 5);
EXPECT_EQ(attributeUInt.m_Elements, 1);
EXPECT_EQ(attributeUInt.m_Type, "unsigned int");
ASSERT_EQ(attributeLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLInt.m_Name, "attributeLInt");
EXPECT_EQ(attributeLInt.m_DataValue, 6);
EXPECT_EQ(attributeLInt.m_Elements, 1);
EXPECT_EQ(attributeLInt.m_Type, "long int");
ASSERT_EQ(attributeULInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULInt.m_Name, "attributeULInt");
EXPECT_EQ(attributeULInt.m_DataValue, 7);
EXPECT_EQ(attributeULInt.m_Elements, 1);
EXPECT_EQ(attributeULInt.m_Type, "unsigned long int");
ASSERT_EQ(attributeLLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLLInt.m_Name, "attributeLLInt");
EXPECT_EQ(attributeLLInt.m_DataValue, 8);
EXPECT_EQ(attributeLLInt.m_Elements, 1);
EXPECT_EQ(attributeLLInt.m_Type, "long long int");
ASSERT_EQ(attributeULLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULLInt.m_Name, "attributeULLInt");
EXPECT_EQ(attributeULLInt.m_DataValue, 9);
EXPECT_EQ(attributeULLInt.m_Elements, 1);
EXPECT_EQ(attributeULLInt.m_Type, "unsigned long long int");
ASSERT_EQ(attributeFloat.m_DataArray, nullptr);
EXPECT_EQ(attributeFloat.m_Name, "attributeFloat");
EXPECT_EQ(attributeFloat.m_DataValue, 10);
EXPECT_EQ(attributeFloat.m_Elements, 1);
EXPECT_EQ(attributeFloat.m_Type, "float");
ASSERT_EQ(attributeDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeDouble.m_Name, "attributeDouble");
EXPECT_EQ(attributeDouble.m_DataValue, 11);
EXPECT_EQ(attributeDouble.m_Elements, 1);
EXPECT_EQ(attributeDouble.m_Type, "double");
ASSERT_EQ(attributeLDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeLDouble.m_Name, "attributeLDouble");
EXPECT_EQ(attributeLDouble.m_DataValue, 12);
EXPECT_EQ(attributeLDouble.m_Elements, 1);
EXPECT_EQ(attributeLDouble.m_Type, "long double");
}
TEST_F(ADIOSDefineAttributeTest, DefineAttributeTypeByReference)
{
// Define ADIOS global value
const std::vector<std::string> vString{"-1", "0", "+1"};
const std::vector<char> vChar = {0, 0 + 1, 0 + 2};
const std::vector<unsigned char> vUChar = {1, 1 + 1, 1 + 2};
const std::vector<short> vShort = {2, 2 + 1, 2 + 2};
const std::vector<unsigned short> vUShort = {3, 3 + 1, 3 + 2};
const std::vector<int> vInt = {4, 4 + 1, 4 + 2};
const std::vector<unsigned int> vUInt = {5, 5 + 1, 5 + 2};
const std::vector<long int> vLInt = {6, 6 + 1, 6 + 2};
const std::vector<unsigned long int> vULInt = {7, 7 + 1, 7 + 2};
const std::vector<long long int> vLLInt = {8, 8 + 1, 8 + 2};
const std::vector<unsigned long long int> vULLInt = {9, 9 + 1, 9 + 2};
const std::vector<float> vFloat = {10, 10 + 1, 10 + 2};
const std::vector<double> vDouble = {11, 11 + 1, 11 + 2};
const std::vector<long double> vLDouble = {12, 12 + 1, 12 + 2};
auto &attributeString =
io.DefineAttribute<std::string>("attributeString", vString.data(), 3);
auto &attributeChar =
io.DefineAttribute<char>("attributeChar", vChar.data(), 3);
auto &attributeUChar =
io.DefineAttribute<unsigned char>("attributeUChar", vUChar.data(), 3);
auto &attributeShort =
io.DefineAttribute<short>("attributeShort", vShort.data(), 3);
auto &attributeUShort = io.DefineAttribute<unsigned short>(
"attributeUShort", vUShort.data(), 3);
auto &attributeInt =
io.DefineAttribute<int>("attributeInt", vInt.data(), 3);
auto &attributeUInt =
io.DefineAttribute<unsigned int>("attributeUInt", vUInt.data(), 3);
auto &attributeLInt =
io.DefineAttribute<long int>("attributeLInt", vLInt.data(), 3);
auto &attributeULInt = io.DefineAttribute<unsigned long int>(
"attributeULInt", vULInt.data(), 3);
auto &attributeLLInt =
io.DefineAttribute<long long int>("attributeLLInt", vLLInt.data(), 3);
auto &attributeULLInt = io.DefineAttribute<unsigned long long int>(
"attributeULLInt", vULLInt.data(), 3);
auto &attributeFloat =
io.DefineAttribute<float>("attributeFloat", vFloat.data(), 3);
auto &attributeDouble =
io.DefineAttribute<double>("attributeDouble", vDouble.data(), 3);
auto &attributeLDouble =
io.DefineAttribute<long double>("attributeLDouble", vLDouble.data(), 3);
// Verify the return type is as expected
::testing::StaticAssertTypeEq<decltype(attributeString),
adios2::Attribute<std::string> &>();
::testing::StaticAssertTypeEq<decltype(attributeChar),
adios2::Attribute<char> &>();
::testing::StaticAssertTypeEq<decltype(attributeUChar),
adios2::Attribute<unsigned char> &>();
::testing::StaticAssertTypeEq<decltype(attributeShort),
adios2::Attribute<short> &>();
::testing::StaticAssertTypeEq<decltype(attributeUShort),
adios2::Attribute<unsigned short> &>();
::testing::StaticAssertTypeEq<decltype(attributeInt),
adios2::Attribute<int> &>();
::testing::StaticAssertTypeEq<decltype(attributeUInt),
adios2::Attribute<unsigned int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLInt),
adios2::Attribute<long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeULInt),
adios2::Attribute<unsigned long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLLInt),
adios2::Attribute<long long int> &>();
::testing::StaticAssertTypeEq<
decltype(attributeULLInt),
adios2::Attribute<unsigned long long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeFloat),
adios2::Attribute<float> &>();
::testing::StaticAssertTypeEq<decltype(attributeDouble),
adios2::Attribute<double> &>();
::testing::StaticAssertTypeEq<decltype(attributeLDouble),
adios2::Attribute<long double> &>();
// Verify the dimensions, name, and type are correct
ASSERT_NE(attributeString.m_DataArray, nullptr);
EXPECT_EQ(attributeString.m_DataArray[0], "-1");
EXPECT_EQ(attributeString.m_DataArray[1], "0");
EXPECT_EQ(attributeString.m_DataArray[2], "+1");
EXPECT_EQ(attributeString.m_Name, "attributeString");
ASSERT_EQ(attributeString.m_DataValue.empty(), true);
EXPECT_EQ(attributeString.m_Elements, 3);
EXPECT_EQ(attributeString.m_Type, "string");
ASSERT_NE(attributeChar.m_DataArray, nullptr);
EXPECT_EQ(attributeChar.m_DataArray[0], 0);
EXPECT_EQ(attributeChar.m_DataArray[1], 0 + 1);
EXPECT_EQ(attributeChar.m_DataArray[2], 0 + 2);
EXPECT_EQ(attributeChar.m_Name, "attributeChar");
EXPECT_EQ(attributeChar.m_Elements, 3);
EXPECT_EQ(attributeChar.m_Type, "char");
ASSERT_NE(attributeUChar.m_DataArray, nullptr);
EXPECT_EQ(attributeUChar.m_DataArray[0], 1);
EXPECT_EQ(attributeUChar.m_DataArray[1], 1 + 1);
EXPECT_EQ(attributeUChar.m_DataArray[2], 1 + 2);
EXPECT_EQ(attributeUChar.m_Name, "attributeUChar");
EXPECT_EQ(attributeUChar.m_Elements, 3);
EXPECT_EQ(attributeUChar.m_Type, "unsigned char");
ASSERT_NE(attributeShort.m_DataArray, nullptr);
EXPECT_EQ(attributeShort.m_DataArray[0], 2);
EXPECT_EQ(attributeShort.m_DataArray[1], 2 + 1);
EXPECT_EQ(attributeShort.m_DataArray[2], 2 + 2);
EXPECT_EQ(attributeShort.m_Name, "attributeShort");
EXPECT_EQ(attributeShort.m_Elements, 3);
EXPECT_EQ(attributeShort.m_Type, "short");
ASSERT_NE(attributeUShort.m_DataArray, nullptr);
EXPECT_EQ(attributeUShort.m_DataArray[0], 3);
EXPECT_EQ(attributeUShort.m_DataArray[1], 3 + 1);
EXPECT_EQ(attributeUShort.m_DataArray[2], 3 + 2);
EXPECT_EQ(attributeUShort.m_Name, "attributeUShort");
EXPECT_EQ(attributeUShort.m_Elements, 3);
EXPECT_EQ(attributeUShort.m_Type, "unsigned short");
ASSERT_NE(attributeInt.m_DataArray, nullptr);
EXPECT_EQ(attributeInt.m_DataArray[0], 4);
EXPECT_EQ(attributeInt.m_DataArray[1], 4 + 1);
EXPECT_EQ(attributeInt.m_DataArray[2], 4 + 2);
EXPECT_EQ(attributeInt.m_Name, "attributeInt");
EXPECT_EQ(attributeInt.m_Elements, 3);
EXPECT_EQ(attributeInt.m_Type, "int");
ASSERT_NE(attributeUInt.m_DataArray, nullptr);
EXPECT_EQ(attributeUInt.m_DataArray[0], 5);
EXPECT_EQ(attributeUInt.m_DataArray[1], 5 + 1);
EXPECT_EQ(attributeUInt.m_DataArray[2], 5 + 2);
EXPECT_EQ(attributeUInt.m_Name, "attributeUInt");
EXPECT_EQ(attributeUInt.m_Elements, 3);
EXPECT_EQ(attributeUInt.m_Type, "unsigned int");
ASSERT_NE(attributeLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLInt.m_DataArray[0], 6);
EXPECT_EQ(attributeLInt.m_DataArray[1], 6 + 1);
EXPECT_EQ(attributeLInt.m_DataArray[2], 6 + 2);
EXPECT_EQ(attributeLInt.m_Name, "attributeLInt");
EXPECT_EQ(attributeLInt.m_Elements, 3);
EXPECT_EQ(attributeLInt.m_Type, "long int");
ASSERT_NE(attributeULInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULInt.m_DataArray[0], 7);
EXPECT_EQ(attributeULInt.m_DataArray[1], 7 + 1);
EXPECT_EQ(attributeULInt.m_DataArray[2], 7 + 2);
EXPECT_EQ(attributeULInt.m_Name, "attributeULInt");
EXPECT_EQ(attributeULInt.m_Elements, 3);
EXPECT_EQ(attributeULInt.m_Type, "unsigned long int");
ASSERT_NE(attributeLLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLLInt.m_DataArray[0], 8);
EXPECT_EQ(attributeLLInt.m_DataArray[1], 8 + 1);
EXPECT_EQ(attributeLLInt.m_DataArray[2], 8 + 2);
EXPECT_EQ(attributeLLInt.m_Name, "attributeLLInt");
EXPECT_EQ(attributeLLInt.m_Elements, 3);
EXPECT_EQ(attributeLLInt.m_Type, "long long int");
ASSERT_NE(attributeULLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULLInt.m_DataArray[0], 9);
EXPECT_EQ(attributeULLInt.m_DataArray[1], 9 + 1);
EXPECT_EQ(attributeULLInt.m_DataArray[2], 9 + 2);
EXPECT_EQ(attributeULLInt.m_Name, "attributeULLInt");
EXPECT_EQ(attributeULLInt.m_Elements, 3);
EXPECT_EQ(attributeULLInt.m_Type, "unsigned long long int");
ASSERT_NE(attributeFloat.m_DataArray, nullptr);
EXPECT_EQ(attributeFloat.m_DataArray[0], 10);
EXPECT_EQ(attributeFloat.m_DataArray[1], 10 + 1);
EXPECT_EQ(attributeFloat.m_DataArray[2], 10 + 2);
EXPECT_EQ(attributeFloat.m_Name, "attributeFloat");
EXPECT_EQ(attributeFloat.m_Elements, 3);
EXPECT_EQ(attributeFloat.m_Type, "float");
ASSERT_NE(attributeDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeDouble.m_DataArray[0], 11);
EXPECT_EQ(attributeDouble.m_DataArray[1], 11 + 1);
EXPECT_EQ(attributeDouble.m_DataArray[2], 11 + 2);
EXPECT_EQ(attributeDouble.m_Name, "attributeDouble");
EXPECT_EQ(attributeDouble.m_Elements, 3);
EXPECT_EQ(attributeDouble.m_Type, "double");
ASSERT_NE(attributeLDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeLDouble.m_DataArray[0], 12);
EXPECT_EQ(attributeLDouble.m_DataArray[1], 12 + 1);
EXPECT_EQ(attributeLDouble.m_DataArray[2], 12 + 2);
EXPECT_EQ(attributeLDouble.m_Name, "attributeLDouble");
EXPECT_EQ(attributeLDouble.m_Elements, 3);
EXPECT_EQ(attributeLDouble.m_Type, "long double");
}
TEST_F(ADIOSDefineAttributeTest, GetAttribute)
{
// Define ADIOS global value
const std::vector<std::string> vString{"-1", "0", "+1"};
const std::vector<char> vChar = {0, 0 + 1, 0 + 2};
const std::vector<unsigned char> vUChar = {1, 1 + 1, 1 + 2};
const std::vector<short> vShort = {2, 2 + 1, 2 + 2};
const std::vector<unsigned short> vUShort = {3, 3 + 1, 3 + 2};
const std::vector<int> vInt = {4, 4 + 1, 4 + 2};
const std::vector<unsigned int> vUInt = {5, 5 + 1, 5 + 2};
const std::vector<long int> vLInt = {6, 6 + 1, 6 + 2};
const std::vector<unsigned long int> vULInt = {7, 7 + 1, 7 + 2};
const std::vector<long long int> vLLInt = {8, 8 + 1, 8 + 2};
const std::vector<unsigned long long int> vULLInt = {9, 9 + 1, 9 + 2};
const std::vector<float> vFloat = {10, 10 + 1, 10 + 2};
const std::vector<double> vDouble = {11, 11 + 1, 11 + 2};
const std::vector<long double> vLDouble = {12, 12 + 1, 12 + 2};
{
io.DefineAttribute<std::string>("attributeString", vString.data(), 3);
io.DefineAttribute<char>("attributeChar", vChar.data(), 3);
io.DefineAttribute<unsigned char>("attributeUChar", vUChar.data(), 3);
io.DefineAttribute<short>("attributeShort", vShort.data(), 3);
io.DefineAttribute<unsigned short>("attributeUShort", vUShort.data(),
3);
io.DefineAttribute<int>("attributeInt", vInt.data(), 3);
io.DefineAttribute<unsigned int>("attributeUInt", vUInt.data(), 3);
io.DefineAttribute<long int>("attributeLInt", vLInt.data(), 3);
io.DefineAttribute<unsigned long int>("attributeULInt", vULInt.data(),
3);
io.DefineAttribute<long long int>("attributeLLInt", vLLInt.data(), 3);
io.DefineAttribute<unsigned long long int>("attributeULLInt",
vULLInt.data(), 3);
io.DefineAttribute<float>("attributeFloat", vFloat.data(), 3);
io.DefineAttribute<double>("attributeDouble", vDouble.data(), 3);
io.DefineAttribute<long double>("attributeLDouble", vLDouble.data(), 3);
}
auto &attributeString = io.GetAttribute<std::string>("attributeString");
auto &attributeChar = io.GetAttribute<char>("attributeChar");
auto &attributeUChar = io.GetAttribute<unsigned char>("attributeUChar");
auto &attributeShort = io.GetAttribute<short>("attributeShort");
auto &attributeUShort = io.GetAttribute<unsigned short>("attributeUShort");
auto &attributeInt = io.GetAttribute<int>("attributeInt");
auto &attributeUInt = io.GetAttribute<unsigned int>("attributeUInt");
auto &attributeLInt = io.GetAttribute<long int>("attributeLInt");
auto &attributeULInt = io.GetAttribute<unsigned long int>("attributeULInt");
auto &attributeLLInt = io.GetAttribute<long long int>("attributeLLInt");
auto &attributeULLInt =
io.GetAttribute<unsigned long long int>("attributeULLInt");
auto &attributeFloat = io.GetAttribute<float>("attributeFloat");
auto &attributeDouble = io.GetAttribute<double>("attributeDouble");
auto &attributeLDouble = io.GetAttribute<long double>("attributeLDouble");
// Verify the return type is as expected
::testing::StaticAssertTypeEq<decltype(attributeString),
adios2::Attribute<std::string> &>();
::testing::StaticAssertTypeEq<decltype(attributeChar),
adios2::Attribute<char> &>();
::testing::StaticAssertTypeEq<decltype(attributeUChar),
adios2::Attribute<unsigned char> &>();
::testing::StaticAssertTypeEq<decltype(attributeShort),
adios2::Attribute<short> &>();
::testing::StaticAssertTypeEq<decltype(attributeUShort),
adios2::Attribute<unsigned short> &>();
::testing::StaticAssertTypeEq<decltype(attributeInt),
adios2::Attribute<int> &>();
::testing::StaticAssertTypeEq<decltype(attributeUInt),
adios2::Attribute<unsigned int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLInt),
adios2::Attribute<long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeULInt),
adios2::Attribute<unsigned long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeLLInt),
adios2::Attribute<long long int> &>();
::testing::StaticAssertTypeEq<
decltype(attributeULLInt),
adios2::Attribute<unsigned long long int> &>();
::testing::StaticAssertTypeEq<decltype(attributeFloat),
adios2::Attribute<float> &>();
::testing::StaticAssertTypeEq<decltype(attributeDouble),
adios2::Attribute<double> &>();
::testing::StaticAssertTypeEq<decltype(attributeLDouble),
adios2::Attribute<long double> &>();
// Verify the dimensions, name, and type are correct
ASSERT_NE(attributeString.m_DataArray, nullptr);
EXPECT_EQ(attributeString.m_DataArray[0], "-1");
EXPECT_EQ(attributeString.m_DataArray[1], "0");
EXPECT_EQ(attributeString.m_DataArray[2], "+1");
EXPECT_EQ(attributeString.m_Name, "attributeString");
ASSERT_EQ(attributeString.m_DataValue.empty(), true);
EXPECT_EQ(attributeString.m_Elements, 3);
EXPECT_EQ(attributeString.m_Type, "string");
ASSERT_NE(attributeChar.m_DataArray, nullptr);
EXPECT_EQ(attributeChar.m_DataArray[0], 0);
EXPECT_EQ(attributeChar.m_DataArray[1], 0 + 1);
EXPECT_EQ(attributeChar.m_DataArray[2], 0 + 2);
EXPECT_EQ(attributeChar.m_Name, "attributeChar");
EXPECT_EQ(attributeChar.m_Elements, 3);
EXPECT_EQ(attributeChar.m_Type, "char");
ASSERT_NE(attributeUChar.m_DataArray, nullptr);
EXPECT_EQ(attributeUChar.m_DataArray[0], 1);
EXPECT_EQ(attributeUChar.m_DataArray[1], 1 + 1);
EXPECT_EQ(attributeUChar.m_DataArray[2], 1 + 2);
EXPECT_EQ(attributeUChar.m_Name, "attributeUChar");
EXPECT_EQ(attributeUChar.m_Elements, 3);
EXPECT_EQ(attributeUChar.m_Type, "unsigned char");
ASSERT_NE(attributeShort.m_DataArray, nullptr);
EXPECT_EQ(attributeShort.m_DataArray[0], 2);
EXPECT_EQ(attributeShort.m_DataArray[1], 2 + 1);
EXPECT_EQ(attributeShort.m_DataArray[2], 2 + 2);
EXPECT_EQ(attributeShort.m_Name, "attributeShort");
EXPECT_EQ(attributeShort.m_Elements, 3);
EXPECT_EQ(attributeShort.m_Type, "short");
ASSERT_NE(attributeUShort.m_DataArray, nullptr);
EXPECT_EQ(attributeUShort.m_DataArray[0], 3);
EXPECT_EQ(attributeUShort.m_DataArray[1], 3 + 1);
EXPECT_EQ(attributeUShort.m_DataArray[2], 3 + 2);
EXPECT_EQ(attributeUShort.m_Name, "attributeUShort");
EXPECT_EQ(attributeUShort.m_Elements, 3);
EXPECT_EQ(attributeUShort.m_Type, "unsigned short");
ASSERT_NE(attributeInt.m_DataArray, nullptr);
EXPECT_EQ(attributeInt.m_DataArray[0], 4);
EXPECT_EQ(attributeInt.m_DataArray[1], 4 + 1);
EXPECT_EQ(attributeInt.m_DataArray[2], 4 + 2);
EXPECT_EQ(attributeInt.m_Name, "attributeInt");
EXPECT_EQ(attributeInt.m_Elements, 3);
EXPECT_EQ(attributeInt.m_Type, "int");
ASSERT_NE(attributeUInt.m_DataArray, nullptr);
EXPECT_EQ(attributeUInt.m_DataArray[0], 5);
EXPECT_EQ(attributeUInt.m_DataArray[1], 5 + 1);
EXPECT_EQ(attributeUInt.m_DataArray[2], 5 + 2);
EXPECT_EQ(attributeUInt.m_Name, "attributeUInt");
EXPECT_EQ(attributeUInt.m_Elements, 3);
EXPECT_EQ(attributeUInt.m_Type, "unsigned int");
ASSERT_NE(attributeLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLInt.m_DataArray[0], 6);
EXPECT_EQ(attributeLInt.m_DataArray[1], 6 + 1);
EXPECT_EQ(attributeLInt.m_DataArray[2], 6 + 2);
EXPECT_EQ(attributeLInt.m_Name, "attributeLInt");
EXPECT_EQ(attributeLInt.m_Elements, 3);
EXPECT_EQ(attributeLInt.m_Type, "long int");
ASSERT_NE(attributeULInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULInt.m_DataArray[0], 7);
EXPECT_EQ(attributeULInt.m_DataArray[1], 7 + 1);
EXPECT_EQ(attributeULInt.m_DataArray[2], 7 + 2);
EXPECT_EQ(attributeULInt.m_Name, "attributeULInt");
EXPECT_EQ(attributeULInt.m_Elements, 3);
EXPECT_EQ(attributeULInt.m_Type, "unsigned long int");
ASSERT_NE(attributeLLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeLLInt.m_DataArray[0], 8);
EXPECT_EQ(attributeLLInt.m_DataArray[1], 8 + 1);
EXPECT_EQ(attributeLLInt.m_DataArray[2], 8 + 2);
EXPECT_EQ(attributeLLInt.m_Name, "attributeLLInt");
EXPECT_EQ(attributeLLInt.m_Elements, 3);
EXPECT_EQ(attributeLLInt.m_Type, "long long int");
ASSERT_NE(attributeULLInt.m_DataArray, nullptr);
EXPECT_EQ(attributeULLInt.m_DataArray[0], 9);
EXPECT_EQ(attributeULLInt.m_DataArray[1], 9 + 1);
EXPECT_EQ(attributeULLInt.m_DataArray[2], 9 + 2);
EXPECT_EQ(attributeULLInt.m_Name, "attributeULLInt");
EXPECT_EQ(attributeULLInt.m_Elements, 3);
EXPECT_EQ(attributeULLInt.m_Type, "unsigned long long int");
ASSERT_NE(attributeFloat.m_DataArray, nullptr);
EXPECT_EQ(attributeFloat.m_DataArray[0], 10);
EXPECT_EQ(attributeFloat.m_DataArray[1], 10 + 1);
EXPECT_EQ(attributeFloat.m_DataArray[2], 10 + 2);
EXPECT_EQ(attributeFloat.m_Name, "attributeFloat");
EXPECT_EQ(attributeFloat.m_Elements, 3);
EXPECT_EQ(attributeFloat.m_Type, "float");
ASSERT_NE(attributeDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeDouble.m_DataArray[0], 11);
EXPECT_EQ(attributeDouble.m_DataArray[1], 11 + 1);
EXPECT_EQ(attributeDouble.m_DataArray[2], 11 + 2);
EXPECT_EQ(attributeDouble.m_Name, "attributeDouble");
EXPECT_EQ(attributeDouble.m_Elements, 3);
EXPECT_EQ(attributeDouble.m_Type, "double");
ASSERT_NE(attributeLDouble.m_DataArray, nullptr);
EXPECT_EQ(attributeLDouble.m_DataArray[0], 12);
EXPECT_EQ(attributeLDouble.m_DataArray[1], 12 + 1);
EXPECT_EQ(attributeLDouble.m_DataArray[2], 12 + 2);
EXPECT_EQ(attributeLDouble.m_Name, "attributeLDouble");
EXPECT_EQ(attributeLDouble.m_Elements, 3);
EXPECT_EQ(attributeLDouble.m_Type, "long double");
}
int main(int argc, char **argv)
{
#ifdef ADIOS2_HAVE_MPI
MPI_Init(nullptr, nullptr);
#endif
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
#ifdef ADIOS2_HAVE_MPI
MPI_Finalize();
#endif
return result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment