Пример #1
0
END_TEST

START_TEST(test_bf_fp_prob_extended)
{
    bloom_filter_params params = {0, 0, 1e6, 0.001};
    bf_params_for_capacity(&params);
    bloom_bitmap map;
    bloom_bloomfilter filter;
    fail_unless(bitmap_from_file(-1, params.bytes, ANONYMOUS, &map) == 0);
    fail_unless(bf_from_bitmap(&map, params.k_num, 1, &filter) == 0);

    // Check all the keys get added
    char buf[100];
    int res;
    int num_wrong = 0;
    for (int i=0;i<1e6;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        res = bf_add(&filter, (char*)&buf);
        if (res == 0) num_wrong++;
    }

    // We added 1M items, with a capacity of 1M and error of 1/1000.
    // Technically we should have 1K false positives
    fail_unless(num_wrong <= 1000);
}
Пример #2
0
END_TEST

START_TEST(test_length)
{
    bloom_filter_params params = {0, 0, 1e6, 1e-4};
    bf_params_for_capacity(&params);
    bloom_bitmap map;
    bitmap_from_file(-1, params.bytes, ANONYMOUS, &map);
    bloom_bloomfilter filter;
    bf_from_bitmap(&map, params.k_num, 1, &filter);

    // Check the size
    fail_unless(bf_size(&filter) == 0);

    // Check all the keys get added
    char buf[100];
    int res;
    for (int i=0;i<1000;i++) {
        snprintf((char*)&buf, 100, "test%d", i);
        res = bf_add(&filter, (char*)&buf);
        fail_unless(res == 1);
    }

    // Check the size
    fail_unless(bf_size(&filter) == 1000);
}
Пример #3
0
END_TEST

START_TEST(make_bitmap_bad_fileno)
{
    bloom_bitmap map;
    int res = bitmap_from_file(500, 4096, SHARED, &map);
    fail_unless(res == -EBADF);
}
Пример #4
0
END_TEST

START_TEST(make_bitmap_zero_size)
{
    bloom_bitmap map;
    int res = bitmap_from_file(-1, 0, ANONYMOUS, &map);
    fail_unless(res == -EINVAL);
}
Пример #5
0
END_TEST

START_TEST(make_bitmap_bad_fileno_persistent)
{
    bloom_bitmap map;
    int res = bitmap_from_file(500, 4096, PERSISTENT, &map);
    fail_unless(res == -EBADF);
}
Пример #6
0
END_TEST

// Tests the call back, increments the in counter
static int sbf_test_callback(void *in, uint64_t bytes, bloom_bitmap *map) {
    uint64_t *counter = (uint64_t*)in;
    *counter = *counter + 1;
    return bitmap_from_file(-1, bytes, ANONYMOUS, map);
}
Пример #7
0
END_TEST

START_TEST(setbit_bitmap_anonymous_one_byte_aligned)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    bitmap_setbit((&map), 8);
    fail_unless(map.mmap[1] == 128);
}
Пример #8
0
END_TEST

START_TEST(getbit_bitmap_anonymous_one_onebyte)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    map.mmap[1] = 128;
    fail_unless(bitmap_getbit((&map), 8) == 1);
}
Пример #9
0
    WidgetImage(gdi::GraphicApi & drawable, int x, int y, const char * filename, Widget2 & parent, NotifyApi* notifier, int group_id = 0)
    : Widget2(drawable, Rect(x,y,1,1), parent, notifier, group_id)
    , bmp(bitmap_from_file(filename))
    {
        this->tab_flag = IGNORE_TAB;
        this->focus_flag = IGNORE_FOCUS;

        this->rect.cx = this->bmp.cx();
        this->rect.cy = this->bmp.cy();
    }
Пример #10
0
END_TEST

START_TEST(getbit_bitmap_anonymous_one)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    memset(map.mmap, 255, 4096);
    for (int idx = 0; idx < 4096*8 ; idx++) {
        fail_unless(bitmap_getbit((&map), idx) == 1);
    }
}
Пример #11
0
END_TEST

START_TEST(make_bf_fresh_not_new)
{
    // Use -1 for anonymous
    bloom_bitmap map;
    bloom_bloomfilter filter;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    int res = bf_from_bitmap(&map, 10, 0, &filter);
    fail_unless(res == -1);
}
Пример #12
0
END_TEST

START_TEST(make_bf_zero_k)
{
    // Use -1 for anonymous
    bloom_bitmap map;
    bloom_bloomfilter filter;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    int res = bf_from_bitmap(&map, 0, 1, &filter);
    fail_unless(res == -EINVAL);
}
Пример #13
0
/**
 * Callback used with SBF to generate file names.
 */
static int bloomf_sbf_callback(void* in, uint64_t bytes, bloom_bitmap *out) {
    // Cast the input pointer
    bloom_filter *filt = in;

    // Check if we are in-memory
    if (filt->filter_config.in_memory) {
        syslog(LOG_INFO, "Creating new in-memory bitmap for filter %s. Size: %llu",
            filt->filter_name, (unsigned long long)bytes);
        return bitmap_from_file(-1, bytes, ANONYMOUS, out);
    }

    // Scan through the folder looking for data files
    struct dirent **namelist = NULL;
    int num_files;

    // Filter only data dirs, in sorted order
    num_files = scandir(filt->full_path, &namelist, filter_data_files, NULL);
    syslog(LOG_INFO, "Found %d files for filter %s.", num_files, filt->filter_name);
    if (num_files < 0) {
        syslog(LOG_ERR, "Error discovering files for filter '%s'. %s",
                filt->filter_name, strerror(errno));
        return -1;
    }


    // Free the memory associated with scandir
    for (int i=0; i < num_files; i++) {
        free(namelist[i]);
    }
    if (namelist) free(namelist);

    // Generate the new file name
    char *filename = NULL;
    int file_name_len;
    file_name_len = asprintf(&filename, DATA_FILE_NAME, num_files);
    assert(file_name_len != -1);

    // Get the full path
    char *full_path = join_path(filt->full_path, filename);
    free(filename);
    syslog(LOG_INFO, "Creating new file: %s for filter %s. Size: %llu",
            full_path, filt->filter_name, (unsigned long long)bytes);

    // Create the bitmap
    bitmap_mode mode = (filt->config->use_mmap) ? SHARED : PERSISTENT;
    int res = bitmap_from_filename(full_path, bytes, 1, mode, out);
    if (res) {
        syslog(LOG_CRIT, "Failed to create new file: %s for filter %s. Err: %s",
            full_path, filt->filter_name, strerror(errno));
    }
    free(full_path);
    return res;
}
Пример #14
0
END_TEST


/*
 * int bitmap_flush(bloom_bitmap *map) {
 */
START_TEST(flush_bitmap_anonymous)
{
    bloom_bitmap map;
    int res = bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    fail_unless(res == 0);
    fail_unless(bitmap_flush(&map) == 0);
}
Пример #15
0
END_TEST


/*
 *#define BITMAP_SETBIT(map, idx, val)
 */
START_TEST(setbit_bitmap_anonymous_one_byte)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    bitmap_setbit((&map), 1);
    fail_unless(map.mmap[0] == 64);
}
Пример #16
0
END_TEST


/*
 *#define BITMAP_GETBIT(map, idx)
 */
START_TEST(getbit_bitmap_anonymous_zero)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    for (int idx = 0; idx < 4096*8 ; idx++) {
        fail_unless(bitmap_getbit((&map), idx) == 0);
    }
}
Пример #17
0
END_TEST

/*
 * int bitmap_close(bloom_bitmap *map) {
 */

START_TEST(close_bitmap_anonymous)
{
    bloom_bitmap map;
    int res = bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    fail_unless(res == 0);
    fail_unless(bitmap_close(&map) == 0);
    fail_unless(map.mmap == NULL);
}
Пример #18
0
END_TEST


START_TEST(setbit_bitmap_anonymous_one)
{
    bloom_bitmap map;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    for (int idx = 0; idx < 4096*8 ; idx++) {
        bitmap_setbit((&map), idx);
    }
    for (int idx = 0; idx < 4096; idx++) {
        fail_unless(map.mmap[idx] == 255);
    }
}
Пример #19
0
int main()
{
    CTSInfo info = {0};
    bitmap bmp_to_find = {0};
    bitmap bmp_target = {0};

    defaultCTS(&info);
    bitmap_from_file(&bmp_to_find, "C:/Users/Brandon/Desktop/find.bmp");
    bitmap_from_file(&bmp_target, "C:/Users/Brandon/Desktop/target.bmp");
    info.targetImage = &bmp_target;



    TestOne(&info);
    printf("\n");

    TestTwo(&info, &bmp_to_find);
    printf("\n");


    freebmp(&bmp_to_find);
    freebmp(&bmp_target);
    return 0;
}
Пример #20
0
END_TEST


START_TEST(test_bf_double_close)
{
    bloom_filter_params params = {0, 0, 1e6, 1e-4};
    bf_params_for_capacity(&params);
    bloom_bitmap map;
    bloom_bloomfilter filter;
    bitmap_from_file(-1, params.bytes, ANONYMOUS, &map);
    bf_from_bitmap(&map, params.k_num, 1, &filter);

    fail_unless(bf_close(&filter) == 0);
    fail_unless(bf_close(&filter) == -1);
}
Пример #21
0
END_TEST

START_TEST(make_bf_fresh_then_restore)
{
    // Use -1 for anonymous
    bloom_bitmap map;
    bloom_bloomfilter filter;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    int res = bf_from_bitmap(&map, 10, 1, &filter); // Make fresh
    fail_unless(res == 0);

    bloom_bloomfilter filter2;
    res = bf_from_bitmap(&map, 10, 0, &filter2); // Restore now
    fail_unless(res == 0);
}
Пример #22
0
END_TEST

START_TEST(test_bf_value_sanity)
{
    // Use -1 for anonymous
    bloom_bitmap map;
    bloom_bloomfilter filter;
    bitmap_from_file(-1, 4096, ANONYMOUS, &map);
    int res = bf_from_bitmap(&map, 10, 1, &filter); // Make fresh
    fail_unless(res == 0);

    fail_unless(filter.bitmap_size == 28672);  // Should be the bitmap size
    fail_unless(filter.offset == 2867);        // Should be size / 10
    fail_unless(filter.header->k_num == 10);
    fail_unless(filter.header->count == 0);
}