static object DoTest(string name, long fileSize, TestCallback testCallback, params object[] args) { long start; long end; long frequency; long clocks; double time; double rate; QueryPerformanceFrequency(out frequency); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); QueryPerformanceCounter(out start); object value = testCallback(args); QueryPerformanceCounter(out end); GetStats(start, end, frequency, fileSize, out clocks, out time, out rate); Console.WriteLine("{0} : {1} ticks, {2:f4} sec., {3:f4} MB/sec.", name.PadRight(25), clocks, time, rate); return(value); }
private void ErrorTemplate(InvokeCallback invoke, TestCallback verify) { this.TestTemplate( invoke, (mock, service, asyncResult) => { mock.DomainClient.Error = new Exception(WebAuthenticationServiceTest.ErrorMessage); mock.DomainClient.RequestCallback(); Assert.IsFalse(mock.DomainClient.CancellationRequested, "Result should not be canceled."); }, verify, true); this.TestTemplate( invoke, (mock, service, asyncResult) => { mock.DomainClient.Error = new Exception(WebAuthenticationServiceTest.ErrorMessage); mock.DomainClient.RequestCallback(WebAuthenticationServiceTest.Delay); this.EnqueueConditional(() => asyncResult.IsCompleted); this.EnqueueCallback(() => { Assert.IsFalse(mock.DomainClient.CancellationRequested, "Result should not be canceled."); }); }, verify, false); this.EnqueueTestComplete(); }
public static void Main () { TestCallback cb = new TestCallback (Test); IAsyncResult ar = cb.BeginInvoke (100, null, null); ar.AsyncWaitHandle.WaitOne (); cb.EndInvoke (ar); }
private void TestTemplate(InvokeCallback invoke, TestCallback proceed, TestCallback verify, bool verifyInCallback) { AuthenticationDomainContext mock = new AuthenticationDomainContext(); MockWebAuthenticationService service = new MockWebAuthenticationService(); service.DomainContext = mock; object state = new object(); bool testCompleted = false; AsyncCallback asyncCallback = ar => { Assert.IsNotNull(ar, "IAsyncResult should not be null."); Assert.AreEqual(state, ar.AsyncState, "States should be equal."); ExceptionHelper.ExpectException <NotSupportedException>( () => Assert.IsNull(ar.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(ar.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); Assert.IsTrue(ar.IsCompleted || mock.DomainClient.CancellationRequested, "IAsyncResult should be complete or cancelled."); try { verify(mock, service, ar); } catch (Exception ex) { this.EnqueueCallback(() => { throw ex; }); } testCompleted = true; }; IAsyncResult asyncResult = invoke(mock, service, verifyInCallback ? asyncCallback : null, state); Assert.IsNotNull(asyncResult, "IAsyncResult should not be null."); Assert.AreEqual(state, asyncResult.AsyncState, "States should be equal."); ExceptionHelper.ExpectException <NotSupportedException>( () => Assert.IsNull(asyncResult.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(asyncResult.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); // We don't have a dispatcher SynchronizationContext when running tests on the // full framework, so the operation will complete on another thread which can happen before we reach this assert // TODO: Try to get tests to run on a dispatcher by using mstest v2 extensobility #if SILVERLIGHT Assert.IsFalse(asyncResult.IsCompleted, "IAsyncResult should not be complete."); #endif proceed(mock, service, asyncResult); if (!verifyInCallback) { this.EnqueueCallback(() => asyncCallback(asyncResult)); } this.EnqueueConditional(() => testCompleted); }
private void CancelTemplate(InvokeCallback invoke, TestCallback proceed, TestCallback verify) { this.TestTemplate( invoke, (mock, service, asyncResult) => { proceed(mock, service, asyncResult); mock.DomainClient.RequestCallback(); Assert.IsTrue(mock.DomainClient.CancellationRequested, "Result should be canceled."); }, verify, false); this.TestTemplate( invoke, (mock, service, asyncResult) => { proceed(mock, service, asyncResult); mock.DomainClient.RequestCallback(WebAuthenticationServiceTest.Delay); this.EnqueueCallback(() => { Assert.IsTrue(mock.DomainClient.CancellationRequested, "Result should be canceled."); }); }, verify, false); this.EnqueueTestComplete(); }
static void rdotnet_discussions_646729(REngine engine) { var setup = @"library(rdotnetsamples) rdotnetsamples::register_default_progress_handler() "; engine.Evaluate(setup); var myRFunction = @" my_r_calculation <- function() { for (i in seq(0, 100, by=20)) { rdotnetsamples::broadcast_progress_update(paste0('Some Update Message for ', i), i); } } "; engine.Evaluate(myRFunction); engine.Evaluate("my_r_calculation()"); var unixDllPath = engine.Evaluate("getLoadedDLLs()$rdotnetsamples[['path']]").AsCharacter()[0]; var dllPath = unixDllPath.Replace("/", "\\"); var dll = new DynamicInterop.UnmanagedDll(dllPath); TestCallback cback = new TestCallback(); CallBackHandlers cbh = new CallBackHandlers(); cback.MyHandler = cbh.ProcessProgress; string cFunctionRegisterCallback = "register_progress_handler"; register_default_progress_handler registerHandlerFun = dll.GetFunction<register_default_progress_handler>(cFunctionRegisterCallback); registerHandlerFun(cback.MyHandler); Console.WriteLine(); Console.WriteLine("After registering the callback with a function pointer to a C# function:"); Console.WriteLine(); engine.Evaluate("my_r_calculation()"); }
public void TestSpectator() { TestCallback callback = new TestCallback(); // Get WCF endpoint EndpointAddress endpointAddress = new EndpointAddress("net.tcp://localhost:8765/TetriNETSpectator"); Binding binding = new NetTcpBinding(SecurityMode.None); InstanceContext instanceContext = new InstanceContext(callback); //_proxy = DuplexChannelFactory<IWCFTetriNET>.CreateChannel(instanceContext, binding, endpointAddress); DuplexChannelFactory <IWCFTetriNETSpectator> factory = new DuplexChannelFactory <IWCFTetriNETSpectator>(instanceContext, binding, endpointAddress); IWCFTetriNETSpectator proxy = factory.CreateChannel(instanceContext); proxy.RegisterSpectator( new Versioning { Major = 1, Minor = 5, }, "joel"); while (true) { System.Threading.Thread.Sleep(10); } }
/// <summary> /// runs one single test without using the reflection mechanisme /// The overhead is very low and therefore better suited for small methods /// However this method doesn't reports results to connected objects like PerformanceTester /// </summary> /// <param name="testMethod">method (delegate) to test</param> /// <returns>test results</returns> public PerformanceTestData RunTest(TestCallback testMethod) { Counter counter = Counter.Instance; PerformanceTestData td = new PerformanceTestData(); td.TestName = testMethod.Method.Name; // single invoke ulong startCount = counter.Count; testMethod(); ulong endCount = counter.Count; td.SingleTime = (uint)Counter.GetElapsed(startCount, endCount); // multiple invoke startCount = counter.Count; for (uint i = 0; i < iterations; i++) { testMethod(); } endCount = counter.Count; td.OverallTime = (uint)Counter.GetElapsed(startCount, endCount); td.TestNum = (uint)iterations; return(td); }
public static void Main() { TestCallback cb = new TestCallback(Test); IAsyncResult ar = cb.BeginInvoke(100, null, null); ar.AsyncWaitHandle.WaitOne(); cb.EndInvoke(ar); }
private void TestTemplate(InvokeCallback invoke, TestCallback proceed, TestCallback verify, bool verifyInCallback) { AuthenticationDomainContext mock = new AuthenticationDomainContext(); MockWebAuthenticationService service = new MockWebAuthenticationService(); service.DomainContext = mock; object state = new object(); bool testCompleted = false; AsyncCallback asyncCallback = ar => { Assert.IsNotNull(ar, "IAsyncResult should not be null."); Assert.AreEqual(state, ar.AsyncState, "States should be equal."); ExceptionHelper.ExpectException <NotSupportedException>( () => Assert.IsNull(ar.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(ar.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); Assert.IsTrue(ar.IsCompleted || mock.DomainClient.CancellationRequested, "IAsyncResult should be complete or cancelled."); verify(mock, service, ar); testCompleted = true; }; IAsyncResult asyncResult = invoke(mock, service, verifyInCallback ? asyncCallback : null, state); Assert.IsNotNull(asyncResult, "IAsyncResult should not be null."); Assert.AreEqual(state, asyncResult.AsyncState, "States should be equal."); ExceptionHelper.ExpectException <NotSupportedException>( () => Assert.IsNull(asyncResult.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(asyncResult.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); Assert.IsFalse(asyncResult.IsCompleted, "IAsyncResult should not be complete."); proceed(mock, service, asyncResult); if (!verifyInCallback) { this.EnqueueCallback(() => asyncCallback(asyncResult)); } this.EnqueueConditional(() => testCompleted); }
public static void Main() { Interfaces.test myTest = (Interfaces.test) Components.CreateInstance("@off.net/test-component;1", typeof(Interfaces.test)); Console.WriteLine("3 + 5 = {0}", myTest.Add(3, 5)); int before = myTest.IntProp; myTest.IntProp = 99; Console.WriteLine("intProp: {0}, (= 99), {1}", before, myTest.IntProp); Console.WriteLine("roIntProp: {0}", myTest.RoIntProp); Console.WriteLine("Invoking callback:"); TestCallback tcb = new TestCallback(); myTest.Callback(tcb); Console.WriteLine("Done!"); }
public void ExecutesDelegate() { Dictionary<string, object> vars = new Dictionary<string, object>(); vars["concat"] = new TestCallback(Concat); FunctionNode fn = new FunctionNode(); fn.Text = "concat"; StringLiteralNode str = new StringLiteralNode(); str.Text = "theValue"; fn.addChild(str); StringLiteralNode str2 = new StringLiteralNode(); str2.Text = "theValue"; fn.addChild(str2); IExpression exp = fn; Assert.AreEqual(string.Format("{0},{1},{2}", this.GetHashCode(), str.Text, str2.Text), exp.GetValue(null, vars)); }
public void ExecutesDelegate() { Hashtable vars = new Hashtable(); vars["concat"] = new TestCallback(Concat); FunctionNode fn = new FunctionNode(); fn.Text = "concat"; StringLiteralNode str = new StringLiteralNode(); str.Text = "theValue"; fn.addChild(str); StringLiteralNode str2 = new StringLiteralNode(); str2.Text = "theValue"; fn.addChild(str2); IExpression exp = fn; Assert.AreEqual(string.Format("{0},{1},{2}", this.GetHashCode(), str.Text, str2.Text), exp.GetValue(null, vars)); }
public async Task CallbackExecuted() { var executor = Mock.Of <ICallbackExecutor <object> >(); var executorMock = Mock.Get(executor); BindingDelegate <object> parameterBinder = context => { }; executorMock .Setup(_ => _.Execute(It.Is <CallbackExecutionParameters <object> >(o => o.Parameters.Length == 1 && o.Binder == parameterBinder && o.ResultTargetType == typeof(string)))).Returns(Task.FromResult(new object())); executorMock.SetupGet(_ => _.CanExecute).Returns(true); var callback = new TestCallback(1, executor, parameterBinder, typeof(string)); var result = await callback.ExecuteAsync("str"); Assert.NotNull(result); }
static bool TestCallback() { TestCallback testCall = new TestCallback("InteropSample_TestDriver", 12345, 10); // Register callback NativeEventHandler eventHandler = new NativeEventHandler(testCall.OnNativeEvent); testCall.OnInterrupt += eventHandler; // Now wait for 10 callbacks bool retVal = testCall.TestCallbacks(); testCall.OnInterrupt -= eventHandler; testCall.Dispose(); return(retVal); }
static void TestSavegameLoad() { Trace.Write("Trying to load savegame"); //Initialize pub class object Publisher p = new Publisher(); TestCallback cb = new TestCallback(); cb.OnStart.Subscribe(TestOnStart); cb.OnUpdate.Subscribe(TestOnUpdate); cb.OnStop.Subscribe(TestOnStop); string filename = @"E:\GitHub\satisfactory-save-repairer-ng\TestBed\NF-Start.sav"; //string filename = @"C:\Users\SillyBits\AppData\Local\FactoryGame\Saved\SaveGames\testfile2.sav"; Savegame.Savegame sg = new Savegame.Savegame(filename); sg.Load(cb); Trace.Write("Finished loading savegame"); }
static void TestPubSub() { //Initialize pub class object Publisher p = new Publisher(); TestCallback cb = new TestCallback(); TestListener l = new TestListener(); //cb.OnStart.Subscribe(TestOnStart); cb.OnStart.Subscribe((sender, data) => l.TestOnStart(sender, data)); cb.OnUpdate.Subscribe(l.TestOnUpdate); cb.OnStop.Subscribe(l.TestOnStop); cb.OnStart.Subscribe(TestOnStart); cb.OnUpdate.Subscribe(TestOnUpdate); cb.OnStop.Subscribe(TestOnStop); //p.Raise(cb.Start, new EventData()); cb.Start(new TestCallback.StartData()); // Line below should show an type error //cb.Update(new TestCallback.StartData()); }
static void rdotnet_discussions_646729(REngine engine) { var setup = @"library(rdotnetsamples) rdotnetsamples::register_default_progress_handler() "; engine.Evaluate(setup); var myRFunction = @" my_r_calculation <- function() { for (i in seq(0, 100, by=20)) { rdotnetsamples::broadcast_progress_update(paste0('Some Update Message for ', i), i); } } "; engine.Evaluate(myRFunction); engine.Evaluate("my_r_calculation()"); var unixDllPath = engine.Evaluate("getLoadedDLLs()$rdotnetsamples[['path']]").AsCharacter()[0]; var dllPath = unixDllPath.Replace("/", "\\"); var dll = new DynamicInterop.UnmanagedDll(dllPath); TestCallback cback = new TestCallback(); CallBackHandlers cbh = new CallBackHandlers(); cback.MyHandler = cbh.ProcessProgress; string cFunctionRegisterCallback = "register_progress_handler"; register_default_progress_handler registerHandlerFun = dll.GetFunction <register_default_progress_handler>(cFunctionRegisterCallback); registerHandlerFun(cback.MyHandler); Console.WriteLine(); Console.WriteLine("After registering the callback with a function pointer to a C# function:"); Console.WriteLine(); engine.Evaluate("my_r_calculation()"); }
static object DoTest(string name, long fileSize, TestCallback testCallback, params object[] args) { long start; long end; long frequency; long clocks; double time; double rate; QueryPerformanceFrequency(out frequency); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); QueryPerformanceCounter(out start); object value = testCallback(args); QueryPerformanceCounter(out end); GetStats(start, end, frequency, fileSize, out clocks, out time, out rate); Console.WriteLine("{0} : {1} ticks, {2:f4} sec., {3:f4} MB/sec.", name.PadRight(25), clocks, time, rate); return value; }
public void SetTimer(TestCallback Callback, int time) { isStart = true; }
public void Hoge(TestCallback Callback, string s) { Callback(s, totalTime); }
public TestRunItem (string url, TestCallback callback) : this (url, null, callback) {}
public TestRunItem (string url, string urlDescription, TestCallback callback) { Url = url; Callback = callback; UrlDescription = urlDescription; }
public string TestClientCallback(string name, TestCallback callback) { return callback.SayHello(name); }
public override void HandleMouseUp(System.Windows.Forms.MouseEventArgs e, TreeNode tn) { if (this.Layout == null || this.Layout.TreeView == null) return; IMaxNode node = TreeMode.GetMaxNode(tn); if (node == null) return; IEnumerable<IMaxNode> contextNodes = TreeMode.GetMaxNodes(this.GetContextNodes(tn)); IntPtr hwnd = MaxInterfaces.MaxHwnd.Handle; Color nodeColor = GetNodeColor(node); IAColor initColor = MaxInterfaces.Global.AColor.Create(nodeColor.R / 255f, nodeColor.G / 255f, nodeColor.B / 255f, nodeColor.A / 255f); IIPoint2 initPos = MaxInterfaces.Global.IPoint2NS.Create(200, 200); IHSVCallback colorPickerCallback = new TestCallback(contextNodes, initColor, PreviewNodeColor, CommitNodeColor); IColorPicker colorPicker = MaxInterfaces.Global.CreateColorPicker(hwnd, initColor, initPos, colorPickerCallback, "Test", 0); //Color color = GetNodeColor(node); //IInterface ip = MaxInterfaces.Global.COREInterface; //if (ip.NodeColorPicker(ip.MAXHWnd, ref color)) //{ // TreeView tree = this.Layout.TreeView; // IEnumerable<TreeNode> nodes = null; // if (tn.IsSelected && !ControlHelpers.ControlPressed) // nodes = tree.SelectedNodes; // else // nodes = new List<TreeNode>(1) { tn }; // IEnumerable<IMaxNode> maxNodes = TreeMode.GetMaxNodes(nodes); // SetNodeColor(maxNodes, Colors.FromMaxColor(color)); // //if (tree.NodeSorter is NodePropertySorter && // // ((NodePropertySorter)tree.NodeSorter).Property == this.Property) // //{ // // tree.StartTimedSort(nodes); // //} //} }
public void TestLogin(TestCallback callback) { GetResponse("rtm.test.login", false, (response) => { if (response.Status == ResponseStatus.OK) { callback(true); } else { if (response.Error.Code == ErrorCode.UserNotLoggedInOrInsufficientPermissions) callback(false); else throw new RtmException(response.Error); } }); }
public TestRunItem(string url, TestCallback callback) : this(url, null, callback) { }
public TestRunItem(string url, string urlDescription, TestCallback callback) { Url = url; Callback = callback; UrlDescription = urlDescription; }
public void Timer(TestCallback Callback) { }
private void TestTemplate(InvokeCallback invoke, TestCallback proceed, TestCallback verify, bool verifyInCallback) { AuthenticationDomainContext mock = new AuthenticationDomainContext(); MockWebAuthenticationService service = new MockWebAuthenticationService() ; service.DomainContext = mock; object state = new object(); bool testCompleted = false; AsyncCallback asyncCallback = ar => { Assert.IsNotNull(ar, "IAsyncResult should not be null."); Assert.AreEqual(state, ar.AsyncState, "States should be equal."); ExceptionHelper.ExpectException<NotSupportedException>( () => Assert.IsNull(ar.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(ar.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); Assert.IsTrue(ar.IsCompleted || mock.DomainClient.CancellationRequested, "IAsyncResult should be complete or cancelled."); verify(mock, service, ar); testCompleted = true; }; IAsyncResult asyncResult = invoke(mock, service, verifyInCallback ? asyncCallback : null, state); Assert.IsNotNull(asyncResult, "IAsyncResult should not be null."); Assert.AreEqual(state, asyncResult.AsyncState, "States should be equal."); ExceptionHelper.ExpectException<NotSupportedException>( () => Assert.IsNull(asyncResult.AsyncWaitHandle, "This property is not supported.")); Assert.IsFalse(asyncResult.CompletedSynchronously, "IAsyncResult should not have completed synchronously."); Assert.IsFalse(asyncResult.IsCompleted, "IAsyncResult should not be complete."); proceed(mock, service, asyncResult); if (!verifyInCallback) { this.EnqueueCallback(() => asyncCallback(asyncResult)); } this.EnqueueConditional(() => testCompleted); }