tests/test_map_generics.c

Sun, 21 May 2023 16:22:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 21 May 2023 16:22:09 +0200
changeset 710
2dd409ed056f
parent 694
ac827d873c17
permissions
-rw-r--r--

fix const-ness of non-mutating iterator creation for maps

universe@691 1 /*
universe@691 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@691 3 *
universe@691 4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
universe@691 5 *
universe@691 6 * Redistribution and use in source and binary forms, with or without
universe@691 7 * modification, are permitted provided that the following conditions are met:
universe@691 8 *
universe@691 9 * 1. Redistributions of source code must retain the above copyright
universe@691 10 * notice, this list of conditions and the following disclaimer.
universe@691 11 *
universe@691 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@691 13 * notice, this list of conditions and the following disclaimer in the
universe@691 14 * documentation and/or other materials provided with the distribution.
universe@691 15 *
universe@691 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@691 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@691 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@691 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@691 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@691 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@691 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@691 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@691 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@691 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@691 26 * POSSIBILITY OF SUCH DAMAGE.
universe@691 27 */
universe@691 28
universe@691 29 #include "test_map_generics.h"
universe@691 30 #include "cx/hash_map.h"
universe@691 31
universe@691 32 CxMap *test_map_generics_step_1(CxAllocator const * allocator) {
universe@691 33 CxMap *map = cxHashMapCreate(allocator, sizeof(cxstring), 0);
universe@691 34
universe@691 35 cxMapPut(map, "test", "test");
universe@692 36 cxMapPut(map, cx_mutstr("foo"), "bar");
universe@691 37 cxMapPut(map, cx_str("hallo"), "welt");
universe@691 38
universe@691 39 return map;
universe@691 40 }
universe@691 41
universe@691 42 void test_map_generics_step_2(CxMap *map) {
universe@691 43 // note: we don't have a destructor here, so remove and detach are the same
universe@691 44 cxMapRemove(map, cx_str("test"));
universe@694 45 char const* hallo = "hallo";
universe@694 46 cxMapDetach(map, hallo);
universe@691 47 cxMapPut(map, cx_hash_key_str("key"), "value");
universe@691 48 }
universe@691 49
universe@691 50 void test_map_generics_step_3(CxMap *map) {
universe@691 51 void *r;
universe@691 52 r = cxMapRemoveAndGet(map, "key");
universe@691 53 r = cxMapRemoveAndGet(map, cx_str("foo"));
universe@691 54 if (r != NULL) map->size = 47;
universe@691 55 }

mercurial