tests/plover/test-uri-handler.c
author J. Ali Harlow <ali@juiblex.co.uk>
Fri Jun 24 17:48:44 2016 +0100 (2016-06-24)
changeset 47 2d0ee44ab3c6
parent 43 6b3034a884dc
child 61 31fb35727621
permissions -rw-r--r--
Remove debugging
     1 /*
     2  * Copyright (C) 2009, 2011, 2016  J. Ali Harlow <ali@juiblex.co.uk>
     3  *
     4  * This program is free software; you can redistribute it and/or modify
     5  * it under the terms of the GNU General Public License as published by
     6  * the Free Software Foundation; either version 2 of the License, or
     7  * (at your option) any later version.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License along
    15  * with this program; if not, write to the Free Software Foundation, Inc.,
    16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    17  */
    18 
    19 #include <stdlib.h>
    20 #include <stdio.h>
    21 #include <string.h>
    22 #include <limits.h>
    23 #include <lua.h>
    24 #include "config.h"
    25 #include "plover/plover.h"
    26 #include "plover/uri-handler.h"
    27 #include "test-uri-handler-gresource.h"
    28 
    29 LUALIB_API int luaopen_posix(lua_State *L);
    30 
    31 void test_resource(void)
    32 {
    33     gchar *prefix,*root,*root_uri,*s;
    34     int ch,changed;
    35     struct comps *comps;
    36     struct comps_group *group;
    37     struct comps_requirement *pkg;
    38     struct plover_vector *packages=NULL;
    39     GError *error=NULL;
    40     GFile *file;
    41     test_uri_handler_register_resource();
    42     root=g_strdup("razor-test-dir-XXXXXX");
    43     g_assert(mkdtemp(root));
    44     file=g_file_new_for_path(root);
    45     root_uri=g_file_get_uri(file);
    46     g_object_unref(file);
    47     g_setenv("RAZOR_ROOT",root_uri,TRUE);
    48     g_free(root_uri);
    49     comps=plover_comps_new_from_uri(
    50       "resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
    51     if (!comps)
    52     {
    53 	perror("resource:///uk/co/juiblex/project/plover/repodata/comps.xml");
    54 	exit(1);
    55     }
    56     prefix=plover_default_prefix_for_vendor(comps->vendor);
    57     group=plover_comps_lookup_group(comps,"base");
    58     if (!group)
    59     {
    60 	fprintf(stderr,"No base group found in comps.xml\n");
    61 	exit(1);
    62     }
    63     packages=plover_vector_new();
    64     do
    65     {
    66 	changed=0;
    67 	for(pkg=group->packages;pkg;pkg=pkg->next)
    68 	{
    69 	    if (plover_vector_contains(packages,pkg->name))
    70 		continue;
    71 	    if (pkg->type==COMPS_REQUIREMENT_DEFAULT ||
    72 	      pkg->type==COMPS_REQUIREMENT_MANDATORY ||
    73 	      pkg->type==COMPS_REQUIREMENT_CONDITIONAL && (!pkg->requires ||
    74 	      plover_vector_contains(packages,pkg->requires)))
    75 	    {
    76 		changed++;
    77 		plover_vector_append(packages,pkg->name);
    78 	    }
    79 	}
    80     } while(changed);
    81     plover_comps_free(comps);
    82     if (!packages->len)
    83     {
    84 	fprintf(stderr,"No packages to install\n");
    85 	exit(1);
    86     }
    87     if (!plover_install_uri("resource:///uk/co/juiblex/project/plover",prefix,
    88       packages->strings,&error))
    89     {
    90 	fprintf(stderr,"%s\n",error->message);
    91 	g_error_free(error);
    92 	exit(1);
    93     }
    94     plover_vector_free(packages);
    95     g_free(prefix);
    96     g_unsetenv("RAZOR_ROOT");
    97     test_uri_handler_unregister_resource();
    98     s=g_build_filename(root,"usr/bin/zsh",NULL);
    99     g_free(root);
   100     if (!g_file_test(s,G_FILE_TEST_EXISTS))
   101 	g_error("%s: Missing file",s);
   102     g_free(s);
   103 }
   104 
   105 int main(int argc,char **argv)
   106 {
   107     int retval;
   108     razor_set_lua_loader("posix",(void (*)())luaopen_posix);
   109     g_test_init(&argc,&argv,NULL);
   110     g_test_bug_base("mailto:ali@juiblex.co.uk");
   111     g_test_add_func("/uri-handler/resource",test_resource);
   112     retval=g_test_run();
   113     return retval;
   114 }