~ubuntu-branches/ubuntu/raring/cmake/raring

« back to all changes in this revision

Viewing changes to Utilities/cmlibarchive/libarchive/test/test_read_data_large.c

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2012-04-30 12:14:32 UTC
  • mfrom: (3.1.30 sid)
  • Revision ID: package-import@ubuntu.com-20120430121432-rqh2fjl3zcblehh5
Tags: 2.8.8-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add xfail_compiler_flag.diff: Mark compiler flag tests as expected
    failures.
  - Add ubuntu_qt_import_dir_variable.diff: define QT_IMPORTS_DIR even
    when that dir does not exist.
* Remove increase_ctest_test_timeout.diff, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * Copyright (c) 2003-2007 Tim Kientzle
3
 
 * All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions
7
 
 * are met:
8
 
 * 1. Redistributions of source code must retain the above copyright
9
 
 *    notice, this list of conditions and the following disclaimer.
10
 
 * 2. Redistributions in binary form must reproduce the above copyright
11
 
 *    notice, this list of conditions and the following disclaimer in the
12
 
 *    documentation and/or other materials provided with the distribution.
13
 
 *
14
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15
 
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16
 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
 
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18
 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
 
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
 
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
 
 */
25
 
#include "test.h"
26
 
__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_data_large.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $");
27
 
 
28
 
/*
29
 
 * Test read/write of a 10M block of data in a single operation.
30
 
 * Uses an in-memory archive with a single 10M entry.  Exercises
31
 
 * archive_read_data() to ensure it can handle large blocks like
32
 
 * this and also exercises archive_read_data_into_fd() (which
33
 
 * had a bug relating to this, fixed in Nov 2006).
34
 
 */
35
 
 
36
 
#if defined(_WIN32) && !defined(__CYGWIN__)
37
 
#define open _open
38
 
#define close _close
39
 
#endif
40
 
 
41
 
char buff1[11000000];
42
 
char buff2[10000000];
43
 
char buff3[10000000];
44
 
 
45
 
DEFINE_TEST(test_read_data_large)
46
 
{
47
 
    struct archive_entry *ae;
48
 
    struct archive *a;
49
 
    char tmpfilename[] = "largefile";
50
 
    int tmpfilefd;
51
 
    FILE *f;
52
 
    unsigned int i;
53
 
    size_t used;
54
 
 
55
 
    /* Create a new archive in memory. */
56
 
    assert((a = archive_write_new()) != NULL);
57
 
    assertA(0 == archive_write_set_format_ustar(a));
58
 
    assertA(0 == archive_write_set_compression_none(a));
59
 
    assertA(0 == archive_write_open_memory(a, buff1, sizeof(buff1), &used));
60
 
 
61
 
    /*
62
 
     * Write a file (with random contents) to it.
63
 
     */
64
 
    assert((ae = archive_entry_new()) != NULL);
65
 
    archive_entry_copy_pathname(ae, "file");
66
 
    archive_entry_set_mode(ae, S_IFREG | 0755);
67
 
    for (i = 0; i < sizeof(buff2); i++)
68
 
        buff2[i] = (unsigned char)rand();
69
 
    archive_entry_set_size(ae, sizeof(buff2));
70
 
    assertA(0 == archive_write_header(a, ae));
71
 
    archive_entry_free(ae);
72
 
    assertA(sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2)));
73
 
 
74
 
    /* Close out the archive. */
75
 
    assertA(0 == archive_write_close(a));
76
 
#if ARCHIVE_VERSION_NUMBER < 2000000
77
 
    archive_write_finish(a);
78
 
#else
79
 
    assertA(0 == archive_write_finish(a));
80
 
#endif
81
 
 
82
 
    /* Check that archive_read_data can handle 10*10^6 at a pop. */
83
 
    assert((a = archive_read_new()) != NULL);
84
 
    assertA(0 == archive_read_support_format_all(a));
85
 
    assertA(0 == archive_read_support_compression_all(a));
86
 
    assertA(0 == archive_read_open_memory(a, buff1, sizeof(buff1)));
87
 
    assertA(0 == archive_read_next_header(a, &ae));
88
 
    failure("Wrote 10MB, but didn't read the same amount");
89
 
    assertEqualIntA(a, sizeof(buff2),archive_read_data(a, buff3, sizeof(buff3)));
90
 
    failure("Read expected 10MB, but data read didn't match what was written");
91
 
    assert(0 == memcmp(buff2, buff3, sizeof(buff3)));
92
 
    assert(0 == archive_read_close(a));
93
 
#if ARCHIVE_VERSION_NUMBER < 2000000
94
 
    archive_read_finish(a);
95
 
#else
96
 
    assert(0 == archive_read_finish(a));
97
 
#endif
98
 
 
99
 
    /* Check archive_read_data_into_fd */
100
 
    assert((a = archive_read_new()) != NULL);
101
 
    assertA(0 == archive_read_support_format_all(a));
102
 
    assertA(0 == archive_read_support_compression_all(a));
103
 
    assertA(0 == archive_read_open_memory(a, buff1, sizeof(buff1)));
104
 
    assertA(0 == archive_read_next_header(a, &ae));
105
 
    tmpfilefd = open(tmpfilename, O_WRONLY | O_CREAT | O_BINARY, 0777);
106
 
    assert(tmpfilefd != 0);
107
 
    assertEqualIntA(a, 0, archive_read_data_into_fd(a, tmpfilefd));
108
 
    assert(0 == archive_read_close(a));
109
 
#if ARCHIVE_VERSION_NUMBER < 2000000
110
 
    archive_read_finish(a);
111
 
#else
112
 
    assert(0 == archive_read_finish(a));
113
 
#endif
114
 
    close(tmpfilefd);
115
 
 
116
 
    f = fopen(tmpfilename, "rb");
117
 
    assert(f != NULL);
118
 
    assertEqualInt(sizeof(buff3), fread(buff3, 1, sizeof(buff3), f));
119
 
    fclose(f);
120
 
    assert(0 == memcmp(buff2, buff3, sizeof(buff3)));
121
 
}