コード例 #1
0
ファイル: EvaluateGUI.cs プロジェクト: RicardoAgra/prologGui
    public void do_calc()
    {
        string[] ql = { "4+6", "11-5", "3*7", "9/3" };
        foreach (String q in ql)
        {
            if (!textBox1.IsHandleCreated)
            {
                IntPtr dummy = textBox1.Handle; // force the Control to be created.
            }
            textBox1.Invoke(new MethodInvoker(delegate { textBox1.Text = q; }));
            evaluate_click(button1, new EventArgs());
        }
        Thread.Sleep(1000); // Make it possible to see the GUI for a short while.
        QueryAnswer answer = session.executeQuery("shutdown");

        session.disconnect();
        process.WaitForExit(10000); // wait 10 seconds.
        if (!process.HasExited)
        {
            try {
                process.Kill();
            } catch (System.InvalidOperationException)
            {
            }
        }
        Environment.Exit(0);
    }
コード例 #2
0
    public static void Main(System.String[] args)
    {
        // Startup the prolog and show its err output!
          int test = 1;
          PrologSession session = null;
          PBTest evalTest = new PBTest();
          evalTest.prolog = args[0];

          try
        {
        //	  SupportClass.ThreadClass t = new SupportClass.ThreadClass(new ThreadStart(evalTest.Run));
          Thread t = new Thread(new ThreadStart(evalTest.Run));
          t.IsBackground = true;
          t.Start();

          // Get the port from the SICStus process (and fail if port is an error value)
          int port = evalTest.Port;
          if (port <= 0)
        {
          evalTest.fail("could not start sicstus", test);
        }

          session = new PrologSession();
        System.Console.Error.WriteLine("DBG: setting port; port==" + port);
        //	  session.Port = port;		// PrologBeans.NET.c# -version
          session.setPort(port);	// PrologBeans.NET.j# -version

          {
        System.Console.Error.WriteLine("DBG: setting timeout=0");
        //	    session.Timeout = 0; 	// PrologBeans.NET.c# -version
        session.setTimeout(0); 	// PrologBeans.NET.j# -version
          }

          // Test 1. - evaluation!
          Bindings bindings = new Bindings().bind("E", "10+20.");
          session.connect();	/* This will connect if neccessary. */
          QueryAnswer answer = session.executeQuery("evaluate(E,R)", bindings);
          PBTerm result = answer.getValue("R");
          if (result != null)
        {
          if (result.intValue() == 30)
        {
          success("10+20=" + result, test++);
        }
          else
        {
          evalTest.fail("Execution failed: " + result, test);
        }
        }
          else
        {
          evalTest.fail("Error " + answer.getError(), test);
        }

          // Test 2 - list reverse!
          bindings = new Bindings().bind("E", "reverse");
          answer = session.executeQuery("reverse(E,R)", bindings);
          result = answer.getValue("R");
          if (result != null)
        {
        //	      if ("esrever".Equals(result.ToString()))
        if (listcompare(result,"esrever"))
        {
          success("rev(reverse) -> " + result, test++);
        }
          else
        {
          evalTest.fail("Execution failed: " + result, test);
        }
        }
          else
        {
          evalTest.fail("Error " + answer.getError(), test);
        }

          // Test 2b - SPRM 13863 transfer lists of small integers
          PBTerm NIL = PBTerm.makeAtom("[]");
          PBTerm eTerm = PBTerm.makeTerm(PBTerm.makeTerm((int)127), PBTerm.makeTerm(PBTerm.makeTerm((int)128), PBTerm.makeTerm(PBTerm.makeTerm((int)129), NIL)));
          PBTerm rTerm = PBTerm.makeTerm(PBTerm.makeTerm((int)129), PBTerm.makeTerm(PBTerm.makeTerm((int)128), PBTerm.makeTerm(PBTerm.makeTerm((int)127), NIL)));
          bindings = new Bindings().bind("E", eTerm);
          answer = session.executeQuery("reverse(E,R)", bindings);
          result = answer.getValue("R");
          if (result != null) {
        if (listcompare(result,rTerm)) {
          success("rev(" + eTerm + ") -> " + result, test++);
        } else {
          evalTest.fail("Execution failed: " + "rev(" + eTerm + ") -> " + result, test);
        }
          } else {
        evalTest.fail("Error " + answer.getError(), test);
          }

          // Test 3 - show developers
          // [PD] 3.12.3 Test non-ascii character in query name
          answer = session.executeQuery("devel\x00f6pers(Dev)");
          result = answer.getValue("Dev");
          if (result != null)
        {
        //		if (result.ProperList)     // PrologBeans.NET.c# -version
        if (result.isProperList()) // PrologBeans.NET.j# -version
        {
          PBTerm list = result;
          if (list.length() == 4 &&
              "Joakim".Equals(list.head().ToString()) &&
              "Niclas".Equals(list.tail().head().ToString()) &&
              "Per".Equals(list.tail().tail().head().ToString()) &&
        // [PD] 3.12.2 Do not use non-ASCII literals
        //		      "едц≈ƒ÷".Equals(list.getTermAt(4).ToString()))
          "\u00e5\u00e4\u00f6\u00c5\u00c4\u00d6".Equals(list.tail().tail().tail().head().ToString())) {
          // [PD] 3.12.3 Test non-ascii character in query name
              success("devel\x00f6pers -> " + result, test++);
            }
          else
            {
              evalTest.fail("Execution failed: " + result, test);
            }
        }
          else
        {
          evalTest.fail("Execution failed: " + result, test);
        }
        }
          else
        {
          evalTest.fail("Error " + answer.getError(), test);
        }

          // Test 4 - send and receive a complex string-list
          String str = "foo\u1267bar";
          bindings = new Bindings().bind("L1", str);
          answer = session.executeQuery("send_receive(L1,L2)", bindings);
          result = answer.getValue("L2");
          if( result != null) {
        //	    if (((PBString)result).equals(str)) {
        if (listcompare(result, str)) {
          success("send_receive(" + str + ") -> " + result, test++);
        } else {
          evalTest.fail("Execution failed: " + result, test);
        }
          } else {
        evalTest.fail("Error " + answer.getError(), test);
          }

          // Test 5 - send and receive a very large atom
          int stringLength = 100000;
          String longStr = new String('x', stringLength);
          bindings = new Bindings().bind("L1", longStr);
          answer = session.executeQuery("send_receive(L1,L2)", bindings);
          result = answer.getValue("L2");
          if( result != null) {
        if (result.getString().Equals(longStr)) {
          success("OK (" + stringLength + " characters)", test++);
        } else {
          evalTest.fail("Execution failed: " + stringLength + " characters",
                test);
        }
          } else {
        evalTest.fail("Error " + answer.getError() + ", " + stringLength
              + " characters", test);
          }

          // Test 6. Attributed variables
          bindings = new Bindings();
          bindings.bind("N",1);
          bindings.bind("M",5);
          answer = session.executeQuery("newVar(X,N,M)",bindings);
          result = answer.getValue("X");
          if( result != null) {
          if (result.isVariable()) {
              success("OK", test++);
          } else {
              evalTest.fail("Execution failed: " + stringLength + " characters", test);
          }
          } else {
          evalTest.fail("Error " + answer.getError() + ", " + stringLength
               + " characters", test);
          }

          // Test 7. shutdown server...
          session.executeQuery("shutdown");
          if (!evalTest.waitForShutdown())
        {
          evalTest.fail("shutdown", test++);
        }
          else
        {
          success("shutdown", test++);
        }
        }
          catch (System.Exception e)
        {
          if (error == 0)
        {
          Console.Error.WriteLine("PBTest.Main caught an exception.");
          System.Console.Error.WriteLine(e);
        //	      SupportClass.WriteStackTrace(e, Console.Error);
              Console.Error.WriteLine(e.ToString());
          Console.Error.Flush();
          evalTest.fail("Exception " + e.Message, test);
        }
        }
          finally
        {
          if (session != null)
        {
          session.disconnect();
        }
          evalTest.shutdown();
          System.Environment.Exit(error);
        }
    }
コード例 #3
0
ファイル: PBTest.cs プロジェクト: samb8s/SemRep
    public static void  Main(System.String[] args)
    {
        // Startup the prolog and show its err output!
        int           test     = 1;
        PrologSession session  = null;
        PBTest        evalTest = new PBTest();

        evalTest.prolog = args[0];

        try
        {
//	  SupportClass.ThreadClass t = new SupportClass.ThreadClass(new ThreadStart(evalTest.Run));
            Thread t = new Thread(new ThreadStart(evalTest.Run));
            t.IsBackground = true;
            t.Start();

            // Get the port from the SICStus process (and fail if port is an error value)
            int port = evalTest.Port;
            if (port <= 0)
            {
                evalTest.fail("could not start sicstus", test);
            }

            session = new PrologSession();
            System.Console.Error.WriteLine("DBG: setting port; port==" + port);
//	  session.Port = port;		// PrologBeans.NET.c# -version
            session.setPort(port);      // PrologBeans.NET.j# -version

            {
                System.Console.Error.WriteLine("DBG: setting timeout=0");
//	    session.Timeout = 0;    // PrologBeans.NET.c# -version
                session.setTimeout(0);  // PrologBeans.NET.j# -version
            }

            // Test 1. - evaluation!
            Bindings bindings = new Bindings().bind("E", "10+20.");
            session.connect();  /* This will connect if neccessary. */
            QueryAnswer answer = session.executeQuery("evaluate(E,R)", bindings);
            PBTerm      result = answer.getValue("R");
            if (result != null)
            {
                if (result.intValue() == 30)
                {
                    success("10+20=" + result, test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + result, test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError(), test);
            }

            // Test 2 - list reverse!
            bindings = new Bindings().bind("E", "reverse");
            answer   = session.executeQuery("reverse(E,R)", bindings);
            result   = answer.getValue("R");
            if (result != null)
            {
//	      if ("esrever".Equals(result.ToString()))
                if (listcompare(result, "esrever"))
                {
                    success("rev(reverse) -> " + result, test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + result, test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError(), test);
            }

            // Test 2b - SPRM 13863 transfer lists of small integers
            PBTerm NIL   = PBTerm.makeAtom("[]");
            PBTerm eTerm = PBTerm.makeTerm(PBTerm.makeTerm((int)127), PBTerm.makeTerm(PBTerm.makeTerm((int)128), PBTerm.makeTerm(PBTerm.makeTerm((int)129), NIL)));
            PBTerm rTerm = PBTerm.makeTerm(PBTerm.makeTerm((int)129), PBTerm.makeTerm(PBTerm.makeTerm((int)128), PBTerm.makeTerm(PBTerm.makeTerm((int)127), NIL)));
            bindings = new Bindings().bind("E", eTerm);
            answer   = session.executeQuery("reverse(E,R)", bindings);
            result   = answer.getValue("R");
            if (result != null)
            {
                if (listcompare(result, rTerm))
                {
                    success("rev(" + eTerm + ") -> " + result, test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + "rev(" + eTerm + ") -> " + result, test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError(), test);
            }



            // Test 3 - show developers
            // [PD] 3.12.3 Test non-ascii character in query name
            answer = session.executeQuery("devel\x00f6pers(Dev)");
            result = answer.getValue("Dev");
            if (result != null)
            {
//		if (result.ProperList)     // PrologBeans.NET.c# -version
                if (result.isProperList()) // PrologBeans.NET.j# -version
                {
                    PBTerm list = result;
                    if (list.length() == 4 &&
                        "Joakim".Equals(list.head().ToString()) &&
                        "Niclas".Equals(list.tail().head().ToString()) &&
                        "Per".Equals(list.tail().tail().head().ToString()) &&
// [PD] 3.12.2 Do not use non-ASCII literals
//		      "едц≈ƒ÷".Equals(list.getTermAt(4).ToString()))
                        "\u00e5\u00e4\u00f6\u00c5\u00c4\u00d6".Equals(list.tail().tail().tail().head().ToString()))
                    {
                        // [PD] 3.12.3 Test non-ascii character in query name
                        success("devel\x00f6pers -> " + result, test++);
                    }
                    else
                    {
                        evalTest.fail("Execution failed: " + result, test);
                    }
                }
                else
                {
                    evalTest.fail("Execution failed: " + result, test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError(), test);
            }

            // Test 4 - send and receive a complex string-list
            String str = "foo\u1267bar";
            bindings = new Bindings().bind("L1", str);
            answer   = session.executeQuery("send_receive(L1,L2)", bindings);
            result   = answer.getValue("L2");
            if (result != null)
            {
//	    if (((PBString)result).equals(str)) {
                if (listcompare(result, str))
                {
                    success("send_receive(" + str + ") -> " + result, test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + result, test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError(), test);
            }

            // Test 5 - send and receive a very large atom
            int    stringLength = 100000;
            String longStr      = new String('x', stringLength);
            bindings = new Bindings().bind("L1", longStr);
            answer   = session.executeQuery("send_receive(L1,L2)", bindings);
            result   = answer.getValue("L2");
            if (result != null)
            {
                if (result.getString().Equals(longStr))
                {
                    success("OK (" + stringLength + " characters)", test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + stringLength + " characters",
                                  test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError() + ", " + stringLength
                              + " characters", test);
            }

            // Test 6. Attributed variables
            bindings = new Bindings();
            bindings.bind("N", 1);
            bindings.bind("M", 5);
            answer = session.executeQuery("newVar(X,N,M)", bindings);
            result = answer.getValue("X");
            if (result != null)
            {
                if (result.isVariable())
                {
                    success("OK", test++);
                }
                else
                {
                    evalTest.fail("Execution failed: " + stringLength + " characters", test);
                }
            }
            else
            {
                evalTest.fail("Error " + answer.getError() + ", " + stringLength
                              + " characters", test);
            }

            // Test 7. shutdown server...
            session.executeQuery("shutdown");
            if (!evalTest.waitForShutdown())
            {
                evalTest.fail("shutdown", test++);
            }
            else
            {
                success("shutdown", test++);
            }
        }
        catch (System.Exception e)
        {
            if (error == 0)
            {
                Console.Error.WriteLine("PBTest.Main caught an exception.");
                System.Console.Error.WriteLine(e);
//	      SupportClass.WriteStackTrace(e, Console.Error);
                Console.Error.WriteLine(e.ToString());
                Console.Error.Flush();
                evalTest.fail("Exception " + e.Message, test);
            }
        }
        finally
        {
            if (session != null)
            {
                session.disconnect();
            }
            evalTest.shutdown();
            System.Environment.Exit(error);
        }
    }