Пример #1
0
        public void ExcludeOnlyTest()
        {
            var filter = new PostFilterRule { ExFilterName = "hogehoge" };
            var post = new PostClass { ScreenName = "hogehoge" };

            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #2
0
        public void MatchOnlyTest()
        {
            var filter = new PostFilterRule { FilterName = "hogehoge" };
            var post = new PostClass { ScreenName = "hogehoge" };

            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }
Пример #3
0
        public void EmptyRuleTest()
        {
            var filter = new PostFilterRule { };
            var post = new PostClass { ScreenName = "hogehoge" };

            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
        }
Пример #4
0
        public void NullTest()
        {
            var filter = new PostFilterRule
            {
                FilterName = null,
                FilterSource = null,
                ExFilterName = null,
                ExFilterSource = null,
            };
            var post = new PostClass { ScreenName = "hogehoge" };

            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            Assert.Throws<ArgumentNullException>(() => filter.FilterBody = null);
            Assert.Throws<ArgumentNullException>(() => filter.ExFilterBody = null);
        }
Пример #5
0
        public void FieldNullAwareTest()
        {
            var nullPost = new PostClass { Source = null };

            // Source が null であっても ArgumentNullException 等を投げない
            var filter1 = new PostFilterRule
            {
                FilterSource = "(hoge){2}",
                UseRegex = true,
            };
            Assert.Equal(MyCommon.HITRESULT.None, filter1.ExecFilter(nullPost));

            // null は空文字列と同じ扱いにする
            var filter2 = new PostFilterRule
            {
                FilterSource = "^$",
                UseRegex = true,
            };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter2.ExecFilter(nullPost));
        }
Пример #6
0
        public void ExFilterSource_ByUrlRegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            // ExFilterByUrl = true の場合は Source ではなく SourceHtml がマッチ対象になる
            filter.ExFilterByUrl = true;

            filter.ExUseRegex = true;
            filter.ExFilterSource = "(hoge){2}";

            // ExFilterSource は ExUseRegex の値に関わらず部分一致
            post = new PostClass { Source = "****", SourceUri = new Uri("http://example.com/hogehoge") };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { Source = "****", SourceUri = new Uri("http://example.com/foo") };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { Source = "****", SourceUri = new Uri("http://example.com/HogeHoge") };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { Source = "****", SourceUri = new Uri("http://example.com/HogeHoge") };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #7
0
        public void ExFilterRt_Test()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.ExFilterRt = true;

            post = new PostClass { RetweetedBy = "hogehoge", RetweetedId = 123L };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
        }
Пример #8
0
        public void FilterSource_RegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.UseRegex = true;
            filter.FilterSource = "(hoge){2}";

            post = new PostClass { Source = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { Source = "foo" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterSource は部分一致 (UseRegex = true の場合)
            post = new PostClass { Source = "_hogehoge_" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.CaseSensitive = true;

            post = new PostClass { Source = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.CaseSensitive = false;

            post = new PostClass { Source = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }
Пример #9
0
        public void PostMatchOptions_MoveTest()
        {
            var filter = new PostFilterRule { FilterName = "hogehoge" };
            var post = new PostClass { ScreenName = "hogehoge" };

            filter.MoveMatches = true;
            filter.MarkMatches = false; // 無視される
            Assert.Equal(MyCommon.HITRESULT.Move, filter.ExecFilter(post));

            filter.MoveMatches = true;
            filter.MarkMatches = true; // 無視される
            Assert.Equal(MyCommon.HITRESULT.Move, filter.ExecFilter(post));
        }
Пример #10
0
        public void ExFilterBody_RegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.ExUseRegex = true;
            filter.ExFilterBody = new[] { "a{3}", "b{3}" };

            post = new PostClass { TextFromApi = "test" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 片方だけではマッチしない
            post = new PostClass { TextFromApi = "aaa" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の文字列が全て含まれている
            post = new PostClass { TextFromApi = "123aaa456bbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // ScreenName にはマッチしない (ExUseNameField = true の場合)
            post = new PostClass { ScreenName = "aaabbb", TextFromApi = "test" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { TextFromApi = "AaaBbb" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { TextFromApi = "AaaBbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #11
0
        /// <summary>
        /// 検索ダイアログを表示し、検索を実行します
        /// </summary>
        private void ShowSearchDialog()
        {
            if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
            {
                this.TopMost = this._cfgCommon.AlwaysTop;
                return;
            }
            this.TopMost = this._cfgCommon.AlwaysTop;

            var searchOptions = this.SearchDialog.ResultOptions;
            if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
            {
                if (searchOptions.NewTab)
                {
                    var tabName = Properties.Resources.SearchResults_TabName;

                    try
                    {
                        tabName = this._statuses.MakeTabName(tabName);
                    }
                    catch (TabException ex)
                    {
                        MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this.AddNewTab(tabName, false, MyCommon.TabUsageType.SearchResults);
                    this._statuses.AddTab(tabName, MyCommon.TabUsageType.SearchResults, null);

                    var filter = new PostFilterRule
                    {
                        FilterBody = new[] { searchOptions.Query },
                        UseRegex = searchOptions.UseRegex,
                        CaseSensitive = searchOptions.CaseSensitive,
                    };

                    var targetTab = this._statuses.Tabs[this._curTab.Text];
                    var posts = targetTab.Posts.Values
                        .Where(x => filter.ExecFilter(x) == MyCommon.HITRESULT.CopyAndMark)
                        .Where(x => targetTab.Contains(x.StatusId));

                    var resultTab = this._statuses.Tabs[tabName];
                    foreach (var post in posts)
                    {
                        resultTab.AddPostToInnerStorage(post);
                    }

                    this._statuses.DistributePosts();
                    this.RefreshTimeline();

                    var tabPage = this.ListTab.TabPages.Cast<TabPage>()
                        .First(x => x.Text == tabName);

                    this.ListTab.SelectedTab = tabPage;
                }
                else
                {
                    this.DoTabSearch(
                        searchOptions.Query,
                        searchOptions.CaseSensitive,
                        searchOptions.UseRegex,
                        SEARCHTYPE.DialogSearch);
                }
            }
            else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
            {
                this.AddNewTabForSearch(searchOptions.Query);
            }
        }
Пример #12
0
        public void SourceHtmlTest(bool useRegex, string pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                // FilterByUrl = true の場合は Source ではなく SourceHtml がマッチ対象になる
                filter.FilterByUrl = true;

                filter.UseRegex = useRegex;
                filter.FilterSource = pattern;
            }
            else
            {
                // ExFilterByUrl = true の場合は Source ではなく SourceHtml がマッチ対象になる
                filter.ExFilterByUrl = true;

                filter.ExUseRegex = useRegex;
                filter.ExFilterSource = pattern;
            }

            // FilterSource は UseRegex の値に関わらず部分一致
            post = new PostClass { SourceHtml = "<a href='http://example.com/hogehoge'>****</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            post = new PostClass { SourceHtml = "<a href='http://example.com/foo'>****</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { SourceHtml = "<a href='http://example.com/HogeHoge'>****</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { SourceHtml = "<a href='http://example.com/HogeHoge'>****</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
        }
Пример #13
0
        public void ExFilterName_RegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.ExUseRegex = true;
            filter.ExFilterName = "(hoge){2}";

            post = new PostClass { ScreenName = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterName は RetweetedBy にもマッチする
            post = new PostClass { ScreenName = "foo", RetweetedBy = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo", RetweetedBy = "bar" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterName は部分一致 (ExUseRegex = true の場合)
            post = new PostClass { ScreenName = "_hogehoge_" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #14
0
        public void BodyAndNameTest(bool useRegex, string[] pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                // UseNameField = false の場合は FilterBody のマッチ対象が Text と ScreenName の両方になる
                filter.UseNameField = false;

                filter.UseRegex = useRegex;
                filter.FilterBody = pattern;
            }
            else
            {
                // ExUseNameField = false の場合は ExFilterBody のマッチ対象が Text と ScreenName の両方になる
                filter.ExUseNameField = false;

                filter.ExUseRegex = useRegex;
                filter.ExFilterBody = pattern;
            }

            post = new PostClass { ScreenName = "hoge", TextFromApi = "test" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // FilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "hoge", TextFromApi = "aaa" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // FilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "aaa", TextFromApi = "test" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // TextFromApi に FilterBody の文字列が全て含まれている
            post = new PostClass { ScreenName = "hoge", TextFromApi = "123aaa456bbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // TextFromApi と ScreenName に FilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "aaa", TextFromApi = "bbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // TextFromApi と RetweetedBy に FilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "hoge", TextFromApi = "bbb", RetweetedBy = "aaa" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // RetweetedBy が null でなくても依然として ScreenName にはマッチする
            post = new PostClass { ScreenName = "aaa", TextFromApi = "bbb", RetweetedBy = "hoge" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            if (!useRegex)
            {
                // ScreenName に対しては完全一致 (UseRegex = false の場合)
                post = new PostClass { ScreenName = "_aaa_", TextFromApi = "bbb" };
                Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));
            }
            else
            {
                // ScreenName に対しても部分一致 (UseRegex = true の場合)
                post = new PostClass { ScreenName = "_aaa_", TextFromApi = "bbb" };
                Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
            }

            // TextFromApi に対しては UseRegex に関わらず常に部分一致
            post = new PostClass { ScreenName = "aaa", TextFromApi = "_bbb_" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "Aaa", TextFromApi = "Bbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            post = new PostClass { ScreenName = "hoge", TextFromApi = "Bbb", RetweetedBy = "Aaa" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "Aaa", TextFromApi = "Bbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            post = new PostClass { ScreenName = "hoge", TextFromApi = "Bbb", RetweetedBy = "Aaa" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
        }
Пример #15
0
        public void PostMatchOptionsTest()
        {
            var filter = new PostFilterRule { FilterName = "hogehoge" };
            var post = new PostClass { ScreenName = "hogehoge" };

            filter.MoveMatches = false;
            filter.MarkMatches = false;
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.Copy));

            filter.MoveMatches = false;
            filter.MarkMatches = true;
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.CopyAndMark));

            filter.MoveMatches = true;
            filter.MarkMatches = false; // 無視される
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.Move));

            filter.MoveMatches = true;
            filter.MarkMatches = true; // 無視される
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.Move));
        }
Пример #16
0
        public void IsRtTest([Values(true, false)] bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
                filter.FilterRt = true;
            else
                filter.ExFilterRt = true;

            post = new PostClass { RetweetedBy = "hogehoge", RetweetedId = 123L };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            post = new PostClass { };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));
        }
Пример #17
0
        public void BodyUrlTest(bool useRegex, string[] pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                // FilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
                filter.FilterByUrl = true;

                filter.UseRegex = useRegex;
                filter.FilterBody = pattern;
            }
            else
            {
                // ExFilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
                filter.ExFilterByUrl = true;

                filter.ExUseRegex = useRegex;
                filter.ExFilterBody = pattern;
            }

            post = new PostClass { Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 片方だけではマッチしない
            post = new PostClass { Text = "<a href='http://example.com/aaa'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // FilterBody の文字列が全て含まれている
            post = new PostClass { Text = "<a href='http://example.com/aaabbb'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // ScreenName にはマッチしない (UseNameField = true の場合)
            post = new PostClass { ScreenName = "aaabbb", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { Text = "<a href='http://example.com/AaaBbb'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { Text = "<a href='http://example.com/AaaBbb'>t.co/hoge</a>" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
        }
Пример #18
0
        public void BodyTest(bool useRegex, string[] pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                filter.UseRegex = useRegex;
                filter.FilterBody = pattern;
            }
            else
            {
                filter.ExUseRegex = useRegex;
                filter.ExFilterBody = pattern;
            }

            post = new PostClass { TextFromApi = "test" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 片方だけではマッチしない
            post = new PostClass { TextFromApi = "aaa" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // FilterBody の文字列が全て含まれている
            post = new PostClass { TextFromApi = "123aaa456bbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            // ScreenName にはマッチしない (UseNameField = true の場合)
            post = new PostClass { ScreenName = "aaabbb", TextFromApi = "test" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { TextFromApi = "AaaBbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { TextFromApi = "AaaBbb" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
        }
Пример #19
0
        public void Disabled_Test()
        {
            var filter = new PostFilterRule { FilterName = "hogehoge" };
            var post = new PostClass { ScreenName = "hogehoge" };

            filter.Enabled = false;
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
        }
Пример #20
0
        public void ExFilterBody_ByUrlRegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            // ExFilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
            filter.ExFilterByUrl = true;

            filter.ExUseRegex = true;
            filter.ExFilterBody = new[] { "a{3}", "b{3}" };

            post = new PostClass { Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 片方だけではマッチしない
            post = new PostClass { Text = "<a href='http://example.com/aaa'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の文字列が全て含まれている
            post = new PostClass { Text = "<a href='http://example.com/aaabbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // ScreenName にはマッチしない (ExUseNameField = true の場合)
            post = new PostClass { ScreenName = "aaabbb", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { Text = "<a href='http://example.com/AaaBbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { Text = "<a href='http://example.com/AaaBbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #21
0
        public void FilterName_Test()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.FilterName = "hogehoge";

            post = new PostClass { ScreenName = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterName は RetweetedBy にもマッチする
            post = new PostClass { ScreenName = "foo", RetweetedBy = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo", RetweetedBy = "bar" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterName は完全一致 (UseRegex = false の場合)
            post = new PostClass { ScreenName = "_hogehoge_" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.CaseSensitive = true;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.CaseSensitive = false;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }
Пример #22
0
        public void ExFilterBodyAndName_RegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            // ExUseNameField = false の場合は ExFilterBody のマッチ対象が TextFromApi と ScreenName の両方になる
            filter.ExUseNameField = false;

            filter.ExUseRegex = true;
            filter.ExFilterBody = new[] { "a{3}", "b{3}" };

            post = new PostClass { ScreenName = "hoge", TextFromApi = "test" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "hoge", TextFromApi = "aaa" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "aaa", TextFromApi = "test" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // TextFromApi に ExFilterBody の文字列が全て含まれている
            post = new PostClass { ScreenName = "hoge", TextFromApi = "123aaa456bbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // TextFromApi と ScreenName に ExFilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "aaa", TextFromApi = "bbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // TextFromApi と RetweetedBy に ExFilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "hoge", TextFromApi = "bbb", RetweetedBy = "aaa" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // RetweetedBy が null でなくても依然として ScreenName にはマッチする
            post = new PostClass { ScreenName = "aaa", TextFromApi = "bbb", RetweetedBy = "hoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // ScreenName に対しても部分一致 (ExUseRegex = true の場合)
            post = new PostClass { ScreenName = "_aaa_", TextFromApi = "bbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // TextFromApi に対しては ExUseRegex に関わらず常に部分一致
            post = new PostClass { ScreenName = "aaa", TextFromApi = "_bbb_" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "Aaa", TextFromApi = "Bbb" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", TextFromApi = "Bbb", RetweetedBy = "Aaa" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "Aaa", TextFromApi = "Bbb" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", TextFromApi = "Bbb", RetweetedBy = "Aaa" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #23
0
        public void NameTest(bool useRegex, string pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                filter.UseRegex = useRegex;
                filter.FilterName = pattern;
            }
            else
            {
                filter.ExUseRegex = useRegex;
                filter.ExFilterName = pattern;
            }

            post = new PostClass { ScreenName = "hogehoge" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterName は RetweetedBy にもマッチする
            post = new PostClass { ScreenName = "foo", RetweetedBy = "hogehoge" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "foo", RetweetedBy = "bar" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            if (!useRegex)
            {
                // FilterName は完全一致 (UseRegex = false の場合)
                post = new PostClass { ScreenName = "_hogehoge_" };
                Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
            }
            else
            {
                // FilterName は部分一致 (UseRegex = true の場合)
                post = new PostClass { ScreenName = "_hogehoge_" };
                Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
            }

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "HogeHoge" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }
Пример #24
0
        public void IsRtTest(bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
                filter.FilterRt = true;
            else
                filter.ExFilterRt = true;

            post = new PostClass { RetweetedBy = "hogehoge", RetweetedId = 123L };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
        }
Пример #25
0
        public void SourceTest(bool useRegex, string pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                filter.UseRegex = useRegex;
                filter.FilterSource = pattern;
            }
            else
            {
                filter.ExUseRegex = useRegex;
                filter.ExFilterSource = pattern;
            }

            post = new PostClass { Source = "hogehoge" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));

            post = new PostClass { Source = "foo" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            if (!useRegex)
            {
                // FilterSource は完全一致 (UseRegex = false の場合)
                post = new PostClass { Source = "_hogehoge_" };
                Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));
            }
            else
            {
                // FilterSource は部分一致 (UseRegex = true の場合)
                post = new PostClass { Source = "_hogehoge_" };
                Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
            }

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { Source = "HogeHoge" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(MyCommon.HITRESULT.None));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { Source = "HogeHoge" };
            Assert.That(filter.ExecFilter(post), Is.EqualTo(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark));
        }
Пример #26
0
        public void FilterSource_ByUrlRegexTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            // FilterByUrl = true の場合は Source ではなく SourceHtml がマッチ対象になる
            filter.FilterByUrl = true;

            filter.UseRegex = true;
            filter.FilterSource = "(hoge){2}";

            // FilterSource は UseRegex の値に関わらず部分一致
            post = new PostClass { SourceHtml = "<a href='http://example.com/hogehoge'>****</a>" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { SourceHtml = "<a href='http://example.com/foo'>****</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.CaseSensitive = true;

            post = new PostClass { SourceHtml = "<a href='http://example.com/HogeHoge'>****</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.CaseSensitive = false;

            post = new PostClass { SourceHtml = "<a href='http://example.com/HogeHoge'>****</a>" };
            Assert.Equal(MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }
Пример #27
0
        public void MatchAndExcludeTest()
        {
            var filter = new PostFilterRule { FilterName = "hogehoge", ExFilterSource = "tetete" };
            var post = new PostClass { ScreenName = "hogehoge", Source = "tetete" };

            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
        }
Пример #28
0
        public void ExFilterSource_Test()
        {
            var filter = new PostFilterRule();
            PostClass post;

            filter.ExFilterSource = "hogehoge";

            post = new PostClass { Source = "hogehoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { Source = "foo" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterSource は完全一致 (ExUseRegex = false の場合)
            post = new PostClass { Source = "_hogehoge_" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { Source = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { Source = "HogeHoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #29
0
        public void ExFilterBodyAndName_ByUrlTest()
        {
            var filter = new PostFilterRule();
            PostClass post;

            // ExFilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
            filter.ExFilterByUrl = true;

            // ExUseNameField = false の場合は ExFilterBody のマッチ対象が Text と ScreenName の両方になる
            filter.ExUseNameField = false;

            filter.ExFilterBody = new[] { "aaa", "bbb" };

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/aaa'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // ExFilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // Text に ExFilterBody の文字列が全て含まれている
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/aaabbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // Text と ScreenName に ExFilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // Text と ScreenName に ExFilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>", RetweetedBy = "aaa" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // RetweetedBy が null でなくても依然として ScreenName にはマッチする
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>", RetweetedBy = "hoge" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // ScreenName に対しては完全一致 (ExUseRegex = false の場合)
            post = new PostClass { ScreenName = "_aaa_", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // Text に対しては ExUseRegex に関わらず常に部分一致
            post = new PostClass { ScreenName = "aaa", Text = "_bbb_" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            // 大小文字を区別する
            filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "Aaa", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>", RetweetedBy = "Aaa" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "Aaa", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>", RetweetedBy = "Aaa" };
            Assert.Equal(MyCommon.HITRESULT.Exclude, filter.ExecFilter(post));
        }
Пример #30
0
        public void BodyUrlAndNameTest(bool useRegex, string[] pattern, bool exclude)
        {
            var filter = new PostFilterRule();
            PostClass post;

            if (!exclude)
            {
                // FilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
                filter.FilterByUrl = true;

                // UseNameField = false の場合は FilterBody のマッチ対象が Text と ScreenName の両方になる
                filter.UseNameField = false;

                filter.UseRegex = useRegex;
                filter.FilterBody = pattern;
            }
            else
            {
                // ExFilterByUrl = true の場合は TextFromApi ではなく Text がマッチ対象になる
                filter.ExFilterByUrl = true;

                // ExUseNameField = false の場合は ExFilterBody のマッチ対象が Text と ScreenName の両方になる
                filter.ExUseNameField = false;

                filter.ExUseRegex = useRegex;
                filter.ExFilterBody = pattern;
            }

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/aaa'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // FilterBody の片方だけではマッチしない
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/123'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // Text に FilterBody の文字列が全て含まれている
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/aaabbb'>t.co/hoge</a>" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            // Text と ScreenName に FilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            // Text と ScreenName に FilterBody の文字列がそれぞれ含まれている
            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>", RetweetedBy = "aaa" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            // RetweetedBy が null でなくても依然として ScreenName にはマッチする
            post = new PostClass { ScreenName = "aaa", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>", RetweetedBy = "hoge" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            if (!useRegex)
            {
                // ScreenName に対しては完全一致 (UseRegex = false の場合)
                post = new PostClass { ScreenName = "_aaa_", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>" };
                Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));
            }
            else
            {
                // ScreenName に対しても部分一致 (UseRegex = true の場合)
                post = new PostClass { ScreenName = "_aaa_", Text = "<a href='http://example.com/bbb'>t.co/hoge</a>" };
                Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
            }

            // Text に対しては UseRegex に関わらず常に部分一致
            post = new PostClass { ScreenName = "aaa", Text = "_bbb_" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            // 大小文字を区別する
            if (!exclude)
                filter.CaseSensitive = true;
            else
                filter.ExCaseSensitive = true;

            post = new PostClass { ScreenName = "Aaa", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>", RetweetedBy = "Aaa" };
            Assert.Equal(MyCommon.HITRESULT.None, filter.ExecFilter(post));

            // 大小文字を区別しない
            if (!exclude)
                filter.CaseSensitive = false;
            else
                filter.ExCaseSensitive = false;

            post = new PostClass { ScreenName = "Aaa", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));

            post = new PostClass { ScreenName = "hoge", Text = "<a href='http://example.com/Bbb'>t.co/hoge</a>", RetweetedBy = "Aaa" };
            Assert.Equal(exclude ? MyCommon.HITRESULT.Exclude : MyCommon.HITRESULT.CopyAndMark, filter.ExecFilter(post));
        }