mirror of
				https://github.com/bblanchon/ArduinoJson.git
				synced 2025-11-04 00:21:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			30 lines
		
	
	
		
			980 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			980 B
		
	
	
	
		
			C++
		
	
	
	
	
	
// ArduinoJson - https://arduinojson.org
 | 
						|
// Copyright © 2014-2022, Benoit BLANCHON
 | 
						|
// MIT License
 | 
						|
 | 
						|
#define ARDUINOJSON_DECODE_UNICODE 1
 | 
						|
#include <ArduinoJson.h>
 | 
						|
#include <catch.hpp>
 | 
						|
 | 
						|
TEST_CASE("Truncated JSON input") {
 | 
						|
  const char* testCases[] = {"\"hello", "\'hello", "'\\u", "'\\u00", "'\\u000",
 | 
						|
                             // false
 | 
						|
                             "f", "fa", "fal", "fals",
 | 
						|
                             // true
 | 
						|
                             "t", "tr", "tru",
 | 
						|
                             // null
 | 
						|
                             "n", "nu", "nul",
 | 
						|
                             // object
 | 
						|
                             "{", "{a", "{a:", "{a:1", "{a:1,", "{a:1,"};
 | 
						|
  const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
 | 
						|
 | 
						|
  DynamicJsonDocument doc(4096);
 | 
						|
 | 
						|
  for (size_t i = 0; i < testCount; i++) {
 | 
						|
    const char* input = testCases[i];
 | 
						|
    CAPTURE(input);
 | 
						|
    REQUIRE(deserializeJson(doc, input) ==
 | 
						|
            DeserializationError::IncompleteInput);
 | 
						|
  }
 | 
						|
}
 |