-
Notifications
You must be signed in to change notification settings - Fork 179
CHECK_TYPE macro #131
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
Comments
I'm assuming that in your example In the past when I've encountered the need to check the type of an object, I just use TEST(TypeCheckingReferences)
{
CHECK(dynamic_cast<std::ostream&>(std::cout)); // passes
CHECK(dynamic_cast<std::istream&>(std::cin)); // passes
CHECK(dynamic_cast<std::ostream&>(std::cin)); // error: Failure in TypeCheckingReferences: Unhandled exception (std::bad_cast) in CHECK(dynamic_cast<std::ostream&>(std::cin))
}
TEST(TypeCheckingPointers)
{
std::ios_base* p_cout = &std::cout;
std::ios_base* p_cin = &std::cin;
CHECK(dynamic_cast<std::ostream*>(p_cout)); // passes
CHECK(dynamic_cast<std::istream*>(p_cin)); // passes
CHECK(dynamic_cast<std::ostream*>(p_cin)); // error: Failure in TypeCheckingPtr: dynamic_cast<std::ostream*>(p_cin)
} |
In my opinion, UnitTest++ is a bit poor in its assertions set. C# for example has plenty of useful Assert.* By the way I would love to have a force-fail assertion, like |
Force fail is CHECK(false); As for the issue the types do not have to be from a hierarchy. In my use Sent from my Nexus 6P On 13 Sep 2016 9:53 a.m., "Gabriel Schlozer" [email protected]
|
It is not the same functionality, it should interrupt the test execution so it should better be If you are not sure about the return type, it should be converted to void* before but I am not sure about the result of dynamic_cast in this case : |
@killoctal you say "poor", I say minimalist. |
@killoctal If I recall correctly, @pjohnmeyer has toyed around with adding custom failure messages to assertions in the past; perhaps you or he could sketch out what that might look like without introducing new macros? |
Force fail with a custom message is currently achievable using
@grahamreeds Can you post a minimal example of what the target code and the proposed unit test would look like? |
Pretty much as it is in my original post. The idea revolves around messages coming in from udp source and a parser creating a tag that is passed to the dispatcher. Actual code would look like
In my little toy project neither |
If compile-time dispatch techniques are in play, can't the compiler just be the check here? struct message_a {};
std::vector<uint8_t> binary_data = { ... };
message_a parsed_data = udp.parse(binary_data); // compile fails if wrong type Or is that not what you meant? |
I was thinking this morning about unit testing a factory class. With a certain set of parameters I need to check that the emitted object is of the correct type. I think this will be similar to the CHECK_EXCEPTION macro.
The text was updated successfully, but these errors were encountered: