Add a test for the MimeHandler class

This commit is contained in:
Pierre Pronchery 2017-12-07 17:52:30 +01:00
parent 94c0dae8a9
commit 66e2e16533
3 changed files with 72 additions and 4 deletions

60
tests/mimehandler.c Normal file
View File

@ -0,0 +1,60 @@
/* $Id$ */
/* Copyright (c) 2017 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS libDesktop */
/* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "../src/mimehandler.c"
/* main */
int main(void)
{
MimeHandler * handler;
char * path;
if((path = getcwd(NULL, 0)) == NULL)
return 2;
if(setenv("XDG_DATA_HOME", path, 1) != 0)
{
free(path);
return 3;
}
free(path);
if((handler = mimehandler_new_load("Root")) == NULL)
return 4;
if(mimehandler_get_type(handler) != MIME_HANDLER_TYPE_DIRECTORY)
{
mimehandler_delete(handler);
return 5;
}
mimehandler_delete(handler);
return 0;
}

View File

@ -1,4 +1,4 @@
targets=htmllint.log,tests.log,widget,xmllint.log
targets=htmllint.log,mimehandler,tests.log,widget,xmllint.log
cppflags_force=-I ../include
cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector-all
ldflags=-pie -Wl,-z,relro -Wl,-z,now
@ -8,17 +8,25 @@ ldflags_force=`pkg-config --libs libSystem gtk+-2.0` $(OBJDIR)../src/libDesktop.
#for Gtk+ 3
#cflags_force=`pkg-config --cflags libSystem gtk+-3.0`
#ldflags_force=`pkg-config --libs libSystem gtk+-3.0` $(OBJDIR)../src/libDesktop.a
dist=Makefile,htmllint.sh,pkgconfig.sh,tests.sh,xmllint.sh
dist=Makefile,applications/Root.desktop,htmllint.sh,pkgconfig.sh,tests.sh,xmllint.sh
[htmllint.log]
type=script
script=./htmllint.sh
depends=htmllint.sh
[mimehandler]
type=binary
sources=mimehandler.c
depends=applications/Root.desktop
[mimehandler.c]
depends=../src/mimehandler.c
[tests.log]
type=script
script=./tests.sh
depends=pkgconfig.sh,tests.sh
depends=$(OBJDIR)mimehandler$(EXEEXT),pkgconfig.sh,tests.sh
[widget]
type=binary

View File

@ -109,7 +109,7 @@ target="$1"
[ "$clean" -ne 0 ] && exit 0
tests="pkgconfig.sh"
tests="mimehandler pkgconfig.sh"
failures=
$DATE > "$target"