HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#include <errno.h>
#include <pcut/pcut.h>
#include <stdio.h>
#include <str.h>
#include <tmpfile.h>
#include <vfs/vfs.h>
PCUT_INIT;
PCUT_TEST_SUITE(stdio);
PCUT_TEST(remove)
{
char buf[L_tmpnam];
char *p;
FILE *f;
int rc;
p = tmpnam(buf);
PCUT_ASSERT_NOT_NULL(p);
rc = remove(buf);
PCUT_ASSERT_TRUE(rc != 0);
f = fopen(buf, "wx");
PCUT_ASSERT_NOT_NULL(f);
fclose(f);
rc = remove(buf);
PCUT_ASSERT_INT_EQUALS(0, rc);
rc = remove(buf);
PCUT_ASSERT_TRUE(rc != 0);
}
PCUT_TEST(rename)
{
char buf1[L_tmpnam];
char buf2[L_tmpnam];
char *p;
FILE *f;
int rc;
p = tmpnam(buf1);
PCUT_ASSERT_NOT_NULL(p);
p = tmpnam(buf2);
PCUT_ASSERT_NOT_NULL(p);
f = fopen(buf1, "wx");
PCUT_ASSERT_NOT_NULL(f);
fclose(f);
rc = rename(buf1, buf2);
PCUT_ASSERT_INT_EQUALS(0, rc);
rc = remove(buf1);
PCUT_ASSERT_TRUE(rc != 0);
rc = remove(buf2);
PCUT_ASSERT_INT_EQUALS(0, rc);
}
PCUT_TEST(tmpfile)
{
FILE *f;
char c;
size_t n;
f = tmpfile();
PCUT_ASSERT_NOT_NULL(f);
c = 'x';
n = fwrite(&c, sizeof(c), 1, f);
PCUT_ASSERT_INT_EQUALS(1, n);
rewind(f);
c = '\0';
n = fread(&c, sizeof(c), 1, f);
PCUT_ASSERT_INT_EQUALS(1, n);
PCUT_ASSERT_INT_EQUALS('x', c);
fclose(f);
}
PCUT_TEST(tmpnam_buf)
{
char buf[L_tmpnam];
char *p;
FILE *f;
p = tmpnam(buf);
PCUT_ASSERT_NOT_NULL(p);
f = fopen(p, "w+x");
PCUT_ASSERT_NOT_NULL(f);
(void) remove(p);
fclose(f);
}
PCUT_TEST(tmpnam_twice)
{
char buf1[L_tmpnam];
char buf2[L_tmpnam];
char *p;
p = tmpnam(buf1);
PCUT_ASSERT_NOT_NULL(p);
p = tmpnam(buf2);
PCUT_ASSERT_NOT_NULL(p);
PCUT_ASSERT_TRUE(str_cmp(buf1, buf2) != 0);
}
PCUT_TEST(tmpnam_null)
{
char *p;
FILE *f;
p = tmpnam(NULL);
PCUT_ASSERT_NOT_NULL(p);
f = fopen(p, "w+x");
PCUT_ASSERT_NOT_NULL(f);
(void) remove(p);
fclose(f);
}
PCUT_TEST(fgetpos_setpos)
{
fpos_t pos;
int rc;
FILE *f;
f = tmpfile();
PCUT_ASSERT_NOT_NULL(f);
rc = fputs("abc", f);
PCUT_ASSERT_TRUE(rc >= 0);
rc = fgetpos(f, &pos);
PCUT_ASSERT_TRUE(rc >= 0);
rewind(f);
rc = fsetpos(f, &pos);
PCUT_ASSERT_TRUE(rc >= 0);
(void) fclose(f);
}
PCUT_TEST(perror_null_msg)
{
errno = EINVAL;
perror(NULL);
}
PCUT_TEST(perror_empty_msg)
{
errno = EINVAL;
perror("");
}
PCUT_TEST(perror_msg)
{
errno = EINVAL;
perror("This is a test");
}
PCUT_EXPORT(stdio);
HelenOS homepage, sources at GitHub