tests/test_hash_key.cpp

changeset 663
d50b5dc1e058
parent 653
e081643aae2a
child 690
2c2304622981
equal deleted inserted replaced
662:d0d95740071b 663:d50b5dc1e058
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 "cx/hash_key.h" 29 #include "cx/hash_key.h"
30 #include "cx/string.h"
30 31
31 #include <gtest/gtest.h> 32 #include <gtest/gtest.h>
32 33
33 TEST(cx_hash_key, functions) { 34 TEST(cx_hash_key, functions) {
34 auto str = "my key"; 35 auto str = "my key";
37 auto str_key = cx_hash_key_str(str); 38 auto str_key = cx_hash_key_str(str);
38 auto bytes_key = cx_hash_key_bytes( 39 auto bytes_key = cx_hash_key_bytes(
39 reinterpret_cast<unsigned char const *>(str), len); 40 reinterpret_cast<unsigned char const *>(str), len);
40 auto obj_key = cx_hash_key( 41 auto obj_key = cx_hash_key(
41 reinterpret_cast<void const *>(str), len); 42 reinterpret_cast<void const *>(str), len);
43 auto cxstr_key = cx_hash_key_cxstr(cx_str(str));
42 44
43 EXPECT_EQ(str_key.hash, bytes_key.hash); 45 EXPECT_EQ(str_key.hash, bytes_key.hash);
44 EXPECT_EQ(obj_key.hash, bytes_key.hash); 46 EXPECT_EQ(obj_key.hash, bytes_key.hash);
47 EXPECT_EQ(cxstr_key.hash, bytes_key.hash);
45 EXPECT_EQ(str_key.len, len); 48 EXPECT_EQ(str_key.len, len);
49 EXPECT_EQ(cxstr_key.len, len);
46 EXPECT_EQ(bytes_key.len, len); 50 EXPECT_EQ(bytes_key.len, len);
47 EXPECT_EQ(bytes_key.len, len); 51 EXPECT_EQ(bytes_key.len, len);
48 EXPECT_EQ(str_key.data.cstr, str); 52 EXPECT_EQ(str_key.data.cstr, str);
49 EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str)); 53 EXPECT_EQ(bytes_key.data.cbytes, reinterpret_cast<unsigned char const *>(str));
50 EXPECT_EQ(bytes_key.data.cobj, reinterpret_cast<void const *>(str)); 54 EXPECT_EQ(bytes_key.data.cobj, reinterpret_cast<void const *>(str));
55 EXPECT_EQ(cxstr_key.data.cobj, reinterpret_cast<void const *>(str));
51 } 56 }
52 57
53 TEST(cx_hash_key, empty_string) { 58 TEST(cx_hash_key, empty_string) {
54 auto str = ""; 59 auto str = "";
55 60

mercurial