Wraps a NATIVE_CALLBACK callback around a JET_CALLBACK. This is used to catch exceptions and provide argument conversion.
Пример #1
0
 public void VerifyIsWrappingReturnsFalseForNoMatch()
 {
     JET_CALLBACK callback = CreateCallback();
     var wrapper = new JetCallbackWrapper(callback);
     Assert.IsFalse(wrapper.IsWrapping(CreateCallback()));
     GC.KeepAlive(callback);
 }
Пример #2
0
        public void VerifyWrapperCallsCallback()
        {
            bool callbackWasCalled = false;
            var wrapper = new JetCallbackWrapper(
                (sesid, dbid, tableid, cbtyp, arg1, arg2, context, unused) =>
                {
                    callbackWasCalled = true;
                    return JET_err.Success;
                });

            wrapper.NativeCallback(IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            Assert.IsTrue(callbackWasCalled);
        }
Пример #3
0
        /// <summary>
        /// Wrap a callback and returns its wrapper. If the callback is
        /// already wrapped then the existing wrapper is returned.
        /// </summary>
        /// <param name="callback">The callback to add.</param>
        /// <returns>The callback wrapper for the callback.</returns>
        public JetCallbackWrapper Add(JET_CALLBACK callback)
        {
            lock (this.lockObject)
            {
                JetCallbackWrapper wrapper;
                if (!this.TryFindWrapperFor(callback, out wrapper))
                {
                    wrapper = new JetCallbackWrapper(callback);
                    this.callbackWrappers.Add(wrapper);
                }

                return wrapper;
            }
        }
Пример #4
0
        /// <summary>
        /// Look in the list of callback wrappers to see if there is already an entry for
        /// this callback.
        /// </summary>
        /// <param name="callback">The callback to look for.</param>
        /// <param name="wrapper">Returns the wrapper, if found.</param>
        /// <returns>True if a wrapper was found, false otherwise.</returns>
        private bool TryFindWrapperFor(JET_CALLBACK callback, out JetCallbackWrapper wrapper)
        {
            foreach (JetCallbackWrapper w in this.callbackWrappers)
            {
                if (w.IsWrapping(callback))
                {
                    wrapper = w;
                    return(true);
                }
            }

            wrapper = null;
            return(false);
        }
Пример #5
0
        /// <summary>
        /// Wrap a callback and returns its wrapper. If the callback is
        /// already wrapped then the existing wrapper is returned.
        /// </summary>
        /// <param name="callback">The callback to add.</param>
        /// <returns>The callback wrapper for the callback.</returns>
        public JetCallbackWrapper Add(JET_CALLBACK callback)
        {
            lock (this.lockObject)
            {
                JetCallbackWrapper wrapper;
                if (!this.TryFindWrapperFor(callback, out wrapper))
                {
                    wrapper = new JetCallbackWrapper(callback);
                    this.callbackWrappers.Add(wrapper);
                }

                return(wrapper);
            }
        }
Пример #6
0
        /// <summary>
        /// Look in the list of callback wrappers to see if there is already an entry for 
        /// this callback.
        /// </summary>
        /// <param name="callback">The callback to look for.</param>
        /// <param name="wrapper">Returns the wrapper, if found.</param>
        /// <returns>True if a wrapper was found, false otherwise.</returns>
        private bool TryFindWrapperFor(JET_CALLBACK callback, out JetCallbackWrapper wrapper)
        {
            foreach (JetCallbackWrapper w in this.callbackWrappers)
            {
                if (w.IsWrapping(callback))
                {
                    wrapper = w;
                    return true;
                }
            }

            wrapper = null;
            return false;
        }
Пример #7
0
        public void VerifyWrapperReturnsReturnCode()
        {
            var wrapper = new JetCallbackWrapper(
                (sesid, dbid, tableid, cbtyp, arg1, arg2, context, unused) => JET_err.WriteConflict);

            Assert.AreEqual(
                JET_err.WriteConflict,
                wrapper.Callback(IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
        }
Пример #8
0
        public void VerifyWrapperPassesArguments()
        {
            JET_SESID expectedSesid = new JET_SESID { Value = (IntPtr)1 };
            JET_DBID expectedDbid = new JET_DBID { Value = 2 };
            JET_TABLEID expectedTableid = new JET_TABLEID { Value = (IntPtr)3 };
            JET_cbtyp expectedCbtyp = JET_cbtyp.AfterReplace;
            object expectedArg1 = null;
            object expectedArg2 = null;
            IntPtr expectedContext = (IntPtr)4;

            JET_SESID actualSesid = new JET_SESID();
            JET_DBID actualDbid = new JET_DBID();
            JET_TABLEID actualTableid = new JET_TABLEID();
            JET_cbtyp actualCbtyp = JET_cbtyp.Null;
            object actualArg1 = null;
            object actualArg2 = null;
            IntPtr actualContext = new IntPtr();

            var wrapper = new JetCallbackWrapper(
                (sesid, dbid, tableid, cbtyp, arg1, arg2, context, unused) =>
                {
                    actualSesid = sesid;
                    actualDbid = dbid;
                    actualTableid = tableid;
                    actualCbtyp = cbtyp;
                    actualArg1 = arg1;
                    actualArg2 = arg2;
                    actualContext = context;
                    return JET_err.Success;
                });

            wrapper.Callback(
                expectedSesid.Value,
                expectedDbid.Value,
                expectedTableid.Value,
                (uint)expectedCbtyp,
                IntPtr.Zero,
                IntPtr.Zero,
                expectedContext,
                IntPtr.Zero);

            Assert.AreEqual(expectedSesid, actualSesid);
            Assert.AreEqual(expectedDbid, actualDbid);
            Assert.AreEqual(expectedTableid, actualTableid);
            Assert.AreEqual(expectedCbtyp, actualCbtyp);
            Assert.AreEqual(expectedArg1, actualArg1);
            Assert.AreEqual(expectedArg2, actualArg2);
            Assert.AreEqual(expectedContext, actualContext);
        }
Пример #9
0
        public void VerifyExceptionInCallbackIsCaught()
        {
            var wrapper = new JetCallbackWrapper(
                (sesid, dbid, tableid, cbtyp, arg1, arg2, context, unused) =>
                {
                    throw new ArgumentNullException();
                });

            Assert.AreEqual(
                JET_err.CallbackFailed,
                wrapper.Callback(IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
        }