changeset 145:24efccba44e4

Remove tests
author David Demelier <markand@malikania.fr>
date Fri, 11 May 2012 00:37:38 +0200
parents 594ca7f7139b
children 5109083b4794
files ini.c tests/ini_test.c tests/ini_test.conf
diffstat 3 files changed, 11 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
--- a/ini.c	Fri May 11 00:12:08 2012 +0200
+++ b/ini.c	Fri May 11 00:37:38 2012 +0200
@@ -160,6 +160,12 @@
 		fputc('\n', stdout);
 	}
 
+	if (F_FAILERROR(cg)) {
+		va_start(ap, fmt);
+		vsnprintf(cg->pv->error, sizeof (cg->pv->error), fmt, ap);
+		va_end(ap);
+	}
+
 	va_end(ap);
 }
 
@@ -499,8 +505,12 @@
 	if (!cg && errno != 0)
 		return strerror(errno);
 
-	if (cg->pv->error[0] == '\0')
+	if (cg->pv->error[0] == '\0') {
+		if (errno != 0)
+			return strerror(errno);
+
 		return "No error";
+	}
 
 	return cg->pv->error;
 }
--- a/tests/ini_test.c	Fri May 11 00:12:08 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <string.h>
-#include <err.h>
-
-#include "ini.h"
-
-#define LENGTH(x)	(sizeof (x)/ sizeof (x[0]))
-
-/*
- * Use this test file with the ini_test.conf like this :
- *
- * #
- * # config file ini_test.conf
- * #
- * [general]
- * nickname	= "markand"
- * email	= "markand@malikania.fr"
- *
- * [ui]
- * verbose	= true
- * editor	= vim
- *
- * # multiple definition
- * [host]
- * alias	= "freenode"
- * host		= "irc.freenode.net"
- * port		= 6667
- *
- * [host]
- * alias	= "malikania"
- * host		= "irc.malikania.fr"
- * port		= 6667
- */
-
-static void
-list_servers(const INI_Config *config)
-{
-	/* Server parameters */
-	char *alias = NULL, *host = NULL;
-	int port = 0;
-
-	/* Extract server information */
-	INI_Handler settings[] = {
-		/* option,	destination,	conversion function	*/
-		{ "alias",	&alias,		&ini_convert_string	},
-		{ "host",	&host,		&ini_convert_string	},
-		{ "port",	&port,		&ini_convert_int	}
-	};
-
-	INI_Section *sc;
-
-	/*
-	 * All sections are added as linked list, so you can just
-	 * seek all and keep only the ones you want.
-	 */
-	for (sc = config->sections; sc != NULL; sc = sc->next) {
-		/* Keep only [host] */
-		if (strcmp(sc->key, "host") != 0)
-			continue;
-
-		ini_dispatch(sc, settings, LENGTH(settings));
-		printf("-- new server\n");
-		printf("-> alias = %s\n", (alias != NULL) ? alias : "<null>");
-		printf("-> host = %s\n", (host != NULL) ? host : "<null>");
-		printf("-> port = %d\n", port);
-
-		free(alias); alias = NULL;
-		free(host); host = NULL;
-	}
-}
-
-static void
-list_options(const INI_Config *config)
-{
-	char *nickname = NULL, *email = NULL, *editor = NULL;
-	bool verbose = 0;
-
-	/* Extract [general] to their values */
-	INI_Handler general[] = {
-		/* option,	destination,	conversion function	*/
-		{ "nickname",	&nickname,	&ini_convert_string	},
-		{ "email",	&email,		&ini_convert_string	}
-	};
-
-	/* Extract [ui] to their values */
-	INI_Handler ui[] = {
-		/* option,	destination,	conversion function	*/
-		{ "verbose",	&verbose,	&ini_convert_bool	},
-		{ "editor",	&editor,	&ini_convert_string	}
-	};
-
-	INI_Section *sc;
-
-	/* Always check if the section is present before dispatching */
-	if ((sc = ini_select_section(config, "general")) != NULL)
-		ini_dispatch(sc, general, LENGTH(general));
-	if ((sc = ini_select_section(config, "ui")) != NULL)
-		ini_dispatch(sc, ui, LENGTH(ui));
-
-	printf("-- general\n");
-	printf("-> nickname = %s\n", (nickname != NULL) ? nickname : "<null>");
-	printf("-> email = %s\n", (email != NULL) ? email : "<null>");
-	printf("-- ui\n");
-	printf("-> verbose = %s\n", (verbose) ? "true" : "false");
-	printf("-> editor = %s\n", (editor != NULL) ? editor : "<null>");
-
-	free(nickname); free(email); free(editor);
-}
-
-static void
-list_raw(const INI_Config *config)
-{
-	INI_Section *sc;
-	INI_Option *opt;
-
-	printf("-- dump of config\n");
-	for (sc = config->sections; sc != NULL; sc = sc->next)
-		for (opt = sc->options; opt != NULL; opt = opt->next)
-			printf("%s.%s = %s\n", sc->key, opt->key,
-			    (opt->value == NULL) ? "<null>" : opt->value);
-}
-
-int
-main(void)
-{
-	INI_Config *config;
-
-	/*
-	 * 1. Try to load the file, it may fails (not found, permissions,
-	 * memory, ...) so check everytime.
-	 *
-	 * INI_VERBOSE flag is great to tell the user about typo in file
-	 */
-	if ((config = ini_load("ini_test.conf", INI_VERBOSE)) == NULL)
-		errx(1, "%s", ini_get_error());
-
-	/* 2. List all servers found as [host] */
-	list_servers(config);
-
-	/* 3. List options from [general] and [ui] */
-	list_options(config);
-
-	/* 4. List all options from all sections */
-	list_raw(config);
-
-	/* Finally free everything */
-	ini_free(config, 1, 1);
-
-	return 0;
-}
--- a/tests/ini_test.conf	Fri May 11 00:12:08 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-#
-# config file ini_test.conf
-#
-[general]
-nickname	= "markand"
-email		= "markand@malikania.fr"
-
-[ui]
-verbose		= true
-editor		= vim
-
-# multiple definition
-[host]
-alias		= "freenode"
-host		= "irc.freenode.net"
-port		= 6667
-
-[host]
-alias		= "malikania"
-host		= "irc.malikania.fr"
-port		= 6667
-
-# vim: set syntax=cfg: