VirtualBox

source: kBuild/vendor/grep/2.12/gnulib-tests/test-quotearg.h

Last change on this file was 2595, checked in by bird, 12 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/* Test of quotearg family of functions.
2 Copyright (C) 2008-2012 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>. */
16
17/* Written by Eric Blake <ebb9@byu.net>, 2008. */
18
19struct result_strings {
20 char const *str1; /* Translation of "". */
21 char const *str2; /* Translation of "\0""1\0". */
22 size_t len2; /* Length of str2. */
23 char const *str3; /* Translation of "simple". */
24 char const *str4; /* Translation of " \t\n'\"\033?""?/\\". */
25 char const *str5; /* Translation of "a:b". */
26 char const *str6; /* Translation of "a\\b". */
27 char const *str7a; /* Translation of LQ RQ, in ASCII charset. */
28 char const *str7b; /* Translation of LQ RQ, in Latin1 or UTF-8 charset. */
29};
30
31struct result_groups {
32 struct result_strings group1; /* Via quotearg_buffer. */
33 struct result_strings group2; /* Via quotearg{,_mem}. */
34 struct result_strings group3; /* Via quotearg_colon{,_mem}. */
35};
36
37/* These quotes are borrowed from a pt_PT.utf8 translation. */
38# define LQ "\302\253"
39# define RQ "\302\273"
40# define LQ_ENC "\\302\\253"
41# define RQ_ENC "\\302\\273"
42# define RQ_ESC "\\\302\273"
43
44static struct result_strings inputs = {
45 "", "\0001\0", 3, "simple", " \t\n'\"\033?""?/\\", "a:b", "a\\b",
46 LQ RQ, NULL
47};
48
49static void
50compare (char const *a, size_t la, char const *b, size_t lb)
51{
52 ASSERT (la == lb);
53 ASSERT (memcmp (a, b, la) == 0);
54 ASSERT (b[lb] == '\0');
55}
56
57static void
58compare_strings (char *(func) (char const *, size_t *),
59 struct result_strings *results, bool ascii_only)
60{
61 size_t len;
62 char *p;
63
64 len = 0;
65 p = func (inputs.str1, &len);
66 compare (results->str1, strlen (results->str1), p, len);
67
68 len = inputs.len2;
69 p = func (inputs.str2, &len);
70 compare (results->str2, results->len2, p, len);
71
72 len = SIZE_MAX;
73 p = func (inputs.str3, &len);
74 compare (results->str3, strlen (results->str3), p, len);
75
76 len = strlen (inputs.str4);
77 p = func (inputs.str4, &len);
78 compare (results->str4, strlen (results->str4), p, len);
79
80 len = SIZE_MAX;
81 p = func (inputs.str5, &len);
82 compare (results->str5, strlen (results->str5), p, len);
83
84 len = strlen (inputs.str6);
85 p = func (inputs.str6, &len);
86 compare (results->str6, strlen (results->str6), p, len);
87
88 len = strlen (inputs.str7a);
89 p = func (inputs.str7a, &len);
90 if (ascii_only)
91 compare (results->str7a, strlen (results->str7a), p, len);
92 else
93 compare (results->str7b, strlen (results->str7b), p, len);
94}
95
96static char *
97use_quotearg_buffer (const char *str, size_t *len)
98{
99 static char buf[100];
100 size_t size;
101 memset (buf, 0xa5, 100);
102 size = quotearg_buffer (buf, 100, str, *len, NULL);
103 *len = size;
104 ASSERT ((unsigned char) buf[size + 1] == 0xa5);
105 return buf;
106}
107
108static char *
109use_quotearg (const char *str, size_t *len)
110{
111 char *p = *len == SIZE_MAX ? quotearg (str) : quotearg_mem (str, *len);
112 *len = strlen (p);
113 return p;
114}
115
116static char *
117use_quote_double_quotes (const char *str, size_t *len)
118{
119 char *p = *len == SIZE_MAX ? quotearg_char (str, '"')
120 : quotearg_char_mem (str, *len, '"');
121 *len = strlen (p);
122 return p;
123}
124
125static char *
126use_quotearg_colon (const char *str, size_t *len)
127{
128 char *p = (*len == SIZE_MAX ? quotearg_colon (str)
129 : quotearg_colon_mem (str, *len));
130 *len = strlen (p);
131 return p;
132}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette