test: Add open-read test.

* build-aux/test-c.sh: Support running by hand.
* lib/tests/posix/50-open-read.c: New test.
* lib/tests/posix/data/open-read: New file.
* build-aux/check-mescc.sh (TESTS): Add it.
This commit is contained in:
Jan Nieuwenhuizen 2019-06-26 21:55:44 +02:00
parent e927a60648
commit c83584f85f
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 61 additions and 1 deletions

View file

@ -105,6 +105,7 @@ lib/tests/stdlib/50-malloc.c
lib/tests/string/50-strcmp.c
lib/tests/string/50-strcpy.c
lib/tests/string/50-strncmp.c
lib/tests/posix/50-open-read.c
lib/tests/scaffold/51-pointer-sub.c
lib/tests/scaffold/54-argc.c
lib/tests/scaffold/54-argv.c

View file

@ -20,6 +20,10 @@
set -e
if test -z "$config_sh"; then
. ./config.sh
fi
if [ "$V" = 2 ]; then
set -x
fi
@ -29,7 +33,7 @@ b=$(dirname "$t")/$(basename "$t" .c)
o="$b"
o=lib/tests/${b#*lib/tests/}
if [ "$o" = "$b" ]; then
o=$(basename "$t" .c)
o=./$(basename "$t" .c)
fi
rm -f "$o"

View file

@ -0,0 +1,54 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2019 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/>.
*/
#include <mes/lib.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main (int argc, char const *argv[])
{
eputs ("test:getenv\n");
char file_name[PATH_MAX];
char *srcdir = getenv ("srcdir");
if (!srcdir)
return 1;
strcpy (file_name, srcdir);
strcpy (file_name + strlen (srcdir), "/lib/tests/posix/data/open-read");
eputs ("test open:");
eputs (file_name);
eputs ("\n");
int filedes = open (file_name, 0, 0);
if (filedes <= 2)
return 2;
char buf[20];
int n = read (filedes, buf, sizeof (buf));
if (n != 5)
return 3;
if (strcmp (buf, "hello"))
return 4;
eputs ("test read: ");
eputs (buf);
eputs ("\n");
return 0;
}

View file

@ -0,0 +1 @@
hello