PrettyPrint_String_Tests.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #include "CppUnitTest.h"
  6. #include "PrettyPrintDecorator.h"
  7. #include "StringBuilder.h"
  8. using namespace ArduinoJson::Internals;
  9. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  10. namespace JsonGeneratorTests
  11. {
  12. TEST_CLASS(PrettyPrint_String_Tests)
  13. {
  14. char buffer[1024];
  15. size_t returnValue;
  16. public:
  17. TEST_METHOD(EmptyString)
  18. {
  19. whenInputIs("");
  20. outputMustBe("");
  21. }
  22. TEST_METHOD(TrickyCharacters)
  23. {
  24. whenInputIs ("\":\\\"',\"");
  25. outputMustBe("\":\\\"',\"");
  26. }
  27. private:
  28. void whenInputIs(const char input[])
  29. {
  30. StringBuilder sb(buffer, sizeof(buffer));
  31. PrettyPrintDecorator decorator(sb);
  32. returnValue = decorator.print(input);
  33. }
  34. void outputMustBe(const char* expected)
  35. {
  36. Assert::AreEqual(expected, buffer);
  37. Assert::AreEqual(strlen(expected), returnValue);
  38. }
  39. };
  40. }