| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | // ArduinoJson - https://arduinojson.org
 | 
					
						
							| 
									
										
										
										
											2025-02-24 15:18:26 +01:00
										 |  |  | // Copyright © 2014-2025, Benoit BLANCHON
 | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | // MIT License
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <ArduinoJson/Memory/ResourceManager.hpp>
 | 
					
						
							| 
									
										
										
										
											2024-08-24 18:18:28 +02:00
										 |  |  | #include <ArduinoJson/Memory/ResourceManagerImpl.hpp>
 | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | #include <catch.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-17 14:39:57 +02:00
										 |  |  | #include "Allocators.hpp"
 | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-17 14:39:57 +02:00
										 |  |  | using namespace ArduinoJson::detail; | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_CASE("ResourceManager::size()") { | 
					
						
							| 
									
										
										
										
											2023-07-25 14:53:54 +02:00
										 |  |  |   TimebombAllocator timebomb(0); | 
					
						
							|  |  |  |   ResourceManager resources(&timebomb); | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   SECTION("Initial size is 0") { | 
					
						
							|  |  |  |     REQUIRE(0 == resources.size()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-17 14:39:57 +02:00
										 |  |  |   SECTION("Doesn't grow when allocation of second pool fails") { | 
					
						
							| 
									
										
										
										
											2023-07-25 14:53:54 +02:00
										 |  |  |     timebomb.setCountdown(1); | 
					
						
							| 
									
										
										
										
											2023-07-17 14:39:57 +02:00
										 |  |  |     for (size_t i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++) | 
					
						
							| 
									
										
										
										
											2024-08-24 18:18:28 +02:00
										 |  |  |       resources.allocVariant(); | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  |     size_t size = resources.size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-24 18:18:28 +02:00
										 |  |  |     resources.allocVariant(); | 
					
						
							| 
									
										
										
										
											2023-06-17 16:10:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     REQUIRE(size == resources.size()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |