Added test mockup
[oweals/gnunet.git] / src / mesh / test_mesh_api.c
1 #include "platform.h"
2 #include "gnunet_util_lib.h"
3 #include "gnunet_dht_service.h"
4 #include "gnunet_mesh_service_new.h"
5
6 static struct GNUNET_MESH_MessageHandler handlers[] = {
7     {NULL, 0, 0}
8 };
9
10 static void
11 run (void *cls,
12      char *const *args,
13      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
14     struct GNUNET_OS_Process            *arm_pid;
15     struct GNUNET_MESH_Handle           *mesh;
16     struct GNUNET_DHT_Handle            *dht;
17 //     struct GNUNET_MESH_Tunnel           *t;
18
19
20     arm_pid = GNUNET_OS_start_process (NULL, NULL,
21                                        "gnunet-service-arm",
22                                        "gnunet-service-arm",
23                                        "-L", "DEBUG",
24                                        "-c", "test_dht_api_data.conf",
25                                        NULL);
26 //     sleep(1);
27 //     printf("%d\n", fopen( "test_mesh.conf", "r"));
28 //     GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_mesh.conf"));
29     //printf("%d\n", GNUNET_CONFIGURATION_load (cfg, NULL));
30 //     printf("%d\n", GNUNET_CONFIGURATION_load (cfg, "test_dht_api_data.conf"));
31     dht = GNUNET_DHT_connect(cfg, 100);
32     if(NULL == dht) {
33 //         fprintf(stderr, "Couldn't connect to dht :(\n");
34 //         return 1; // succeed anyway
35     } else {
36 //         fprintf(stderr, "YAY! CONNECTED TO DHT :D\n");
37     }
38 //     mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, NULL);
39 //     if(NULL == mesh) {
40 //         fprintf(stderr, "Couldn't connect to mesh :(\n");
41 //         return 1; // succeed anyway
42 //     } else {
43 //         fprintf(stderr, "YAY! CONNECTED TO MESH :D\n");
44 //     }
45 //     mesh = realloc(mesh, 0); // don't complain about *mesh
46 //     printf("MESH TEST\n");
47 //     t = GNUNET_MESH_tunnel_create(mesh, );
48
49     /* do real test work here */
50     if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
51         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
52     GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
53     GNUNET_OS_process_close (arm_pid);
54
55     return;
56 }
57
58 static int
59 check ()
60 {
61   int ret;
62   char *const argv[] = {"test-mesh-api",
63     "-c",
64     "test_dht_api_data.conf",
65 #if VERBOSE
66     "-L", "DEBUG",
67 #endif
68     NULL
69   };
70   struct GNUNET_GETOPT_CommandLineOption options[] = {
71     GNUNET_GETOPT_OPTION_END
72   };
73   ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
74                       argv, "test-mesh-api", "nohelp",
75                       options, &run, NULL);
76   if (ret != GNUNET_OK)
77     {
78       GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
79     }
80   return GNUNET_OK;
81 }
82
83 int main (int argc, char *argv[]) {
84     if(GNUNET_OK == check())
85         return 0;
86     else return 1;
87 }