| 
									
										
										
										
											2018-08-21 18:07:41 +02:00
										 |  |  | #include <ArduinoJson.h>
 | 
					
						
							|  |  |  | #include <catch.hpp>
 | 
					
						
							|  |  |  | #include <limits>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2022-08-09 16:52:17 +02:00
										 |  |  | void check(T value, const std::string& expected) { | 
					
						
							| 
									
										
										
										
											2023-07-17 18:15:13 +02:00
										 |  |  |   JsonDocument doc; | 
					
						
							| 
									
										
										
										
											2018-08-21 18:07:41 +02:00
										 |  |  |   doc.to<JsonVariant>().set(value); | 
					
						
							|  |  |  |   char buffer[256] = ""; | 
					
						
							|  |  |  |   size_t returnValue = serializeMsgPack(doc, buffer, sizeof(buffer)); | 
					
						
							|  |  |  |   REQUIRE(expected == buffer); | 
					
						
							|  |  |  |   REQUIRE(expected.size() == returnValue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-29 14:09:09 +01:00
										 |  |  | TEST_CASE("serializeMsgPack(MemberProxy)") { | 
					
						
							| 
									
										
										
										
											2023-07-17 18:15:13 +02:00
										 |  |  |   JsonDocument doc; | 
					
						
							| 
									
										
										
										
											2018-08-21 18:07:41 +02:00
										 |  |  |   deserializeJson(doc, "{\"hello\":42}"); | 
					
						
							|  |  |  |   JsonObject obj = doc.as<JsonObject>(); | 
					
						
							|  |  |  |   std::string result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   serializeMsgPack(obj["hello"], result); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   REQUIRE(result == "*"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-29 14:09:09 +01:00
										 |  |  | TEST_CASE("serializeMsgPack(ElementProxy)") { | 
					
						
							| 
									
										
										
										
											2023-07-17 18:15:13 +02:00
										 |  |  |   JsonDocument doc; | 
					
						
							| 
									
										
										
										
											2018-08-21 18:07:41 +02:00
										 |  |  |   deserializeJson(doc, "[42]"); | 
					
						
							|  |  |  |   JsonArray arr = doc.as<JsonArray>(); | 
					
						
							|  |  |  |   std::string result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   serializeMsgPack(arr[0], result); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   REQUIRE(result == "*"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("serializeMsgPack(JsonVariantSubscript)") { | 
					
						
							| 
									
										
										
										
											2023-07-17 18:15:13 +02:00
										 |  |  |   JsonDocument doc; | 
					
						
							| 
									
										
										
										
											2018-08-21 18:07:41 +02:00
										 |  |  |   deserializeJson(doc, "[42]"); | 
					
						
							|  |  |  |   JsonVariant var = doc.as<JsonVariant>(); | 
					
						
							|  |  |  |   std::string result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   serializeMsgPack(var[0], result); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   REQUIRE(result == "*"); | 
					
						
							|  |  |  | } |