mirror of
				https://git.kernel.org/pub/scm/network/wireless/iwd.git
				synced 2025-10-31 04:57:25 +01:00 
			
		
		
		
	unit: add test for nested arrays
This commit is contained in:
		
							parent
							
								
									e38dcbbdbf
								
							
						
					
					
						commit
						f3e2147e72
					
				| @ -423,6 +423,51 @@ static void test_json_arrays(const void *data) | ||||
| 	json_contents_free(c); | ||||
| } | ||||
| 
 | ||||
| static void test_json_nested_arrays(const void *data) | ||||
| { | ||||
| 	char json[] = "{\"array\":[[], {}, [1, 2], {\"key\":\"value\"}]}"; | ||||
| 	int count = 0; | ||||
| 	struct json_iter iter; | ||||
| 	struct json_iter array; | ||||
| 	struct json_iter inner; | ||||
| 	struct json_contents *c = json_contents_new(json, strlen(json)); | ||||
| 
 | ||||
| 	json_iter_init(&iter, c); | ||||
| 	assert(json_iter_parse(&iter, | ||||
| 			JSON_MANDATORY("array", JSON_ARRAY, &array), | ||||
| 			JSON_UNDEFINED)); | ||||
| 
 | ||||
| 	while (json_iter_next(&array)) { | ||||
| 		int count2 = 0; | ||||
| 
 | ||||
| 		assert(json_iter_get_container(&array, &inner)); | ||||
| 
 | ||||
| 		while (json_iter_next(&inner)) | ||||
| 			count2++; | ||||
| 
 | ||||
| 		/*
 | ||||
| 		 * TODO: add checks for object iteration. Currently these will | ||||
| 		 * just count all tokens in the object. | ||||
| 		 */ | ||||
| 		switch (count) { | ||||
| 		case 0: | ||||
| 			assert(count2 == 0); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			assert(count2 == 2); | ||||
| 			break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 
 | ||||
| 		count++; | ||||
| 	} | ||||
| 
 | ||||
| 	assert(count == 4); | ||||
| 
 | ||||
| 	json_contents_free(c); | ||||
| } | ||||
| 
 | ||||
| int main(int argc, char *argv[]) | ||||
| { | ||||
| 	l_test_init(&argc, &argv); | ||||
| @ -435,6 +480,7 @@ int main(int argc, char *argv[]) | ||||
| 	l_test_add("json larger object", test_json_larger_object, NULL); | ||||
| 	l_test_add("json test primitives", test_json_primitives, NULL); | ||||
| 	l_test_add("json test arrays", test_json_arrays, NULL); | ||||
| 	l_test_add("json test nested arrays", test_json_nested_arrays, NULL); | ||||
| 
 | ||||
| 	return l_test_run(); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 James Prestwood
						James Prestwood