44 printf (
"initialised\n");
46 printf (
"destroyed\n");
53 TEST (configitem_simple)
57 LumieraConfigitem item;
59 item = lumiera_configitem_new (argv[2]);
62 printf (
"line = '%s'\n", item->line);
64 printf (
"key = '%.*s'\n", (
int)item->key_size, item->key);
67 printf (
"delim = '%c'\n", *item->delim);
68 printf (
"value = '%s'\n", item->delim+1);
71 lumiera_configitem_delete (item, NULL);
78 lumiera_config_lookup lookup;
81 LumieraConfigitem item = lumiera_configitem_new (
"foo.bar = test");
85 CHECK (found == item);
103 printf (
"failure setting first time '%s%s': %s\n", argv[2], argv[3],
lumiera_error ());
105 if (lumiera_config_get (argv[2], &value))
106 printf (
"%s\n", value);
108 printf (
"failure retrieving '%s': %s\n", argv[2],
lumiera_error ());
111 printf (
"failure setting second time '%s%s': %s\n", argv[2], argv[4],
lumiera_error ());
113 if (lumiera_config_get (argv[2], &value))
114 printf (
"%s\n", value);
116 printf (
"failure retrieving '%s': %s\n", argv[2],
lumiera_error ());
127 printf (
"failure setting first time '%s%s': %s\n", argv[2], argv[3],
lumiera_error ());
130 printf (
"failure setting second time '%s%s': %s\n", argv[2], argv[3],
lumiera_error ());
133 if (lumiera_config_get (argv[2], &value))
134 printf (
"%s\n", value);
136 printf (
"failure retrieving '%s': %s\n", argv[2],
lumiera_error ());
147 long long number = 0;
152 printf (
"%lld\n", number);
158 TEST (number_get_nodefault)
162 long long number = 0;
165 printf (
"%lld\n", number);
176 signed long long number = atoll (argv[3]);
178 if (!lumiera_config_number_set (argv[2], &number))
179 printf (
"failed setting number '%s=%lld': %s\n", argv[2], number,
lumiera_error ());
182 printf (
"'%lld'\n", number);
197 if (lumiera_config_string_get (argv[2], &
string))
198 printf (
"'%s'\n",
string);
209 if (!lumiera_config_string_set (argv[2], &argv[3]))
210 printf (
"failed setting string '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
213 if (lumiera_config_string_get (argv[2], &
string))
214 printf (
"'%s'\n",
string);
229 if (lumiera_config_word_get (argv[2], &word))
230 printf (
"'%s'\n", word);
243 if (!lumiera_config_word_set (argv[2], &argv[3]))
244 printf (
"failed setting word '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
247 if (lumiera_config_word_get (argv[2], &word))
248 printf (
"'%s'\n", word);
254 TEST (configitem_simple_ctor_dtor)
258 LumieraConfigitem item;
260 item = lumiera_configitem_new (argv[2]);
264 TEST (configitem_simple_content_check)
268 LumieraConfigitem item;
270 item = lumiera_configitem_new (argv[2]);
274 printf(
"item->line = '%s'\n", item->line);
276 if ( item->key_size )
278 printf(
"item->key_size = '%zi'\n", item->key_size);
282 printf(
"item->key = '%s'\n", item->key);
286 printf(
"item->delim = '%s'\n", item->delim);
291 TEST (wordlist_get_nth)
297 if (!lumiera_config_wordlist_set (argv[2], &argv[3]))
298 printf (
"failed setting word '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
302 printf (
"'%s'\n", word?word:
"NULL");
312 if (!lumiera_config_wordlist_set (argv[2], &argv[3]))
313 printf (
"failed setting word '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
317 printf (
"'%d'\n", n);
321 TEST (wordlist_replace)
329 if (!lumiera_config_wordlist_set (argv[2], &argv[3]))
330 printf (
"failed setting word '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
335 printf (
"'%s'\n", wordlist);
348 if (!lumiera_config_wordlist_set (argv[2], &argv[3]))
349 printf (
"failed setting word '%s=%s': %s\n", argv[2], argv[3],
lumiera_error ());
353 printf (
"'%s'\n", wordlist);
359 printf (
"'%s'\n", wordlist);
LumieraConfigLookupentry lumiera_config_lookup_insert(LumieraConfigLookup self, LumieraConfigitem item)
Add a config item to a lookup structure.
const char * lumiera_config_wordlist_replace(const char *key, const char *value, const char *subst1, const char *subst2, const char *delims)
Universal word replacement function.
Draft for a configuration system (2008).
LumieraConfigitem lumiera_config_lookup_item_find(LumieraConfigLookup self, const char *key)
Find a the topmost config item stored to a given key.
Helpers and support macros for defining test executables in C.
Interface for a lumiera configuration system (draft).
Round robin temporary buffers.
int lumiera_config_wordlist_find(const char *key, const char *value, const char *delims)
Find the index of a word in a wordlist.
LumieraConfigitem lumiera_config_setdefault(const char *line)
Installs a default value for a config key.
lumiera_err lumiera_error(void)
Get and clear current error state.
const char * lumiera_config_wordlist_get_nth(const char *key, unsigned nth, const char *delims)
return nth word of a wordlist
LumieraConfigitem lumiera_config_lookup_remove(LumieraConfigLookup self, LumieraConfigitem item)
Remove a config item from a lookup structure.
void lumiera_config_destroy()
Destroys the configuration subsystem.
LumieraConfigLookup lumiera_config_lookup_destroy(LumieraConfigLookup self)
Destroy a lookup structure.
const char * lumiera_config_number_get(const char *key, long long *value)
Number signed integer numbers, in different formats (decimal, hex, oct, binary(for masks)) ...
const char * lumiera_config_wordlist_add(const char *key, const char *value, const char *delims)
Add a word to the end of a wordlist if it doesn't exist already.
LumieraConfigLookup lumiera_config_lookup_init(LumieraConfigLookup self)
Initialise a lookup structure.
LumieraConfigitem lumiera_config_set(const char *key, const char *delim_value)
char * lumiera_tmpbuf_snprintf(size_t size, const char *fmt,...)
Construct a string in a tmpbuf.