tests/plover/test-uri-handler.c
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Jul 16 11:07:18 2016 +0100 (2016-07-16)
changeset 61 31fb35727621
parent 44 43ffed8669ce
permissions -rw-r--r--
Support parallel installations. The idea is that for CAD screener, we want
to be able to install this on the same machine as a standard AVOT setup
(most notably for John's laptop). To allow for the possibility of a second
application that might have the same requirements, we add the concept of
vendor-specific distributions. Thus we can have one distribution for CAD
screener and one for The Next Big Thing. It doesn't seem trivial to have
both CAD screener and AVOT under the same vendor tag so we'll have to have
AVOT under "City Occupational" and CAD screener under "City Occupational Ltd"
or some such kludge.

Most of this is done although we are very short of test cases (in particular
we don't test that it's actually possible to install CAD screener in parallel
with AVOT or to update either of them once installed, which is fundamental).

We also have a lot of baggage left over, including an intercept of razor_set.
The problem that this was introduced to debug has been fixed but it looks
like there are a number of memory leaks which it might be useful to help
track down so it has been left in place for now.

There is still a lot of confusion in plover between path-based and URI-based
API. We should review the API, decide what we want and have a general clear up.

There is also confusion as to the purpose of RAZOR_ROOT (and meaning; path or
URI). This is not used at all in librazor (although it is used in razor.exe).
Ideally we shouldn't use it in plover or plover-gtk either although again, we
might want to support it or an equivalent in (some of) the various executables.

Work that would still to nice to do for CAD screener:

- uninstall (ideally as an installed program that hooks into Add/Remove programs
but even re-running the installer would be acceptable).
- xz support (smaller packages).
- repomd.xml and xml:base (would be needed for an Internet installer).
- graphical installer.
     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",&error);
    51     if (!comps)
    52     {
    53 	fprintf(stderr,"%s\n",error->message);
    54 	exit(1);
    55     }
    56     prefix=plover_comps_get_default_prefix(comps);
    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 }