25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include "prop_tests.h" |
29 #include "prop_tests.h" |
|
30 #include "ucx/mempool.h" |
30 |
31 |
31 UCX_TEST(test_ucx_properties_new) { |
32 UCX_TEST(test_ucx_properties_new) { |
32 UcxProperties *parser = ucx_properties_new(); |
33 UcxProperties *parser = ucx_properties_new(); |
33 |
34 |
34 UCX_TEST_BEGIN |
35 UCX_TEST_BEGIN |
361 free(long_value); |
362 free(long_value); |
362 ucx_properties_free(parser); |
363 ucx_properties_free(parser); |
363 } |
364 } |
364 |
365 |
365 UCX_TEST(test_ucx_properties2map) { |
366 UCX_TEST(test_ucx_properties2map) { |
366 UcxMap *map = ucx_map_new(16); |
367 UcxMempool *mp = ucx_mempool_new(64); |
|
368 UcxAllocator *a = ucx_mempool_allocator(mp); |
|
369 UcxMap *map = ucx_map_new_a(a, 16); |
367 UcxProperties *parser = ucx_properties_new(); |
370 UcxProperties *parser = ucx_properties_new(); |
368 |
371 |
369 UCX_TEST_BEGIN |
372 UCX_TEST_BEGIN |
370 |
373 |
371 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; |
374 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; |
388 UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2"); |
391 UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2"); |
389 UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3"); |
392 UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3"); |
390 |
393 |
391 // second test |
394 // second test |
392 ucx_map_free(map); |
395 ucx_map_free(map); |
393 free(v1); |
396 map = ucx_map_new_a(a, 16); |
394 free(v2); |
|
395 free(v3); |
|
396 map = ucx_map_new(16); |
|
397 |
397 |
398 str = "\n#comment\n"; |
398 str = "\n#comment\n"; |
399 ucx_properties_fill(parser, (char*)str, strlen(str)); |
399 ucx_properties_fill(parser, (char*)str, strlen(str)); |
400 |
400 |
401 r = ucx_properties2map(parser, map); |
401 r = ucx_properties2map(parser, map); |
412 char *v = (char*)ucx_map_cstr_get(map, "key1"); |
412 char *v = (char*)ucx_map_cstr_get(map, "key1"); |
413 UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value"); |
413 UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value"); |
414 |
414 |
415 UCX_TEST_END |
415 UCX_TEST_END |
416 |
416 |
|
417 ucx_mempool_destroy(mp); |
417 ucx_properties_free(parser); |
418 ucx_properties_free(parser); |
418 } |
419 } |
419 |
420 |
420 UCX_TEST(test_ucx_properties_load) { |
421 UCX_TEST(test_ucx_properties_load) { |
421 UCX_TEST_BEGIN |
422 UCX_TEST_BEGIN |