Browse Source

Add a little program to test reading from a file using IsoFileSource.

release-1.5.4.branch
Vreixo Formoso 14 years ago
parent
commit
db533b2d99
  1. 1
      .bzrignore
  2. 7
      Makefile.am
  3. 72
      test/cat.c
  4. 14
      test/lsl.c

1
.bzrignore

@ -22,3 +22,4 @@ test/iso
*.lo
*.la
./test/lsl
./test/cat

7
Makefile.am

@ -24,12 +24,17 @@ libinclude_HEADERS = \
## Build test applications
noinst_PROGRAMS = \
test/lsl
test/lsl \
test/cat
test_lsl_CPPFLAGS = -Isrc
test_lsl_LDADD = $(src_libisofs_la_OBJECTS) $(THREAD_LIBS)
test_lsl_SOURCES = test/lsl.c
test_cat_CPPFLAGS = -Isrc
test_cat_LDADD = $(src_libisofs_la_OBJECTS) $(THREAD_LIBS)
test_cat_SOURCES = test/cat.c
## Build unit test

72
test/cat.c

@ -0,0 +1,72 @@
/*
* Copyright (c) 2007 Vreixo Formoso
*
* This file is part of the libisofs project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See COPYING file for details.
*/
#include "libisofs.h"
#include "fsource.h"
#include <stdio.h>
#include <stdlib.h>
/*
* Little test program to test filesystem implementations.
* Outputs file contents to stdout!
*/
int main(int argc, char **argv)
{
int res;
IsoFilesystem *fs;
IsoFileSource *file;
struct stat info;
if (argc != 2) {
fprintf(stderr, "Usage: cat /path/to/file\n");
return 1;
}
/* create filesystem object */
res = iso_local_filesystem_new(&fs);
if (res < 0) {
fprintf(stderr, "Can't get local fs object, err = %d\n", res);
return 1;
}
res = fs->get_by_path(fs, argv[1], &file);
if (res < 0) {
fprintf(stderr, "Can't get file, err = %d\n", res);
return 1;
}
res = file->lstat(file, &info);
if (res < 0) {
fprintf(stderr, "Can't stat file, err = %d\n", res);
return 1;
}
if (S_ISDIR(info.st_mode)) {
fprintf(stderr, "Path refers to a directory!!\n");
return 1;
} else {
char buf[1024];
res = file->open(file);
if (res < 0) {
fprintf(stderr, "Can't open file, err = %d\n", res);
return 1;
}
while ((res = file->read(file, buf, 1024)) > 0) {
fwrite(buf, 1, res, stdout);
}
if (res < 0) {
fprintf(stderr, "Error reading, err = %d\n", res);
return 1;
}
file->close(file);
}
return 0;
}

14
test/lsl.c

@ -11,6 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
/*
* Little test program to test filesystem implementations.
@ -40,8 +41,6 @@ print_permissions(mode_t mode)
static void
print_type(mode_t mode)
{
char type[1];
switch(mode & S_IFMT) {
case S_IFSOCK: printf("[S] "); break;
case S_IFLNK: printf("[L] "); break;
@ -61,8 +60,14 @@ print_file_src(IsoFileSource *file)
print_type(info.st_mode);
print_permissions(info.st_mode);
name = file->get_name(file);
printf(" %s\n", name);
printf(" %s", name);
free(name);
if (S_ISLNK(info.st_mode)) {
char buf[PATH_MAX];
file->readlink(file, buf, PATH_MAX);
printf(" -> %s\n", buf);
}
printf("\n");
}
int main(int argc, char **argv)
@ -74,7 +79,7 @@ int main(int argc, char **argv)
struct stat info;
if (argc != 2) {
fprintf(stderr, "Usage: iso /path/to/dir\n");
fprintf(stderr, "Usage: lsl /path/to/file\n");
return 1;
}
@ -97,7 +102,6 @@ int main(int argc, char **argv)
return 1;
}
//TODO check dir vs file
if (S_ISDIR(info.st_mode)) {
res = dir->open(dir);
if (res < 0) {

Loading…
Cancel
Save