ASSERT_EQ does not work with refrence
pischky opened this issue · 3 comments
ASSERT_EQ from aunit/contrib/gtest.h does not compile when reference is used:
uint8_t& ref = a[2];
ASSERT_EQ( 0x83, ref );
Compiler message is:
invalid static_cast from type 'int' to type 'uint8_t& {aka unsigned char&}'
removing the cast from the macros make it compile.
#define ASSERT_EQ(expected, value) assertEqual((expected),(value))
May be there is a better (improved) version instead of static_cast<decltype(a)>(e)
Complete sketch:
ArrayTest_with_AUnit.ino.txt
May be a solution is to use remove_reference
:
#define ASSERT_EQ(expected, actual) \
assertEqual( \
static_cast< std::remove_reference< \
decltype(actual) >::type >(expected), \
actual)
But remove_reference
is not support in current Arduino version (1.8.19) so you need also ArxTypeTraits 0.2.3 by Hideaki Tai.
Maybe the solution is to remove the static_cast<decltype(a)>
? See if the following helps:
https://github.com/bxparks/AUnit/tree/gtest_ref_cast
It fixes your specific problem.
I don't have any code that uses <gtest.h>
, and I'm not entirely sure I understand all the edge cases of the Google Test framework, so not really sure if this is the best solution.
Thanks for your suggestion to remove the static_cast. Yes
that fixes my problem. I thought the static_cast has
the intention to select the correct function from
the set of overloaded assertEqual(). I hoped be the original
author of gtest.h did know.
I'm porting some Tests from x86 to arduino. So I'm doing further
testing with my variant using remove_reference.
So far it seems to work fine. Only disadvantage is that ArxTypeTraits
is required.