-
Notifications
You must be signed in to change notification settings - Fork 533
Add interface to compare signed byte-sized data #968
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
Conversation
@@ -788,7 +788,7 @@ const void* returnConstPointerValueOrDefault_c(const void * defaultValue) | |||
|
|||
void (*functionPointerReturnValue_c())() | |||
{ | |||
return actualCall->returnFunctionPointerValue(); | |||
return (void (*)()) actualCall->returnFunctionPointerValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cast has nothing to do with this PR - I checked the new code against the Cl2000 and it requires this cast. But it is also currently broken because of added features, and not easy to fix, so I can take this one out here, but there won't be a (working) PR for the Cl2000.
{ | ||
SimpleString s(DecimalStringFrom(-5)); | ||
SimpleString s2(DecimalStringFrom(-5)); | ||
CHECK(s == s2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't really test much :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has many siblings :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, we would do well to change all of them to something like:
SimpleString s(DecimalStringFrom(-5);
STRCMP_QUAL("-5", s.asCharString());
Any reason why these tests were written like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you test the CHECK, it might be useful. But in this case, you test the DecimalStringFormat, then it isn't useful whatsoever :)
Whats the difference between this and BYTES_EQUAL? |
BYTES_EQUAL compares bytes as characters, e.g. 'a' or '¶'. When your code is dealing with numeric (decimal) values, it is not helpful to be presented some weird characters when you get a failure ;-) Actually, I still find two problems with it (the tests elegantly skip over that)
for signed values as well as
|
Why not have BYTES equal print the value, the hex and the character? |
Why indeed not :) |
My code doesn't do unsigned char correctly though. Will need to fix that as well. |
Actually, I got confused. Sorry about that. BYTES_EQUAL does unsigned. That's the problem. The solution I'm trying to find is being able to do both signed and unsigned comparisons properly for byte-sized data. |
@basvodde pls have another look. How could this still be improved? |
I got some things mixed up in my comments. The current situation (before this PR) is:
Normally, we have macros like "LONGS_EQUAL" vs. "UNSIGNED_LONGS_EQUAL. The C interface has two new macros: CHECK_EQUAL_C_UBYTE and CHECK_EQUAL_C_SBYTE. The C interface doesn't mirror all of the new macros we have for C++. |
Uhm, but now the output is not "num hex char" like mentioned? |
True. But it never included char, only in the C interface. So, if we do that, it will be like a new feature:
I suggest to give it some more thought and, perhaps, add it later. It would make sense for the C macro though, in which case there would be no new macros. |
Uhm, well to me it is just 3 different representations of the same information. As sometimes showing it in a different representation will trigger an AH!, I think it is useful. I would do it for all of them, or perhaps only when it is in the printable ascii range :) |
Hmm. So SIGNED_BYTES_EQUAL and BYTES_EQUAL would then display:
where X, Y, and Z would be the actual screen representation of that character. Similar for the C interface (will take a look next week). |
Yes, and then we could check whether the character is printable or not, and not print it if it isn't. |
I don't have much time right now, and if I do add the character, I will need to change the tests. Since I want to test negative numbers and 'large' unsigned bytes, I would have to limit printing to printable characters for reasonable tests. Can we perhaps merge this 'as is', and add printing the character later? (I can add an issue for that). |
If I display the character along with numeric data, then CHECK_EQUAL_C_CHAR() which displays a literal character, would be redundant.
would handle unsigned char and signed char, respectively. But we need to keep CHECK_EQUAL_C_CHAR(), because it's always been there. Should we then do: CHECK_EQUAL_C_CHAR() // does signed char
CHECK_EQUAL_C_BYTE() // does unsigned char or leave all three (with CHECK_EQUAL_C_UBYTE() giving identical output to CHECK_EQUAL_C_CHAR()? |
@@ -232,6 +232,18 @@ | |||
#define BYTES_EQUAL_TEXT(expected, actual, text)\ | |||
LONGS_EQUAL_TEXT((expected) & 0xff, (actual) & 0xff, text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will need to be changed to one of the others. But you want to do that later, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
I noticed that CppUTest currently makes no provision for comparing signed byte-sized values. In my experience, in embedded development, sint8_t is frequently used.
This is an attempt at providing the missing functionality.