Initial commit of libpnd 0.0.5 so we cna restart with GIT
[pandora-libraries.git] / test / conftest.c
1
2 #include <stdio.h> /* for printf, NULL */
3 #include <stdlib.h> /* for free */
4
5 #include "pnd_conf.h"
6 #include "pnd_container.h"
7 #include "pnd_apps.h"
8
9 int main ( void ) {
10
11   // attempt to fetch a sensible default searchpath for configs
12   char *configpath = pnd_conf_query_searchpath();
13   printf ( "Config searchpath is: '%s'\n", configpath );
14
15   // attempt to fetch the 'apps' config
16   pnd_conf_handle apph;
17
18   apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
19
20   if ( ! apph ) {
21     printf ( "Couldn't locate apps config!\n" );
22     return ( -1 );
23   }
24
25   // dump the config file
26   printf ( "Config file name is: '%s'\n", pnd_box_get_name ( apph ) );
27   char *value = pnd_box_get_head ( apph );
28   printf ( "Config has key '%s'\n", pnd_box_get_key ( value ) );
29   printf ( "Config has value '%s'\n", value );
30   while ( ( value = pnd_box_get_next ( value ) ) ) {
31     printf ( "Config has key '%s'\n", pnd_box_get_key ( value ) );
32     printf ( "Config has value '%s'\n", value );
33   }
34
35   // lets query the apps config
36   char *binpath;
37
38   binpath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
39
40   if ( ! binpath ) {
41     printf ( "Couldn't locate the app auto-discovery searchpath!\n" );
42     return ( -2 );
43   }
44
45   printf ( "Located auto-discovery searchpath '%s'\n", binpath );
46
47   // exeunt with alarums
48   free ( configpath );
49   pnd_box_delete ( apph );
50
51   return ( 0 );
52 }