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

Using FakeArduino for unit testing with platform io #1676

Closed
tickietackie opened this issue Nov 18, 2021 · 3 comments
Closed

Using FakeArduino for unit testing with platform io #1676

tickietackie opened this issue Nov 18, 2021 · 3 comments
Labels

Comments

@tickietackie
Copy link

tickietackie commented Nov 18, 2021

Describe the issue
I'm trying to do the same as the guy here #548.
Using FakeArduino native to unit test with platform io, where ArduinoJson is deeply integrated.
I already tried the fix from the issue there, but I suppose sth. changed, that makes it not work anymore, or I missed something.

Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:

ArduinoJson Troubleshooter's report
  1. The issue happens at compile time
  2. The error is not in the list

Environment
Here is the environment that I'm using':

  • Microconroller: NA
  • Core/runtime: NA
  • IDE: Platform IO and VS Code

Further information
platform.ini file content:

[env:native]
platform = native
test_ignore = embedded
build_flags = -std=gnu++11
lib_deps = 
	ArduinoJson-6.18.5
	ArduinoFake
#lib_archive = false 

Compile output:

lib/ArduinoJson-6.18.5/src/ArduinoJson/Polyfills/pgmspace_generic.hpp:14:10: error: reinterpret_cast from 'const void' to 'const __FlashStringHelper *' is not allowed
  return reinterpret_cast<T>(pgm_read_ptr(p));
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/ArduinoJson-6.18.5/src/ArduinoJson/Deserialization/DeserializationError.hpp:100:12: note: in instantiation of function template specialization 'ArduinoJson6185_F1::pgm_read<const __FlashStringHelper *>' requested here
    return ARDUINOJSON_READ_STATIC_ARRAY(const __FlashStringHelper*, messages,
           ^
lib/ArduinoJson-6.18.5/src/ArduinoJson/Polyfills/static_array.hpp:20:7: note: expanded from macro 'ARDUINOJSON_READ_STATIC_ARRAY'
      pgm_read<type>(name + index)
@bblanchon
Copy link
Owner

bblanchon commented Nov 19, 2021

Hi @tickietackie,

I couldn't find the source of FakeArduino, but it seems that pgm_read_ptr() doesn't return the correct type: it should be const void*, but the error message says it's const void.

This is a common bug in cores that emulate the original pgmspace.h header.
It already poped up in #1381, #1442, #1519, #1536, and #1591.
The root of this bug was fixed a year ago in arduino/ArduinoCore-API#118, but many clones are still using the old code.
I invite you to open a PR in the FakeArduino repository.

In the meantime, you can work around this issue by disabling PROGMEM in ArduinoJson by setting ARDUINOJSON_ENABLE_PROGMEM to 0.

Best regards,
Benoit

@tickietackie
Copy link
Author

Thx, for the quick response. The workaround works as supposed.

@maxgerhardt
Copy link

For completness' sake: This was addresses in the FakeArduino library (FabioBatSilva/ArduinoFake#21) and so one can reference the latest git version

[env:native]
platform = native
build_flags = -std=gnu++11
lib_deps =
     https:/FabioBatSilva/ArduinoFake/archive/refs/heads/master.zip
     bblanchon/ArduinoJson @ ^6.18.5

and that makes that error go away.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants