Exemple #1
0
 static private void QuitJavaApp(bool waitKey)
 {
     if (procNotepad != null && procNotepad.HasExited == false)
     {
         try
         {
             //this call will throw an exception because the process being disconnected
             remoteBridge.InvokeJavaStaticMethod(procNotepad.Id, "java.lang.System", "exit", 0);
         }
         catch (System.Exception)
         { }
     }
     //----
     if (waitKey != false)
     {
         Console.Write("Press any key to quit... ");
         while (Console.KeyAvailable == false)
         {
             System.Threading.Thread.Sleep(10);
         }
         Char ch = Console.ReadKey(true).KeyChar;
     }
     return;
 }
Exemple #2
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //short<->char test
            Console.Write("  Char single value test using shorts... ");
            try
            {
                char nBaseChar = (char)10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test", nBaseChar);
                if (res.GetType() != typeof(short))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((short)res != 255 - (short)nBaseChar)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //short<->char array test
            Console.Write("  Char array test using shorts... ");
            try
            {
                char[, ,] arrayChar = new char[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayChar[i, j, k] = (char)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test3D", new object[] { arrayChar });
                if (res.GetType() != typeof(short[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                short[, ,] arrayCharRes = (short[, ,])res;
                if (arrayCharRes.GetLength(0) != 4 || arrayCharRes.GetLength(1) != 6 || arrayCharRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayCharRes[i, j, k] != 255 - (short)arrayChar[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #3
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //bool<->bool test
            Console.Write("  Boolean single value test... ");
            try
            {
                bool   bBaseBool = true;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test", bBaseBool);
                if (res.GetType() != typeof(bool))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((bool)res != (!bBaseBool))
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //bool<->bool array test
            Console.Write("  Boolean array test... ");
            try
            {
                bool[, ,] arrayBool = new bool[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayBool[i, j, k] = (((i + j + k) & 1) != 0) ? true : false;
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test3D", new object[] { arrayBool });
                if (res.GetType() != typeof(bool[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                bool[, ,] arrayBoolRes = (bool[, , ])res;
                if (arrayBoolRes.GetLength(0) != 4 || arrayBoolRes.GetLength(1) != 6 || arrayBoolRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayBoolRes[i, j, k] != (!arrayBool[i, j, k]))
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }
Exemple #4
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //bool<->bool test
            Console.Write("  String single value test... ");
            try
            {
                string szBaseString = "this is a test string";
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test", szBaseString);
                if (res.GetType() != typeof(string))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((string)res != "[" + szBaseString + "]")
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //string<->string array test
            Console.Write("  String array test... ");
            try
            {
                string szBaseString = "this is a test string";
                string[, ,] arrayStr = new string[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayStr[i, j, k] = szBaseString + " " + i.ToString() + "/" + j.ToString() + "/" + k.ToString();
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test3D", new object[] { arrayStr });
                if (res.GetType() != typeof(string[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                string[, ,] arrayStrRes = (string[, ,])res;
                if (arrayStrRes.GetLength(0) != 4 || arrayStrRes.GetLength(1) != 6 || arrayStrRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayStrRes[i, j, k] != "[" + arrayStr[i, j, k] + "]")
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #5
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //short<->char test
            Console.Write("  Char single value test using shorts... ");
            try
            {
                char   nBaseChar = (char)10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test", nBaseChar);
                if (res.GetType() != typeof(short))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((short)res != 255 - (short)nBaseChar)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //short<->char array test
            Console.Write("  Char array test using shorts... ");
            try
            {
                char[, ,] arrayChar = new char[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayChar[i, j, k] = (char)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaCharTest", "Test3D", new object[] { arrayChar });
                if (res.GetType() != typeof(short[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                short[, ,] arrayCharRes = (short[, , ])res;
                if (arrayCharRes.GetLength(0) != 4 || arrayCharRes.GetLength(1) != 6 || arrayCharRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayCharRes[i, j, k] != 255 - (short)arrayChar[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }
Exemple #6
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //int<->int test
            Console.Write("  Integer single value test... ");
            try
            {
                int    nBaseInt = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseInt);
                if (res.GetType() != typeof(int))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((int)res != 255 - nBaseInt)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //int<->int array test
            Console.Write("  Integer array test... ");
            try
            {
                int[, ,] arrayInt = new int[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayInt[i, j, k] = (int)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayInt });
                if (res.GetType() != typeof(int[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                int[, ,] arrayIntRes = (int[, , ])res;
                if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayIntRes[i, j, k] != 255 - arrayInt[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //byte<->int test
            Console.Write("  Integer single value test using bytes... ");
            try
            {
                byte   nBaseByte = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseByte);
                if (res.GetType() != typeof(int))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((byte)(int)res != 255 - nBaseByte)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //byte<->int array test
            Console.Write("  Integer array test using bytes... ");
            try
            {
                byte[, ,] arrayByte = new byte[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayByte[i, j, k] = (byte)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayByte });
                if (res.GetType() != typeof(int[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                int[, ,] arrayIntRes = (int[, , ])res;
                if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayIntRes[i, j, k] != 255 - (int)arrayByte[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //short<->int test
            Console.Write("  Integer single value test using shorts... ");
            try
            {
                short  nBaseShort = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseShort);
                if (res.GetType() != typeof(int))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((short)(int)res != 255 - nBaseShort)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //short<->int array test
            Console.Write("  Integer array test using shorts... ");
            try
            {
                short[, ,] arrayShort = new short[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayShort[i, j, k] = (short)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayShort });
                if (res.GetType() != typeof(int[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                int[, ,] arrayIntRes = (int[, , ])res;
                if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayIntRes[i, j, k] != 255 - (int)arrayShort[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //long<->int test
            Console.Write("  Integer single value test using longs... ");
            try
            {
                long   nBaseLong = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test", nBaseLong);
                if (res.GetType() != typeof(int))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((long)(int)res != 255 - nBaseLong)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //long<->int array test
            Console.Write("  Integer array test using longs... ");
            try
            {
                long[, ,] arrayLong = new long[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayLong[i, j, k] = (long)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaIntegerTest", "Test3D", new object[] { arrayLong });
                if (res.GetType() != typeof(int[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                int[, ,]  arrayIntRes = (int[, , ])res;
                if (arrayIntRes.GetLength(0) != 4 || arrayIntRes.GetLength(1) != 6 || arrayIntRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if ((long)arrayIntRes[i, j, k] != 255 - arrayLong[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            object         continueEv;
            INktJavaObject topLevelFrame;
            int            verMajor, verMinor;

            Console.WriteLine("This example launches the Java Development Kit Notepad demo application and...");
            Console.WriteLine("   a) Changes the main frame caption.");
            Console.WriteLine("   b) Creates a JTextArea with a text and inserts it at the bottom.");
            Console.WriteLine("   c) Sends System.exit() on exit to gracefully close Notepad if still running.");

            remoteBridge = new NktRemoteBridge();
            if (remoteBridge == null)
            {
                Console.Write("Error: NktRemoteBridge not registered.");
                return;
            }

            try
            {
                String s;
                int    pid;

                Console.Write("Launching NOTEPAD.JAR... ");
                s = FindJavaLauncher(args);
                if (s == "")
                {
                    Console.WriteLine("Cannot locate a registered jarfile launcher.");
                    return;
                }
                //create command line
                s = "\"" + s + "\" ";
                if (DoVerboseJNI(args) != false)
                {
                    s += "-Xcheck:jni -verbose:jni ";
                }
                s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                s += "\\..\\Samples\\Demos4Test\\Java\\Notepad\\notepad.jar\"";
                //create process
                pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv);
                if (pid == 0)
                {
                    Console.WriteLine("failed.");
                    return;
                }
                procNotepad = Process.GetProcessById(pid);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return;
            }

            //---------------- INJECT

            try
            {
                Console.Write("Injecting... ");
                remoteBridge.Hook(procNotepad.Id, eNktHookFlags.flgDebugPrintInterfaces);
                if (continueEv != null)
                {
                    remoteBridge.ResumeProcess(procNotepad.Id, continueEv);
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return;
            }

            //---------------- WAIT UNTIL JVM INITIALIZATION

            Console.Write("Waiting for JVM initialization... ");
            try
            {
                while (remoteBridge.IsJVMAttached(procNotepad.Id, out verMajor, out verMinor) == false)
                {
                    if (procNotepad.HasExited != false)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Hooked process has ended. Quitting.");
                        return;
                    }
                    if (Console.KeyAvailable != false)
                    {
                        Char ch = Console.ReadKey(true).KeyChar;
                        if (ch == 27)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Exiting by user request.");
                            //close java notepad if still open
                            QuitJavaApp(true);
                            return;
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                //close java notepad if still open
                QuitJavaApp(true);
                return;
            }

            //---------------- PERFORM TASKS

            Console.Write("Obtaining main JFrame... ");
            topLevelFrame = null;
            while (topLevelFrame == null)
            {
                object frames;

                if (procNotepad.HasExited != false)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Exiting by user request.");
                        //close java notepad if still open
                        QuitJavaApp(true);
                        return;
                    }
                }
                //get top level frame
                try
                {
                    frames = remoteBridge.InvokeJavaStaticMethod(procNotepad.Id, "javax.swing.JFrame", "getFrames", null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("failed.");
                    Console.WriteLine(ex.ToString());
                    QuitJavaApp(true);
                    return;
                }
                if (frames is Array)
                {
                    if (((object[])frames).Length > 0)
                    {
                        topLevelFrame = ((object[])frames)[0] as INktJavaObject;
                    }
                }
                if (topLevelFrame == null)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
            Console.WriteLine("OK");

            Console.Write("Waiting until visible... ");
            while ((bool)(topLevelFrame.InvokeMethod("isVisible", null)) == false)
            {
                System.Threading.Thread.Sleep(10);
            }
            Console.WriteLine("OK");

            //set new caption
            topLevelFrame.InvokeMethod("setTitle", "Nektra - Notepad");

            //get main frame content pane
            INktJavaObject cntPane = topLevelFrame.InvokeMethod("getContentPane", null) as INktJavaObject;

            //add a new JTextArea at the bottom
            INktJavaObject newTxArea = remoteBridge.CreateJavaObject(procNotepad.Id, "javax.swing.JTextArea", "Nektra Demo");

            cntPane.InvokeMethod("add", new object[] { "South", newTxArea });

            //resize window in order to force a re-layout
            topLevelFrame.InvokeMethod("setSize", new object[] { 500, 601 });

            //free resources
            Marshal.ReleaseComObject(cntPane);
            Marshal.ReleaseComObject(newTxArea);
            Marshal.ReleaseComObject(topLevelFrame);

            //---------------- WAIT FOR EXIT

            Console.WriteLine("Press 'ESC' key to quit");
            while (true)
            {
                if (procNotepad.HasExited != false)
                {
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    break;
                }
                if (Console.KeyAvailable == false)
                {
                    System.Threading.Thread.Sleep(10);
                    continue;
                }
                Char ch = Console.ReadKey(true).KeyChar;
                if (ch == 27)
                {
                    break;
                }
            }

            //---------------- CLOSE JAVA APP IF STILL RUNNING

            QuitJavaApp(false);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            object continueEv;
            INktJavaObject topLevelFrame;
            int verMajor, verMinor;

            Console.WriteLine("This example launches the Java Development Kit Notepad demo application and...");
            Console.WriteLine("   a) Changes the main frame caption.");
            Console.WriteLine("   b) Creates a JTextArea with a text and inserts it at the bottom.");
            Console.WriteLine("   c) Sends System.exit() on exit to gracefully close Notepad if still running.");

            remoteBridge = new NktRemoteBridge();
            if (remoteBridge == null)
            {
                Console.Write("Error: NktRemoteBridge not registered.");
                return;
            }

            try
            {
                String s;
                int pid;

                Console.Write("Launching NOTEPAD.JAR... ");
                s = FindJavaLauncher(args);
                if (s == "")
                {
                    Console.WriteLine("Cannot locate a registered jarfile launcher.");
                    return;
                }
                //create command line
                s = "\"" + s + "\" ";
                if (DoVerboseJNI(args) != false)
                    s += "-Xcheck:jni -verbose:jni ";
                s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                s += "\\..\\Samples\\Demos4Test\\Java\\Notepad\\notepad.jar\"";
                //create process
                pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv);
                if (pid == 0)
                {
                    Console.WriteLine("failed.");
                    return;
                }
                procNotepad = Process.GetProcessById(pid);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return;
            }

            //---------------- INJECT

            try
            {
                Console.Write("Injecting... ");
                remoteBridge.Hook(procNotepad.Id, eNktHookFlags.flgDebugPrintInterfaces);
                if (continueEv != null)
                    remoteBridge.ResumeProcess(procNotepad.Id, continueEv);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return;
            }

            //---------------- WAIT UNTIL JVM INITIALIZATION

            Console.Write("Waiting for JVM initialization... ");
            try
            {
                while (remoteBridge.IsJVMAttached(procNotepad.Id, out verMajor, out verMinor) == false)
                {
                    if (procNotepad.HasExited != false)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Hooked process has ended. Quitting.");
                        return;
                    }
                    if (Console.KeyAvailable != false)
                    {
                        Char ch = Console.ReadKey(true).KeyChar;
                        if (ch == 27)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Exiting by user request.");
                            //close java notepad if still open
                            QuitJavaApp(true);
                            return;
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                //close java notepad if still open
                QuitJavaApp(true);
                return;
            }

            //---------------- PERFORM TASKS

            Console.Write("Obtaining main JFrame... ");
            topLevelFrame = null;
            while (topLevelFrame == null)
            {
                object frames;

                if (procNotepad.HasExited != false)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Exiting by user request.");
                        //close java notepad if still open
                        QuitJavaApp(true);
                        return;
                    }
                }
                //get top level frame
                try
                {
                    frames = remoteBridge.InvokeJavaStaticMethod(procNotepad.Id, "javax.swing.JFrame", "getFrames", null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("failed.");
                    Console.WriteLine(ex.ToString());
                    QuitJavaApp(true);
                    return;
                }
                if (frames is Array)
                {
                    if (((object[])frames).Length > 0)
                        topLevelFrame = ((object[])frames)[0] as INktJavaObject;
                }
                if (topLevelFrame == null)
                    System.Threading.Thread.Sleep(100);
            }
            Console.WriteLine("OK");

            Console.Write("Waiting until visible... ");
            while ((bool)(topLevelFrame.InvokeMethod("isVisible", null)) == false)
            {
                System.Threading.Thread.Sleep(10);
            }
            Console.WriteLine("OK");

            //set new caption
            topLevelFrame.InvokeMethod("setTitle", "Nektra - Notepad");

            //get main frame content pane
            INktJavaObject cntPane = topLevelFrame.InvokeMethod("getContentPane", null) as INktJavaObject;

            //add a new JTextArea at the bottom
            INktJavaObject newTxArea = remoteBridge.CreateJavaObject(procNotepad.Id, "javax.swing.JTextArea", "Nektra Demo");
            cntPane.InvokeMethod("add", new object[] { "South", newTxArea });

            //resize window in order to force a re-layout
            topLevelFrame.InvokeMethod("setSize", new object[] { 500, 601 });

            //free resources
            Marshal.ReleaseComObject(cntPane);
            Marshal.ReleaseComObject(newTxArea);
            Marshal.ReleaseComObject(topLevelFrame);

            //---------------- WAIT FOR EXIT

            Console.WriteLine("Press 'ESC' key to quit");
            while (true)
            {
                if (procNotepad.HasExited != false)
                {
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    break;
                }
                if (Console.KeyAvailable == false)
                {
                    System.Threading.Thread.Sleep(10);
                    continue;
                }
                Char ch = Console.ReadKey(true).KeyChar;
                if (ch == 27)
                    break;
            }

            //---------------- CLOSE JAVA APP IF STILL RUNNING

            QuitJavaApp(false);
        }
Exemple #9
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //date<->date test
            Console.Write("  Date single value test... ");
            try
            {
                DateTime sBaseDate = new DateTime(2013, 10, 13, 16, 00, 00);
                object   res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test", sBaseDate);
                if (res.GetType() != typeof(DateTime))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((DateTime)res != sBaseDate.AddYears(1))
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //date<->date array test
            Console.Write("  Date array test... ");
            try
            {
                DateTime[, ,] arrayDate = new DateTime[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDate[i, j, k] = new DateTime(2013, 10, 13, i, j, k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test3D", new object[] { arrayDate });
                if (res.GetType() != typeof(DateTime[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                DateTime[, ,] arrayDateRes = (DateTime[, , ])res;
                if (arrayDateRes.GetLength(0) != 4 || arrayDateRes.GetLength(1) != 6 || arrayDateRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayDateRes[i, j, k] != arrayDate[i, j, k].AddYears(1))
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }
Exemple #10
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //bool<->bool test
            Console.Write("  Boolean single value test... ");
            try
            {
                bool bBaseBool = true;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test", bBaseBool);
                if (res.GetType() != typeof(bool))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((bool)res != (!bBaseBool))
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //bool<->bool array test
            Console.Write("  Boolean array test... ");
            try
            {
                bool[, ,] arrayBool = new bool[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayBool[i, j, k] = (((i+j+k) & 1) != 0) ? true : false;
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaBooleanTest", "Test3D", new object[] { arrayBool });
                if (res.GetType() != typeof(bool[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                bool[, ,] arrayBoolRes = (bool[, ,])res;
                if (arrayBoolRes.GetLength(0) != 4 || arrayBoolRes.GetLength(1) != 6 || arrayBoolRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayBoolRes[i, j, k] != (!arrayBool[i, j, k]))
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #11
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //long<->long test
            Console.Write("  Long single value test... ");
            try
            {
                long nBaseLong = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseLong);
                if (res.GetType() != typeof(long))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((long)res != 255 - nBaseLong)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //long<->long array test
            Console.Write("  Long array test... ");
            try
            {
                long[, ,] arrayLong = new long[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayLong[i, j, k] = (long)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayLong });
                if (res.GetType() != typeof(long[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                long[, ,] arrayLongRes = (long[, ,])res;
                if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayLongRes[i, j, k] != 255 - arrayLong[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //byte<->long test
            Console.Write("  Long single value test using bytes... ");
            try
            {
                byte nBaseByte = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseByte);
                if (res.GetType() != typeof(long))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((byte)(long)res != 255 - nBaseByte)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //byte<->long array test
            Console.Write("  Long array test using bytes... ");
            try
            {
                byte[, ,] arrayByte = new byte[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayByte[i, j, k] = (byte)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayByte });
                if (res.GetType() != typeof(long[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                long[, ,] arrayLongRes = (long[, ,])res;
                if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayLongRes[i, j, k] != 255 - (long)arrayByte[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //short<->long test
            Console.Write("  Long single value test using shorts... ");
            try
            {
                short nBaseShort = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseShort);
                if (res.GetType() != typeof(long))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((short)(long)res != 255 - nBaseShort)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //short<->long array test
            Console.Write("  Long array test using shorts... ");
            try
            {
                short[, ,] arrayShort = new short[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayShort[i, j, k] = (short)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayShort });
                if (res.GetType() != typeof(long[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                long[, ,] arrayLongRes = (long[, ,])res;
                if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayLongRes[i, j, k] != 255 - (long)arrayShort[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //int<->long test
            Console.Write("  Long single value test using ints... ");
            try
            {
                int nBaseInt = 10;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test", nBaseInt);
                if (res.GetType() != typeof(long))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((int)(long)res != 255 - nBaseInt)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //int<->long array test
            Console.Write("  Long array test using ints... ");
            try
            {
                int[, ,] arrayInt = new int[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayInt[i, j, k] = (int)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaLongTest", "Test3D", new object[] { arrayInt });
                if (res.GetType() != typeof(long[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                long[, ,] arrayLongRes = (long[, ,])res;
                if (arrayLongRes.GetLength(0) != 4 || arrayLongRes.GetLength(1) != 6 || arrayLongRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayLongRes[i, j, k] != 255 - (long)arrayInt[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #12
0
        static void Main(string[] args)
        {
            object continueEv;
            INktJavaObject topLevelFrame;
            int verMajor, verMinor;

            Console.WriteLine("This example performs some tests on RemoteBridge's Java functionality.");

            remoteBridge = new NktRemoteBridge();
            if (remoteBridge == null)
            {
                Console.Write("Error: NktRemoteBridge not registered.");
                QuitJavaApp(true);
                return;
            }

            try
            {
                String s;
                int pid;

                Console.Write("Launching JAVATEST.JAR... ");
                s = FindJavaLauncher(args);
                if (s == "")
                {
                    Console.WriteLine("Cannot locate a registered jarfile launcher.");
                    return;
                }
                //create command line
                s = "\"" + s + "\" ";
                if (DoVerboseJNI(args) != false)
                    s += "-Xcheck:jni -verbose:jni ";
                s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                s += "\\..\\Samples\\Demos4Test\\Java\\Test\\JavaTest.jar\"";
                //create process
                pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv);
                if (pid == 0)
                {
                    Console.WriteLine("failed.");
                    return;
                }
                procJavaTest = Process.GetProcessById(pid);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- INJECT

            try
            {
                Console.Write("Injecting... ");
                remoteBridge.Hook(procJavaTest.Id, eNktHookFlags.flgDebugPrintInterfaces);
                if (continueEv != null)
                    remoteBridge.ResumeProcess(procJavaTest.Id, continueEv);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- WAIT UNTIL JVM INITIALIZATION

            Console.Write("Waiting for JVM initialization... ");
            try
            {
                while (remoteBridge.IsJVMAttached(procJavaTest.Id, out verMajor, out verMinor) == false)
                {
                    if (procJavaTest.HasExited != false)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Hooked process has ended. Quitting.");
                        return;
                    }
                    if (Console.KeyAvailable != false)
                    {
                        Char ch = Console.ReadKey(true).KeyChar;
                        if (ch == 27)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Exiting by user request.");
                            //close java test if still open
                            QuitJavaApp(false);
                            return;
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- FIND TOPLEVEL WINDOW

            Console.Write("Obtaining main Window... ");
            topLevelFrame = null;
            while (topLevelFrame == null)
            {
                object frames;

                if (procJavaTest.HasExited != false)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Exiting by user request.");
                        //close java test if still open
                        QuitJavaApp(false);
                        return;
                    }
                }
                //get top level frame
                try
                {
                    frames = remoteBridge.InvokeJavaStaticMethod(procJavaTest.Id, "javax.swing.JFrame", "getFrames", null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("failed.");
                    Console.WriteLine(ex.ToString());
                    QuitJavaApp(true);
                    return;
                }
                if (frames is Array)
                {
                    if (((object[])frames).Length > 0)
                        topLevelFrame = ((object[])frames)[0] as INktJavaObject;
                }
                if (topLevelFrame == null)
                    System.Threading.Thread.Sleep(10);
            }
            Console.WriteLine("OK");

            //---------------- RUN TESTS

            Console.Write("Running tests...");
            for (int testNo=1; testNo<=12; testNo++)
            {
                if (procJavaTest.HasExited != false)
                {
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("Exiting by user request.");
                        //close java test if still open
                        QuitJavaApp(false);
                        return;
                    }
                }
                //run test
                bool b = false;
                switch (testNo)
                {
                    case 1:
                        b = BooleanTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 2:
                        b = ByteTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 3:
                        b = ShortTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 4:
                        b = CharTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 5:
                        b = IntTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 6:
                        b = LongTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 7:
                        b = FloatTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 8:
                        b = DoubleTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 9:
                        b = DateTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 10:
                        b = BigDecimalTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 11:
                        b = StringTests.RunTests(procJavaTest.Id, remoteBridge);
                        break;
                    case 12:
                        remoteBridge.OnJavaCustomNativeCall += Test_OnJavaCustomNativeCall;
                        b = EventCallbackTests.RunTests(procJavaTest.Id, remoteBridge);
                        remoteBridge.OnJavaCustomNativeCall -= Test_OnJavaCustomNativeCall;
                        break;
                }
                if (b == false)
                {
                    QuitJavaApp(true);
                    return;
                }
            }

            //---------------- CLOSE JAVA APP IF STILL RUNNING

            QuitJavaApp(true);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            object         continueEv;
            INktJavaObject topLevelFrame;
            int            verMajor, verMinor;

            Console.WriteLine("This example performs some tests on RemoteBridge's Java functionality.");

            remoteBridge = new NktRemoteBridge();
            if (remoteBridge == null)
            {
                Console.Write("Error: NktRemoteBridge not registered.");
                QuitJavaApp(true);
                return;
            }

            try
            {
                String s;
                int    pid;

                Console.Write("Launching JAVATEST.JAR... ");
                s = FindJavaLauncher(args);
                if (s == "")
                {
                    Console.WriteLine("Cannot locate a registered jarfile launcher.");
                    return;
                }
                //create command line
                s = "\"" + s + "\" ";
                if (DoVerboseJNI(args) != false)
                {
                    s += "-Xcheck:jni -verbose:jni ";
                }
                s += "-jar \"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                s += "\\..\\Samples\\Demos4Test\\Java\\Test\\JavaTest.jar\"";
                //create process
                pid = remoteBridge.CreateProcess(s, (DoDelayedHook(args) != false) ? false : true, out continueEv);
                if (pid == 0)
                {
                    Console.WriteLine("failed.");
                    return;
                }
                procJavaTest = Process.GetProcessById(pid);
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- INJECT

            try
            {
                Console.Write("Injecting... ");
                remoteBridge.Hook(procJavaTest.Id, eNktHookFlags.flgDebugPrintInterfaces);
                if (continueEv != null)
                {
                    remoteBridge.ResumeProcess(procJavaTest.Id, continueEv);
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- WAIT UNTIL JVM INITIALIZATION

            Console.Write("Waiting for JVM initialization... ");
            try
            {
                while (remoteBridge.IsJVMAttached(procJavaTest.Id, out verMajor, out verMinor) == false)
                {
                    if (procJavaTest.HasExited != false)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Hooked process has ended. Quitting.");
                        return;
                    }
                    if (Console.KeyAvailable != false)
                    {
                        Char ch = Console.ReadKey(true).KeyChar;
                        if (ch == 27)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("Exiting by user request.");
                            //close java test if still open
                            QuitJavaApp(false);
                            return;
                        }
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                QuitJavaApp(true);
                return;
            }

            //---------------- FIND TOPLEVEL WINDOW

            Console.Write("Obtaining main Window... ");
            topLevelFrame = null;
            while (topLevelFrame == null)
            {
                object frames;

                if (procJavaTest.HasExited != false)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Exiting by user request.");
                        //close java test if still open
                        QuitJavaApp(false);
                        return;
                    }
                }
                //get top level frame
                try
                {
                    frames = remoteBridge.InvokeJavaStaticMethod(procJavaTest.Id, "javax.swing.JFrame", "getFrames", null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("failed.");
                    Console.WriteLine(ex.ToString());
                    QuitJavaApp(true);
                    return;
                }
                if (frames is Array)
                {
                    if (((object[])frames).Length > 0)
                    {
                        topLevelFrame = ((object[])frames)[0] as INktJavaObject;
                    }
                }
                if (topLevelFrame == null)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }
            Console.WriteLine("OK");

            //---------------- RUN TESTS

            Console.Write("Running tests...");
            for (int testNo = 1; testNo <= 12; testNo++)
            {
                if (procJavaTest.HasExited != false)
                {
                    Console.WriteLine("Hooked process has ended. Quitting.");
                    return;
                }
                if (Console.KeyAvailable != false)
                {
                    Char ch = Console.ReadKey(true).KeyChar;
                    if (ch == 27)
                    {
                        Console.WriteLine("Exiting by user request.");
                        //close java test if still open
                        QuitJavaApp(false);
                        return;
                    }
                }
                //run test
                bool b = false;
                switch (testNo)
                {
                case 1:
                    b = BooleanTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 2:
                    b = ByteTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 3:
                    b = ShortTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 4:
                    b = CharTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 5:
                    b = IntTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 6:
                    b = LongTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 7:
                    b = FloatTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 8:
                    b = DoubleTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 9:
                    b = DateTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 10:
                    b = BigDecimalTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 11:
                    b = StringTests.RunTests(procJavaTest.Id, remoteBridge);
                    break;

                case 12:
                    remoteBridge.OnJavaCustomNativeCall += Test_OnJavaCustomNativeCall;
                    b = EventCallbackTests.RunTests(procJavaTest.Id, remoteBridge);
                    remoteBridge.OnJavaCustomNativeCall -= Test_OnJavaCustomNativeCall;
                    break;
                }
                if (b == false)
                {
                    QuitJavaApp(true);
                    return;
                }
            }

            //---------------- CLOSE JAVA APP IF STILL RUNNING

            QuitJavaApp(true);
        }
Exemple #14
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //date<->date test
            Console.Write("  Date single value test... ");
            try
            {
                DateTime sBaseDate = new DateTime(2013, 10, 13, 16, 00, 00);
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test", sBaseDate);
                if (res.GetType() != typeof(DateTime))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((DateTime)res != sBaseDate.AddYears(1))
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //date<->date array test
            Console.Write("  Date array test... ");
            try
            {
                DateTime[, ,] arrayDate = new DateTime[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDate[i, j, k] = new DateTime(2013, 10, 13, i, j, k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaDateTest", "Test3D", new object[] { arrayDate });
                if (res.GetType() != typeof(DateTime[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                DateTime[, ,] arrayDateRes = (DateTime[, ,])res;
                if (arrayDateRes.GetLength(0) != 4 || arrayDateRes.GetLength(1) != 6 || arrayDateRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayDateRes[i, j, k] != arrayDate[i, j, k].AddYears(1))
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #15
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //float<->float test
            Console.Write("  Float single value test... ");
            try
            {
                float nBaseFloat = 10.0F;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseFloat);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((float)res != 255.0F - nBaseFloat)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //float<->float array test
            Console.Write("  Float array test... ");
            try
            {
                float[, ,] arrayFloat = new float[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayFloat[i, j, k] = (float)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayFloat });
                if (res.GetType() != typeof(float[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                float[, ,] arrayFloatRes = (float[, ,])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayFloatRes[i, j, k] != 255.0 - arrayFloat[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //double<->float test
            Console.Write("  Float single value test using doubles... ");
            try
            {
                double nBaseDouble = 10.0;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDouble);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((double)(float)res != 255.0 - nBaseDouble)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //double<->float array test
            Console.Write("  Float array test using doubles... ");
            try
            {
                double[, ,] arrayDouble = new double[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDouble[i, j, k] = (double)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDouble });
                if (res.GetType() != typeof(float[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                float[, ,] arrayFloatRes = (float[, ,])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if ((double)arrayFloatRes[i, j, k] != 255.0 - arrayDouble[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //decimal<->float test
            Console.Write("  Float single value test using BigDecimal... ");
            try
            {
                Decimal nBaseDecimal = 10.0M;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDecimal);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                if ((Decimal)(float)(res) != 255.0M - nBaseDecimal)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return false;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");

            //decimal<->float array test
            Console.Write("  Float array test using BigDecimal... ");
            try
            {
                Decimal[, ,] arrayDecimal = new Decimal[4, 6, 5];
                object res;
                int i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDecimal[i, j, k] = new Decimal(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDecimal });
                if (res.GetType() != typeof(float[, ,]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return false;
                }
                float[, ,] arrayFloatRes = (float[, ,])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return false;
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if ((Decimal)arrayFloatRes[i, j, k] != 255.0M - arrayDecimal[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return false;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return false;
            }
            Console.WriteLine("  OK");
            return true;
        }
Exemple #16
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //float<->float test
            Console.Write("  Float single value test... ");
            try
            {
                float  nBaseFloat = 10.0F;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseFloat);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((float)res != 255.0F - nBaseFloat)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //float<->float array test
            Console.Write("  Float array test... ");
            try
            {
                float[, ,] arrayFloat = new float[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayFloat[i, j, k] = (float)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayFloat });
                if (res.GetType() != typeof(float[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                float[, ,] arrayFloatRes = (float[, , ])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayFloatRes[i, j, k] != 255.0 - arrayFloat[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //double<->float test
            Console.Write("  Float single value test using doubles... ");
            try
            {
                double nBaseDouble = 10.0;
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDouble);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((double)(float)res != 255.0 - nBaseDouble)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //double<->float array test
            Console.Write("  Float array test using doubles... ");
            try
            {
                double[, ,] arrayDouble = new double[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDouble[i, j, k] = (double)(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDouble });
                if (res.GetType() != typeof(float[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                float[, ,] arrayFloatRes = (float[, , ])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if ((double)arrayFloatRes[i, j, k] != 255.0 - arrayDouble[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //decimal<->float test
            Console.Write("  Float single value test using BigDecimal... ");
            try
            {
                Decimal nBaseDecimal = 10.0M;
                object  res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test", nBaseDecimal);
                if (res.GetType() != typeof(float))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((Decimal)(float)(res) != 255.0M - nBaseDecimal)
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //decimal<->float array test
            Console.Write("  Float array test using BigDecimal... ");
            try
            {
                Decimal[, ,] arrayDecimal = new Decimal[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayDecimal[i, j, k] = new Decimal(i + j + k);
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaFloatTest", "Test3D", new object[] { arrayDecimal });
                if (res.GetType() != typeof(float[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                float[, ,] arrayFloatRes = (float[, , ])res;
                if (arrayFloatRes.GetLength(0) != 4 || arrayFloatRes.GetLength(1) != 6 || arrayFloatRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if ((Decimal)arrayFloatRes[i, j, k] != 255.0M - arrayDecimal[i, j, k])
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }
Exemple #17
0
        public static bool RunTests(int pid, NktRemoteBridge remoteBridge)
        {
            //bool<->bool test
            Console.Write("  String single value test... ");
            try
            {
                string szBaseString = "this is a test string";
                object res;

                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test", szBaseString);
                if (res.GetType() != typeof(string))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                if ((string)res != "[" + szBaseString + "]")
                {
                    Console.WriteLine("Error: Returned data mismatch");
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");

            //string<->string array test
            Console.Write("  String array test... ");
            try
            {
                string szBaseString = "this is a test string";
                string[, ,] arrayStr = new string[4, 6, 5];
                object res;
                int    i, j, k;

                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            arrayStr[i, j, k] = szBaseString + " " + i.ToString() + "/" + j.ToString() + "/" + k.ToString();
                        }
                    }
                }
                res = remoteBridge.InvokeJavaStaticMethod(pid, "JavaStringTest", "Test3D", new object[] { arrayStr });
                if (res.GetType() != typeof(string[, , ]))
                {
                    Console.WriteLine("Error: Invalid returned type");
                    return(false);
                }
                string[, ,] arrayStrRes = (string[, , ])res;
                if (arrayStrRes.GetLength(0) != 4 || arrayStrRes.GetLength(1) != 6 || arrayStrRes.GetLength(2) != 5)
                {
                    Console.WriteLine("Error: Returned array size mismatch");
                    return(false);
                }
                for (i = 0; i < 4; i++)
                {
                    for (j = 0; j < 6; j++)
                    {
                        for (k = 0; k < 5; k++)
                        {
                            if (arrayStrRes[i, j, k] != "[" + arrayStr[i, j, k] + "]")
                            {
                                Console.WriteLine("Error: Returned data mismatch (" + i.ToString() + "," + j.ToString() + "," + k.ToString() + ")");
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("failed.");
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("  OK");
            return(true);
        }