コード例 #1
0
        public void IsMatchTest_PossibleIssueWithAddressPatternWildcard5()
        {
            string addressPattern = "/?*test";
            string address        = "/1_test";

            Assert.IsTrue(OscAddress.IsMatch(addressPattern, address));
        }
コード例 #2
0
        public void IsMatchTest_PossibleIssueWithAddressPatternWildcard8()
        {
            string addressPattern = "/???test??";
            string address        = "/test";

            Assert.IsFalse(OscAddress.IsMatch(addressPattern, address));
        }
コード例 #3
0
ファイル: OscAddressTest.cs プロジェクト: tilde-love/osc-core
        public void IsMatchTest_LiteralMatch()
        {
            string addressPattern = "/container_A/method_A";
            string address        = "/container_A/method_A";

            Assert.True(OscAddress.IsMatch(addressPattern, address));
        }
コード例 #4
0
        public void IsMatchTest_PossibleIssueWithAddressPatternWildcard10()
        {
            string addressPattern = "/???test*?";
            string address        = "/123test9";

            Assert.IsTrue(OscAddress.IsMatch(addressPattern, address));
        }
コード例 #5
0
        public string ReadAddress(bool validate)
        {
            OscSerializationToken token = ReadNextToken(out string value);

            if (token != OscSerializationToken.Literal)
            {
                throw new OscException(OscError.ErrorParsingOscAdress, $"Unexpected serialization token {token}");
            }

            string address = value.Trim();

            if (validate != true)
            {
                return(address);
            }

            if (string.IsNullOrWhiteSpace(address))
            {
                throw new Exception("Address was empty");
            }

            if (OscAddress.IsValidAddressPattern(address) == false)
            {
                throw new Exception("Invalid address");
            }

            return(address);
        }
コード例 #6
0
        public void IsMatchTest_LiteralMissmatch2()
        {
            string addressPattern = "/container_A/method_A";
            string address        = "/container_B/method_A";

            Assert.IsFalse(OscAddress.IsMatch(addressPattern, address));
        }
コード例 #7
0
        public void Match_NonMatchingAddressAndPattern_False(string addressString, string patternString)
        {
            var sut     = new Interpreter(new Lexer());
            var address = new OscAddress(addressString);
            var pattern = new OscAddressPattern(patternString);

            Assert.False(sut.Match(address, pattern));
        }
コード例 #8
0
        void Ctor_StringWithTrailingSlash_EmptySegment()
        {
            var sut = new OscAddress("/abc/");

            Assert.Collection(sut.Segments,
                              segment => Assert.Equal("abc", segment),
                              segment => Assert.Equal("", segment));
        }
コード例 #9
0
        public void IsValid_BasicAddress_True()
        {
            var sut = new OscAddress("/abc");

            var result = sut.IsValid(out var messages);

            Assert.True(result);
            Assert.Empty(messages);
        }
コード例 #10
0
        void Ctor_StringWithConsecutiveSlashes_EmptySegments()
        {
            var sut = new OscAddress("/a//bc");

            Assert.Collection(sut.Segments,
                              segment => Assert.Equal("a", segment),
                              segment => Assert.Equal("", segment),
                              segment => Assert.Equal("bc", segment));
        }
コード例 #11
0
        public static void CreateAddresses(int count)
        {
            int length = StaticObjects.Good_AddressPatterns.Length;

            for (int i = 0; i < count; i++)
            {
                OscAddress address = new OscAddress(StaticObjects.Good_AddressPatterns[i % length]);
            }
        }
コード例 #12
0
        void Ctor_StringWithMultipleSlashes_MultipleSegments()
        {
            var sut = new OscAddress("/a/b/c");

            Assert.Collection(sut.Segments,
                              segment => Assert.Equal("a", segment),
                              segment => Assert.Equal("b", segment),
                              segment => Assert.Equal("c", segment));
        }
コード例 #13
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var controls = OscAddress.GetChildrenWithValue(this);

            this.Vm          = new SynthViewModel(controls);
            this.DataContext = Vm;
            Vm.Parent        = this.Parent as Window;
            Vm.Initialize();
        }
コード例 #14
0
        public void IsValid_EmptySegment_False()
        {
            var sut = new OscAddress("/a//bc");

            var result = sut.IsValid(out var messages);

            Assert.False(result);
            Assert.Collection(messages,
                              m => Assert.Equal("1: Segment cannot be empty.", m));
        }
コード例 #15
0
        public void OscAddress_Constructor_Good()
        {
            for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Good_AddressPatterns[i];

                OscAddress result = new OscAddress(address);

                Assert.AreEqual(address, result.ToString_Rebuild(), String.Format("Failed to parse address pattern {0} '{1}'", i, address));
            }
        }
コード例 #16
0
ファイル: OscAddressTest.cs プロジェクト: tilde-love/osc-core
        public void IsValidAddressPatternTest_Good()
        {
            for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Good_AddressPatterns[i];

                bool result = OscAddress.IsValidAddressPattern(address);

                Assert.True(result, $"Failed to validate address pattern {i} '{address}'");
            }
        }
コード例 #17
0
        public void IsValidAddressPatternTest_Good()
        {
            for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Good_AddressPatterns[i];

                bool result = OscAddress.IsValidAddressPattern(address);

                Assert.IsTrue(result, String.Format("Failed to validate address pattern {0} '{1}'", i, address));
            }
        }
コード例 #18
0
ファイル: OscAddressTest.cs プロジェクト: tilde-love/osc-core
        public void IsValidAddressPatternTest_Bad()
        {
            for (int i = 0; i < UnitTestHelper.Bad_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Bad_AddressPatterns[i];

                bool result = OscAddress.IsValidAddressPattern(address);

                Assert.False(result, $"Incorrectly validated address pattern {i} '{address}'");
            }
        }
コード例 #19
0
        public void OscAddress_Constructor_Good()
        {
            for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Good_AddressPatterns[i];

                OscAddress result = new OscAddress(address);

                Assert.AreEqual(address, result.ToString(), $"Failed to parse address pattern {i} '{address}'");
            }
        }
コード例 #20
0
ファイル: BaseControl.cs プロジェクト: mohabouje/Polyhedrus
        private void SetModuleAddress()
        {
            var children = OscAddress.GetChildrenWithValue(this);

            foreach (var child in children)
            {
                var currentVal = OscAddress.GetAddress(child.Key);
                var newVal     = currentVal.Replace("*", moduleAddress);
                OscAddress.SetAddress(child.Key, newVal);
            }
        }
コード例 #21
0
        public void IsValidAddressPatternTest_Bad()
        {
            for (int i = 0; i < UnitTestHelper.Bad_AddressPatterns.Length; i++)
            {
                string address = UnitTestHelper.Bad_AddressPatterns[i];

                bool result = OscAddress.IsValidAddressPattern(address);

                Assert.IsFalse(result, String.Format("Incorrectly validated address pattern {0} '{1}'", i, address));
            }
        }
コード例 #22
0
ファイル: UnitTestHelper.cs プロジェクト: tilde-love/osc-core
        public static string RebuildOscAddress(OscAddress address)
        {
            StringBuilder sb = new StringBuilder();

            foreach (OscAddressPart part in address)
            {
                sb.Append(part.Interpreted);
            }

            return(sb.ToString());
        }
コード例 #23
0
 private void ListenerAddress_TextChanged(object sender, EventArgs e)
 {
     // try to parse the osc address literal
     if (OscAddress.IsValidAddressPattern(m_ListenerAddress.Text) == true)
     {
         // if it parsed ok then green
         m_ListenerAddress.BackColor = Color.LightGreen;
     }
     else
     {
         // if there was a problem parsing the address then red (pink)
         m_ListenerAddress.BackColor = Color.Pink;
     }
 }
コード例 #24
0
ファイル: StaticObjects.cs プロジェクト: HakanL/Haukcode.Osc
        static StaticObjects()
        {
            #region Parsed_Addresses

            Parsed_Addresses = new OscAddress[StaticObjects.Good_AddressPatterns.Length];

            for (int i = 0; i < Parsed_Addresses.Length; i++)
            {
                Parsed_Addresses[i] = new OscAddress(StaticObjects.Good_AddressPatterns[i]);
            }

            #endregion

            #region Parsed_AddressPatternMatches

            Parsed_AddressPatternMatches = new OscAddress[StaticObjects.Good_AddressPatternMatches.Length];

            for (int i = 0; i < Parsed_AddressPatternMatches.Length; i++)
            {
                Parsed_AddressPatternMatches[i] = new OscAddress(StaticObjects.Good_AddressPatternMatches[i]);
            }

            #endregion

            All_Addresses = new string[StaticObjects.Good_AddressPatterns.Length + StaticObjects.Good_AddressPatternMatches.Length];

            for (int i = 0; i < Good_AddressPatterns.Length; i++)
            {
                All_Addresses[i] = StaticObjects.Good_AddressPatterns[i];
            }

            for (int i = 0; i < Good_AddressPatternMatches.Length; i++)
            {
                All_Addresses[StaticObjects.Good_AddressPatterns.Length + i] = StaticObjects.Good_AddressPatternMatches[i];
            }

            Parsed_Messages = new OscMessage[All_Addresses.Length];

            for (int i = 0; i < All_Addresses.Length; i++)
            {
                Parsed_Messages[i] = new OscMessage(StaticObjects.All_Addresses[i]);
            }

            Mananger = new OscAddressManager();

            for (int i = 0; i < Good_AddressPatterns.Length; i++)
            {
                Mananger.Attach(StaticObjects.Good_AddressPatterns[i], DummyMethod);
            }
        }
コード例 #25
0
        public void AddressPatternMatches()
        {
            for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++)
            {
                string pattern = UnitTestHelper.Good_AddressPatterns[i];
                string address = UnitTestHelper.Good_AddressPatternMatches[i];

                OscAddress target = new OscAddress(pattern);

                bool result = target.Match(address);

                Assert.IsTrue(result, String.Format("Failed to match address pattern {0} '{1}' to '{2}'", i, pattern, address));
            }
        }
コード例 #26
0
        public void IsValid_IllegalCharsSegment_False()
        {
            var sut = new OscAddress("/a /b#*,?[]{}");

            var result = sut.IsValid(out var messages);

            Assert.False(result);
            Assert.Collection(messages,
                              m => Assert.Equal("0: Segment may not contain ' '.", m),
                              m => Assert.Equal("1: Segment may not contain '#'.", m),
                              m => Assert.Equal("1: Segment may not contain '*'.", m),
                              m => Assert.Equal("1: Segment may not contain ','.", m),
                              m => Assert.Equal("1: Segment may not contain '?'.", m),
                              m => Assert.Equal("1: Segment may not contain '['.", m),
                              m => Assert.Equal("1: Segment may not contain ']'.", m),
                              m => Assert.Equal("1: Segment may not contain '{'.", m),
                              m => Assert.Equal("1: Segment may not contain '}'.", m));
        }
コード例 #27
0
ファイル: Interpreter.cs プロジェクト: secretlocation/osc-net
        public bool Match(OscAddress oscAddress, OscAddressPattern pattern)
        {
            if (oscAddress.Segments.Length != pattern.Segments.Length)
            {
                return(false);
            }

            for (var i = 0; i < oscAddress.Segments.Length; i++)
            {
                var tokens = lexer.GetTokens(pattern.Segments[i]);
                var regex  = GetRegex(tokens);

                if (!regex.IsMatch(oscAddress.Segments[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #28
0
ファイル: OscMessage.cs プロジェクト: tilde-love/osc-core
        /// <summary>
        ///     Construct a OSC message
        /// </summary>
        /// <param name="origin">the origin of the OSC message</param>
        /// <param name="address">An OSC address that is the destination for this message</param>
        /// <param name="args">
        ///     Object array of OSC argument values. The type tag string will be created automatically according to
        ///     each argument type
        /// </param>
        /// <example>OscMessage message = new OscMessage("/test/test", 1, 2, 3);</example>
        public OscMessage(Uri origin, string address, params object[] args)
        {
            Origin    = origin;
            Address   = address;
            arguments = args;

            if (string.IsNullOrWhiteSpace(Address))
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (OscAddress.IsValidAddressPattern(address) == false)
            {
                throw new ArgumentException($"The address '{address}' is not a valid osc address", nameof(address));
            }

            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            CheckArguments(arguments);
        }
コード例 #29
0
        private void SetIndex()
        {
            int index = StartIndex;

            foreach (var childP in RoutesStackPanel.Children)
            {
                var childPanel = childP as StackPanel;
                if (childPanel == null)
                {
                    continue;
                }

                var children = OscAddress.GetChildrenWithValue(childPanel);
                foreach (var child in children)
                {
                    var currentVal = OscAddress.GetAddress(child.Key);
                    var newVal     = currentVal.Replace("*", index.ToString());
                    OscAddress.SetAddress(child.Key, newVal);
                }

                index++;
            }
        }
コード例 #30
0
 internal OscPatternEvent(OscAddress address)
 {
     Address = address;
     Event   = null;
 }