-
Notifications
You must be signed in to change notification settings - Fork 56
adding Serial.prinf(const char* format, ...) #84
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,40 @@ | ||
| #include "ArduinoFake.h" | ||
| #include "PrintFake.h" | ||
| #include <stdarg.h> | ||
|
|
||
| size_t Print::write(const uint8_t *buffer, size_t size) | ||
| { | ||
| return ArduinoFakeInstance(Print, this)->write(buffer, size); | ||
| } | ||
|
|
||
|
|
||
| size_t Print::printf(const char *format, ...) { | ||
| va_list arg; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a call to the fake instance not a concrete implementation. This might help : https://github.com/FabioBatSilva/ArduinoFake/blob/master/CONTRIBUTING.md
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried - maybe not very hard - but mocking method with ... did not work for me at all.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I will try one more time. thanks for fast feedback! |
||
| va_start(arg, format); | ||
|
|
||
| char loc_buf[64]; | ||
| char *temp = loc_buf; | ||
| int len = vsnprintf(temp, sizeof(loc_buf), format, arg); | ||
| if (len < 0) { | ||
| va_end(arg); | ||
| return 0; | ||
| } | ||
| if (len >= (int)sizeof(loc_buf)) { // comparison of same sign type for the compiler | ||
| temp = (char *)malloc(len + 1); | ||
| if (temp == NULL) { | ||
| va_end(arg); | ||
| return 0; | ||
| } | ||
| len = vsnprintf(temp, len + 1, format, arg); | ||
| } | ||
| va_end(arg); | ||
| len = write((uint8_t *)temp, len); | ||
| if (temp != loc_buf) { | ||
| free(temp); | ||
| } | ||
| return len; | ||
| } | ||
|
|
||
| size_t Print::print(const __FlashStringHelper *ifsh) | ||
| { | ||
| return ArduinoFakeInstance(Print, this)->print(ifsh); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,10 @@ void setUp(void) | |
| { | ||
| ArduinoFakeReset(); | ||
| } | ||
| void tearDown(void) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
|
|
||
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.
why is this necessary ?
Uh oh!
There was an error while loading. Please reload this page.
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 is necessary to fix unit test ArduinoContextTest::test_reset. It failed on my pc all the time no matter what.
It failed because CRT, used in g++ compiler shipped with msys64 installed on Windows, reuses very same memory address (value of this->Instances) when re-creating object just after deleting it. So I created new object first and then deleted the old one