Esempio n. 1
0
        public void TestTraversalBeyondVisible(bool forwards)
        {
            var sets = new List <BeatmapSetInfo>();

            const int total_set_count = 200;

            for (int i = 0; i < total_set_count; i++)
            {
                sets.Add(TestResources.CreateTestBeatmapSetInfo());
            }

            loadBeatmaps(sets);

            for (int i = 1; i < total_set_count; i += i)
            {
                selectNextAndAssert(i);
            }

            void selectNextAndAssert(int amount)
            {
                setSelected(forwards ? 1 : total_set_count, 1);

                AddStep($"{(forwards ? "Next" : "Previous")} beatmap {amount} times", () =>
                {
                    for (int i = 0; i < amount; i++)
                    {
                        carousel.SelectNext(forwards ? 1 : -1);
                    }
                });

                waitForSelection(forwards ? amount + 1 : total_set_count - amount);
            }
        }
Esempio n. 2
0
        public void TestSelectionEnteringFromEmptyRuleset()
        {
            var sets = new List <BeatmapSetInfo>();

            AddStep("Create beatmaps for taiko only", () =>
            {
                sets.Clear();

                var rulesetBeatmapSet = TestResources.CreateTestBeatmapSetInfo(1);
                var taikoRuleset      = rulesets.AvailableRulesets.ElementAt(1);
                rulesetBeatmapSet.Beatmaps.ForEach(b => b.Ruleset = taikoRuleset);

                sets.Add(rulesetBeatmapSet);
            });

            loadBeatmaps(sets, () => new FilterCriteria {
                Ruleset = rulesets.AvailableRulesets.ElementAt(0)
            });

            AddStep("Set non-empty mode filter", () =>
                    carousel.Filter(new FilterCriteria {
                Ruleset = rulesets.AvailableRulesets.ElementAt(1)
            }, false));

            AddAssert("Something is selected", () => carousel.SelectedBeatmapInfo != null);
        }
Esempio n. 3
0
        public void TestSortingWithFiltered()
        {
            List <BeatmapSetInfo> sets = new List <BeatmapSetInfo>();

            for (int i = 0; i < 3; i++)
            {
                var set = TestResources.CreateTestBeatmapSetInfo(3);
                set.Beatmaps[0].StarRating = 3 - i;
                set.Beatmaps[2].StarRating = 6 + i;
                sets.Add(set);
            }

            loadBeatmaps(sets);

            AddStep("Filter to normal", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Difficulty, SearchText = "Normal"
            }, false));
            AddAssert("Check first set at end", () => carousel.BeatmapSets.First().Equals(sets.Last()));
            AddAssert("Check last set at start", () => carousel.BeatmapSets.Last().Equals(sets.First()));

            AddStep("Filter to insane", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Difficulty, SearchText = "Insane"
            }, false));
            AddAssert("Check first set at start", () => carousel.BeatmapSets.First().Equals(sets.First()));
            AddAssert("Check last set at end", () => carousel.BeatmapSets.Last().Equals(sets.Last()));
        }
Esempio n. 4
0
        public void TestSortingStability()
        {
            var sets = new List <BeatmapSetInfo>();

            for (int i = 0; i < 20; i++)
            {
                var set = TestResources.CreateTestBeatmapSetInfo();

                // only need to set the first as they are a shared reference.
                var beatmap = set.Beatmaps.First();

                beatmap.Metadata.Artist = "same artist";
                beatmap.Metadata.Title  = "same title";

                sets.Add(set);
            }

            int idOffset = sets.First().OnlineID;

            loadBeatmaps(sets);

            AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Artist
            }, false));
            AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b));

            AddStep("Sort by title", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Title
            }, false));
            AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b));
        }
Esempio n. 5
0
        private void loadBeatmaps(List <BeatmapSetInfo> beatmapSets = null, Func <FilterCriteria> initialCriteria = null, Action <BeatmapCarousel> carouselAdjust = null, int?count = null, bool randomDifficulties = false)
        {
            bool changed = false;

            if (beatmapSets == null)
            {
                beatmapSets = new List <BeatmapSetInfo>();

                for (int i = 1; i <= (count ?? set_count); i++)
                {
                    beatmapSets.Add(randomDifficulties
                        ? TestResources.CreateTestBeatmapSetInfo()
                        : TestResources.CreateTestBeatmapSetInfo(3));
                }
            }

            createCarousel(beatmapSets, c =>
            {
                carouselAdjust?.Invoke(c);

                carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria());
                carousel.BeatmapSetsChanged = () => changed = true;
                carousel.BeatmapSets        = beatmapSets;
            });

            AddUntilStep("Wait for load", () => changed);
        }
Esempio n. 6
0
        public void TestCarouselRemembersSelection()
        {
            List <BeatmapSetInfo> manySets = new List <BeatmapSetInfo>();

            for (int i = 1; i <= 50; i++)
            {
                manySets.Add(TestResources.CreateTestBeatmapSetInfo(3));
            }

            loadBeatmaps(manySets);

            advanceSelection(direction: 1, diff: false);

            for (int i = 0; i < 5; i++)
            {
                AddStep("Toggle non-matching filter", () =>
                {
                    carousel.Filter(new FilterCriteria {
                        SearchText = Guid.NewGuid().ToString()
                    }, false);
                });

                AddStep("Restore no filter", () =>
                {
                    carousel.Filter(new FilterCriteria(), false);
                    eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
                });
            }

            // always returns to same selection as long as it's available.
            AddAssert("Selection was remembered", () => eagerSelectedIDs.Count == 1);
        }
Esempio n. 7
0
        public void Setup() => Schedule(() =>
        {
            Child = new Container
            {
                Anchor = Anchor.Centre,
                Origin = Anchor.Centre,
                Size   = new Vector2(300, 500),
                Child  = playlistOverlay = new PlaylistOverlay
                {
                    Anchor           = Anchor.Centre,
                    Origin           = Anchor.Centre,
                    RelativeSizeAxes = Axes.X,
                    State            = { Value = Visibility.Visible }
                }
            };

            beatmapSets.Clear();

            for (int i = 0; i < 100; i++)
            {
                beatmapSets.Add(TestResources.CreateTestBeatmapSetInfo().ToLiveUnmanaged());
            }

            first = beatmapSets.First();

            playlistOverlay.BeatmapSets.BindTo(beatmapSets);
        });
Esempio n. 8
0
        public void TestAudioRemainsCorrectOnRulesetChange(bool rulesetsInSameBeatmap)
        {
            createSongSelect();

            // start with non-osu! to avoid convert confusion
            changeRuleset(1);

            if (rulesetsInSameBeatmap)
            {
                AddStep("import multi-ruleset map", () =>
                {
                    var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
                    manager.Import(TestResources.CreateTestBeatmapSetInfo(rulesets: usableRulesets));
                });
            }
            else
            {
                addRulesetImportStep(1);
                addRulesetImportStep(0);
            }

            checkMusicPlaying(true);

            AddStep("manual pause", () => music.TogglePause());
            checkMusicPlaying(false);

            changeRuleset(0);
            checkMusicPlaying(!rulesetsInSameBeatmap);
        }
Esempio n. 9
0
        public void TestSubscriptionWithAsyncWrite()
        {
            ChangeSet?lastChanges = null;

            RunTestWithRealm((realm, _) =>
            {
                var registration = realm.RegisterForNotifications(r => r.All <BeatmapSetInfo>(), onChanged);

                realm.Run(r => r.Refresh());

                // Without forcing the write onto its own thread, realm will internally run the operation synchronously, which can cause a deadlock with `WaitSafely`.
                Task.Run(async() =>
                {
                    await realm.WriteAsync(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
                }).WaitSafely();

                realm.Run(r => r.Refresh());

                Assert.That(lastChanges?.InsertedIndices, Has.One.Items);

                registration.Dispose();
            });

            void onChanged(IRealmCollection <BeatmapSetInfo> sender, ChangeSet?changes, Exception error) => lastChanges = changes;
        }
Esempio n. 10
0
        public void TestPropertyChangedSubscriptionWithContextLoss()
        {
            RunTestWithRealm((realm, _) =>
            {
                bool?receivedValue = null;

                realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));

                var subscription = realm.SubscribeToPropertyChanged(
                    r => r.All <BeatmapSetInfo>().First(),
                    setInfo => setInfo.Protected,
                    val => receivedValue = val);

                Assert.That(receivedValue, Is.Not.Null);
                receivedValue = null;

                using (realm.BlockAllOperations())
                {
                }

                // re-registration after context restore.
                realm.Run(r => r.Refresh());
                Assert.That(receivedValue, Is.Not.Null);

                subscription.Dispose();
                receivedValue = null;

                using (realm.BlockAllOperations())
                    Assert.That(receivedValue, Is.Null);

                realm.Run(r => r.Refresh());
                Assert.That(receivedValue, Is.Null);
            });
        }
Esempio n. 11
0
        public void TestExternalRulesetChange()
        {
            createCarousel(new List <BeatmapSetInfo>());

            AddStep("filter to ruleset 0", () => carousel.Filter(new FilterCriteria
            {
                Ruleset = rulesets.AvailableRulesets.ElementAt(0),
                AllowConvertedBeatmaps = true,
            }, false));

            AddStep("add mixed ruleset beatmapset", () =>
            {
                var testMixed = TestResources.CreateTestBeatmapSetInfo(3);

                for (int i = 0; i <= 2; i++)
                {
                    testMixed.Beatmaps[i].Ruleset = rulesets.AvailableRulesets.ElementAt(i);
                }

                carousel.UpdateBeatmapSet(testMixed);
            });

            AddUntilStep("wait for filtered difficulties", () =>
            {
                var visibleBeatmapPanels = carousel.Items.OfType <DrawableCarouselBeatmap>().Where(p => p.IsPresent).ToArray();

                return(visibleBeatmapPanels.Length == 1 &&
                       visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item).BeatmapInfo.Ruleset.OnlineID == 0) == 1);
            });

            AddStep("filter to ruleset 1", () => carousel.Filter(new FilterCriteria
            {
                Ruleset = rulesets.AvailableRulesets.ElementAt(1),
                AllowConvertedBeatmaps = true,
            }, false));

            AddUntilStep("wait for filtered difficulties", () =>
            {
                var visibleBeatmapPanels = carousel.Items.OfType <DrawableCarouselBeatmap>().Where(p => p.IsPresent).ToArray();

                return(visibleBeatmapPanels.Length == 2 &&
                       visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item).BeatmapInfo.Ruleset.OnlineID == 0) == 1 &&
                       visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item).BeatmapInfo.Ruleset.OnlineID == 1) == 1);
            });

            AddStep("filter to ruleset 2", () => carousel.Filter(new FilterCriteria
            {
                Ruleset = rulesets.AvailableRulesets.ElementAt(2),
                AllowConvertedBeatmaps = true,
            }, false));

            AddUntilStep("wait for filtered difficulties", () =>
            {
                var visibleBeatmapPanels = carousel.Items.OfType <DrawableCarouselBeatmap>().Where(p => p.IsPresent).ToArray();

                return(visibleBeatmapPanels.Length == 2 &&
                       visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item).BeatmapInfo.Ruleset.OnlineID == 0) == 1 &&
                       visibleBeatmapPanels.Count(p => ((CarouselBeatmap)p.Item).BeatmapInfo.Ruleset.OnlineID == 2) == 1);
            });
        }
Esempio n. 12
0
        public void TestSorting()
        {
            var sets = new List <BeatmapSetInfo>();

            const string zzz_string = "zzzzz";

            for (int i = 0; i < 20; i++)
            {
                var set = TestResources.CreateTestBeatmapSetInfo();

                if (i == 4)
                {
                    set.Beatmaps.ForEach(b => b.Metadata.Artist = zzz_string);
                }

                if (i == 16)
                {
                    set.Beatmaps.ForEach(b => b.Metadata.Author.Username = zzz_string);
                }

                sets.Add(set);
            }

            loadBeatmaps(sets);

            AddStep("Sort by author", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Author
            }, false));
            AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Author.Username == zzz_string);
            AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria {
                Sort = SortMode.Artist
            }, false));
            AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_string);
        }
Esempio n. 13
0
        private void load(GameHost host, AudioManager audio)
        {
            Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
            Dependencies.Cache(manager  = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
            Dependencies.Cache(Realm);

            importedBeatmapSet = manager.Import(TestResources.CreateTestBeatmapSetInfo(8, rulesets.AvailableRulesets.ToArray()));
        }
Esempio n. 14
0
        private void load(GameHost host, AudioManager audio)
        {
            Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
            Dependencies.Cache(manager  = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));

            var beatmapSet = TestResources.CreateTestBeatmapSetInfo();

            manager.Import(beatmapSet).Wait();
        }
Esempio n. 15
0
        public void TestFilteringByUserStarDifficulty()
        {
            BeatmapSetInfo set = null;

            loadBeatmaps(new List <BeatmapSetInfo>());

            AddStep("add mixed difficulty set", () =>
            {
                set = TestResources.CreateTestBeatmapSetInfo(1);
                set.Beatmaps.Clear();

                for (int i = 1; i <= 15; i++)
                {
                    set.Beatmaps.Add(new BeatmapInfo
                    {
                        DifficultyName = $"Stars: {i}",
                        Ruleset        = new OsuRuleset().RulesetInfo,
                        StarRating     = i,
                    });
                }

                carousel.UpdateBeatmapSet(set);
            });

            AddStep("select added set", () => carousel.SelectBeatmap(set.Beatmaps[0], false));

            AddStep("filter [5..]", () => carousel.Filter(new FilterCriteria {
                UserStarDifficulty = { Min = 5 }
            }));
            AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
            checkVisibleItemCount(true, 11);

            AddStep("filter to [0..7]", () => carousel.Filter(new FilterCriteria {
                UserStarDifficulty = { Max = 7 }
            }));
            AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
            checkVisibleItemCount(true, 7);

            AddStep("filter to [5..7]", () => carousel.Filter(new FilterCriteria {
                UserStarDifficulty = { Min = 5, Max = 7 }
            }));
            AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
            checkVisibleItemCount(true, 3);

            AddStep("filter [2..2]", () => carousel.Filter(new FilterCriteria {
                UserStarDifficulty = { Min = 2, Max = 2 }
            }));
            AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
            checkVisibleItemCount(true, 1);

            AddStep("filter to [0..]", () => carousel.Filter(new FilterCriteria {
                UserStarDifficulty = { Min = 0 }
            }));
            AddUntilStep("Wait for debounce", () => !carousel.PendingFilterTask);
            checkVisibleItemCount(true, 15);
        }
Esempio n. 16
0
        public void TestScrollPositionMaintainedOnAdd()
        {
            loadBeatmaps(count: 1, randomDifficulties: false);

            for (int i = 0; i < 10; i++)
            {
                AddRepeatStep("Add some sets", () => carousel.UpdateBeatmapSet(TestResources.CreateTestBeatmapSetInfo()), 4);

                checkSelectionIsCentered();
            }
        }
Esempio n. 17
0
        public void TestSubscriptionCollectionAndPropertyChanges()
        {
            int collectionChanges = 0;
            int propertyChanges   = 0;

            ChangeSet?lastChanges = null;

            RunTestWithRealm((realm, _) =>
            {
                var registration = realm.RegisterForNotifications(r => r.All <BeatmapSetInfo>(), onChanged);

                realm.Run(r => r.Refresh());

                realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
                realm.Run(r => r.Refresh());

                Assert.That(collectionChanges, Is.EqualTo(1));
                Assert.That(propertyChanges, Is.EqualTo(0));
                Assert.That(lastChanges?.InsertedIndices, Has.One.Items);
                Assert.That(lastChanges?.ModifiedIndices, Is.Empty);
                Assert.That(lastChanges?.NewModifiedIndices, Is.Empty);

                realm.Write(r => r.All <BeatmapSetInfo>().First().Beatmaps.First().CountdownOffset = 5);
                realm.Run(r => r.Refresh());

                Assert.That(collectionChanges, Is.EqualTo(1));
                Assert.That(propertyChanges, Is.EqualTo(1));
                Assert.That(lastChanges?.InsertedIndices, Is.Empty);
                Assert.That(lastChanges?.ModifiedIndices, Has.One.Items);
                Assert.That(lastChanges?.NewModifiedIndices, Has.One.Items);

                registration.Dispose();
            });

            void onChanged(IRealmCollection <BeatmapSetInfo> sender, ChangeSet?changes, Exception error)
            {
                lastChanges = changes;

                if (changes == null)
                {
                    return;
                }

                if (changes.HasCollectionChanges())
                {
                    Interlocked.Increment(ref collectionChanges);
                }
                else
                {
                    Interlocked.Increment(ref propertyChanges);
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Imports test beatmap sets to show in the carousel.
        /// </summary>
        /// <param name="difficultyCountPerSet">
        /// The exact count of difficulties to create for each beatmap set.
        /// A <see langword="null"/> value causes the count of difficulties to be selected randomly.
        /// </param>
        private void addManyTestMaps(int?difficultyCountPerSet = null)
        {
            AddStep("import test maps", () =>
            {
                var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();

                for (int i = 0; i < 10; i++)
                {
                    manager.Import(TestResources.CreateTestBeatmapSetInfo(difficultyCountPerSet, usableRulesets));
                }
            });
        }
Esempio n. 19
0
        private void addManyTestMaps()
        {
            AddStep("import test maps", () =>
            {
                var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();

                for (int i = 0; i < 100; i += 10)
                {
                    manager.Import(TestResources.CreateTestBeatmapSetInfo(rulesets: usableRulesets)).Wait();
                }
            });
        }
Esempio n. 20
0
        public override void SetUp()
        {
            storage = new TemporaryNativeStorage("realm-benchmark");
            storage.DeleteDirectory(string.Empty);

            realm = new RealmAccess(storage, "client");

            realm.Run(r =>
            {
                realm.Write(c => c.Add(TestResources.CreateTestBeatmapSetInfo(rulesets: new[] { new OsuRuleset().RulesetInfo })));
            });

            updateThread = new UpdateThread(() => { }, null);
            updateThread.Start();
        }
Esempio n. 21
0
        private BeatmapSetInfo importBeatmapSet(IEnumerable<RulesetInfo> difficultyRulesets)
        {
            var rulesets = difficultyRulesets.ToArray();

            var beatmapSet = TestResources.CreateTestBeatmapSetInfo(rulesets.Length, rulesets);

            for (int i = 0; i < rulesets.Length; i++)
            {
                var beatmap = beatmapSet.Beatmaps[i];

                beatmap.StarRating = i + 1;
                beatmap.DifficultyName = $"SR{i + 1}";
            }

            return Game.BeatmapManager.Import(beatmapSet)?.Value;
        }
Esempio n. 22
0
        public void TestDifficultyIconSelectingForDifferentRuleset()
        {
            changeRuleset(0);

            createSongSelect();

            AddStep("import multi-ruleset map", () =>
            {
                var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
                manager.Import(TestResources.CreateTestBeatmapSetInfo(3, usableRulesets));
            });

            DrawableCarouselBeatmapSet set = null;

            AddUntilStep("Find the DrawableCarouselBeatmapSet", () =>
            {
                set = songSelect.Carousel.ChildrenOfType <DrawableCarouselBeatmapSet>().FirstOrDefault();
                return(set != null);
            });

            FilterableDifficultyIcon difficultyIcon = null;

            AddUntilStep("Find an icon for different ruleset", () =>
            {
                difficultyIcon = set.ChildrenOfType <FilterableDifficultyIcon>()
                                 .FirstOrDefault(icon => icon.Item.BeatmapInfo.Ruleset.OnlineID == 3);
                return(difficultyIcon != null);
            });

            AddAssert("Check ruleset is osu!", () => Ruleset.Value.OnlineID == 0);

            int previousSetID = 0;

            AddStep("record set ID", () => previousSetID = ((IBeatmapSetInfo)Beatmap.Value.BeatmapSetInfo).OnlineID);

            AddStep("Click on a difficulty", () =>
            {
                InputManager.MoveMouseTo(difficultyIcon);

                InputManager.Click(MouseButton.Left);
            });

            AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.OnlineID == 3);

            AddAssert("Selected beatmap still same set", () => songSelect.Carousel.SelectedBeatmapInfo.BeatmapSet?.OnlineID == previousSetID);
            AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.OnlineID == 3);
        }
Esempio n. 23
0
        public void TestChangingRulesetOnMultiRulesetBeatmap()
        {
            int changeCount = 0;

            AddStep("change convert setting", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, false));
            AddStep("bind beatmap changed", () =>
            {
                Beatmap.ValueChanged += onChange;
                changeCount           = 0;
            });

            changeRuleset(0);

            createSongSelect();

            AddStep("import multi-ruleset map", () =>
            {
                var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
                manager.Import(TestResources.CreateTestBeatmapSetInfo(3, usableRulesets));
            });

            int previousSetID = 0;

            AddUntilStep("wait for selection", () => !Beatmap.IsDefault);

            AddStep("record set ID", () => previousSetID = ((IBeatmapSetInfo)Beatmap.Value.BeatmapSetInfo).OnlineID);
            AddAssert("selection changed once", () => changeCount == 1);

            AddAssert("Check ruleset is osu!", () => Ruleset.Value.OnlineID == 0);

            changeRuleset(3);

            AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.OnlineID == 3);

            AddUntilStep("selection changed", () => changeCount > 1);

            AddAssert("Selected beatmap still same set", () => Beatmap.Value.BeatmapSetInfo.OnlineID == previousSetID);
            AddAssert("Selected beatmap is mania", () => Beatmap.Value.BeatmapInfo.Ruleset.OnlineID == 3);

            AddAssert("selection changed only fired twice", () => changeCount == 2);

            AddStep("unbind beatmap changed", () => Beatmap.ValueChanged -= onChange);
            AddStep("change convert setting", () => config.SetValue(OsuSetting.ShowConvertedBeatmaps, true));

            // ReSharper disable once AccessToModifiedClosure
            void onChange(ValueChangedEvent <WorkingBeatmap> valueChangedEvent) => changeCount++;
        }
Esempio n. 24
0
        public void TestSelectingFilteredRuleset()
        {
            BeatmapSetInfo testMixed = null;

            createCarousel();

            AddStep("add mixed ruleset beatmapset", () =>
            {
                testMixed = TestResources.CreateTestBeatmapSetInfo(3);

                for (int i = 0; i <= 2; i++)
                {
                    testMixed.Beatmaps[i].Ruleset   = rulesets.AvailableRulesets.ElementAt(i);
                    testMixed.Beatmaps[i].RulesetID = i;
                }

                carousel.UpdateBeatmapSet(testMixed);
            });
            AddStep("filter to ruleset 0", () =>
                    carousel.Filter(new FilterCriteria {
                Ruleset = rulesets.AvailableRulesets.ElementAt(0)
            }, false));
            AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testMixed.Beatmaps[1], false));
            AddAssert("unfiltered beatmap not selected", () => carousel.SelectedBeatmapInfo.RulesetID == 0);

            AddStep("remove mixed set", () =>
            {
                carousel.RemoveBeatmapSet(testMixed);
                testMixed = null;
            });
            BeatmapSetInfo testSingle = null;

            AddStep("add single ruleset beatmapset", () =>
            {
                testSingle = TestResources.CreateTestBeatmapSetInfo(3);
                testSingle.Beatmaps.ForEach(b =>
                {
                    b.Ruleset   = rulesets.AvailableRulesets.ElementAt(1);
                    b.RulesetID = b.Ruleset.ID ?? 1;
                });

                carousel.UpdateBeatmapSet(testSingle);
            });
            AddStep("select filtered map skipping filtered", () => carousel.SelectBeatmap(testSingle.Beatmaps[0], false));
            checkNoSelection();
            AddStep("remove single ruleset set", () => carousel.RemoveBeatmapSet(testSingle));
        }
Esempio n. 25
0
        public void TestRandomFallbackOnNonMatchingPrevious()
        {
            List <BeatmapSetInfo> manySets = new List <BeatmapSetInfo>();

            AddStep("populate maps", () =>
            {
                for (int i = 0; i < 10; i++)
                {
                    manySets.Add(TestResources.CreateTestBeatmapSetInfo(3, new[]
                    {
                        // all taiko except for first
                        rulesets.GetRuleset(i > 0 ? 1 : 0)
                    }));
                }
            });

            loadBeatmaps(manySets);

            for (int i = 0; i < 10; i++)
            {
                AddStep("Reset filter", () => carousel.Filter(new FilterCriteria(), false));

                AddStep("select first beatmap", () => carousel.SelectBeatmap(manySets.First().Beatmaps.First()));

                AddStep("Toggle non-matching filter", () =>
                {
                    carousel.Filter(new FilterCriteria {
                        SearchText = Guid.NewGuid().ToString()
                    }, false);
                });

                AddAssert("selection lost", () => carousel.SelectedBeatmapInfo == null);

                AddStep("Restore different ruleset filter", () =>
                {
                    carousel.Filter(new FilterCriteria {
                        Ruleset = rulesets.GetRuleset(1)
                    }, false);
                    eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID);
                });

                AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First()));
            }

            AddAssert("Selection was random", () => eagerSelectedIDs.Count > 2);
        }
Esempio n. 26
0
        public void TestTraversalBeyondVisibleDifficulties()
        {
            var sets = new List <BeatmapSetInfo>();

            const int total_set_count = 20;

            for (int i = 0; i < total_set_count; i++)
            {
                sets.Add(TestResources.CreateTestBeatmapSetInfo(3));
            }

            loadBeatmaps(sets);

            // Selects next set once, difficulty index doesn't change
            selectNextAndAssert(3, true, 2, 1);

            // Selects next set 16 times (50 \ 3 == 16), difficulty index changes twice (50 % 3 == 2)
            selectNextAndAssert(50, true, 17, 3);

            // Travels around the carousel thrice (200 \ 60 == 3)
            // continues to select 20 times (200 \ 60 == 20)
            // selects next set 6 times (20 \ 3 == 6)
            // difficulty index changes twice (20 % 3 == 2)
            selectNextAndAssert(200, true, 7, 3);

            // All same but in reverse
            selectNextAndAssert(3, false, 19, 3);
            selectNextAndAssert(50, false, 4, 1);
            selectNextAndAssert(200, false, 14, 1);

            void selectNextAndAssert(int amount, bool forwards, int expectedSet, int expectedDiff)
            {
                // Select very first or very last difficulty
                setSelected(forwards ? 1 : 20, forwards ? 1 : 3);

                AddStep($"{(forwards ? "Next" : "Previous")} difficulty {amount} times", () =>
                {
                    for (int i = 0; i < amount; i++)
                    {
                        carousel.SelectNext(forwards ? 1 : -1, false);
                    }
                });

                waitForSelection(expectedSet, expectedDiff);
            }
        }
Esempio n. 27
0
        public void TestGroupedDifficultyIconSelecting()
        {
            changeRuleset(0);

            createSongSelect();

            BeatmapSetInfo imported = null;

            AddStep("import huge difficulty count map", () =>
            {
                var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
                imported           = manager.Import(TestResources.CreateTestBeatmapSetInfo(50, usableRulesets))?.Value;
            });

            AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First()));

            DrawableCarouselBeatmapSet set = null;

            AddUntilStep("Find the DrawableCarouselBeatmapSet", () =>
            {
                set = songSelect.Carousel.ChildrenOfType <DrawableCarouselBeatmapSet>().FirstOrDefault();
                return(set != null);
            });

            FilterableGroupedDifficultyIcon groupIcon = null;

            AddUntilStep("Find group icon for different ruleset", () =>
            {
                return((groupIcon = set.ChildrenOfType <FilterableGroupedDifficultyIcon>()
                                    .FirstOrDefault(icon => icon.Items.First().BeatmapInfo.Ruleset.OnlineID == 3)) != null);
            });

            AddAssert("Check ruleset is osu!", () => Ruleset.Value.OnlineID == 0);

            AddStep("Click on group", () =>
            {
                InputManager.MoveMouseTo(groupIcon);

                InputManager.Click(MouseButton.Left);
            });

            AddUntilStep("Check ruleset changed to mania", () => Ruleset.Value.OnlineID == 3);

            AddAssert("Check first item in group selected", () => Beatmap.Value.BeatmapInfo.MatchesOnlineID(groupIcon.Items.First().BeatmapInfo));
        }
Esempio n. 28
0
        public void TestHiding()
        {
            BeatmapSetInfo        hidingSet  = null;
            List <BeatmapSetInfo> hiddenList = new List <BeatmapSetInfo>();

            AddStep("create hidden set", () =>
            {
                hidingSet = TestResources.CreateTestBeatmapSetInfo(3);
                hidingSet.Beatmaps[1].Hidden = true;

                hiddenList.Clear();
                hiddenList.Add(hidingSet);
            });

            loadBeatmaps(hiddenList);

            setSelected(1, 1);

            checkVisibleItemCount(true, 2);
            advanceSelection(true);
            waitForSelection(1, 3);

            setHidden(3);
            waitForSelection(1, 1);

            setHidden(2, false);
            advanceSelection(true);
            waitForSelection(1, 2);

            setHidden(1);
            waitForSelection(1, 2);

            setHidden(2);
            checkNoSelection();

            void setHidden(int diff, bool hidden = true)
            {
                AddStep((hidden ? "" : "un") + $"hide diff {diff}", () =>
                {
                    hidingSet.Beatmaps[diff - 1].Hidden = hidden;
                    carousel.UpdateBeatmapSet(hidingSet);
                });
            }
        }
Esempio n. 29
0
 public TestSceneDeleteLocalScore()
 {
     Children = new Drawable[]
     {
         contextMenuContainer = new OsuContextMenuContainer
         {
             RelativeSizeAxes = Axes.Both,
             Child            = leaderboard = new BeatmapLeaderboard
             {
                 Origin      = Anchor.Centre,
                 Anchor      = Anchor.Centre,
                 Size        = new Vector2(550f, 450f),
                 Scope       = BeatmapLeaderboardScope.Local,
                 BeatmapInfo = TestResources.CreateTestBeatmapSetInfo().Beatmaps.First()
             }
         },
         dialogOverlay = new DialogOverlay()
     };
 }
Esempio n. 30
0
        public void TestPropertyChangedSubscription()
        {
            RunTestWithRealm((realm, _) =>
            {
                bool?receivedValue = null;

                realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));

                using (realm.SubscribeToPropertyChanged(r => r.All <BeatmapSetInfo>().First(), setInfo => setInfo.Protected, val => receivedValue = val))
                {
                    Assert.That(receivedValue, Is.False);

                    realm.Write(r => r.All <BeatmapSetInfo>().First().Protected = true);

                    realm.Run(r => r.Refresh());

                    Assert.That(receivedValue, Is.True);
                }
            });
        }