コード例 #1
0
TEST(cps_api_key,key_insert) {
    cps_api_key_t key;
    memset(&key,0,sizeof(key));
    cps_api_key_set(&key,0,0);
    cps_api_key_set(&key,1,1);
    cps_api_key_set(&key,2,2);
    cps_api_key_set_len(&key,3);

    cps_api_key_t new_key ;
    cps_api_key_copy(&new_key,&key);


    cps_api_key_remove_element(&new_key,0);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,0)== 1);
    ASSERT_TRUE(cps_api_key_get_len(&new_key)==2);

    cps_api_key_insert_element(&new_key,0,5);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,0)== 5);
    ASSERT_TRUE(cps_api_key_get_len(&new_key)==3);

    cps_api_key_insert_element(&new_key,3,5);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,3)== 5);
    ASSERT_TRUE(cps_api_key_get_len(&new_key)==4);

    cps_api_key_insert_element(&new_key,2,5);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,2)== 5);
    ASSERT_TRUE(cps_api_key_get_len(&new_key)==5);

    ASSERT_TRUE(cps_api_key_element_at(&new_key,0)== 5);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,2)== 5);
    ASSERT_TRUE(cps_api_key_element_at(&new_key,4)== 5);

}
コード例 #2
0
TEST(cps_api_key_cache,test_key_inserts) {
    size_t ix = 0;
    size_t mx = lst.size();
    for ( ; ix < mx ; ++ix ) {
        if ((rand()%20)==1) {
            char b1[100];
            missing.push_back(lst[ix]);
            entry e;
            _missing_cache.insert(lst[ix],e);
            printf("Skipping.. %s\n",cps_api_key_print(lst[ix],b1,sizeof(b1)));
            ASSERT_TRUE(_missing_cache.find(lst[ix],e,true));
            continue;
        }
        entry e;
        cps_api_key_copy(&e.key,lst[ix]);
        e.ix = ix;

        ASSERT_FALSE(cache.find(&e.key,e,true));

        cache.insert(&e.key,e);

        size_t klen = (rand() % 4) + 1;
        cps_api_key_set_len(&e.key,klen);
        if (cache.find(&e.key,e,true)) continue;
        cache.insert(&e.key,e);

    }
}
コード例 #3
0
TEST(cps_api_key_cache,test_key_inserts_full) {
    size_t ix = 0;
    size_t mx = lst.size();
    for ( ; ix < mx ; ++ix ) {
        entry e;

        cps_api_key_copy(&e.key,lst[ix]);
        e.ix = ix;

        ASSERT_FALSE(full_cache.find(&e.key,e,true));
        full_cache.insert(&e.key,e);
        ASSERT_TRUE(full_cache.find(&e.key,e,true));
    }
}
コード例 #4
0
TEST(cps_api_key,key_compare) {
    char buff1[1024];
    char buff2[1024];

    cps_api_key_t key;
    memset(&key,0,sizeof(key));
    cps_api_key_set(&key,0,1);
    cps_api_key_set(&key,1,3);
    cps_api_key_set(&key,2,1);
    cps_api_key_set(&key,3,1);
    cps_api_key_set_len(&key,4);

    cps_api_key_t key2;
    memset(&key2,0,sizeof(key2));
    cps_api_key_set(&key2,0,1);
    cps_api_key_set(&key2,1,3);
    cps_api_key_set(&key2,2,1);
    cps_api_key_set(&key2,3,1);
    cps_api_key_set_len(&key2,4);
    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)==0);

    cps_api_key_set(&key2,1,4);
    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)!=0);

    cps_api_key_set(&key2,1,3);
    cps_api_key_set(&key2,4,2);
    cps_api_key_set_len(&key2,3);
    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)==0);

    cps_api_key_set(&key2,1,2);
    cps_api_key_set_len(&key2,4);
    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)!=0);

    cps_api_key_t key3;
    memset(&key3,0,sizeof(key3));
    cps_api_key_set(&key3,0,1);
    cps_api_key_set(&key3,1,3);
    cps_api_key_set(&key3,2,1);
    cps_api_key_set_len(&key3,3);

    ASSERT_TRUE(cps_api_key_matches(&key,&key3,true)!=0);
    cps_api_key_set_len(&key3,1);
    ASSERT_TRUE(cps_api_key_matches(&key,&key3,false)==0);
    cps_api_key_set_len(&key3,2);
    ASSERT_TRUE(cps_api_key_matches(&key,&key3,false)==0);

    cps_api_key_set(&key2,1,3);
    ASSERT_TRUE(cps_api_key_matches(&key,&key2,true)==0);
    printf("Key 1 %s, Key 2 %s\n",cps_api_key_print(&key,buff1,sizeof(buff1)),
            cps_api_key_print(&key2,buff2,sizeof(buff2)));

    cps_api_key_set_len(&key2,2);
    cps_api_key_set(&key2,2,4);

    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)==0);
    printf("Key 1 %s, Key 2 %s\n",cps_api_key_print(&key,buff1,sizeof(buff1)),
            cps_api_key_print(&key2,buff2,sizeof(buff2)));

    ASSERT_TRUE(cps_api_key_matches(&key2,&key,false)!=0);

    cps_api_key_set(&key2,2,2);
    cps_api_key_set(&key,2,0);

    ASSERT_TRUE(cps_api_key_matches(&key,&key2,false)==0);

    printf("Key 1 %s, Key 2 %s\n",cps_api_key_print(&key,buff1,sizeof(buff1)),
            cps_api_key_print(&key2,buff2,sizeof(buff2)));

    memset(&key2,0,sizeof(key2));
    cps_api_key_copy(&key2,&key);

    ASSERT_TRUE(cps_api_key_matches(&key,&key2,true)==0);

    printf("Final\nKey 1 %s, Key 2 %s\n",cps_api_key_print(&key,buff1,sizeof(buff1)),
            cps_api_key_print(&key2,buff2,sizeof(buff2)));
}
コード例 #5
0
static void _make_key(_key_t &ek, const cps_api_key_t *ck) {
    cps_api_key_copy(_int_key_to_cps_key(ek),(cps_api_key_t *)ck);
}