2008-08-07 06:09:50 +02:00
|
|
|
/*
|
2008-08-13 08:35:31 +02:00
|
|
|
test-config.c - test the config system
|
2008-08-07 06:09:50 +02:00
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Christian Thaeter <ct@pipapo.org>
|
2008-08-13 08:35:31 +02:00
|
|
|
Simeon Voelkel <simeon_voelkel@arcor.de>
|
2008-08-07 06:09:50 +02:00
|
|
|
|
|
|
|
|
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; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
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, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
#include "lib/safeclib.h"
|
|
|
|
|
|
|
|
|
|
#include "backend/config.h"
|
2008-08-13 08:35:31 +02:00
|
|
|
#include "backend/configitem.h"
|
2008-08-07 06:09:50 +02:00
|
|
|
|
|
|
|
|
#include "tests/test.h"
|
|
|
|
|
|
|
|
|
|
TESTS_BEGIN
|
|
|
|
|
|
|
|
|
|
TEST ("init")
|
|
|
|
|
{
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
printf ("initialized\n");
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
printf ("destroyed\n");
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-07 11:43:06 +02:00
|
|
|
|
2008-08-17 00:35:40 +02:00
|
|
|
TEST ("configitem_simple")
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
LumieraConfigitem item;
|
|
|
|
|
|
|
|
|
|
item = lumiera_configitem_new (argv[2]);
|
|
|
|
|
ENSURE (item);
|
|
|
|
|
|
|
|
|
|
printf ("line = '%s'\n", item->line);
|
|
|
|
|
if (item->key)
|
|
|
|
|
printf ("key = '%.*s'\n", (int)item->key_size, item->key);
|
|
|
|
|
if (item->delim)
|
|
|
|
|
{
|
|
|
|
|
printf ("delim = '%c'\n", *item->delim);
|
|
|
|
|
printf ("value = '%s'\n", item->delim+1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lumiera_configitem_delete (item);
|
|
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST ("lookup")
|
|
|
|
|
{
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
lumiera_config_lookup lookup;
|
|
|
|
|
lumiera_config_lookup_init (&lookup);
|
|
|
|
|
|
|
|
|
|
LumieraConfigitem item = lumiera_configitem_new ("foo.bar = test");
|
|
|
|
|
lumiera_config_lookup_insert (&lookup, item);
|
|
|
|
|
|
2008-08-17 00:50:56 +02:00
|
|
|
LumieraConfigitem found = lumiera_config_lookup_item_find (&lookup, "foo.bar");
|
|
|
|
|
ENSURE (found == item);
|
2008-08-17 00:35:40 +02:00
|
|
|
|
2008-08-17 00:50:56 +02:00
|
|
|
lumiera_config_lookup_remove (&lookup, found);
|
|
|
|
|
ENSURE (!lumiera_config_lookup_item_find (&lookup, "foo.bar"));
|
2008-08-17 00:35:40 +02:00
|
|
|
|
|
|
|
|
lumiera_config_lookup_destroy (&lookup);
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-07 11:43:06 +02:00
|
|
|
TEST ("number_get")
|
|
|
|
|
{
|
2008-08-07 14:55:17 +02:00
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
REQUIRE (argv[3]);
|
|
|
|
|
|
2008-08-07 11:43:06 +02:00
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
long long number = 0;
|
|
|
|
|
|
2008-08-07 14:55:17 +02:00
|
|
|
if (!lumiera_config_number_get (argv[2], &number, argv[3]))
|
2008-08-07 11:43:06 +02:00
|
|
|
printf ("%lld\n", number);
|
|
|
|
|
else
|
2008-08-08 08:21:38 +02:00
|
|
|
printf ("%s, %lld\n", lumiera_error (), number);
|
2008-08-07 11:43:06 +02:00
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST ("number_get_nodefault")
|
|
|
|
|
{
|
2008-08-07 14:55:17 +02:00
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
|
2008-08-07 11:43:06 +02:00
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
long long number = 0;
|
|
|
|
|
|
2008-08-07 14:55:17 +02:00
|
|
|
if (!lumiera_config_number_get (argv[2], &number, NULL))
|
2008-08-07 11:43:06 +02:00
|
|
|
printf ("%lld\n", number);
|
|
|
|
|
else
|
|
|
|
|
printf ("%s\n", lumiera_error ());
|
|
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-08 08:28:07 +02:00
|
|
|
|
|
|
|
|
TEST ("string_get")
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
REQUIRE (argv[3]);
|
|
|
|
|
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
char* string;
|
|
|
|
|
|
|
|
|
|
if (!lumiera_config_string_get (argv[2], &string, argv[3]))
|
|
|
|
|
printf ("'%s'\n", string);
|
|
|
|
|
else
|
|
|
|
|
printf ("%s, '%s'\n", lumiera_error (), string);
|
|
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-10 11:52:24 +02:00
|
|
|
TEST ("string_set")
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
REQUIRE (argv[3]);
|
|
|
|
|
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
lumiera_config_string_set (argv[2], &argv[3], NULL);
|
|
|
|
|
FIXME ("handle error");
|
|
|
|
|
|
|
|
|
|
const char* string;
|
|
|
|
|
if (!lumiera_config_get (argv[2], &string))
|
|
|
|
|
printf ("'%s'\n", string);
|
|
|
|
|
else
|
|
|
|
|
printf ("%s, '%s'\n", lumiera_error (), string);
|
|
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST ("word_get")
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (argv[2]);
|
|
|
|
|
REQUIRE (argv[3]);
|
|
|
|
|
|
|
|
|
|
lumiera_config_init ("./");
|
|
|
|
|
|
|
|
|
|
char* word;
|
|
|
|
|
|
|
|
|
|
if (!lumiera_config_word_get (argv[2], &word, argv[3]))
|
|
|
|
|
printf ("'%s'\n", word);
|
|
|
|
|
else
|
|
|
|
|
printf ("%s, '%s'\n", lumiera_error (), word);
|
|
|
|
|
|
|
|
|
|
lumiera_config_destroy ();
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-07 06:09:50 +02:00
|
|
|
TESTS_END
|