#216 test hashing functions

Sun, 23 Oct 2022 16:49:35 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 23 Oct 2022 16:49:35 +0200
changeset 596
52fcaf3c9154
parent 595
0da254bf23e6
child 597
8b48126671cf

#216 test hashing functions

test/CMakeLists.txt file | annotate | diff | comparison | revisions
test/test_hash_key.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/test/CMakeLists.txt	Sun Oct 23 16:40:53 2022 +0200
     1.2 +++ b/test/CMakeLists.txt	Sun Oct 23 16:49:35 2022 +0200
     1.3 @@ -19,6 +19,7 @@
     1.4          test_buffer.cpp
     1.5          test_list.cpp
     1.6          test_tree.cpp
     1.7 +        test_hash_key.cpp
     1.8          test_map.cpp
     1.9          test_basic_mempool.cpp
    1.10          selftest.cpp
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/test_hash_key.cpp	Sun Oct 23 16:49:35 2022 +0200
     2.3 @@ -0,0 +1,50 @@
     2.4 +/*
     2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     2.6 + *
     2.7 + * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
     2.8 + *
     2.9 + * Redistribution and use in source and binary forms, with or without
    2.10 + * modification, are permitted provided that the following conditions are met:
    2.11 + *
    2.12 + *   1. Redistributions of source code must retain the above copyright
    2.13 + *      notice, this list of conditions and the following disclaimer.
    2.14 + *
    2.15 + *   2. Redistributions in binary form must reproduce the above copyright
    2.16 + *      notice, this list of conditions and the following disclaimer in the
    2.17 + *      documentation and/or other materials provided with the distribution.
    2.18 + *
    2.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    2.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    2.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    2.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    2.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    2.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    2.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    2.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    2.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    2.29 + * POSSIBILITY OF SUCH DAMAGE.
    2.30 + */
    2.31 +
    2.32 +#include "cx/hash_key.h"
    2.33 +
    2.34 +#include <gtest/gtest.h>
    2.35 +
    2.36 +TEST(cx_hash_key, functions) {
    2.37 +    auto str = "my key";
    2.38 +    auto len = 1 + strlen(str);
    2.39 +
    2.40 +    auto str_key = cx_hash_key_str(str);
    2.41 +    auto bytes_key = cx_hash_key_bytes(
    2.42 +            reinterpret_cast<unsigned char const *>(str), len);
    2.43 +    auto obj_key = cx_hash_key((void *) str, len);
    2.44 +
    2.45 +    EXPECT_EQ(str_key.hash, bytes_key.hash);
    2.46 +    EXPECT_EQ(obj_key.hash, bytes_key.hash);
    2.47 +    EXPECT_EQ(str_key.len, len);
    2.48 +    EXPECT_EQ(bytes_key.len, len);
    2.49 +    EXPECT_EQ(bytes_key.len, len);
    2.50 +    EXPECT_EQ(str_key.data.cstr, str);
    2.51 +    EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str));
    2.52 +    EXPECT_EQ(bytes_key.data.obj, (void *) str);
    2.53 +}

mercurial