mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add test-fmemopen.
This commit is contained in:
parent
c428ec4d83
commit
dc73d0d7a1
2 changed files with 62 additions and 0 deletions
|
@ -14,6 +14,7 @@ BINARIES:=\
|
|||
regress \
|
||||
|
||||
TESTS:=\
|
||||
test-fmemopen \
|
||||
test-pthread-argv \
|
||||
test-pthread-basic \
|
||||
test-pthread-main-join \
|
||||
|
|
61
regress/test-fmemopen.c++
Normal file
61
regress/test-fmemopen.c++
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2014.
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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
|
||||
this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
test-fmemopen.c++
|
||||
Tests basic fmemopen() usage.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "test.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char* string = "VYl/plYoFGAg2";
|
||||
size_t string_length = strlen(string);
|
||||
|
||||
FILE* fp;
|
||||
int c;
|
||||
|
||||
unsigned char* buffer = (unsigned char*) string;
|
||||
size_t buffer_size = string_length;
|
||||
|
||||
if ( !(fp = fmemopen(buffer, buffer_size, "r")) )
|
||||
test_error(errno, "fmemopen");
|
||||
|
||||
for ( size_t i = 0; i < buffer_size; i++ )
|
||||
{
|
||||
c = fgetc(fp);
|
||||
test_assert(!(c == EOF && feof(fp)));
|
||||
test_assert(!(c == EOF && ferror(fp)));
|
||||
test_assert(c != EOF);
|
||||
test_assert((unsigned char) c == buffer[i]);
|
||||
test_assert(!feof(fp));
|
||||
test_assert(!ferror(fp));
|
||||
}
|
||||
|
||||
c = fgetc(fp);
|
||||
test_assert(c == EOF);
|
||||
test_assert(!ferror(fp));
|
||||
test_assert(feof(fp));
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue