PrettyPrint_String_Tests.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Arduino JSON library
  3. * Benoit Blanchon 2014 - MIT License
  4. */
  5. #include "CppUnitTest.h"
  6. #include "JsonPrettyPrint.h"
  7. #include "StringBuilder.h"
  8. using namespace ArduinoJson::Internals;
  9. using namespace ArduinoJson::Generator;
  10. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  11. namespace JsonGeneratorTests
  12. {
  13. TEST_CLASS(PrettyPrint_String_Tests)
  14. {
  15. char buffer[1024];
  16. size_t returnValue;
  17. public:
  18. TEST_METHOD(EmptyString)
  19. {
  20. whenInputIs("");
  21. outputMustBe("");
  22. }
  23. TEST_METHOD(TrickyCharacters)
  24. {
  25. whenInputIs ("\":\\\"',\"");
  26. outputMustBe("\":\\\"',\"");
  27. }
  28. TEST_METHOD(OpeningCurlyBrace)
  29. {
  30. whenInputIs ("\"{\"");
  31. outputMustBe("\"{\"");
  32. }
  33. TEST_METHOD(OpeningSquareBrace)
  34. {
  35. whenInputIs("\"[\"");
  36. outputMustBe("\"[\"");
  37. }
  38. TEST_METHOD(ClosingCurlyBrace)
  39. {
  40. whenInputIs("\"}\"");
  41. outputMustBe("\"}\"");
  42. }
  43. TEST_METHOD(ClosingSquareBrace)
  44. {
  45. whenInputIs("\"]\"");
  46. outputMustBe("\"]\"");
  47. }
  48. private:
  49. void whenInputIs(const char input[])
  50. {
  51. StringBuilder sb(buffer, sizeof(buffer));
  52. IndentedPrint indentedPrint(sb);
  53. JsonPrettyPrint decorator(indentedPrint);
  54. returnValue = decorator.print(input);
  55. }
  56. void outputMustBe(const char* expected)
  57. {
  58. Assert::AreEqual(expected, buffer);
  59. Assert::AreEqual(strlen(expected), returnValue);
  60. }
  61. };
  62. }