File: test-mmap.c

package info (click to toggle)
libchewing 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,220 kB
  • ctags: 10,179
  • sloc: ansic: 103,539; sh: 11,563; makefile: 316; python: 98
file content (76 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
 * test-mmap.c
 *
 * Copyright (c) 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#ifdef HAVE_CONFIG_H
#    include <config.h>
#endif

#ifndef _GNU_SOURCE
#    define _GNU_SOURCE
#endif

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "testhelper.h"
#include "plat_mmap.h"

FILE *fd;

void test_UnitFromPlatMmap()
{
    unsigned int idx;
    plat_mmap m_mmap;
    size_t offset = 0;
    size_t csize;
    char *data_buf;
    char hard_copy[] = "ji3cp3vu3cj0 vup dj4up <E>";
    int i;

    start_testcase(NULL, fd);

    idx = plat_mmap_create(&m_mmap, TEST_DATA_DIR PLAT_SEPARATOR "default-test.txt", FLAG_ATTRIBUTE_READ);
    ok(idx == 28, "plat_mmap_create");
    if (idx > 0) {
        csize = idx;
        data_buf = (char *) plat_mmap_set_view(&m_mmap, &offset, &csize);
        for (i = 0; i < 26; i++) {
            if (data_buf[i] != hard_copy[i])
                break;
        }
        ok(i == 26, "plat_mmap_set_view");
    }
    plat_mmap_close(&m_mmap);
}

int main(int argc, char *argv[])
{
    char *logname;
    int ret;

    putenv("CHEWING_PATH=" CHEWING_DATA_PREFIX);
    putenv("CHEWING_USER_PATH=" TEST_HASH_DIR);

    ret = asprintf(&logname, "%s.log", argv[0]);
    if (ret == -1)
        return -1;
    fd = fopen(logname, "w");
    assert(fd);
    free(logname);


    test_UnitFromPlatMmap();

    fclose(fd);

    return exit_status();
}