Add a test for the <Browser/VFS.h> API

This commit is contained in:
Pierre Pronchery 2015-04-03 23:34:45 +02:00
parent 641898cb57
commit 5c069a7c54
5 changed files with 96 additions and 5 deletions

View File

@ -114,6 +114,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/plugins/common.c \ $(PACKAGE)-$(VERSION)/src/plugins/common.c \
$(PACKAGE)-$(VERSION)/src/plugins/project.conf \ $(PACKAGE)-$(VERSION)/src/plugins/project.conf \
$(PACKAGE)-$(VERSION)/tests/plugins.c \ $(PACKAGE)-$(VERSION)/tests/plugins.c \
$(PACKAGE)-$(VERSION)/tests/vfs.c \
$(PACKAGE)-$(VERSION)/tests/Makefile \ $(PACKAGE)-$(VERSION)/tests/Makefile \
$(PACKAGE)-$(VERSION)/tests/tests.sh \ $(PACKAGE)-$(VERSION)/tests/tests.sh \
$(PACKAGE)-$(VERSION)/tests/project.conf \ $(PACKAGE)-$(VERSION)/tests/project.conf \

View File

@ -1,4 +1,4 @@
TARGETS = $(OBJDIR)plugins $(OBJDIR)tests.log TARGETS = $(OBJDIR)plugins $(OBJDIR)vfs $(OBJDIR)tests.log
OBJDIR = OBJDIR =
PREFIX = /usr/local PREFIX = /usr/local
DESTDIR = DESTDIR =
@ -25,14 +25,24 @@ plugins_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
$(OBJDIR)plugins: $(plugins_OBJS) $(OBJDIR)plugins: $(plugins_OBJS)
$(CC) -o $(OBJDIR)plugins $(plugins_OBJS) $(plugins_LDFLAGS) $(CC) -o $(OBJDIR)plugins $(plugins_OBJS) $(plugins_LDFLAGS)
$(OBJDIR)tests.log: plugins tests.sh vfs_OBJS = $(OBJDIR)vfs.o
vfs_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
vfs_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L../src -Wl,-rpath,../src -lBrowser
$(OBJDIR)vfs: $(vfs_OBJS)
$(CC) -o $(OBJDIR)vfs $(vfs_OBJS) $(vfs_LDFLAGS)
$(OBJDIR)tests.log: plugins vfs tests.sh
./tests.sh -P "$(PREFIX)" -- "$(OBJDIR)tests.log" ./tests.sh -P "$(PREFIX)" -- "$(OBJDIR)tests.log"
$(OBJDIR)plugins.o: plugins.c $(OBJDIR)plugins.o: plugins.c
$(CC) $(plugins_CFLAGS) -o $(OBJDIR)plugins.o -c plugins.c $(CC) $(plugins_CFLAGS) -o $(OBJDIR)plugins.o -c plugins.c
$(OBJDIR)vfs.o: vfs.c
$(CC) $(vfs_CFLAGS) -o $(OBJDIR)vfs.o -c vfs.c
clean: clean:
$(RM) -- $(plugins_OBJS) $(tests.log_OBJS) $(RM) -- $(plugins_OBJS) $(vfs_OBJS) $(tests.log_OBJS)
./tests.sh -c -P "$(PREFIX)" -- "tests.log" ./tests.sh -c -P "$(PREFIX)" -- "tests.log"
distclean: clean distclean: clean

View File

@ -1,4 +1,4 @@
targets=plugins,tests.log targets=plugins,vfs,tests.log
cppflags_force=-I ../include cppflags_force=-I ../include
cflags_force=-W `pkg-config --cflags libDesktop` cflags_force=-W `pkg-config --cflags libDesktop`
cflags=-Wall -g -O2 cflags=-Wall -g -O2
@ -9,7 +9,12 @@ dist=Makefile,tests.sh
type=binary type=binary
sources=plugins.c sources=plugins.c
[vfs]
type=binary
ldflags=-L../src -Wl,-rpath,../src -lBrowser
sources=vfs.c
[tests.log] [tests.log]
type=script type=script
script=./tests.sh script=./tests.sh
depends=plugins,tests.sh depends=plugins,vfs,tests.sh

View File

@ -100,6 +100,7 @@ $DATE > "$target"
FAILED= FAILED=
echo "Performing tests:" 1>&2 echo "Performing tests:" 1>&2
_test "plugins" _test "plugins"
_test "vfs"
#echo "Expected failures:" 1>&2 #echo "Expected failures:" 1>&2
#_fail "plugins" #_fail "plugins"
if [ -n "$FAILED" ]; then if [ -n "$FAILED" ]; then

74
tests/vfs.c Normal file
View File

@ -0,0 +1,74 @@
/* $Id$ */
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Browser */
/* 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, version 3 of the License.
*
* 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/>. */
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <Desktop/mime.h>
#include "Browser/vfs.h"
/* vfs */
static int _vfs(void)
{
int ret = 0;
Mime * mime;
char const downloads[] = "/home/user/Downloads";
char const * type;
GdkPixbuf * icon;
if((mime = mime_new(NULL)) == NULL)
return -1;
if((type = browser_vfs_mime_type(mime, downloads, S_IFDIR)) == NULL
|| strcmp(type, "inode/directory") != 0)
ret = -1;
else
printf("%s\n", type);
if((icon = browser_vfs_mime_icon(mime, downloads, type, NULL, NULL, 48))
!= NULL)
g_object_unref(icon);
mime_delete(mime);
return ret;
}
/* usage */
static int _usage(void)
{
fputs("Usage: vfs\n", stderr);
return 1;
}
/* main */
int main(int argc, char * argv[])
{
int o;
gtk_init(&argc, &argv);
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{
default:
return _usage();
}
if(optind != argc)
return _usage();
return (_vfs() == 0) ? 0 : 2;
}