Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/macos-arm.yml → .github/workflows/arm.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ITK.macOS.Arm64
name: ITK.Arm64

on:
push:
Expand Down Expand Up @@ -36,12 +36,24 @@ env:
jobs:
build:
runs-on: ${{ matrix.os }}
timeout-minutes: 0
timeout-minutes: 600

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04-arm
name: "Ubuntu-24.04-arm"
cmake-build-type: "Release"
cmake-generator: "Ninja"
python-version: ""
ctest-cache: |
BUILD_SHARED_LIBS:BOOL=OFF
BUILD_EXAMPLES:BOOL=OFF
ITK_WRAP_PYTHON:BOOL=OFF
ITK_USE_CLANG_FORMAT:BOOL=OFF
ctest-options: ""

- os: macos-15
name: "x86_64-rosetta"
cmake-build-type: "Release"
Expand All @@ -67,7 +79,7 @@ jobs:
ITK_USE_CLANG_FORMAT:BOOL=OFF
ctest-options: "-E itkPyBufferMemoryLeakTest"

name: macOS-${{ matrix.name }}
name: ARMBUILD-${{ matrix.name }}

steps:
- name: Checkout
Expand Down
61 changes: 61 additions & 0 deletions Modules/Core/Common/test/itkMetaDataDictionaryGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
*=========================================================================*/

#include "itkGTest.h"
#include "itkGTestPredicate.h"

#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.h"
#include "itkTestVerifyMetaData.h"

#include <iterator>
#include <numeric> // For iota.
Expand All @@ -44,6 +46,62 @@ createMetaDataDictionary()
return metaDataDictionary;
}


template <typename T>
static void
CheckMetaData(itk::MetaDataDictionary & metaDict, const std::string & key, const T & knownValue)
Comment thread
hjmjohnson marked this conversation as resolved.
{
itk::EncapsulateMetaData<T>(metaDict, key, knownValue);
ITK_EXPECT_METADATA_VALUE(metaDict, key, knownValue);
}


static void
doExposeMetaDatas()
{
// Simplified version of tests found in HDF5 reading/writing
// that are broken out here to improve localization of bugs
// found during linux-arm building
itk::MetaDataDictionary metaDict;

CheckMetaData<bool>(metaDict, "TestBool", false);
#if !defined(ITK_FUTURE_LEGACY_REMOVE)
CheckMetaData<char>(metaDict, "TestChar", 'c');
#endif
CheckMetaData<unsigned char>(metaDict, "TestUChar", 'u');
CheckMetaData<short>(metaDict, "TestShort", 1);
CheckMetaData<unsigned short>(metaDict, "TestUShort", 3);
CheckMetaData<int>(metaDict, "TestInt", 5);
CheckMetaData<unsigned int>(metaDict, "TestUInt", 7);
CheckMetaData<long>(metaDict, "TestLong", 5);
CheckMetaData<unsigned long>(metaDict, "TestULong", 7);
CheckMetaData<long long>(metaDict, "TestLLong", -5);
CheckMetaData<unsigned long long>(metaDict, "TestULLong", 7ull);
CheckMetaData<float>(metaDict, "TestFloat", 1.23456f);
CheckMetaData<double>(metaDict, "TestDouble", 1.23456);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
itk::Array<char> metaDataCharArray(5);
metaDataCharArray[0] = 'h';
metaDataCharArray[1] = 'e';
metaDataCharArray[2] = 'l';
metaDataCharArray[3] = 'l';
metaDataCharArray[4] = 'o';
CheckMetaData<itk::Array<char>>(metaDict, "TestCharArray", metaDataCharArray);
#endif

itk::Array<double> metaDataDoubleArray(5);
metaDataDoubleArray[0] = 3.0;
metaDataDoubleArray[1] = 1.0;
metaDataDoubleArray[2] = 4.0;
metaDataDoubleArray[3] = 5.0;
metaDataDoubleArray[4] = 2.0;
CheckMetaData<itk::Array<double>>(metaDict, "TestDoubleArray", metaDataDoubleArray);

CheckMetaData<std::string>(metaDict, "StdString", "Test std::string");
}


template <typename T>
itk::MetaDataObjectBase::Pointer
createMetaDataObject(const T & invalue)
Expand All @@ -56,6 +114,9 @@ createMetaDataObject(const T & invalue)

TEST(MetaDataDictionary, Basic)
{
// Isolate
doExposeMetaDatas();

// This test exercises and checks the non-constant interface
itk::MetaDataDictionary dic = createMetaDataDictionary();

Expand Down
121 changes: 121 additions & 0 deletions Modules/Core/TestKernel/include/itkGTestPredicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "gtest/gtest.h"

#include "itkNumericTraits.h"
#include "itkMetaDataDictionary.h"
#include "itkMetaDataObject.h"
#include <cmath>


Expand All @@ -33,6 +35,11 @@
#define ITK_EXPECT_VECTOR_NEAR(val1, val2, rmsError) \
EXPECT_PRED_FORMAT3(itk::GTest::Predicate::VectorDoubleRMSPredFormat, val1, val2, rmsError)

/** A custom GTest macro for verifying a value in a MetaDataDictionary.
*/
#define ITK_EXPECT_METADATA_VALUE(metaDict, key, knownValue) \
EXPECT_PRED_FORMAT3(itk::GTest::Predicate::CheckMetaDataPredFormat, metaDict, key, knownValue)


/** \namespace itk::GTest::Predicate
* \brief The Predicate namespace contains functions used to
Expand All @@ -41,6 +48,120 @@
namespace itk::GTest::Predicate
{

/** Implements GTest Predicate Formatter for ITK_EXPECT_METADATA_VALUE
* macro.
*/
template <typename T>
inline ::testing::AssertionResult
CheckMetaDataPredFormat(const char * metaDictExpr,
const char * keyExpr,
const char * knownValueExpr,
itk::MetaDataDictionary & metaDict,
const std::string & key,
const T & knownValue)
{
T exposedValue{};

#if defined ITK_FUTURE_LEGACY_REMOVE
static_assert(
!std::is_same_v<itk::Array<char>, T>,
"Should not use the ambiguous 'char' stored in meta data, because it is not-cross platform consistent.");
static_assert(
!std::is_same_v<char, T>,
"Should not use the ambiguous 'char' stored in meta data, because it is not-cross platform consistent.");
if (!itk::ExposeMetaData<T>(metaDict, key, exposedValue))
{
return ::testing::AssertionFailure() << "Failure ExposeMetaData for key '" << key << "' (" << keyExpr << ") in "
<< metaDictExpr;
}
#else
if constexpr (std::is_same_v<itk::Array<char>, T>)
{
if (!itk::ExposeMetaData<itk::Array<char>>(metaDict, key, exposedValue))
{
if constexpr (std::is_signed_v<char>)
{
itk::Array<signed char> temp_value{};
if (!itk::ExposeMetaData<itk::Array<signed char>>(metaDict, key, temp_value))
{
return ::testing::AssertionFailure()
<< "Failure ExposeMetaData '" << key << "' (" << keyExpr << ") in " << metaDictExpr;
}
exposedValue = temp_value;
}
else
{
itk::Array<unsigned char> temp_value{};
if (!itk::ExposeMetaData<itk::Array<unsigned char>>(metaDict, key, temp_value))
{
return ::testing::AssertionFailure()
<< "Failure ExposeMetaData '" << key << "' (" << keyExpr << ") in " << metaDictExpr;
}
exposedValue = temp_value;
}
}
}
else if constexpr (std::is_same_v<char, T>)
{
if (!itk::ExposeMetaData<char>(metaDict, key, exposedValue))
{
if constexpr (std::is_signed_v<char>)
{
signed char temp_value{};
if (!itk::ExposeMetaData<signed char>(metaDict, key, temp_value))
{
return ::testing::AssertionFailure()
<< "Failure ExposeMetaData '" << key << "' (" << keyExpr << ") in " << metaDictExpr;
}
exposedValue = static_cast<T>(temp_value);
}
else
{
unsigned char temp_value{};
if (!itk::ExposeMetaData<unsigned char>(metaDict, key, temp_value))
{
return ::testing::AssertionFailure()
<< "Failure ExposeMetaData '" << key << "' (" << keyExpr << ") in " << metaDictExpr;
}
exposedValue = static_cast<T>(temp_value);
}
}
}
else if (!itk::ExposeMetaData<T>(metaDict, key, exposedValue))
{
return ::testing::AssertionFailure() << "Failure ExposeMetaData for key '" << key << "' (" << keyExpr << ") in "
<< metaDictExpr;
}
#endif

bool match = false;
if constexpr (std::is_floating_point_v<T>)
{
match = itk::Math::AlmostEquals(exposedValue, knownValue);
}
else
{
match = (exposedValue == knownValue);
}

if (match)
{
return ::testing::AssertionSuccess();
}

::testing::AssertionResult failure = ::testing::AssertionFailure();
failure << "Incorrect meta value read in for " << keyExpr << " ('" << key << "') in " << metaDictExpr << "\n"
<< " Actual: " << exposedValue << "\n"
<< " Expected: " << knownValue << " (" << knownValueExpr << ")\n";
failure << "========================================\n";
std::stringstream ss;
metaDict.Print(ss);
failure << ss.str();
failure << "========================================";
return failure;
}


/** Implements GTest Predicate Formatter for ITK_EXPECT_VECTOR_NEAR
* macro. This macro and formatter work with any combination of ITK
* array-like objects which are supported by itk::NumericTraits. The
Expand Down
Loading
Loading