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

« back to all changes in this revision

Viewing changes to libarchive/test/test_compat_pax_libarchive_2x.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:
 
1
/*-
 
2
 * Copyright (c) 2011 Michihiro NAKAJIMA
 
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");
 
27
 
 
28
#include <locale.h>
 
29
 
 
30
/*
 
31
 * Test "tar:compat-2x" option that enables the string conversion of
 
32
 * libarchive 2.x, which made incorrect UTF-8 form filenames for the
 
33
 * pax format on some platform the wchar_t of which was not Unicode form.
 
34
 * The option is unneeded if people have been using UTF-8 locale during
 
35
 * making tar files(in pax format).
 
36
 *
 
37
 * NOTE: The sample tar file was made with bsdtar 2.x in LANG=KOI8-R on
 
38
 * FreeBSD.
 
39
 */
 
40
 
 
41
DEFINE_TEST(test_compat_pax_libarchive_2x)
 
42
{
 
43
#if (defined(_WIN32) && !defined(__CYGWIN__)) \
 
44
         || defined(__STDC_ISO_10646__) || defined(__APPLE__)
 
45
        skipping("This test only for the platform the WCS of which is "
 
46
            "not Unicode.");
 
47
#else
 
48
        struct archive *a;
 
49
        struct archive_entry *ae;
 
50
        char c;
 
51
        wchar_t wc;
 
52
        const char *refname = "test_compat_pax_libarchive_2x.tar.Z";
 
53
 
 
54
        /*
 
55
        * Read incorrect format UTF-8 filename in ru_RU.KOI8-R with
 
56
        * "tar:compat-2x" option. We should correctly
 
57
        * read two filenames.
 
58
        */
 
59
        if (NULL == setlocale(LC_ALL, "ru_RU.KOI8-R")) {
 
60
                skipping("ru_RU.KOI8-R locale not available on this system.");
 
61
                return;
 
62
        }
 
63
 
 
64
        /*
 
65
         * Test if wchar_t format is the same as FreeBSD wchar_t.
 
66
         */
 
67
        assert(-1 != wctomb(NULL, L'\0'));
 
68
        wc = (wchar_t)0xd0;
 
69
        c = 0;
 
70
        if (wctomb(&c, wc) != 1 || (unsigned char)c != 0xd0) {
 
71
                skipping("wchar_t format is different on this platform.");
 
72
                return;
 
73
        }
 
74
 
 
75
        extract_reference_file(refname);
 
76
 
 
77
        assert((a = archive_read_new()) != NULL);
 
78
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
 
79
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
 
80
        assertEqualIntA(a, ARCHIVE_OK,
 
81
            archive_read_set_options(a, "tar:compat-2x"));
 
82
        assertEqualIntA(a, ARCHIVE_OK,
 
83
            archive_read_open_filename(a, refname, 10240));
 
84
 
 
85
        /* Verify regular first file. */
 
86
        assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
 
87
        assertEqualString("\xd0\xd2\xc9\xd7\xc5\xd4",
 
88
            archive_entry_pathname(ae));
 
89
        assertEqualInt(6, archive_entry_size(ae));
 
90
 
 
91
        /* Verify regular second file. */
 
92
        assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
 
93
        assertEqualString("\xf0\xf2\xe9\xf7\xe5\xf4",
 
94
            archive_entry_pathname(ae));
 
95
        assertEqualInt(6, archive_entry_size(ae));
 
96
 
 
97
 
 
98
        /* End of archive. */
 
99
        assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
100
 
 
101
        /* Verify archive format. */
 
102
        assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
 
103
        assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
 
104
            archive_format(a));
 
105
 
 
106
        /* Close the archive. */
 
107
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 
108
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 
109
 
 
110
        /*
 
111
         * Without "tar:compat-2x" option.
 
112
         * Neither first file name nor second file name can be translated
 
113
         * to KOI8-R.
 
114
         */
 
115
        assert((a = archive_read_new()) != NULL);
 
116
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
 
117
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
 
118
        assertEqualIntA(a, ARCHIVE_OK,
 
119
            archive_read_open_filename(a, refname, 10240));
 
120
 
 
121
        /* We cannot correctly read the filename. */
 
122
        assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
 
123
        assert(strcmp("\xd0\xd2\xc9\xd7\xc5\xd4",
 
124
            archive_entry_pathname(ae)) != 0);
 
125
        assertEqualInt(6, archive_entry_size(ae));
 
126
 
 
127
        /* We cannot correctly read the filename. */
 
128
        assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae));
 
129
        assert(strcmp("\xf0\xf2\xe9\xf7\xe5\xf4",
 
130
            archive_entry_pathname(ae)) != 0);
 
131
        assertEqualInt(6, archive_entry_size(ae));
 
132
 
 
133
 
 
134
        /* End of archive. */
 
135
        assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
 
136
 
 
137
        /* Verify archive format. */
 
138
        assertEqualIntA(a, ARCHIVE_FILTER_COMPRESS, archive_filter_code(a, 0));
 
139
        assertEqualIntA(a, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE,
 
140
            archive_format(a));
 
141
 
 
142
        /* Close the archive. */
 
143
        assertEqualInt(ARCHIVE_OK, archive_read_close(a));
 
144
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 
145
#endif
 
146
}