]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
basic conv test suite
authorPrashanth Mundkur <prashanth.mundkur@citrix.com>
Wed, 8 Apr 2009 20:07:51 +0000 (13:07 -0700)
committerPrashanth Mundkur <prashanth.mundkur@citrix.com>
Wed, 8 Apr 2009 20:07:51 +0000 (13:07 -0700)
libs/json/OMakefile
libs/json/jsonc_tests/OMakefile [new file with mode: 0644]
libs/json/jsonc_tests/OMakefile.omc [new file with mode: 0644]
libs/json/jsonc_tests/test_types.ml [new file with mode: 0644]
libs/json/jsonc_tests/tester.ml [new file with mode: 0644]

index 5e0462fdd302ef2a5fe5ff8063c19a2383596c46..9a9a3387ed5fd5d73f99f7da000e69a1145f88b2 100644 (file)
@@ -29,9 +29,12 @@ section
 
        JSON_CONV_PROG = jsonc
        JSON_CONV = $(OCamlProgram $(JSON_CONV_PROG), $(CONV_FILES))
-       export JSON_CONV
+       export JSON_CONV JSON_CONV_PROG
+
 
 .DEFAULT: $(JSON_LIB) $(TEST_PARSER) $(JSON_CONV)
 
 clean:
     rm -f $(filter-proper-targets $(ls R, .)) *.annot *.cmo
+
+.SUBDIRS: jsonc_tests
diff --git a/libs/json/jsonc_tests/OMakefile b/libs/json/jsonc_tests/OMakefile
new file mode 100644 (file)
index 0000000..17ea766
--- /dev/null
@@ -0,0 +1,22 @@
+.PHONY: clean
+
+OCAMLFLAGS += -I ..
+
+test_types_json_conv.ml: test_types.ml $(JSON_CONV)
+       ../$(JSON_CONV_PROG) -i $< -o $@
+
+TESTER_FILES[] =
+       test_types
+       test_types_json_conv
+       tester
+
+OCAML_LIBS[] +=
+       ../json
+TESTER_PROG = test_conv
+TESTER = $(OCamlProgram $(TESTER_PROG), $(TESTER_FILES))
+
+.DEFAULT: $(TESTER)
+
+clean:
+    rm -f $(filter-proper-targets $(ls R, .)) *.annot *.cmo
+
diff --git a/libs/json/jsonc_tests/OMakefile.omc b/libs/json/jsonc_tests/OMakefile.omc
new file mode 100644 (file)
index 0000000..6b7c45c
Binary files /dev/null and b/libs/json/jsonc_tests/OMakefile.omc differ
diff --git a/libs/json/jsonc_tests/test_types.ml b/libs/json/jsonc_tests/test_types.ml
new file mode 100644 (file)
index 0000000..b7ddaf8
--- /dev/null
@@ -0,0 +1,45 @@
+
+type base_type =
+        | B_int of int
+        | B_int64 of int64
+        | B_bool of bool
+        | B_string of string
+
+type simple_type =
+        | S_int_option of int option
+        | S_int64_option of int64 option
+        | S_bool_option of bool option
+        | S_string_option of string option
+
+        | S_int_list of int list
+        | S_bool_list of bool list
+        | S_int64_list of int64 list
+        | S_string_list of string list
+
+        | S_int_array of int array
+        | S_bool_array of bool array
+        | S_int64_array of int64 array
+        | S_string_array of string array
+
+type record_type =
+{
+        int: int;
+        int64: int64;
+        bool: bool;
+        string: string;
+
+        int_list: int list;
+        int64_option_array: (int64 option) array;
+        bool_array: bool array;
+
+        prod_list: ((int * bool) list) * string;
+}
+          
+
+type complex_type1 = ((int list) * bool) array
+
+type complex_type2 =
+{
+        record: record_type;
+        complex_type1: complex_type1;
+}
diff --git a/libs/json/jsonc_tests/tester.ml b/libs/json/jsonc_tests/tester.ml
new file mode 100644 (file)
index 0000000..a2a0395
--- /dev/null
@@ -0,0 +1,94 @@
+open Test_types
+open Test_types_json_conv
+
+
+let test_list to_j of_j o_list =
+       List.iter (fun t ->
+                       let j = to_j t in
+                       let o = of_j j in
+                       (* Printf.printf "testing of_j(to_j(.) == . for %s\n" (Json.json_to_string j); *)
+                       assert (o = t)
+                 ) o_list;
+       let j_list = List.map to_j o_list in
+       List.iter (fun t ->
+                       let o = of_j t in
+                       let j = to_j o in
+                       (* Printf.printf "testing to_j(of_j(.) == . for %s\n" (Json.json_to_string j); *)
+                       assert (j = t)
+                 ) j_list
+
+
+let check_base_type () =
+       let bs = [ B_int 3;
+                  B_int64 1L;
+                  B_bool false;
+                  B_string "test"
+                ] in
+       test_list base_type_to_json base_type_of_json bs
+
+let check_simple_type () =
+       let ss = [ S_int_option None;
+                  S_int_option (Some 2);
+                  S_int64_option (Some 0L);
+                  S_bool_option (Some true);
+                  S_string_option (Some "tset");
+
+                  S_int_list [ ];
+                  S_int_list [ 3; 2; -1 ];
+                  S_bool_list [ true; false; false; true; false ];
+                  S_int64_list [ 1L; -3L; 2L; 5L];
+                  S_string_list [ "iggy"; "franti"; "zappa" ];
+
+                  S_int_array [| |];
+                  S_int_array [| 1; 3; 2 |];
+                  S_bool_array [| false; true; false; false; true |];
+                  S_int64_array [| 1L; 3L; -2L; 5L |];
+                  S_string_array [| "iggy"; "franti"; "zappa" |]
+                ] in
+         test_list simple_type_to_json simple_type_of_json ss
+
+let check_record_type () =
+       let rs = [ { int = 32;
+                    int64 = 32L;
+                    bool = false;
+                    string = "record";
+
+                    int_list = [ 0; 1; 2; -6; 4; 5];
+                    int64_option_array = [| Some 0L; Some (-3L); None; Some (-1L); Some 5L |];
+                    bool_array = [| false; true; false; false; true |];
+
+                    prod_list = [ (1,false); (-23, true); (-1000, true) ], "prod"
+                  } ] in
+       test_list record_type_to_json record_type_of_json rs
+
+let check_complex_type1 () =
+       let cs = [ [| |];
+                  [| ([], true) |];
+                  [| ([4; 3; 1], false); ([1; 3; 4], true) |];
+                ] in
+       test_list complex_type1_to_json complex_type1_of_json cs
+
+let check_complex_type2 () =
+       let cs = [ { record = { int = 32;
+                               int64 = 32L;
+                               bool = false;
+                               string = "record";
+
+                               int_list = [ 0; 1; 2; -6; 4; 5];
+                               int64_option_array = [| Some 0L; Some (-3L); None; Some (-1L); Some 5L |];
+                               bool_array = [| false; true; false; false; true |];
+
+                               prod_list = [ (1,false); (-23, true); (-1000, true) ], "prod"
+                             };
+                    complex_type1 = [| ([4; 3; 1], false); ([1; 3; 4], true) |];
+                  }
+                ] in
+       test_list complex_type2_to_json complex_type2_of_json cs
+       
+let _ =
+       check_base_type ();
+       check_simple_type ();
+       check_record_type ();
+       check_complex_type1 ();
+       check_complex_type2 ()
+