Enforce numeric application IDs
[src/app-framework-main.git] / src / tests / test-unit / test-unit.c
index 09b7c86..a879a12 100644 (file)
@@ -1,5 +1,5 @@
 /*
- Copyright 2016, 2017 IoT.bzh
+ Copyright (C) 2016-2019 IoT.bzh
 
  author: José Bollo <jose.bollo@iot.bzh>
 
@@ -36,7 +36,7 @@
 
 
 
-static int process1(const struct unitdesc *desc)
+static int processunit(const struct unitdesc *desc)
 {
        int isuser = desc->scope == unitscope_user;
        int issystem = desc->scope == unitscope_system;
@@ -46,25 +46,42 @@ static int process1(const struct unitdesc *desc)
        const char *content = desc->content;
 
 printf("\n##########################################################");
-printf("\n### usr=%d sys=%d soc=%d srv=%d    name  %s%s", isuser, issystem, issock, isserv, name?:"?", issock?".socket":isserv?".service":"");
+printf("\n### usr=%d sys=%d soc=%d srv=%d    name  %s%s", isuser, issystem, issock,
+                       isserv, name?:"?", issock?".socket":isserv?".service":"");
 printf("\n##########################################################");
 printf("\n%s\n\n",content);
        return 0;
 }
 
-static int process(void *closure, const struct unitdesc descs[], unsigned count)
+static int process(void *closure, const struct generatedesc *desc)
 {
-       while (count--)
-               process1(descs++);
+       int i;
+printf("\n##########################################################");
+printf("\n###### J S O N D E S C    AFTER                    #######");
+printf("\n##########################################################");
+puts(json_object_to_json_string_ext(desc->desc, JSON_C_TO_STRING_PRETTY));
+       for (i = 0 ; i < desc->nunits ; i++)
+               processunit(&desc->units[i]);
        return 0;
 }
 
+static int new_afid()
+{
+       static int r = 1;
+       return r++;
+}
+
 int main(int ac, char **av)
 {
+       struct unitconf conf;
        struct json_object *obj;
        int rc;
 
-       rc = unit_generator_on(*++av);
+       conf.installdir = "INSTALL-DIR";
+       conf.icondir = "ICONS-DIR";
+       conf.new_afid = new_afid;
+       conf.base_http_ports = 20000;
+       rc = unit_generator_open_template(*++av);
        if (rc < 0)
                error("can't read template %s: %m",*av);
        while(*++av) {
@@ -72,13 +89,11 @@ int main(int ac, char **av)
                if (!obj)
                        error("can't read widget config at %s: %m",*av);
 
-               j_add_string_m(obj, "#metadata.install-dir", "INSTALL-DIR");
-               j_add_string_m(obj, "#metadata.app-data-dir", "%h/app-data");
-               j_add_string_m(obj, "#metadata.icons-dir", "ICONS-DIR");
-               j_add_string_m(obj, "#metadata.http-port", "HTTP-PORT");
-
-               puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY));
-               rc = unit_generator_process(obj, process, NULL);
+printf("\n##########################################################");
+printf("\n###### J S O N D E S C    BEFORE                   #######");
+printf("\n##########################################################");
+puts(json_object_to_json_string_ext(obj, JSON_C_TO_STRING_PRETTY));
+               rc = unit_generator_process(obj, &conf, process, NULL);
                if (rc)
                        error("can't apply generate units, error %d",rc);
                json_object_put(obj);