ovs-vsctl-bashcomp: Fix build failure when bash version < 4.0.
[cascardo/ovs.git] / tests / test-ovsdb.c
index 3b48778..99f41c1 100644 (file)
 #include "tests/idltest.h"
 #include "timeval.h"
 #include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
-static struct command all_commands[];
-
-static void usage(void) NO_RETURN;
+OVS_NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
+static struct command *get_all_commands(void);
 
 int
 main(int argc, char *argv[])
 {
     set_program_name(argv[0]);
     parse_options(argc, argv);
-    run_command(argc - optind, argv + optind, all_commands);
+    run_command(argc - optind, argv + optind, get_all_commands());
     return 0;
 }
 
@@ -218,16 +217,13 @@ unbox_json(struct json *json)
     }
 }
 
-static size_t
+static void
 print_and_free_json(struct json *json)
 {
     char *string = json_to_string(json, JSSF_SORT);
-    size_t length = strlen(string);
     json_destroy(json);
     puts(string);
     free(string);
-
-    return length;
 }
 
 static void
@@ -445,10 +441,7 @@ do_parse_atoms(int argc, char *argv[])
         if (error) {
             print_and_free_ovsdb_error(error);
         } else {
-            size_t length;
-
-            length = print_and_free_json(ovsdb_atom_to_json(&atom, base.type));
-            ovs_assert(length == ovsdb_atom_json_length(&atom, base.type));
+            print_and_free_json(ovsdb_atom_to_json(&atom, base.type));
             ovsdb_atom_destroy(&atom, base.type);
         }
     }
@@ -500,14 +493,12 @@ do_parse_data__(int argc, char *argv[],
 
     for (i = 2; i < argc; i++) {
         struct ovsdb_datum datum;
-        size_t length;
 
         json = unbox_json(parse_json(argv[i]));
         check_ovsdb_error(parse(&datum, &type, json, NULL));
         json_destroy(json);
 
-        length = print_and_free_json(ovsdb_datum_to_json(&datum, &type));
-        ovs_assert(length == ovsdb_datum_json_length(&datum, &type));
+        print_and_free_json(ovsdb_datum_to_json(&datum, &type));
 
         ovsdb_datum_destroy(&datum, &type);
     }
@@ -1517,13 +1508,13 @@ static void
 do_transact(int argc, char *argv[])
 {
     static const struct command do_transact_commands[] = {
-        { "commit", 0, 0, do_transact_commit },
-        { "abort", 0, 0, do_transact_abort },
-        { "insert", 2, 3, do_transact_insert },
-        { "delete", 1, 1, do_transact_delete },
-        { "modify", 2, 3, do_transact_modify },
-        { "print", 0, 0, do_transact_print },
-        { NULL, 0, 0, NULL },
+        { "commit", NULL, 0, 0, do_transact_commit },
+        { "abort", NULL, 0, 0, do_transact_abort },
+        { "insert", NULL, 2, 3, do_transact_insert },
+        { "delete", NULL, 1, 1, do_transact_delete },
+        { "modify", NULL, 2, 3, do_transact_modify },
+        { "print", NULL, 0, 0, do_transact_print },
+        { NULL, NULL, 0, 0, NULL },
     };
 
     struct ovsdb_schema *schema;
@@ -1902,7 +1893,7 @@ do_idl(int argc, char *argv[])
         rpc = NULL;
     }
 
-    setvbuf(stdout, NULL, _IOLBF, 0);
+    setvbuf(stdout, NULL, _IONBF, 0);
 
     symtab = ovsdb_symbol_table_create();
     for (i = 2; i < argc; i++) {
@@ -1972,32 +1963,38 @@ do_idl(int argc, char *argv[])
 }
 
 static struct command all_commands[] = {
-    { "log-io", 2, INT_MAX, do_log_io },
-    { "default-atoms", 0, 0, do_default_atoms },
-    { "default-data", 0, 0, do_default_data },
-    { "parse-atomic-type", 1, 1, do_parse_atomic_type },
-    { "parse-base-type", 1, 1, do_parse_base_type },
-    { "parse-type", 1, 1, do_parse_type },
-    { "parse-atoms", 2, INT_MAX, do_parse_atoms },
-    { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings },
-    { "parse-data", 2, INT_MAX, do_parse_data },
-    { "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
-    { "sort-atoms", 2, 2, do_sort_atoms },
-    { "parse-column", 2, 2, do_parse_column },
-    { "parse-table", 2, 3, do_parse_table },
-    { "parse-rows", 2, INT_MAX, do_parse_rows },
-    { "compare-rows", 2, INT_MAX, do_compare_rows },
-    { "parse-conditions", 2, INT_MAX, do_parse_conditions },
-    { "evaluate-conditions", 3, 3, do_evaluate_conditions },
-    { "parse-mutations", 2, INT_MAX, do_parse_mutations },
-    { "execute-mutations", 3, 3, do_execute_mutations },
-    { "query", 3, 3, do_query },
-    { "query-distinct", 4, 4, do_query_distinct },
-    { "transact", 1, INT_MAX, do_transact },
-    { "parse-schema", 1, 1, do_parse_schema },
-    { "execute", 2, INT_MAX, do_execute },
-    { "trigger", 2, INT_MAX, do_trigger },
-    { "idl", 1, INT_MAX, do_idl },
-    { "help", 0, INT_MAX, do_help },
-    { NULL, 0, 0, NULL },
+    { "log-io", NULL, 2, INT_MAX, do_log_io },
+    { "default-atoms", NULL, 0, 0, do_default_atoms },
+    { "default-data", NULL, 0, 0, do_default_data },
+    { "parse-atomic-type", NULL, 1, 1, do_parse_atomic_type },
+    { "parse-base-type", NULL, 1, 1, do_parse_base_type },
+    { "parse-type", NULL, 1, 1, do_parse_type },
+    { "parse-atoms", NULL, 2, INT_MAX, do_parse_atoms },
+    { "parse-atom-strings", NULL, 2, INT_MAX, do_parse_atom_strings },
+    { "parse-data", NULL, 2, INT_MAX, do_parse_data },
+    { "parse-data-strings", NULL, 2, INT_MAX, do_parse_data_strings },
+    { "sort-atoms", NULL, 2, 2, do_sort_atoms },
+    { "parse-column", NULL, 2, 2, do_parse_column },
+    { "parse-table", NULL, 2, 3, do_parse_table },
+    { "parse-rows", NULL, 2, INT_MAX, do_parse_rows },
+    { "compare-rows", NULL, 2, INT_MAX, do_compare_rows },
+    { "parse-conditions", NULL, 2, INT_MAX, do_parse_conditions },
+    { "evaluate-conditions", NULL, 3, 3, do_evaluate_conditions },
+    { "parse-mutations", NULL, 2, INT_MAX, do_parse_mutations },
+    { "execute-mutations", NULL, 3, 3, do_execute_mutations },
+    { "query", NULL, 3, 3, do_query },
+    { "query-distinct", NULL, 4, 4, do_query_distinct },
+    { "transact", NULL, 1, INT_MAX, do_transact },
+    { "parse-schema", NULL, 1, 1, do_parse_schema },
+    { "execute", NULL, 2, INT_MAX, do_execute },
+    { "trigger", NULL, 2, INT_MAX, do_trigger },
+    { "idl", NULL, 1, INT_MAX, do_idl },
+    { "help", NULL, 0, INT_MAX, do_help },
+    { NULL, NULL, 0, 0, NULL },
 };
+
+static struct command *
+get_all_commands(void)
+{
+    return all_commands;
+}