Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASSERT_EQ does not work with refrence #85

Open
pischky opened this issue Jan 10, 2022 · 3 comments
Open

ASSERT_EQ does not work with refrence #85

pischky opened this issue Jan 10, 2022 · 3 comments

Comments

@pischky
Copy link

pischky commented Jan 10, 2022

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

@pischky
Copy link
Author

pischky commented Jan 10, 2022

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.

@bxparks
Copy link
Owner

bxparks commented Jan 10, 2022

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.

@pischky
Copy link
Author

pischky commented Jan 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants