test/test_hash_key.cpp

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
child 603
c49104015a6b
permissions
-rw-r--r--

#216 test hashing functions

universe@596 1 /*
universe@596 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@596 3 *
universe@596 4 * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
universe@596 5 *
universe@596 6 * Redistribution and use in source and binary forms, with or without
universe@596 7 * modification, are permitted provided that the following conditions are met:
universe@596 8 *
universe@596 9 * 1. Redistributions of source code must retain the above copyright
universe@596 10 * notice, this list of conditions and the following disclaimer.
universe@596 11 *
universe@596 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@596 13 * notice, this list of conditions and the following disclaimer in the
universe@596 14 * documentation and/or other materials provided with the distribution.
universe@596 15 *
universe@596 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@596 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@596 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@596 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@596 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@596 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@596 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@596 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@596 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@596 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@596 26 * POSSIBILITY OF SUCH DAMAGE.
universe@596 27 */
universe@596 28
universe@596 29 #include "cx/hash_key.h"
universe@596 30
universe@596 31 #include <gtest/gtest.h>
universe@596 32
universe@596 33 TEST(cx_hash_key, functions) {
universe@596 34 auto str = "my key";
universe@596 35 auto len = 1 + strlen(str);
universe@596 36
universe@596 37 auto str_key = cx_hash_key_str(str);
universe@596 38 auto bytes_key = cx_hash_key_bytes(
universe@596 39 reinterpret_cast<unsigned char const *>(str), len);
universe@596 40 auto obj_key = cx_hash_key((void *) str, len);
universe@596 41
universe@596 42 EXPECT_EQ(str_key.hash, bytes_key.hash);
universe@596 43 EXPECT_EQ(obj_key.hash, bytes_key.hash);
universe@596 44 EXPECT_EQ(str_key.len, len);
universe@596 45 EXPECT_EQ(bytes_key.len, len);
universe@596 46 EXPECT_EQ(bytes_key.len, len);
universe@596 47 EXPECT_EQ(str_key.data.cstr, str);
universe@596 48 EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str));
universe@596 49 EXPECT_EQ(bytes_key.data.obj, (void *) str);
universe@596 50 }

mercurial