~mordred/libmemcached/fix-weird-link

« back to all changes in this revision

Viewing changes to tests/hashkit_functions.c

  • Committer: Brian Aker
  • Date: 2010-01-19 23:18:01 UTC
  • Revision ID: brian@gaz-20100119231801-g4kjmjqunwe7txkk
Updated for custom hash functions/setting functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
305
305
  return TEST_SUCCESS;
306
306
}
307
307
 
 
308
static test_return_t hashkit_set_base_function_test(hashkit_st *hashk)
 
309
{
 
310
  for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++) 
 
311
  {
 
312
    hashkit_return_t rc;
 
313
    uint32_t x;
 
314
    const char **ptr;
 
315
    uint32_t *list;
 
316
 
 
317
    rc= hashkit_set_base_function(hashk, algo);
 
318
 
 
319
    /* Hsieh is disabled most of the time for patent issues */
 
320
    if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
 
321
      continue;
 
322
 
 
323
    test_true(rc == HASHKIT_SUCCESS);
 
324
 
 
325
    switch (algo)
 
326
    {
 
327
    case HASHKIT_HASH_DEFAULT:
 
328
      list= one_at_a_time_values;
 
329
      break;
 
330
    case HASHKIT_HASH_MD5:
 
331
      list= md5_values;
 
332
      break;
 
333
    case HASHKIT_HASH_CRC:
 
334
      list= crc_values;
 
335
      break;
 
336
    case HASHKIT_HASH_FNV1_64:
 
337
      list= fnv1_64_values;
 
338
      break;
 
339
    case HASHKIT_HASH_FNV1A_64:
 
340
      list= fnv1a_64_values;
 
341
      break;
 
342
    case HASHKIT_HASH_FNV1_32:
 
343
      list= fnv1_32_values;
 
344
      break;
 
345
    case HASHKIT_HASH_FNV1A_32:
 
346
      list= fnv1a_32_values;
 
347
      break;
 
348
    case HASHKIT_HASH_HSIEH:
 
349
      list= hsieh_values;
 
350
      break;
 
351
    case HASHKIT_HASH_MURMUR:
 
352
      list= murmur_values;
 
353
      break;
 
354
    case HASHKIT_HASH_JENKINS:
 
355
      list= jenkins_values;
 
356
      break;
 
357
    case HASHKIT_HASH_MAX:
 
358
    default:
 
359
      list= NULL;
 
360
      test_fail("We ended up on a non-existent hash");
 
361
    }
 
362
 
 
363
    // Now we make sure we did set the hash correctly.
 
364
    for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
 
365
    {
 
366
      uint32_t hash_val;
 
367
 
 
368
      hash_val= hashkit_generate_value(hashk, *ptr, strlen(*ptr));
 
369
      test_true(list[x] == hash_val);
 
370
    }
 
371
  }
 
372
 
 
373
  return TEST_SUCCESS;
 
374
}
 
375
 
 
376
static test_return_t hashkit_set_base_function_custom_test(hashkit_st *hashk)
 
377
{
 
378
  hashkit_return_t rc;
 
379
  uint32_t x;
 
380
  const char **ptr;
 
381
 
 
382
 
 
383
  rc= hashkit_set_base_function_custom(hashk, hashkit_md5, NULL);
 
384
  test_true(rc == HASHKIT_SUCCESS);
 
385
 
 
386
  for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
 
387
  {
 
388
    uint32_t hash_val;
 
389
 
 
390
    hash_val= hashkit_generate_value(hashk, *ptr, strlen(*ptr));
 
391
    test_true(md5_values[x] == hash_val);
 
392
  }
 
393
 
 
394
  return TEST_SUCCESS;
 
395
}
 
396
 
308
397
test_st hashkit_st_functions[] ={
309
398
  {"hashkit_generate_value", 0, (test_callback_fn)hashkit_generate_value_test},
 
399
  {"hashkit_set_base_function", 0, (test_callback_fn)hashkit_set_base_function_test},
 
400
  {"hashkit_set_base_function_custom", 0, (test_callback_fn)hashkit_set_base_function_custom_test},
310
401
  {0, 0, 0}
311
402
};
312
403