Fix even more leaks
[pandora-libraries.git] / test / conftest.c
1
2 #include <stdio.h> /* for printf, NULL */
3 #include <stdlib.h> /* for free */
4 #include <string.h> /* for strlen */
5
6 #include "pnd_conf.h"
7 #include "pnd_container.h"
8 #include "pnd_apps.h"
9
10 int main ( int argc, char *argv[] ) {
11
12   // if an argument specified, try to load that one instead
13   if ( argc > 1 ) {
14     pnd_conf_handle h;
15     h = pnd_conf_fetch_by_path ( argv [ 1 ] );
16     char *i = pnd_box_get_head ( h );
17     printf ( "%s -> %s [%p:%d]\n", pnd_box_get_key ( i ), i, i, strlen ( i ) );
18     while ( ( i = pnd_box_get_next ( i ) ) ) {
19       printf ( "%s -> %s [%p:%d]\n", pnd_box_get_key ( i ), i, i, strlen ( i ) );
20     }
21
22     char *poop = pnd_conf_get_as_char ( h, "info.viewer_args" );
23     printf ( "info.viewer_args test: %s [%p:%d]\n", poop, poop, strlen ( poop ) );
24
25     exit ( 0 );
26   }
27
28   // attempt to fetch a sensible default searchpath for configs
29   char *configpath = pnd_conf_query_searchpath();
30   printf ( "Config searchpath is: '%s'\n", configpath );
31
32   // attempt to fetch the 'apps' config
33   pnd_conf_handle apph;
34
35   apph = pnd_conf_fetch_by_id ( pnd_conf_apps, configpath );
36
37   if ( ! apph ) {
38     printf ( "Couldn't locate apps config!\n" );
39     return ( -1 );
40   }
41
42   // dump the config file
43   printf ( "Config file name is: '%s'\n", pnd_box_get_name ( apph ) );
44   char *value = pnd_box_get_head ( apph );
45   printf ( "Config has key '%s'\n", pnd_box_get_key ( value ) );
46   printf ( "Config has value '%s'\n", value );
47   while ( ( value = pnd_box_get_next ( value ) ) ) {
48     printf ( "Config has key '%s'\n", pnd_box_get_key ( value ) );
49     printf ( "Config has value '%s'\n", value );
50   }
51
52   // lets query the apps config
53   char *binpath;
54
55   binpath = pnd_conf_get_as_char ( apph, PND_APPS_KEY );
56
57   if ( ! binpath ) {
58     printf ( "Couldn't locate the app auto-discovery searchpath!\n" );
59     return ( -2 );
60   }
61
62   printf ( "Located auto-discovery searchpath '%s'\n", binpath );
63
64   // exeunt with alarums
65   free ( configpath );
66   pnd_box_delete ( apph );
67
68   return ( 0 );
69 }