~ubuntu-branches/ubuntu/vivid/lvm2/vivid

« back to all changes in this revision

Viewing changes to test/unit/matcher_t.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2012-05-01 20:27:50 UTC
  • mto: (3.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 72.
  • Revision ID: package-import@ubuntu.com-20120501202750-gljjjtblowwq9mw8
Tags: upstream-2.02.95
ImportĀ upstreamĀ versionĀ 2.02.95

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
 
3
 * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
 
4
 *
 
5
 * This file is part of LVM2.
 
6
 *
 
7
 * This copyrighted material is made available to anyone wishing to use,
 
8
 * modify, copy, or redistribute it subject to the terms and conditions
 
9
 * of the GNU General Public License v.2.
 
10
 *
 
11
 * You should have received a copy of the GNU General Public License
 
12
 * along with this program; if not, write to the Free Software Foundation,
 
13
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
14
 */
 
15
 
 
16
#include "libdevmapper.h"
 
17
#include "log.h"
 
18
 
 
19
#include <stdio.h>
 
20
#include <ctype.h>
 
21
#include <string.h>
 
22
#include <sys/types.h>
 
23
#include <sys/stat.h>
 
24
#include <unistd.h>
 
25
#include <fcntl.h>
 
26
#include <sys/mman.h>
 
27
 
 
28
#include <CUnit/CUnit.h>
 
29
#include "matcher_data.h"
 
30
 
 
31
int regex_init(void);
 
32
int regex_fini(void);
 
33
 
 
34
static struct dm_pool *mem = NULL;
 
35
 
 
36
int regex_init(void) {
 
37
        mem = dm_pool_create("bitset test", 1024);
 
38
        return mem == NULL;
 
39
}
 
40
 
 
41
int regex_fini(void) {
 
42
        dm_pool_destroy(mem);
 
43
        return 0;
 
44
}
 
45
 
 
46
static struct dm_regex *make_scanner(const char **rx)
 
47
{
 
48
        struct dm_regex *scanner;
 
49
        int nrx = 0;
 
50
        for (; rx[nrx]; ++nrx);
 
51
 
 
52
        scanner = dm_regex_create(mem, rx, nrx);
 
53
        CU_ASSERT_FATAL(scanner != NULL);
 
54
        return scanner;
 
55
}
 
56
 
 
57
static void test_fingerprints(void) {
 
58
        struct dm_regex *scanner;
 
59
 
 
60
        scanner = make_scanner(dev_patterns);
 
61
        CU_ASSERT_EQUAL(dm_regex_fingerprint(scanner), 0x7f556c09);
 
62
 
 
63
        scanner = make_scanner(random_patterns);
 
64
        CU_ASSERT_EQUAL(dm_regex_fingerprint(scanner), 0x9f11076c);
 
65
}
 
66
 
 
67
static void test_matching(void) {
 
68
        struct dm_regex *scanner;
 
69
        int i;
 
70
 
 
71
        scanner = make_scanner(dev_patterns);
 
72
        for (i = 0; devices[i].str; ++i)
 
73
                CU_ASSERT_EQUAL(dm_regex_match(scanner, devices[i].str), devices[i].expected - 1);
 
74
 
 
75
        scanner = make_scanner(nonprint_patterns);
 
76
        for (i = 0; nonprint[i].str; ++i)
 
77
                CU_ASSERT_EQUAL(dm_regex_match(scanner, nonprint[i].str), nonprint[i].expected - 1);
 
78
}
 
79
 
 
80
CU_TestInfo regex_list[] = {
 
81
        { (char*)"fingerprints", test_fingerprints },
 
82
        { (char*)"matching", test_matching },
 
83
        CU_TEST_INFO_NULL
 
84
};
 
85