Allow parse_dotdesktop() to mark libpnd origin or not, and convenience filter to...
[pandora-libraries.git] / test / discotest.c
index 6254539..985968c 100644 (file)
@@ -1,13 +1,16 @@
 
 #include <stdio.h> /* for printf, NULL */
 #include <stdlib.h> /* for free */
+#include <string.h> /* for strdup */
 
 #include "pnd_conf.h"
 #include "pnd_container.h"
 #include "pnd_apps.h"
 #include "pnd_pxml.h"
 #include "pnd_discovery.h"
+#include "pnd_desktop.h"
 #include "pnd_locate.h"
+#include "pnd_utility.h"
 
 int main ( int argc, char *argv[] ) {
   char *configpath;
@@ -17,6 +20,7 @@ int main ( int argc, char *argv[] ) {
   unsigned char do_exec = 0;
   unsigned char do_icon = 0;
   unsigned char do_dotdesktop = 0;
+  char dotdesktoppath [ 1024 ] = "";
 
   for ( i = 1; i < argc; i++ ) {
 
@@ -29,11 +33,15 @@ int main ( int argc, char *argv[] ) {
     } else if ( argv [ i ][ 0 ] == '-' && argv [ i ][ 1 ] == 'd' ) {
       printf ( "Will attempt to extract dotdesktop.\n" );
       do_dotdesktop = 1;
+    } else if ( strstr ( argv [ i ], ".desktop" ) ) {
+      strncpy ( dotdesktoppath, argv [ i ], 1023 );
+      printf ( "Will scan '%s' instead of performing discovery\n", dotdesktoppath );
     } else {
-      printf ( "%s [-e] [-i] [-d]\n", argv [ 0 ] );
+      printf ( "%s [-e] [-i] [-d] [dotdesktop-file]\n", argv [ 0 ] );
       printf ( "-e\tOptional. Attempt to exec a random app.\n" );
       printf ( "-i\tOptional. Attempt to dump icon files from the end of pnd's to ./testdata/dotdesktop.\n" );
       printf ( "-d\tOptional. Attempt to dump dotdesktop files from the end of pnd's to ./testdata/dotdesktop.\n" );
+      printf ( "dotdesktop-file\tIf path specified and ends with .desktop, try to scan that .desktop instead of pnd-discovery\n" );
       exit ( 0 );
     }
 
@@ -106,7 +114,17 @@ int main ( int argc, char *argv[] ) {
    */
   pnd_box_handle applist;
 
-  applist = pnd_disco_search ( appspath, overridespath );
+  if ( dotdesktoppath [ 0 ] ) {
+    pnd_disco_t *p = pnd_parse_dotdesktop ( dotdesktoppath, PND_DOTDESKTOP_LIBPND_ONLY );
+    pnd_box_handle disco_box = pnd_box_new ( "discovery" );
+    if ( p ) {
+      pnd_disco_t *ai = pnd_box_allocinsert ( disco_box, dotdesktoppath, sizeof(pnd_disco_t) );
+      memmove ( ai, p, sizeof(pnd_disco_t) );
+    }
+    applist = disco_box;
+  } else {
+    applist = pnd_disco_search ( appspath, overridespath );
+  }
 
   // list the found apps (if any)
 
@@ -122,7 +140,10 @@ int main ( int argc, char *argv[] ) {
       printf ( "  Base path: %s filename: %s\n", d -> object_path, d -> object_filename );
 
       if ( d -> title_en ) {
-       printf ( "  Name: %s\n", d -> title_en );
+       printf ( "  Name EN: %s\n", d -> title_en );
+      }
+      if ( d -> desc_en ) {
+       printf ( "  Desc EN: %s\n", d -> desc_en );
       }
       if ( d -> icon ) {
        printf ( "  Icon: %s\n", d -> icon );
@@ -145,20 +166,50 @@ int main ( int argc, char *argv[] ) {
       if ( d -> clockspeed ) {
        printf ( "  Clockspeed: %s\n", d -> clockspeed );
       }
-
-      if ( do_dotdesktop ) {
-       pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d );
+      if ( d -> preview_pic1 ) {
+       printf ( "  Preview Pic 1: %s\n", d -> preview_pic1 );
+      }
+      if ( d -> preview_pic2 ) {
+       printf ( "  Preview Pic 2: %s\n", d -> preview_pic2 );
+      }
+      if ( d -> mkdir_sp ) {
+       printf ( "  mkdir requests: %s\n", d -> mkdir_sp );
       }
 
       if ( do_icon ) {
-       pnd_emit_icon ( "./testdata/dotdesktop", d );
+       if ( pnd_emit_icon ( "./testdata/dotdesktop", d ) ) {
+         printf ( "  -> icon dump succeeded\n" );
+
+         // fix up icon path to new one..
+         free ( d -> icon );
+         char buffer [ FILENAME_MAX ];
+         sprintf ( buffer, "%s/%s.png", "discotest-temp/", d -> unique_id );
+         d -> icon = strdup ( buffer );
+
+       } else {
+         printf ( "  -> icon dump failed\n" );
+       }
       }
 
+      if ( do_dotdesktop ) {
+       if ( pnd_emit_dotdesktop ( "./testdata/dotdesktop", pndrun, d ) ) {
+         printf ( "  -> dotdesktop dump succeeded\n" );
+       } else {
+         printf ( "  -> dotdesktop dump failed\n" );
+       }
+      }
+
+      // free current disco <o/
+      pnd_disco_destroy( d );
+
       // next!
       d = pnd_box_get_next ( d );
 
     } // while applist
 
+    // delete our search
+    pnd_box_delete( applist );
+
   } else {
     printf ( "No applications found in search path\n" );
   }
@@ -182,8 +233,19 @@ int main ( int argc, char *argv[] ) {
          } else if ( d -> object_type == pnd_object_type_pnd ) {
            sprintf ( fullpath, "%s/%s", d -> object_path, d -> object_filename );
          }
+
+         printf ( "Guessing appdata path..\n" );
+         char appdata_path [ 1024 ];
+         pnd_get_ro_mountpoint ( fullpath, d -> unique_id, appdata_path, 1024 );
+         printf ( "Guessed readonly app mountpoint '%s'\n", appdata_path );
+         if ( pnd_get_appdata_path ( fullpath, d -> unique_id, appdata_path, 1024 ) ) {
+           printf ( "  Appdata should be: %s\n", appdata_path );
+         } else {
+           printf ( "  Error determining appdata path..\n" );
+         }
+
          printf ( "Trying to exec '%s'\n", fullpath );
-         pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, atoi ( d -> clockspeed ) );
+         pnd_apps_exec ( pndrun, fullpath, d -> unique_id, d -> exec, d -> startdir, NULL, atoi ( d -> clockspeed ), PND_EXEC_OPTION_BLOCK );
        }
       }
 
@@ -197,5 +259,12 @@ int main ( int argc, char *argv[] ) {
     pnd_box_delete ( apph );
   }
 
+  // extra testing - tilde-substitution
+  printf ( "Unrelated test..\n" );
+  char *p = strdup ( "~/.applications" );
+  printf ( "Tilde substitution: in '%s'\n", p );
+  char *expand = pnd_expand_tilde ( p );
+  printf ( "                   out '%s'\n", expand ); free(expand);
+
   return ( 0 );
 }