Index: pobysoC-4.0/src/test-pobyso-evaluate-constant.c
===================================================================
--- pobysoC-4.0/src/test-pobyso-evaluate-constant.c	(revision 0)
+++ pobysoC-4.0/src/test-pobyso-evaluate-constant.c	(revision 142)
@@ -0,0 +1,145 @@
+/** @file test-pobyso-evaluate-constant.c
+ * Name & purpose
+ *
+ * Two arguments are expected : an functional expression and a
+ * constant expression. The functional expression is evaluated at the value
+ * of the constant expression.
+ * If only the functional expression is literally "NULL" the
+ * pobyso_evaluate_constant is tested with a NULL argument as for the function.
+ *
+ * The second argument is not looked for.
+ *
+ * @author S. T.
+ * @date 2014-12-05
+ *
+ * @details Verbosity manipulation are performed  to make sur  that verbosity
+ *  suppression is correctly managed in pobyso_is_constant_expression()
+ *  function.
+ */
+/******************************************************************************/
+/* Headers, applying the "particular to general" convention.*/
+
+#include "pobyso.h"
+
+/* includes of local headers */
+
+/* includes of project headers */
+
+/* includes of system headers */
+
+/* Other declarations */
+
+/* Internal prototypes */
+
+/* Types, constants and macros definitions */
+
+/* Global variables */
+
+/* Functions */
+
+int
+main(int argc, char** argv)
+{
+  pobyso_func_exp_t funcExpSo  = NULL;
+  mpfr_t evaluationMp;
+  mpfr_t argumentMp;
+  sollya_obj_t argumentSo = NULL;
+  int outcome = 1;
+
+  sollya_lib_init();
+
+  /* Two command line arguments expected. */
+  if (argc < 3)
+  {
+    fprintf(stderr,"\n\n");
+    fprintf(stderr, "Usage: %s funcExp constExpArg\n", argv[0]);
+    fprintf(stderr,
+            "            funcExp: a quoted functional expression for Sollya;\n");
+    fprintf(stderr,
+            "            constExpArg: a (possibly quoted) Sollya constant expression for the argument.");
+    fprintf(stderr,"\n\n");
+    sollya_lib_close();
+    return 1;
+  }
+
+  if (! strcmp(argv[1], "NULL")) /* First parameter is the "NULL" string) */
+  {
+    outcome = pobyso_evaluate_constant(NULL, argumentMp, evaluationMp);
+    sollya_lib_close();
+    return outcome;
+  }
+  pobyso_set_canonical_on();
+  argumentSo = pobyso_parse_string(argv[2]);
+  if (argumentSo == NULL)
+  {
+    fprintf(stderr,
+        "\n\n%s: can't parse \"%s\" to a valid expression. Aborting!\n\n",
+        argv[0], argv[2]);
+    sollya_lib_close();
+    return 1;
+  }
+  if (! pobyso_is_constant_expression(argumentSo))
+  {
+    fprintf(stderr,
+        "\n\n%s: can't evaluate \"%s\" to a constant expression. Aborting!\n\n",
+        argv[0], argv[2]);
+    sollya_lib_clear_obj(argumentSo);
+    sollya_lib_close();
+    return 1;
+  }
+  mpfr_init2(argumentMp, 512);
+  if (! sollya_lib_get_constant(argumentMp, argumentSo))
+  {
+    fprintf(stderr,
+        "\n\n%s: can't recover the value of \"%s\". Aborting!\n\n",
+        argv[0], argv[2]);
+    mpfr_clear(argumentMp);
+    sollya_lib_clear_obj(argumentSo);
+    sollya_lib_close();
+    return 1;
+  }
+  if (argc > 3)
+  {
+    fprintf(stdout, "argument: ");
+    mpfr_out_str(stdout, 10, 17, argumentMp, MPFR_RNDN);
+    fprintf(stdout, "\n");
+  }
+  /* Not needed any more. */
+  sollya_lib_clear_obj(argumentSo);
+  funcExpSo = pobyso_parse_string(argv[1]);
+  if (funcExpSo == NULL)
+  {
+    fprintf(stderr,
+        "\n\n%s: could not parse \"%s\" as a valid Sollya expression. Aborting!\n\n",
+        argv[0], argv[1]);
+    mpfr_clear(argumentMp);
+    sollya_lib_close();
+    return 1;
+  }
+  if (argc > 3)
+  {
+    fprintf(stdout, "Functional expression: ");
+    pobyso_autoprint(funcExpSo);
+  }
+  /* Precision does not matter: the callee adjusts it as needed. */
+  mpfr_init(evaluationMp);
+  outcome = pobyso_evaluate_constant(funcExpSo, argumentMp, evaluationMp);
+  if (outcome)
+  {
+    switch(outcome)
+    {
+      case POBYSO_NAN:
+        fprintf(stderr, "%s: evaluated to NaN.\n", argv[0]); break;
+      case POBYSO_UNFAITHFUL:
+        fprintf(stderr, "%s: result is unfaithful.\n", argv[0]); break;
+    } /* End switch. */
+  }
+  fprintf(stdout, "Evaluation: ");
+  mpfr_out_str(stdout, 10, 17, evaluationMp, MPFR_RNDN);
+  fprintf(stdout, "\n");
+  sollya_lib_clear_obj(funcExpSo);
+  mpfr_clear(argumentMp);
+  mpfr_clear(evaluationMp);
+  sollya_lib_close();
+  return outcome;
+} /* End main */

Property changes on: pobysoC-4.0/src/test-pobyso-evaluate-constant.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain

