2012-01-19 13:36:13 +01:00
|
|
|
/*
|
|
|
|
* Spdylay - SPDY Library
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "spdylay_map_test.h"
|
|
|
|
|
|
|
|
#include <CUnit/CUnit.h>
|
|
|
|
|
|
|
|
#include "spdylay_map.h"
|
|
|
|
|
2012-03-22 18:17:48 +01:00
|
|
|
void test_spdylay_map(void)
|
2012-01-19 13:36:13 +01:00
|
|
|
{
|
|
|
|
spdylay_map map;
|
2012-02-21 15:23:47 +01:00
|
|
|
spdylay_map_init(&map);
|
2012-05-13 10:38:29 +02:00
|
|
|
CU_ASSERT(0 == spdylay_map_insert(&map, 1, (void*)"foo"));
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(strcmp("foo", spdylay_map_find(&map, 1)) == 0);
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(1 == spdylay_map_size(&map));
|
2012-05-13 10:38:29 +02:00
|
|
|
CU_ASSERT(SPDYLAY_ERR_INVALID_ARGUMENT == spdylay_map_insert(&map, 1,
|
|
|
|
(void*)"FOO"));
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(1 == spdylay_map_size(&map));
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(strcmp("foo", spdylay_map_find(&map, 1)) == 0);
|
2012-05-13 10:38:29 +02:00
|
|
|
CU_ASSERT(0 == spdylay_map_insert(&map, 2, (void*)"bar"));
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(2 == spdylay_map_size(&map));
|
2012-05-13 10:38:29 +02:00
|
|
|
CU_ASSERT(0 == spdylay_map_insert(&map, 3, (void*)"baz"));
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(3 == spdylay_map_size(&map));
|
2012-05-13 10:38:29 +02:00
|
|
|
CU_ASSERT(0 == spdylay_map_insert(&map, 4, (void*)"shrubbery"));
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(4 == spdylay_map_size(&map));
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(strcmp("baz", spdylay_map_find(&map, 3)) == 0);
|
|
|
|
|
|
|
|
spdylay_map_erase(&map, 3);
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(3 == spdylay_map_size(&map));
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(NULL == spdylay_map_find(&map, 3));
|
|
|
|
spdylay_map_erase(&map, 1);
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(2 == spdylay_map_size(&map));
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(NULL == spdylay_map_find(&map, 1));
|
|
|
|
|
2012-01-25 18:28:58 +01:00
|
|
|
/* Erasing non-existent entry */
|
2012-01-25 16:21:31 +01:00
|
|
|
spdylay_map_erase(&map, 1);
|
2012-01-25 18:28:58 +01:00
|
|
|
CU_ASSERT(2 == spdylay_map_size(&map));
|
2012-01-25 16:21:31 +01:00
|
|
|
CU_ASSERT(NULL == spdylay_map_find(&map, 1));
|
|
|
|
|
2012-01-19 13:36:13 +01:00
|
|
|
CU_ASSERT(strcmp("bar", spdylay_map_find(&map, 2)) == 0);
|
|
|
|
CU_ASSERT(strcmp("shrubbery", spdylay_map_find(&map, 4)) == 0);
|
|
|
|
|
|
|
|
spdylay_map_free(&map);
|
|
|
|
}
|