|
Packit Service |
3749ba |
/*
|
|
Packit Service |
3749ba |
* Copyright (c) 2012 Red Hat Inc.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
3749ba |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
3749ba |
* are met:
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* * Redistributions of source code must retain the above
|
|
Packit Service |
3749ba |
* copyright notice, this list of conditions and the
|
|
Packit Service |
3749ba |
* following disclaimer.
|
|
Packit Service |
3749ba |
* * Redistributions in binary form must reproduce the
|
|
Packit Service |
3749ba |
* above copyright notice, this list of conditions and
|
|
Packit Service |
3749ba |
* the following disclaimer in the documentation and/or
|
|
Packit Service |
3749ba |
* other materials provided with the distribution.
|
|
Packit Service |
3749ba |
* * The names of contributors to this software may not be
|
|
Packit Service |
3749ba |
* used to endorse or promote products derived from this
|
|
Packit Service |
3749ba |
* software without specific prior written permission.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit Service |
3749ba |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit Service |
3749ba |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit Service |
3749ba |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit Service |
3749ba |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit Service |
3749ba |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
Packit Service |
3749ba |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
Packit Service |
3749ba |
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
Packit Service |
3749ba |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Packit Service |
3749ba |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
Packit Service |
3749ba |
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
Packit Service |
3749ba |
* DAMAGE.
|
|
Packit Service |
3749ba |
*
|
|
Packit Service |
3749ba |
* Author: Stef Walter <stefw@gnome.org>
|
|
Packit Service |
3749ba |
*/
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "config.h"
|
|
Packit Service |
3749ba |
#include "test.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include <assert.h>
|
|
Packit Service |
3749ba |
#include <stdint.h>
|
|
Packit Service |
3749ba |
#include <stdlib.h>
|
|
Packit Service |
3749ba |
#include <stdio.h>
|
|
Packit Service |
3749ba |
#include <string.h>
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
#include "hash.h"
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_murmur3 (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
uint32_t one, two, four, seven, eleven, split;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (sizeof (one) == P11_HASH_MURMUR3_LEN);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&one, "one", 3, NULL);
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&two, "two", 3, NULL);
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&four, "four", 4, NULL);
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&seven, "seven", 5, NULL);
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&eleven, "eleven", 6, NULL);
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&split, "ele", 3, "ven", 3, NULL);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (one != two);
|
|
Packit Service |
3749ba |
assert (one != four);
|
|
Packit Service |
3749ba |
assert (one != seven);
|
|
Packit Service |
3749ba |
assert (one != eleven);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (two != four);
|
|
Packit Service |
3749ba |
assert (two != seven);
|
|
Packit Service |
3749ba |
assert (two != eleven);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (four != seven);
|
|
Packit Service |
3749ba |
assert (four != eleven);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert (split == eleven);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
static void
|
|
Packit Service |
3749ba |
test_murmur3_incr (void)
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
uint32_t first, second;
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&first,
|
|
Packit Service |
3749ba |
"this is the long input!", (size_t)23,
|
|
Packit Service |
3749ba |
NULL);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
p11_hash_murmur3 ((unsigned char *)&second,
|
|
Packit Service |
3749ba |
"this", (size_t)4,
|
|
Packit Service |
3749ba |
" ", (size_t)1,
|
|
Packit Service |
3749ba |
"is ", (size_t)3,
|
|
Packit Service |
3749ba |
"the long ", (size_t)9,
|
|
Packit Service |
3749ba |
"in", (size_t)2,
|
|
Packit Service |
3749ba |
"p", (size_t)1,
|
|
Packit Service |
3749ba |
"u", (size_t)1,
|
|
Packit Service |
3749ba |
"t", (size_t)1,
|
|
Packit Service |
3749ba |
"!", (size_t)1,
|
|
Packit Service |
3749ba |
NULL);
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
assert_num_eq (first, second);
|
|
Packit Service |
3749ba |
}
|
|
Packit Service |
3749ba |
|
|
Packit Service |
3749ba |
int
|
|
Packit Service |
3749ba |
main (int argc,
|
|
Packit Service |
3749ba |
char *argv[])
|
|
Packit Service |
3749ba |
{
|
|
Packit Service |
3749ba |
p11_test (test_murmur3, "/hash/murmur3");
|
|
Packit Service |
3749ba |
p11_test (test_murmur3_incr, "/hash/murmur3-incr");
|
|
Packit Service |
3749ba |
return p11_test_run (argc, argv);
|
|
Packit Service |
3749ba |
}
|