Example #1
0
        public void TypeTh()
        {
            var            i      = new Throwable();
            RegistryRecord record = Registry.GetRecord(i);

            Assert.IsNotNull(record);
        }
Example #2
0
        public void TypeEx()
        {
            var            i      = new Exception();
            RegistryRecord record = Registry.GetRecord(i);

            Assert.IsNotNull(record);
        }
Example #3
0
        public void TypeNewIface()
        {
            MyClass        val    = new MyClass();
            RegistryRecord record = Registry.GetRecord(val);

            Assert.IsNotNull(record);
        }
Example #4
0
        public void TypeJInt2()
        {
            Integer        i      = new Integer(1);
            RegistryRecord record = Registry.GetRecord(i);

            Assert.IsNotNull(record);
        }
Example #5
0
        public static TRes Cast <TRes>(object obj)
        {
            Type reqType = typeof(TRes);

            if (IsCLRInstance(obj))
            {
                throw new JNIException("Can't cast CLR instance of " + obj.GetType() + " to " + reqType);
            }
            IJvmProxy proxy = obj as IJvmProxy;

            if (!reqType.IsInterface && !typeof(IObject).IsAssignableFrom(reqType))
            {
                throw new JNIException("Can't cast to CLR class");
            }
            RegistryRecord record = Registry.GetCLRRecord(reqType);
            Class          clazz  = proxy.getClass();

            if (!record.JVMInterface.isAssignableFrom(clazz))
            {
                throw new InvalidCastException("Can't cast JVM instance of " + clazz + " to " + record.JVMInterface + "\n (" + clazz.getClassLoader() + "->" + record.JVMInterface.getClassLoader() + ")");
            }
            IJvmProxy res = record.CopyCLRProxy(JNIEnv.ThreadEnv, proxy.JvmHandle);

            return((TRes)res);
        }
Example #6
0
        public void TypeString()
        {
            var            value  = "test";
            RegistryRecord record = Registry.GetRecord(value);

            Assert.IsNotNull(record);
        }
        public IRegistryRecord StringToRegistryRecord(string textToConvertFrom)
        {
            if (StringExtensions.IsNullOrEmptyWhitespace_Ext(textToConvertFrom))
            {
                throw new ArgumentNullException(nameof(textToConvertFrom));
            }

            string[] text = textToConvertFrom.Split(new char[] { ',' });

            ValidateInputData(text);

            string tmpRoot = GetRootFromRegistryPath(text[0]);
            string key     = GetRegistryPathFromString(text[0], tmpRoot);

            RegistryKey       root      = RegistryRecord.ConvertStringToRegistryKey(tmpRoot);
            string            valueName = text[1];
            string            value     = text[2];
            RegistryValueKind valueKind = RegistryValueKind.DWord; // Default value

            if (text.Length == 4)
            {
                valueKind = (RegistryValueKind)Enum.Parse(typeof(RegistryValueKind), text[3], true);
            }

            return(new RegistryRecord(root, key, valueName, value, valueKind));
        }
Example #8
0
        public void TypeInt()
        {
            var            value  = 1;
            RegistryRecord record = Registry.GetRecord(value);

            Assert.IsNotNull(record);
        }
Example #9
0
        public void EqualsIRegRecArg_NullObj_ExpectFalse()
        {
            RegistryRecord registryRecordOther = null;

            bool comparisonResult = registryRecord_testSubject.Equals(registryRecordOther);

            Assert.IsFalse(comparisonResult);
        }
Example #10
0
        public void TypeNewJIface()
        {
            JInterfacesHelper h   = new JInterfacesHelper();
            var            val    = h.createJWithClrInterfaceExt(0);
            RegistryRecord record = Registry.GetRecord(val);

            Assert.IsNotNull(record);
        }
Example #11
0
        public void EqualsObjArg_SameObjWithOtherPointerName_ExpectTrue()
        {
            RegistryRecord anotherPtr = registryRecord_testSubject;

            bool comparisonResult = registryRecord_testSubject.Equals((object)anotherPtr);

            Assert.IsTrue(comparisonResult);
        }
Example #12
0
 private void InitRegistryRecordTestSubject()
 {
     registryRecord_testSubject = new RegistryRecord(Registry.CurrentUser,
                                                     "MyKey/SomePath",
                                                     "TestValueName",
                                                     "11",
                                                     RegistryValueKind.DWord);
 }
Example #13
0
        public void EqualsObjArg_ThisTypeNullObj_ExpectFalse()
        {
            RegistryRecord otherObj = null;

            bool comparisonResult = registryRecord_testSubject.Equals((object)otherObj);

            Assert.IsFalse(comparisonResult);
        }
Example #14
0
        public void OperatorNotEqual_SameObjOtherPtr_ExpectFalse()
        {
            RegistryRecord registryRecordOther = registryRecord_testSubject;

            bool comparisonResult = registryRecord_testSubject != registryRecordOther;

            Assert.IsFalse(comparisonResult);
        }
Example #15
0
        public void ConvertStringToRegistryKey_ClassesRootString_ExpectClassesRootObj()
        {
            string      root = "hkey_CLASSES_root";
            RegistryKey expectedRegistryKey = Registry.ClassesRoot;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Example #16
0
 internal static void Init(JNIEnv env)
 {
     if (Bridge.Setup.BindNative)
     {
         MethodInfo     initializer = Registry.GetWrapperInitializer(typeof(__Bridge), "__Init2");
         RegistryRecord record      = Registry.GetCLRRecord(typeof(Bridge));
         Registry.RegisterNative(initializer, env, record.JVMProxy, record.JVMInterface);
     }
 }
Example #17
0
        public void ConvertStringToRegistryKey_LocalMachineRootStringUpperCase_ExpectLocalMachineRootObj()
        {
            string      root = "HKEY_LOCAL_MACHINE";
            RegistryKey expectedRegistryKey = Registry.LocalMachine;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Example #18
0
        public void ConvertStringToRegistryKey_CurrentUserRootString_ExpectCurrentUserRootObj()
        {
            string      root = "HKEY_CURRENT_USER";
            RegistryKey expectedRegistryKey = Registry.CurrentUser;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Example #19
0
        public void ConvertStringToRegistryKey_LocalMachineRootStringLowerCase_ExpectLocalMachineRootObj()
        {
            string      root = "hkey_local_machine";
            RegistryKey expectedRegistryKey = Registry.LocalMachine;

            RegistryKey actualRegistryKey = RegistryRecord.ConvertStringToRegistryKey(root);

            Assert.AreEqual(expectedRegistryKey, actualRegistryKey);
        }
Example #20
0
        public void TypeCbyCLRProxy()
        {
            JInterfacesHelper  h               = new JInterfacesHelper();
            CWithJavaInterface cwc             = h.getCWithJavaInterfaceC(new CWithJavaInterface(0));
            Object             val             = Bridge.WrapCLR(cwc);
            JniGlobalHandle    jniGlobalHandle = ((IClrProxy)val).JvmHandle;
            RegistryRecord     record          = Registry.GetRecord(JNIEnv.ThreadEnv, jniGlobalHandle, val.getClass());

            Assert.IsNotNull(record);
            jniGlobalHandle.HoldThisHandle();
        }
Example #21
0
        public void EqualsIRegRecArg_ThisTypeObjWithDifferentValues_ExpectFalse()
        {
            IRegistryRecord registryRecordOther = new RegistryRecord(Registry.ClassesRoot,
                                                                     "Key",
                                                                     "ValueName",
                                                                     "",
                                                                     RegistryValueKind.DWord);

            bool comparisonResult = registryRecord_testSubject.Equals(registryRecordOther);

            Assert.IsFalse(comparisonResult);
        }
Example #22
0
        public void OperatorNotEqual_OtherObjWithTheSameValues_ExpectTrue()
        {
            RegistryRecord registryRecordOther = new RegistryRecord(Registry.CurrentUser,
                                                                    "MyKey/SomePath",
                                                                    "TestValueName",
                                                                    "11",
                                                                    RegistryValueKind.DWord);

            bool comparisonResult = registryRecord_testSubject != registryRecordOther;

            Assert.IsTrue(comparisonResult);
        }
Example #23
0
        public void OperatorNotEqual_OtherObjWithDifferentValues_ExpectTrue()
        {
            RegistryRecord registryRecordOther = new RegistryRecord(Registry.ClassesRoot,
                                                                    "Key",
                                                                    "ValueName",
                                                                    "",
                                                                    RegistryValueKind.DWord);

            bool comparisonResult = registryRecord_testSubject != registryRecordOther;

            Assert.IsTrue(comparisonResult);
        }
Example #24
0
        public void EqualsIRegRecArg_ThisTypeObjWithTheSameValues_ExpectTrue()
        {
            IRegistryRecord registryRecordOther = new RegistryRecord(Registry.CurrentUser,
                                                                     "MyKey/SomePath",
                                                                     "TestValueName",
                                                                     "11",
                                                                     RegistryValueKind.DWord);

            bool comparisonResult = registryRecord_testSubject.Equals(registryRecordOther);

            Assert.IsTrue(comparisonResult);
        }
Example #25
0
        public void ConvertStringToRegistryKey_NotSupportedRegistryRoot_ExpectArgumentException()
        {
            string      root        = "HKEY_iMaGiNeD_rOoT_tYpE";
            RegistryKey registryKey = null;

            bool exceptionWasTrown = false;

            try {
                registryKey = RegistryRecord.ConvertStringToRegistryKey(root);
            } catch (ArgumentException) {
                exceptionWasTrown = true;
            }

            Assert.IsTrue(exceptionWasTrown);
            Assert.IsNull(registryKey);
        }
Example #26
0
        private static long WrapJVM(IntPtr __envp, JniLocalHandle __class, JniLocalHandle obj)
        {
            JNIEnv env = JNIEnv.Wrap(__envp);

            try
            {
                Class          clazz    = env.GetObjectClass(obj);
                RegistryRecord record   = Registry.GetJVMRecord(clazz);
                IJvmProxy      clrProxy = record.CreateCLRProxy(env, obj);
                return(IntHandle.Alloc(clrProxy));
            }
            catch (Exception ex)
            {
                env.ThrowExisting(ex);
            }
            return(0);
        }
Example #27
0
        public void StringToRegistryRecordTest_StringWithExistingRegistryPathWithRegKind_NewRegistryPathObject()
        {
            string textToConvertFrom = @"HKEY_CURRENT_USER\Control Panel\Desktop,MenuShowDelay,1,QWord";
            TxtToRegistryRecordSerializer txtToRegistryRecordSerialize = new TxtToRegistryRecordSerializer();

            RegistryKey       root      = Registry.CurrentUser;
            string            key       = @"Control Panel\Desktop";
            string            valueName = "MenuShowDelay";
            string            value     = "1";
            RegistryValueKind valueKind = RegistryValueKind.QWord;

            RegistryRecord expectedRegistryRecord = new RegistryRecord(root, key, valueName, value, valueKind);

            RegistryRecord actualRecord = (RegistryRecord)txtToRegistryRecordSerialize.StringToRegistryRecord(textToConvertFrom);

            Assert.AreEqual(expectedRegistryRecord, actualRecord);
        }
Example #28
0
        public static TRes CreateProxy <TRes>(JniGlobalHandle jvmHandle)
        {
            Type reqType = typeof(TRes);

            if (!reqType.IsInterface && !typeof(IObject).IsAssignableFrom(reqType))
            {
                throw new JNIException("Can't create proxy to CLR class");
            }
            RegistryRecord record = Registry.GetCLRRecord(reqType);
            JNIEnv         env    = JNIEnv.ThreadEnv;
            Class          clazz  = env.GetObjectClass(jvmHandle);

            if (!record.JVMInterface.isAssignableFrom(clazz))
            {
                throw new InvalidCastException("Can't cast JVM instance of " + clazz + " to " + record.JVMInterface + "\n (" + clazz.getClassLoader() + "->" + record.JVMInterface.getClassLoader() + ")");
            }
            IJvmProxy res = record.CopyCLRProxy(env, jvmHandle);

            return((TRes)res);
        }
Example #29
0
        public static Object WrapCLR(object obj)
        {
            var proxy    = obj as IJvmProxy;
            var clrProxy = proxy as IClrProxy;

            if (proxy != null)
            {
                if (clrProxy != null)
                {
                    return((Object)clrProxy);
                }
                throw new JNIException("Can't wrap JVM instance");
            }
            Type   type = obj.GetType();
            JNIEnv env  = JNIEnv.ThreadEnv;

            RegistryRecord record   = Registry.GetCLRRecord(type);
            JniLocalHandle jvmProxy = record.CreateJVMProxy(env, obj);

            return((Object)__IClrProxy.CreateProxy(env, jvmProxy));
        }
Example #30
0
        private static JniLocalHandle Cast(IntPtr @__envp, JniLocalHandle @__class, JniLocalHandle obj, JniLocalHandle expectedInterface)
        {
            JNIEnv env = JNIEnv.Wrap(@__envp);

            try
            {
                Class          expectedInterfaceClass = Convertor.StrongJ2CpClass(env, expectedInterface);
                object         real    = __IClrProxy.GetObject(env, obj);
                Type           type    = real.GetType();
                RegistryRecord record  = Registry.GetJVMRecord(expectedInterfaceClass);
                Type           reqType = record.CLRInterface;
                if (!reqType.IsAssignableFrom(type))
                {
                    throw new InvalidCastException("Can't convert instance of CLR type " + type + " to " + reqType);
                }

                return(record.CreateJVMProxy(env, real));
            }
            catch (Exception ex)
            {
                env.ThrowExisting(ex);
            }
            return(JniLocalHandle.Zero);
        }