public void GestureCallbacksTest() { GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath); string eventName; // Hold our accessor callbacks Dictionary<string, GestureCallback> gestureCallbacks = new Dictionary<string, GestureCallback>(); gestureCallbacks.Add("Sync", (eventArgs) => { eventName = eventArgs.Name; }); gestureCallbacks.Add("Wave", (eventArgs) => { eventName = eventArgs.Name; }); gestureCallbacks.Add("Shake", (eventArgs) => { eventName = eventArgs.Name; }); try { // Set the Gesture Callbacks recognizer.GestureCallbacks = gestureCallbacks; // Make sure the Gesture Callbacks were updated Assert.AreEqual(gestureCallbacks, recognizer.GestureCallbacks); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SyncGestureTest() { try { GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath); // Hold our sync gesture IavaGesture syncGesture = new IavaGesture("Sync", new List<IavaSnapshot>()); try { // Set the Sync Gesture recognizer.SyncGesture = syncGesture; // Make sure the Sync Gesture was updated Assert.AreEqual(syncGesture, recognizer.SyncGesture); } catch (Exception ex) { Assert.Fail(ex.Message); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void SupportedGesturesTest() { try { GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath); // Hold our supported gestures List<IavaGesture> supportedGestures = new List<IavaGesture>(); supportedGestures.Add(new IavaGesture("Sync", new List<IavaSnapshot>())); supportedGestures.Add(new IavaGesture("Wave", new List<IavaSnapshot>())); supportedGestures.Add(new IavaGesture("Shake", new List<IavaSnapshot>())); try { // Set the Supported Gestures recognizer.SupportedGestures = supportedGestures; // Make sure the Supported Gestures were updated Assert.AreEqual(supportedGestures, recognizer.SupportedGestures); } catch (Exception ex) { Assert.Fail(ex.Message); } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void GestureRecognizerConstructorTest() { // Supply an empty file filepath try { GestureRecognizer recognizer = new GestureRecognizer(string.Empty); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } // Pass in a null file filepath try { GestureRecognizer recognizer = new GestureRecognizer(null); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } // Pass in a file filepath that does not exist try { GestureRecognizer recognizer = new GestureRecognizer(@"C:\Does\not\exist\"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } // Pass in an existing filepath try { GestureRecognizer recognizer = new GestureRecognizer(_directoryPath); } catch (Exception ex) { Assert.Fail(ex.Message); } try { GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath); // Make sure GestureCallbacks exist Assert.IsNotNull(recognizer.GestureCallbacks); // Make sure the GestureCallbacks is a dictionary Assert.IsInstanceOfType(recognizer.GestureCallbacks, typeof(Dictionary<string, GestureCallback>)); // Hold our accessor callbacks (in this case empty) Dictionary<string, GestureCallback> expectedCallbacks = new Dictionary<string, GestureCallback>(); // Make sure we have the same number of callbacks as we are expecting Assert.AreEqual(recognizer.GestureCallbacks.Count, expectedCallbacks.Count); // Make sure SupportedGestures exist Assert.IsNotNull(recognizer.SupportedGestures); // Make sure the SupportedGestures is a list Assert.IsInstanceOfType(recognizer.SupportedGestures, typeof(List<IavaGesture>)); // Hold our accessor gestures (in this case empty) List<string> expectedGestures = new List<string>(); // Make sure we have the same number of gestures as we are expecting Assert.AreEqual(recognizer.SupportedGestures.Count, expectedGestures.Count); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void GestureUnsubscribeTest() { try { GestureRecognizer_Accessor recognizer = new GestureRecognizer_Accessor(_directoryPath); string eventName; // Hold our accessor callbacks and a key kinectFrame pair for the subscription signature Dictionary<string, GestureCallback> expectedCallbacks = new Dictionary<string, GestureCallback>(); KeyValuePair<string, GestureCallback> subscriptionSignature = new KeyValuePair<string, GestureCallback>(); // Try to do things correctly the first time try { // Create the subscription signature for the 'Sync' Gesture subscriptionSignature = new KeyValuePair<string, GestureCallback>("Sync", (eventArgs) => { eventName = eventArgs.Name; }); // Subscribe to the gesture recognizer.Subscribe(subscriptionSignature.Key, subscriptionSignature.Value); // Add it to our accessor callbacks expectedCallbacks.Add(subscriptionSignature.Key, subscriptionSignature.Value); // Create the subscription signature for the 'Wave' Gesture subscriptionSignature = new KeyValuePair<string, GestureCallback>("Wave", (eventArgs) => { eventName = eventArgs.Name; }); // Subscribe to the gesture recognizer.Subscribe(subscriptionSignature.Key, subscriptionSignature.Value); // Add it to our accessor callbacks expectedCallbacks.Add(subscriptionSignature.Key, subscriptionSignature.Value); // Unsubscribe from the 'Wave' gesture recognizer.Unsubscribe("Wave"); // Remove it from our accessor callbacks expectedCallbacks.Remove("Wave"); // Make sure we have the same number of callbacks Assert.AreEqual(expectedCallbacks.Count, recognizer.GestureCallbacks.Count); // Do a deep inspection to make sure all the elements are the same foreach (var pair in recognizer.GestureCallbacks) { string key = pair.Key; Assert.IsTrue(recognizer.GestureCallbacks.ContainsKey(key)); Assert.AreEqual(expectedCallbacks[key], recognizer.GestureCallbacks[key]); } } catch (Exception ex) { Assert.Fail(ex.Message); } // Try to unsubscribe while passing in an empty gesture name try { recognizer.Unsubscribe(string.Empty); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } // Try to unsubscribe without passing in a gesture name try { recognizer.Unsubscribe(null); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); } // Try to unsubscribe from a gesture that doesn't exist try { recognizer.Unsubscribe("Nonexistant Gesture"); } catch (Exception ex) { Assert.Fail(ex.Message); } // Try to unsubscribe from a gesture that we already removed try { recognizer.Unsubscribe("Wave"); } catch (Exception ex) { Assert.Fail(ex.Message); } // After all that make sure nothing has changed Assert.AreEqual(expectedCallbacks.Count, recognizer.GestureCallbacks.Count); // Do a deep inspection to make sure all the elements are the same foreach (var pair in recognizer.GestureCallbacks) { string key = pair.Key; Assert.IsTrue(recognizer.GestureCallbacks.ContainsKey(key)); Assert.AreEqual(expectedCallbacks[key], recognizer.GestureCallbacks[key]); } } catch (Exception ex) { Assert.Fail(ex.Message); } }