isValidMember.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "isValidMember.h"
  2. #include "Resources/validyMacros.h"
  3. #include "../../Source/JSONValidator.h"
  4. /*
  5. *
  6. * !!! ATTENTION !!!
  7. *
  8. * libjson currently has three number parsing methods, they are being merged
  9. * behind the scenes, but all three interfaces must be consistent, so every set
  10. * of numbers need to be tested in all three spots
  11. *
  12. * JSONValidator/isValidMember *this file*
  13. * * Soon to come actual parser *
  14. */
  15. /**
  16. * This tests the three valid members that is not string, number, or container
  17. */
  18. void testJSONValidator__isValidMember::testMembers(void){
  19. #ifdef JSON_VALIDATE
  20. assertValid_Depth("true,", isValidMember, ',');
  21. assertValid_Depth("false,", isValidMember, ',');
  22. assertValid_Depth("null,", isValidMember, ',');
  23. #endif
  24. }
  25. /**
  26. * This tests that json's case sensitive rules are to be obeyed
  27. */
  28. void testJSONValidator__isValidMember::testStrict(void){
  29. #ifdef JSON_VALIDATE
  30. #ifdef JSON_STRICT
  31. assertNotValid_Depth("TRUE,", isValidMember, ',');
  32. assertNotValid_Depth("FALSE,", isValidMember, ',');
  33. assertNotValid_Depth("NULL,", isValidMember, ',');
  34. assertNotValid_Depth(",", isValidMember, ','); //also accepted as null usually
  35. #endif
  36. #endif
  37. }
  38. /**
  39. * This tests that json's case sensitive rules are not obeyed normally
  40. */
  41. void testJSONValidator__isValidMember::testNotStrict(void){
  42. #ifdef JSON_VALIDATE
  43. #ifndef JSON_STRICT
  44. assertValid_Depth("TRUE,", isValidMember, ',');
  45. assertValid_Depth("FALSE,", isValidMember, ',');
  46. assertValid_Depth("NULL,", isValidMember, ',');
  47. assertValid_Depth(",", isValidMember, ','); //also accepted as null usually
  48. #endif
  49. #endif
  50. }
  51. /**
  52. * This tests that non member values are not allowed
  53. */
  54. void testJSONValidator__isValidMember::testNotMembers(void){
  55. #ifdef JSON_VALIDATE
  56. assertNotValid_Depth("tru,", isValidMember, ',');
  57. assertNotValid_Depth("fals,", isValidMember, ',');
  58. assertNotValid_Depth("nul,", isValidMember, ',');
  59. assertNotValid_Depth("", isValidMember, ','); //needs a comma after it because of how the pipeline works
  60. assertNotValid_Depth("xxx,", isValidMember, ',');
  61. assertNotValid_Depth("nonsense,", isValidMember, ',');
  62. #endif
  63. }
  64. /**
  65. * This tests that for all cases, if the string suddely ends, it recovers
  66. */
  67. void testJSONValidator__isValidMember::testSuddenEnd(void){
  68. #ifdef JSON_VALIDATE
  69. assertNotValid_Depth("", isValidMember, ',');
  70. //--- void testJSONValidator__isValidMember::testSuddenEnd(void){
  71. assertNotValid_Depth("true", isValidMember, ',');
  72. assertNotValid_Depth("false", isValidMember, ',');
  73. assertNotValid_Depth("null", isValidMember, ',');
  74. //strict stuff
  75. assertNotValid_Depth("TRUE", isValidMember, ',');
  76. assertNotValid_Depth("FALSE", isValidMember, ',');
  77. assertNotValid_Depth("NULL", isValidMember, ',');
  78. //--- void testJSONValidator__isValidMember::testNotMembers(void){
  79. assertNotValid_Depth("tru", isValidMember, ',');
  80. assertNotValid_Depth("fals", isValidMember, ',');
  81. assertNotValid_Depth("nul", isValidMember, ',');
  82. assertNotValid_Depth("", isValidMember, ','); //needs a comma after it because of how the pipeline works
  83. assertNotValid_Depth("xxx", isValidMember, ',');
  84. assertNotValid_Depth("nonsense", isValidMember, ',');
  85. assertNotValid_Depth("1234", isValidMember, ',');
  86. #endif
  87. }