• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2002
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /* 01/02/2003	Port to LTP	avenkat&us.ibm.com */
21 /* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
22 
23 /*
24  * NAME
25  *	memcmp1 -- buffer  compare
26  *
27  * CALLS
28  *	memcmp(3)
29  *
30  * ALGORITHM
31  *	Check boundary conditions.
32  *
33  * RESTRICTIONS
34  */
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <errno.h>
41 
42 /*****	LTP Port	*****/
43 #include "test.h"
44 
45 char *TCID = "memcmp1";
46 
47 #undef  BSIZE
48 #define BSIZE	4096
49 #define LEN	100
50 #define FAILED 0
51 #define PASSED 1
52 /*****	**	**	*****/
53 
54 char buf[BSIZE];
55 
56 /*****	LTP Port	*****/
57 int local_flag = PASSED;
58 int block_number;
59 FILE *temp;
60 int TST_TOTAL = 2;
61 int anyfail();
62 int blenter();
63 int blexit();
64 int instress();
65 
66 void setup();
67 /*****	**	**	*****/
68 
69 void clearit();
70 void fill(char *str);
71 int checkit(char *str);
72 
73 /*--------------------------------------------------------------*/
main(int argc,char * argv[])74 int main(int argc, char *argv[])
75 {
76 	char *p, *q;
77 
78 	setup();		/* temp file is now open        */
79 /*--------------------------------------------------------------*/
80 	blenter();
81 
82 	clearit();
83 
84 	p = &buf[100];
85 	q = &buf[800];
86 
87 	fill(p);
88 	fill(q);
89 
90 	if (memcmp(p, q, LEN)) {
91 		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
92 		local_flag = FAILED;
93 	}
94 
95 	p[LEN - 1] = 0;
96 
97 	if (!memcmp(p, q, LEN)) {
98 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
99 		local_flag = FAILED;
100 	};
101 
102 	p[LEN - 1] = 'a';
103 	p[0] = 0;
104 
105 	if (!memcmp(p, q, LEN)) {
106 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
107 		local_flag = FAILED;
108 	};
109 
110 	p[0] = 'a';
111 	q[LEN - 1] = 0;
112 
113 	if (!memcmp(p, q, LEN)) {
114 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
115 		local_flag = FAILED;
116 	};
117 
118 	q[LEN - 1] = 'a';
119 	q[0] = 0;
120 
121 	if (!memcmp(p, q, LEN)) {
122 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
123 		local_flag = FAILED;
124 	};
125 
126 	q[0] = 'a';
127 
128 	if (memcmp(p, q, LEN)) {
129 		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
130 		local_flag = FAILED;
131 	}
132 
133 	blexit();
134 /*--------------------------------------------------------------*/
135 	blenter();
136 
137 	clearit();
138 
139 	p = &buf[800];
140 	q = &buf[100];
141 
142 	fill(p);
143 	fill(q);
144 
145 	if (memcmp(p, q, LEN)) {
146 		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
147 		local_flag = FAILED;
148 	}
149 
150 	p[LEN - 1] = 0;
151 
152 	if (!memcmp(p, q, LEN)) {
153 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
154 		local_flag = FAILED;
155 	};
156 
157 	p[LEN - 1] = 'a';
158 	p[0] = 0;
159 
160 	if (!memcmp(p, q, LEN)) {
161 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
162 		local_flag = FAILED;
163 	};
164 
165 	p[0] = 'a';
166 	q[LEN - 1] = 0;
167 
168 	if (!memcmp(p, q, LEN)) {
169 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
170 		local_flag = FAILED;
171 	};
172 
173 	q[LEN - 1] = 'a';
174 	q[0] = 0;
175 
176 	if (!memcmp(p, q, LEN)) {
177 		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
178 		local_flag = FAILED;
179 	};
180 
181 	q[0] = 'a';
182 
183 	if (memcmp(p, q, LEN)) {
184 		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
185 		local_flag = FAILED;
186 	}
187 
188 	blexit();
189 /*--------------------------------------------------------------*/
190 /* Clean up any files created by test before call to anyfail.	*/
191 
192 	anyfail();		/* THIS CALL DOES NOT RETURN - EXITS!!  */
193 	tst_exit();
194 }
195 
196 /*--------------------------------------------------------------*/
197 /* FUNCTIONS GO HERE */
198 
clearit(void)199 void clearit(void)
200 {
201 	register int i;
202 
203 	for (i = 0; i < BSIZE; i++)
204 		buf[i] = 0;
205 }
206 
fill(char * str)207 void fill(char *str)
208 {
209 	register int i;
210 	for (i = 0; i < LEN; i++)
211 		*str++ = 'a';
212 }
213 
checkit(char * str)214 int checkit(char *str)
215 {
216 	register int i;
217 	for (i = 0; i < LEN; i++)
218 		if (*str++ != 'a')
219 			return (-1);
220 
221 	return (0);
222 }
223 
anyfail(void)224 int anyfail(void)
225 {
226 	tst_exit();
227 }
228 
setup(void)229 void setup(void)
230 {
231 	temp = stderr;
232 }
233 
blenter(void)234 int blenter(void)
235 {
236 	local_flag = PASSED;
237 	return 0;
238 }
239 
blexit(void)240 int blexit(void)
241 {
242 	(local_flag == FAILED) ? tst_resm(TFAIL,
243 					  "Test failed") : tst_resm(TPASS,
244 								    "Test passed");
245 	return 0;
246 }
247