[Pkg-libvirt-commits] [libguestfs] 258/384: php: add a simple bindtests test

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 16:57:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 3b8d56d491d657e5c1377329d1212188e77fa2a2
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Feb 10 17:28:01 2015 +0100

    php: add a simple bindtests test
    
    Generate a simple bindtests test for the PHP binding, so it is possible
    to easily test all the argument types.
    
    Unlike the bindtests for other languages, optional arguments are not
    tested, due to the limitations of optional arguments in PHP (or maybe
    they way we implement them).
---
 .gitignore             |  1 +
 generator/bindtests.ml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 generator/main.ml      |  1 +
 3 files changed, 65 insertions(+)

diff --git a/.gitignore b/.gitignore
index 1b02af0..b165c81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -387,6 +387,7 @@ Makefile.in
 /php/extension/php-for-tests.sh
 /php/extension/php_guestfs_php.h
 /php/extension/run-tests.php
+/php/extension/tests/guestfs_php_bindtests.phpt
 /php/extension/tmp-php.ini
 /pick-guests.pl
 /po-docs/*/*.1
diff --git a/generator/bindtests.ml b/generator/bindtests.ml
index b75de15..2e9b6d3 100644
--- a/generator/bindtests.ml
+++ b/generator/bindtests.ml
@@ -909,6 +909,69 @@ and generate_golang_bindtests () =
   pr "    return &s;\n";
   pr "}\n"
 
+and generate_php_bindtests () =
+  (* No header for this, as it is a .phpt file. *)
+
+  (* Unfortunately, due to the way optional arguments work in PHP,
+   * we cannot test arbitrary arguments skipping the previous ones
+   * in the function signatures.
+   *
+   * Hence, check only the non-optional arguments, and fix the
+   * baseline output to expect always "unset" optional arguments.
+   *)
+
+  pr "--TEST--\n";
+  pr "General PHP binding test.\n";
+  pr "--FILE--\n";
+  pr "<?php\n";
+  pr "$g = guestfs_create ();\n";
+
+  let mkargs args =
+    String.concat ", " (
+      List.map (
+        function
+        | CallString s -> "\"" ^ s ^ "\""
+        | CallOptString None -> "NULL"
+        | CallOptString (Some s) -> sprintf "\"%s\"" s
+        | CallStringList xs ->
+          sprintf "array(%s)"
+            (String.concat "," (List.map (sprintf "\"%s\"") xs))
+        | CallInt i -> string_of_int i
+        | CallInt64 i -> Int64.to_string i
+        | CallBool b -> if b then "1" else "0"
+        | CallBuffer s -> "\"" ^ c_quote s ^ "\""
+      ) args
+    )
+  in
+
+  generate_lang_bindtests (
+    fun f args optargs ->
+      pr "if (guestfs_%s ($g, %s) == false) {\n" f (mkargs args);
+      pr "  echo (\"Call failed: \" . guestfs_last_error ($g) . \"\\n\");\n";
+      pr "  exit;\n";
+      pr "}\n";
+  );
+
+  pr "echo (\"EOF\\n\");\n";
+  pr "?>\n";
+  pr "--EXPECT--\n";
+
+  let dump filename =
+    let chan = open_in filename in
+    let rec loop () =
+      let line = input_line chan in
+      (match string_split ":" line with
+      | ("obool"|"oint"|"oint64"|"ostring"|"ostringlist") as x :: _ ->
+        pr "%s: unset\n" x
+      | _ -> pr "%s\n" line
+      );
+      loop ()
+    in
+    (try loop () with End_of_file -> ());
+    close_in chan in
+
+  dump "bindtests"
+
 (* Language-independent bindings tests - we do it this way to
  * ensure there is parity in testing bindings across all languages.
  *)
diff --git a/generator/main.ml b/generator/main.ml
index 436d72d..abeae0c 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -160,6 +160,7 @@ Run it from the top source directory using the command
   output_to "csharp/Libguestfs.cs" generate_csharp;
   output_to "php/extension/php_guestfs_php.h" generate_php_h;
   output_to "php/extension/guestfs_php.c" generate_php_c;
+  output_to "php/extension/tests/guestfs_php_bindtests.phpt" generate_php_bindtests;
   output_to "erlang/guestfs.erl" generate_erlang_erl;
   output_to "erlang/erl-guestfs.c" generate_erlang_c;
   output_to ~perm:0o555 "erlang/bindtests.erl" generate_erlang_bindtests;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list