示例#1
0
static char *test_md5_compare()
{
    int res = 0;
    unsigned char m1[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };
    unsigned char m2[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    };
    unsigned char m3[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };
    unsigned char m4[] = {
        0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    };

    res = md5_compare(m1, m2);
    mu_assert_msg(res < 0, "Expected m1 is less the m2")
    res = md5_compare(m3, m4);
    mu_assert_msg(res < 0, "Expected m3 is less the m4")

    return NULL;
}
示例#2
0
static char *test_md5_get()
{
    unsigned char got[16], expected[16] = {
        0x46, 0x3b, 0x70, 0x08, 0xd0, 0xbd, 0xe3, 0xa7,
        0xc7, 0x11, 0x99, 0x89, 0xc4, 0xa6, 0x02, 0x8c,
    };
    char md5exp[] = "463b7008d0bde3a7c7119989c4a6028c";
    char md5got[33];

    md5_get("test/testfile", got);
    mu_assert_msg(md5_compare(got, expected) == 0, "md5sum mismatch")

    for (int i = 0; i < 16; i++) {
        sprintf(md5got+(i*2), "%02x", got[i]);
    }
    mu_assert_msg(strncmp(md5exp, md5got, 32) == 0, "md5sum mismatch")

    return NULL;
}
示例#3
0
文件: CMiniCache.c 项目: tanec/fcache
/**************************************************************************
	//Function:			FindNode
	//Description:		根据关键字查找节点
	//Calls:
	//Called by:
	//Input:
						tKey				记录主关键字
	//Output:
						pNode				指向查找到节点的指针
	//Return:
						返回值				说明
						0					成功
						负值				失败
	//Others:
	//Author:	fanyh	Email: [email protected]
	//Date:		2008-06-16
	**************************************************************************/
int
FindNode(CMiniCache *cache, map_key_t tKey, CMiniCacheNode **pOldNode)
{
  size_t lPos;
  if (!pOldNode) return -1;

  lPos = hashVal(tKey, cache->m_lHashSize);

  if(cache->m_ppHash[lPos]) {
    *pOldNode = cache->m_ppHash[lPos];
    while(*pOldNode) {
      if(md5_compare((*pOldNode)->tKey->digest, tKey->digest) == 0)
        return 0;
      else
	*pOldNode = (*pOldNode)->pDown;
    }
  }
  return -1;
}
示例#4
0
static void
test(gpointer data, gpointer user_data)
{
    int tn = *((int *)data), dn = *((int *)user_data);

    printf("===> test start: %d\n", tn);
    val_t vals[dn];
    int i, mul=1;
    while (mul < dn) mul *= 10;
    for (i=0; i<dn; i++) {
        vals[i].num = tn*mul + i;
        vals[i].tm  = time(NULL);
        md5_digest(&vals[i].num, sizeof(int), vals[i].key.digest);

        DelData(cache, &vals[i].key);
    }

    for (i=0; i<dn; i++) {
        sleep(time(NULL)%2);
        int result;
        size_t data_size=sizeof(val_t);
        result = AddData(cache, &vals[i].key, (void *)&vals[i], data_size);
        if (result != 0) {
            ret = 1;
            val_t *v = &vals[i];
            printf("+>set error: v(%p).num = %d\n", v, ((val_t *)v)->num);
        }
    }

    for (i=0; i<dn; i++) {
        val_t *v;
        size_t data_size;
        GetData(cache, &vals[i].key, (void *)&v, &data_size);
        if (v == NULL) {
            ret = 2;
            printf("-> get wrong: v=%p\n", v);
        } else {
            if (v != &vals[i]) {
                ret = 2;
                printf("-> get wrong: v(%p) != vals[%d](%p)\n",
                       v, i, &vals[i]);
            }
            if (v->num != vals[i].num) {
                ret = 2;
                printf("-> get wrong: v->num(%d) != vals[%d].num(%d)\n",
                       v->num, i, vals[i].num);
            }
            if (v->tm  != vals[i].tm) {
                ret = 2;
                printf("-> get wrong: v->tm (%d) != vals[%d].tm (%d)\n",
                       v->tm,  i, vals[i].tm);
            }
            if (md5_compare(((map_key_t)v)->digest,
                            ((map_key_t)&vals[i].key)->digest)!=0) {
                ret = 2;
                printf("-> get wrong: md5\n");
            }
        }
    }

    for (i=0; i<dn; i++) {
        int result;
        result = DelData(cache, &vals[i].key);
        if (result != 0) {
            ret = 3;
            printf("-> remove wrong: v=%p\n", &vals[i]);
        }
    }

    printf("===> test stop : %d\n", tn);
    run--;
}