~ubuntu-branches/ubuntu/quantal/libarchive/quantal

« back to all changes in this revision

Viewing changes to libarchive/test/test_write_disk.c

  • Committer: Package Import Robot
  • Author(s): Andres Mejia
  • Date: 2012-02-23 19:29:24 UTC
  • mfrom: (8.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20120223192924-73n4iedok5fwgsyr
Tags: 3.0.3-5
* Detect if locales or locales-all is installed for use with test suite.
* Bump Standards-Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "test.h"
26
26
__FBSDID("$FreeBSD: head/lib/libarchive/test/test_write_disk.c 201247 2009-12-30 05:59:21Z kientzle $");
27
27
 
28
 
#if ARCHIVE_VERSION_NUMBER >= 1009000
29
 
 
30
28
#define UMASK 022
31
29
/*
32
30
 * When comparing mode values, ignore high-order bits
47
45
        failure("%s", msg);
48
46
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
49
47
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
50
 
#if ARCHIVE_VERSION_NUMBER < 2000000
51
 
        archive_write_finish(ad);
52
 
#else
53
 
        assertEqualInt(0, archive_write_finish(ad));
54
 
#endif
 
48
        assertEqualInt(0, archive_write_free(ad));
 
49
 
55
50
        /* Test the entries on disk. */
56
51
        assert(0 == stat(archive_entry_pathname(ae), &st));
57
52
        failure("%s", msg);
97
92
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
98
93
        assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data)));
99
94
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
100
 
#if ARCHIVE_VERSION_NUMBER < 2000000
101
 
        archive_write_finish(ad);
102
 
#else
103
 
        assertEqualInt(0, archive_write_finish(ad));
104
 
#endif
 
95
        assertEqualInt(0, archive_write_free(ad));
 
96
 
105
97
        /* Test the entries on disk. */
106
98
        assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777);
107
99
        assertFileSize(archive_entry_pathname(ae), sizeof(data));
136
128
                    archive_write_data_block(ad, data + i, 1000, i));
137
129
        }
138
130
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
139
 
        assertEqualInt(0, archive_write_finish(ad));
 
131
        assertEqualInt(0, archive_write_free(ad));
140
132
 
141
133
        /* Test the entries on disk. */
142
134
        assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777);
159
151
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
160
152
        assertEqualInt(5, archive_write_data(ad, data, sizeof(data)));
161
153
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
162
 
#if ARCHIVE_VERSION_NUMBER < 2000000
163
 
        archive_write_finish(ad);
164
 
#else
165
 
        assertEqualInt(0, archive_write_finish(ad));
166
 
#endif
 
154
        assertEqualInt(0, archive_write_free(ad));
 
155
 
167
156
        /* Test the entry on disk. */
168
157
        assert(0 == stat(archive_entry_pathname(ae), &st));
169
158
        failure("st.st_mode=%o archive_entry_mode(ae)=%o",
188
177
        assertEqualInt(ARCHIVE_OK,
189
178
            archive_write_data_block(ad, data, sizeof(data), 0));
190
179
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
191
 
#if ARCHIVE_VERSION_NUMBER < 2000000
192
 
        archive_write_finish(ad);
193
 
#else
194
 
        assertEqualInt(0, archive_write_finish(ad));
195
 
#endif
 
180
        assertEqualInt(0, archive_write_free(ad));
 
181
 
196
182
        /* Test the entry on disk. */
197
183
        assert(0 == stat(archive_entry_pathname(ae), &st));
198
184
        failure("st.st_mode=%o archive_entry_mode(ae)=%o",
209
195
{
210
196
        static const char data[]="abcdefghijklmnopqrstuvwxyz";
211
197
        struct archive *ad;
212
 
        struct stat st;
213
 
        char *p, *fname;
 
198
        struct _stat st;
 
199
        wchar_t *p, *fname;
214
200
        size_t l;
215
201
 
216
202
        /* Write the entry to disk. */
217
203
        assert((ad = archive_write_disk_new()) != NULL);
218
 
        archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME);
 
204
        archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME);
219
205
        failure("%s", msg);
220
206
        archive_entry_set_size(ae, sizeof(data));
221
207
        archive_entry_set_mtime(ae, 123456789, 0);
222
208
        assertEqualIntA(ad, 0, archive_write_header(ad, ae));
223
209
        assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data)));
224
210
        assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
225
 
#if ARCHIVE_VERSION_NUMBER < 2000000
226
 
        archive_write_finish(ad);
227
 
#else
228
 
        assertEqualInt(0, archive_write_finish(ad));
229
 
#endif
 
211
        assertEqualInt(0, archive_write_free(ad));
 
212
 
230
213
        /* Test the entries on disk. */
231
 
        l = strlen(archive_entry_pathname(ae));
232
 
        fname = malloc(l + 1);
 
214
        l = wcslen(archive_entry_pathname_w(ae));
 
215
        fname = malloc((l + 1) * sizeof(wchar_t));
233
216
        assert(NULL != fname);
234
 
        strcpy(fname, archive_entry_pathname(ae));
 
217
        wcscpy(fname, archive_entry_pathname_w(ae));
 
218
        p = fname;
 
219
        /* Skip leading drive letter from archives created
 
220
         * on Windows. */
 
221
        if (((p[0] >= L'a' && p[0] <= L'z') ||
 
222
             (p[0] >= L'A' && p[0] <= L'Z')) &&
 
223
                 p[1] == L':' && p[2] == L'\\') {
 
224
                p += 3;
 
225
        }
235
226
        /* Replace unusable characters in Windows to '_' */
236
 
        for (p = fname; *p != '\0'; p++)
237
 
                if (*p == ':' || *p == '*' || *p == '?' ||
238
 
                    *p == '"' || *p == '<' || *p == '>' || *p == '|')
 
227
        for (; *p != L'\0'; p++)
 
228
                if (*p == L':' || *p == L'*' || *p == L'?' ||
 
229
                    *p == L'"' || *p == L'<' || *p == L'>' || *p == L'|')
239
230
                        *p = '_';
240
 
        assert(0 == stat(fname, &st));
 
231
        assert(0 == _wstat(fname, &st));
241
232
        failure("st.st_mode=%o archive_entry_mode(ae)=%o",
242
233
            st.st_mode, archive_entry_mode(ae));
243
234
        assertEqualInt(st.st_size, sizeof(data));
 
235
        free(fname);
244
236
}
245
237
#endif /* _WIN32 && !__CYGWIN__ */
246
 
#endif
247
238
 
248
239
DEFINE_TEST(test_write_disk)
249
240
{
250
 
#if ARCHIVE_VERSION_NUMBER < 1009000
251
 
        skipping("archive_write_disk interface");
252
 
#else
253
241
        struct archive_entry *ae;
 
242
#if defined(_WIN32) && !defined(__CYGWIN__)
 
243
        wchar_t *fullpath;
 
244
        DWORD l;
 
245
#endif
254
246
 
255
247
        /* Force the umask to something predictable. */
256
248
        assertUmask(UMASK);
314
306
#if defined(_WIN32) && !defined(__CYGWIN__)
315
307
        /* A file with unusable characters in its file name. */
316
308
        assert((ae = archive_entry_new()) != NULL);
317
 
        archive_entry_copy_pathname(ae, "f:i*l?e\"f<i>l|e");
 
309
        archive_entry_copy_pathname_w(ae, L"f:i*l?e\"f<i>l|e");
318
310
        archive_entry_set_mode(ae, S_IFREG | 0755);
319
311
        create_reg_file_win(ae, "Test creating a regular file"
320
312
            " with unusable characters in its file name");
322
314
 
323
315
        /* A file with unusable characters in its directory name. */
324
316
        assert((ae = archive_entry_new()) != NULL);
325
 
        archive_entry_copy_pathname(ae, "d:i*r?e\"c<t>o|ry/file1");
326
 
        archive_entry_set_mode(ae, S_IFREG | 0755);
327
 
        create_reg_file_win(ae, "Test creating a regular file"
328
 
            " with unusable characters in its file name");
329
 
        archive_entry_free(ae);
 
317
        archive_entry_copy_pathname_w(ae, L"d:i*r?e\"c<t>o|ry/file1");
 
318
        archive_entry_set_mode(ae, S_IFREG | 0755);
 
319
        create_reg_file_win(ae, "Test creating a regular file"
 
320
            " with unusable characters in its file name");
 
321
        archive_entry_free(ae);
 
322
 
 
323
        /* A full-path file with unusable characters in its file name. */
 
324
        assert((l = GetCurrentDirectoryW(0, NULL)) != 0);
 
325
        assert((fullpath = malloc((l + 20) * sizeof(wchar_t))) != NULL);
 
326
        assert((l = GetCurrentDirectoryW(l, fullpath)) != 0);
 
327
        wcscat(fullpath, L"\\f:i*l?e\"f<i>l|e");
 
328
        assert((ae = archive_entry_new()) != NULL);
 
329
        archive_entry_copy_pathname_w(ae, fullpath);
 
330
        archive_entry_set_mode(ae, S_IFREG | 0755);
 
331
        create_reg_file_win(ae, "Test creating a regular file"
 
332
            " with unusable characters in its file name");
 
333
        archive_entry_free(ae);
 
334
        free(fullpath);
 
335
 
 
336
        /* A full-path file with unusable characters in its directory name. */
 
337
        assert((l = GetCurrentDirectoryW(0, NULL)) != 0);
 
338
        assert((fullpath = malloc((l + 30) * sizeof(wchar_t))) != NULL);
 
339
        assert((l = GetCurrentDirectoryW(l, fullpath)) != 0);
 
340
        wcscat(fullpath, L"\\d:i*r?e\"c<t>o|ry/file1");
 
341
        assert((ae = archive_entry_new()) != NULL);
 
342
        archive_entry_copy_pathname_w(ae, fullpath);
 
343
        archive_entry_set_mode(ae, S_IFREG | 0755);
 
344
        create_reg_file_win(ae, "Test creating a regular file"
 
345
            " with unusable characters in its file name");
 
346
        archive_entry_free(ae);
 
347
        free(fullpath);
330
348
#endif /* _WIN32 && !__CYGWIN__ */
331
 
#endif
332
349
}