mes/scaffold/tests/7a-struct-char-array.c

145 lines
3.7 KiB
C
Raw Normal View History

/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
test: Remove 30-test.i indirection. * include/30-test.i: Remove. * scaffold/tests/30-strlen.c: Remove 30-test.i indirection. * scaffold/tests/31-eputs.c: Likewise. * scaffold/tests/32-compare.c: Likewise. * scaffold/tests/33-and-or.c: Likewise. * scaffold/tests/34-pre-post.c: Likewise. * scaffold/tests/35-compare-char.c: Likewise. * scaffold/tests/36-compare-arithmetic.c: Likewise. * scaffold/tests/37-compare-assign.c: Likewise. * scaffold/tests/38-compare-call.c: Likewise. * scaffold/tests/40-if-else.c: Likewise. * scaffold/tests/41-?.c: Likewise. * scaffold/tests/42-goto-label.c: Likewise. * scaffold/tests/43-for-do-while.c: Likewise. * scaffold/tests/44-switch.c: Likewise. * scaffold/tests/45-void-call.c: Likewise. * scaffold/tests/46-function-static.c: Likewise. * scaffold/tests/50-assert.c: Likewise. * scaffold/tests/51-strcmp.c: Likewise. * scaffold/tests/52-itoa.c: Likewise. * scaffold/tests/53-strcpy.c: Likewise. * scaffold/tests/60-math.c: Likewise. * scaffold/tests/63-struct-cell.c: Likewise. * scaffold/tests/64-make-cell.c: Likewise. * scaffold/tests/65-read.c: Likewise. * scaffold/tests/66-local-char-array.c: Likewise. * scaffold/tests/70-printf.c: Likewise. * scaffold/tests/71-struct-array.c: Likewise. * scaffold/tests/72-typedef-struct-def.c: Likewise. * scaffold/tests/73-union.c: Likewise. * scaffold/tests/74-multi-line-string.c: Likewise. * scaffold/tests/75-struct-union.c: Likewise. * scaffold/tests/76-pointer-arithmetic.c: Likewise. * scaffold/tests/77-pointer-assign.c: Likewise. * scaffold/tests/78-union-struct.c: Likewise. * scaffold/tests/79-int-array.c: Likewise. * scaffold/tests/7a-struct-char-array.c: Likewise. * scaffold/tests/7b-struct-int-array.c: Likewise. * scaffold/tests/7c-dynarray.c: Likewise. * scaffold/tests/7d-cast-char.c: Likewise. * scaffold/tests/7e-struct-array-access.c: Likewise. * scaffold/tests/7f-struct-pointer-arithmetic.c: Likewise. * scaffold/tests/7g-struct-byte-word-field.c: Likewise. * scaffold/tests/7h-struct-assign.c: Likewise. * scaffold/tests/7i-struct-struct.c: Likewise. * scaffold/tests/7j-strtoull.c: Likewise. * scaffold/tests/7k-for-each-elem.c: Likewise. * scaffold/tests/7l-struct-any-size-array.c: Likewise. * scaffold/tests/7m-struct-char-array-assign.c: Likewise. * scaffold/tests/7n-struct-struct-array.c: Likewise. * scaffold/tests/80-setjmp.c: Likewise. * scaffold/tests/81-qsort.c: Likewise. * scaffold/tests/86-strncpy.c: Likewise. * scaffold/tests/87-sscanf.c: Likewise.
2018-08-15 16:01:14 +00:00
#include <libmes.h>
#include <stdio.h>
#include <string.h>
struct file {
char buffer[1];
};
struct xfile {
char *buffer;
};
struct file file;
struct xfile xfile;
char *buffer = "aaaaaaaaaaaa";
char *bufzor = "bbbbbbbbbbbb";
int
test: Remove 30-test.i indirection. * include/30-test.i: Remove. * scaffold/tests/30-strlen.c: Remove 30-test.i indirection. * scaffold/tests/31-eputs.c: Likewise. * scaffold/tests/32-compare.c: Likewise. * scaffold/tests/33-and-or.c: Likewise. * scaffold/tests/34-pre-post.c: Likewise. * scaffold/tests/35-compare-char.c: Likewise. * scaffold/tests/36-compare-arithmetic.c: Likewise. * scaffold/tests/37-compare-assign.c: Likewise. * scaffold/tests/38-compare-call.c: Likewise. * scaffold/tests/40-if-else.c: Likewise. * scaffold/tests/41-?.c: Likewise. * scaffold/tests/42-goto-label.c: Likewise. * scaffold/tests/43-for-do-while.c: Likewise. * scaffold/tests/44-switch.c: Likewise. * scaffold/tests/45-void-call.c: Likewise. * scaffold/tests/46-function-static.c: Likewise. * scaffold/tests/50-assert.c: Likewise. * scaffold/tests/51-strcmp.c: Likewise. * scaffold/tests/52-itoa.c: Likewise. * scaffold/tests/53-strcpy.c: Likewise. * scaffold/tests/60-math.c: Likewise. * scaffold/tests/63-struct-cell.c: Likewise. * scaffold/tests/64-make-cell.c: Likewise. * scaffold/tests/65-read.c: Likewise. * scaffold/tests/66-local-char-array.c: Likewise. * scaffold/tests/70-printf.c: Likewise. * scaffold/tests/71-struct-array.c: Likewise. * scaffold/tests/72-typedef-struct-def.c: Likewise. * scaffold/tests/73-union.c: Likewise. * scaffold/tests/74-multi-line-string.c: Likewise. * scaffold/tests/75-struct-union.c: Likewise. * scaffold/tests/76-pointer-arithmetic.c: Likewise. * scaffold/tests/77-pointer-assign.c: Likewise. * scaffold/tests/78-union-struct.c: Likewise. * scaffold/tests/79-int-array.c: Likewise. * scaffold/tests/7a-struct-char-array.c: Likewise. * scaffold/tests/7b-struct-int-array.c: Likewise. * scaffold/tests/7c-dynarray.c: Likewise. * scaffold/tests/7d-cast-char.c: Likewise. * scaffold/tests/7e-struct-array-access.c: Likewise. * scaffold/tests/7f-struct-pointer-arithmetic.c: Likewise. * scaffold/tests/7g-struct-byte-word-field.c: Likewise. * scaffold/tests/7h-struct-assign.c: Likewise. * scaffold/tests/7i-struct-struct.c: Likewise. * scaffold/tests/7j-strtoull.c: Likewise. * scaffold/tests/7k-for-each-elem.c: Likewise. * scaffold/tests/7l-struct-any-size-array.c: Likewise. * scaffold/tests/7m-struct-char-array-assign.c: Likewise. * scaffold/tests/7n-struct-struct-array.c: Likewise. * scaffold/tests/80-setjmp.c: Likewise. * scaffold/tests/81-qsort.c: Likewise. * scaffold/tests/86-strncpy.c: Likewise. * scaffold/tests/87-sscanf.c: Likewise.
2018-08-15 16:01:14 +00:00
main ()
{
char *p;
struct file *pfile = &file;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
p = pfile->buffer;
if (p[1] != '1') return 1;
if (file.buffer[1] != '1') return 2;
if (pfile->buffer[1] != '1') return 3;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
memcpy (pfile->buffer + 1, " ", 1);
eputs (file.buffer);
if (p[1] != ' ') return 4;
if (file.buffer[1] != ' ') return 5;
if (pfile->buffer[1] != ' ') return 6;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
p[2] = ' ';
eputs (file.buffer);
if (p[2] != ' ') return 7;
if (file.buffer[2] != ' ') return 8;
if (pfile->buffer[2] != ' ') return 9;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
file.buffer[3] = ' ';
eputs (file.buffer);
if (p[3] != ' ') return 10;
if (p[4] != '4') return 11;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
pfile->buffer[4] = ' ';
eputs (file.buffer);
if (p[4] != ' ') return 12;
if (p[5] != '5') return 13;
xfile.buffer = &buffer;
struct xfile *pxfile = &xfile;
strcpy (xfile.buffer, "0123456789\n");
eputs (xfile.buffer);
p = pxfile->buffer;
if (p[5] != '5') return 20;
if (xfile.buffer[5] != '5') return 22;
if (pxfile->buffer[5] != '5') return 23;
strcpy (xfile.buffer, "0123456789\n");
eputs (xfile.buffer);
memcpy (pxfile->buffer + 5, " ", 1);
eputs (xfile.buffer);
if (p[5] != ' ') return 24;
if (xfile.buffer[5] != ' ') return 25;
if (pxfile->buffer[5] != ' ') return 26;
strcpy (xfile.buffer, "0123456789\n");
eputs (xfile.buffer);
p[6] = ' ';
eputs (xfile.buffer);
if (p[6] != ' ') return 27;
if (xfile.buffer[6] != ' ') return 28;
if (pxfile->buffer[6] != ' ') return 29;
strcpy (xfile.buffer, "0123456789\n");
eputs (xfile.buffer);
xfile.buffer[7] = ' ';
eputs (xfile.buffer);
if (p[7] != ' ') return 30;
if (p[8] != '8') return 31;
strcpy (xfile.buffer, "0123456789\n");
eputs (xfile.buffer);
pxfile->buffer[8] = ' ';
eputs (xfile.buffer);
if (p[8] != ' ') return 32;
if (p[9] != '9') return 33;
short *ps;
ps = pfile->buffer;
p = pfile->buffer;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
memcpy (ps + 1, " ", 2);
eputs (file.buffer);
eputs (itoa (ps[1])); eputs ("\n");
eputs (itoa (((' ' << 8) + ' '))); eputs ("\n");
if (ps[1] != ((' ' << 8) + ' ')) return 40;
if (p[4] != '4') return 41;
strcpy (file.buffer, "0123456789\n");
eputs (file.buffer);
ps[2] = ((' ' << 8) + ' ');
eputs (file.buffer);
eputs (itoa (ps[2])); eputs ("\n");
eputs (itoa (((' ' << 8) + ' '))); eputs ("\n");
if (ps[2] != ((' ' << 8) + ' ')) return 42;
if (p[6] != '6') return 43;
return 0;
}