Esempio n. 1
0
        public void TestSongsSubdirectories()
        {
            using (var storage = new TemporaryNativeStorage("stable-songs-folder"))
            {
                var songsStorage = storage.GetStorageForDirectory(StableStorage.STABLE_DEFAULT_SONGS_PATH);

                // normal beatmap folder
                var beatmap1 = songsStorage.GetStorageForDirectory("beatmap1");
                createFile(beatmap1, "beatmap.osu");

                // songs subdirectory
                var subdirectory = songsStorage.GetStorageForDirectory("subdirectory");
                createFile(subdirectory, Path.Combine("beatmap2", "beatmap.osu"));
                createFile(subdirectory, Path.Combine("beatmap3", "beatmap.osu"));
                createFile(subdirectory, Path.Combine("sub-subdirectory", "beatmap4", "beatmap.osu"));

                // songs subdirectory with system file
                var subdirectory2 = songsStorage.GetStorageForDirectory("subdirectory2");
                createFile(subdirectory2, ".DS_Store");
                createFile(subdirectory2, Path.Combine("beatmap5", "beatmap.osu"));
                createFile(subdirectory2, Path.Combine("beatmap6", "beatmap.osu"));

                // empty songs subdirectory
                songsStorage.GetStorageForDirectory("subdirectory3");

                string[] paths = importer.GetStableImportPaths(songsStorage).ToArray();
                Assert.That(paths.Length, Is.EqualTo(6));
                Assert.That(paths.Contains(songsStorage.GetFullPath("beatmap1")));
                Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "beatmap2"))));
                Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "beatmap3"))));
                Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory", "sub-subdirectory", "beatmap4"))));
                Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory2", "beatmap5"))));
                Assert.That(paths.Contains(songsStorage.GetFullPath(Path.Combine("subdirectory2", "beatmap6"))));
            }
Esempio n. 2
0
        public void TestExceptionLogging()
        {
            TestException resolvedException = null;

            void logTest(LogEntry entry)
            {
                if (entry.Exception is TestException ex)
                {
                    Assert.IsNull(resolvedException, "exception was forwarded more than once");
                    resolvedException = ex;
                }
            }

            using (var storage = new TemporaryNativeStorage(nameof(TestExceptionLogging)))
            {
                Logger.Storage = storage;
                Logger.Enabled = true;

                Logger.NewEntry += logTest;
                Logger.Error(new TestException(), "message");
                Logger.NewEntry -= logTest;

                Assert.IsNotNull(resolvedException, "exception wasn't forwarded by logger");

                Logger.Enabled = false;
                Logger.Flush();
            }
        }
        public override void SetUp()
        {
            SixLabors.ImageSharp.Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateDefault();

            baseResources = new NamespacedResourceStore <byte[]>(new DllResourceStore(@"osu.Framework.dll"), @"Resources");
            sharedTemp    = new TemporaryNativeStorage("fontstore-test-" + Guid.NewGuid());
        }
Esempio n. 4
0
        public void TestAccessAfterStorageMigrate()
        {
            RunTestWithRealm((realm, storage) =>
            {
                var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());

                Live <BeatmapInfo>?liveBeatmap = null;

                realm.Run(r =>
                {
                    r.Write(_ => r.Add(beatmap));

                    liveBeatmap = beatmap.ToLive(realm);
                });

                using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target"))
                {
                    migratedStorage.DeleteDirectory(string.Empty);

                    using (realm.BlockAllOperations())
                    {
                        storage.Migrate(migratedStorage);
                    }

                    Assert.IsFalse(liveBeatmap?.PerformRead(l => l.Hidden));
                }
            });
        }
Esempio n. 5
0
        public void TestAccessAfterStorageMigrate()
        {
            RunTestWithRealm((realmFactory, storage) =>
            {
                var beatmap = new RealmBeatmap(CreateRuleset(), new RealmBeatmapDifficulty(), new RealmBeatmapMetadata());

                ILive <RealmBeatmap> liveBeatmap;

                using (var context = realmFactory.CreateContext())
                {
                    context.Write(r => r.Add(beatmap));

                    liveBeatmap = beatmap.ToLive(realmFactory);
                }

                using (var migratedStorage = new TemporaryNativeStorage("realm-test-migration-target"))
                {
                    migratedStorage.DeleteDirectory(string.Empty);

                    storage.Migrate(migratedStorage);

                    Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
                }
            });
        }
Esempio n. 6
0
        public void OneTimeSetUp()
        {
            storage           = new TemporaryNativeStorage("fontstore-test");
            fontResourceStore = new NamespacedResourceStore <byte[]>(new DllResourceStore(typeof(Drawable).Assembly.Location), "Resources.Fonts.OpenSans");

            storage.GetFullPath("./", true);
        }
        public void TestMonitorUpdateFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int updates = 0;
                    monitor.FileUpdated += _ => updates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    using (var stream = storage.GetStream(name, FileAccess.Write, FileMode.Open))
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write("Hello");
                            writer.Flush();
                        }

                    Thread.Sleep(10);

                    Assert.IsTrue(updates == 1);
                }
        }
Esempio n. 8
0
        public void TestSaveLoad()
        {
            const double test_volume = 0.65;

            using (var storage = new TemporaryNativeStorage(new Guid().ToString()))
            {
                using (var configManager = new FrameworkConfigManager(storage))
                {
                    var bindable = configManager.GetBindable <double>(FrameworkSetting.VolumeMusic);

                    Assert.AreEqual(bindable.Default, bindable.Value);
                    Assert.IsTrue(bindable.IsDefault);

                    bindable.Value = test_volume;
                    Assert.AreEqual(test_volume, bindable.Value);
                }

                using (var configManager = new FrameworkConfigManager(storage))
                {
                    var bindable = configManager.GetBindable <double>(FrameworkSetting.VolumeMusic);

                    Assert.IsFalse(bindable.IsDefault);
                    Assert.AreEqual(test_volume, bindable.Value);
                }
            }
        }
Esempio n. 9
0
        public void TestLogOutputFromManyQueuedScheduledTasks([Values(false, true)] bool withFlushing)
        {
            int matchingLogCount = 0;

            using (var storage = new TemporaryNativeStorage(nameof(TestLogOutputFromManyQueuedScheduledTasks)))
            {
                Logger.Storage = storage;
                Logger.Enabled = true;

                Logger.NewEntry += logTest;

                Assert.AreEqual(0, matchingLogCount);

                for (int i = 0; i < Scheduler.LOG_EXCESSSIVE_QUEUE_LENGTH_INTERVAL / 2; i++)
                {
                    scheduler.AddDelayed(() => { }, 0);
                    if (withFlushing)
                    {
                        scheduler.Update();
                    }
                }

                Assert.AreEqual(0, matchingLogCount);

                for (int i = 0; i < Scheduler.LOG_EXCESSSIVE_QUEUE_LENGTH_INTERVAL / 2; i++)
                {
                    scheduler.AddDelayed(() => { }, 0);
                    if (withFlushing)
                    {
                        scheduler.Update();
                    }
                }

                Assert.AreEqual(withFlushing ? 0 : 1, matchingLogCount);

                for (int i = 0; i < Scheduler.LOG_EXCESSSIVE_QUEUE_LENGTH_INTERVAL; i++)
                {
                    scheduler.AddDelayed(() => { }, 0);
                    if (withFlushing)
                    {
                        scheduler.Update();
                    }
                }

                Assert.AreEqual(withFlushing ? 0 : 2, matchingLogCount);

                Logger.NewEntry -= logTest;
                Logger.Enabled   = false;
                Logger.Flush();

                void logTest(LogEntry entry)
                {
                    if (entry.Target == LoggingTarget.Performance && entry.Message.Contains("tasks pending"))
                    {
                        matchingLogCount++;
                    }
                }
            }
        }
Esempio n. 10
0
        public void TestGetEmptySubDirectoryStorage()
        {
            string guid = Guid.NewGuid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory(string.Empty).GetFullPath(string.Empty), Is.EqualTo(storage.GetFullPath(string.Empty)));
            }
        }
 public void BenchmarkRawCaching()
 {
     using (var temp = new TemporaryNativeStorage("fontstore-test" + Guid.NewGuid()))
         using (var store = new RawCachingGlyphStore(baseResources, font_name)
         {
             CacheStorage = temp
         })
             runFor(store);
 }
        public void TestGetSubDirectoryStorage()
        {
            var guid = new Guid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.That(storage.GetStorageForDirectory("subdir").GetFullPath(string.Empty), Is.EqualTo(Path.Combine(storage.GetFullPath(string.Empty), "subdir")));
            }
        }
        public void TestAttemptEscapeRoot()
        {
            var guid = new Guid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                Assert.Throws <ArgumentException>(() => storage.GetStream("../test"));
                Assert.Throws <ArgumentException>(() => storage.GetStorageForDirectory("../"));
            }
        }
Esempio n. 14
0
        public void TestDefault()
        {
            using (var storage = new TemporaryNativeStorage(new Guid().ToString()))
            {
                using (var configManager = new FrameworkConfigManager(storage))
                {
                    var bindable = configManager.GetBindable <string>(FrameworkSetting.Locale);

                    Assert.AreEqual(string.Empty, bindable.Value);
                    Assert.AreEqual(string.Empty, bindable.Default);
                    Assert.IsTrue(bindable.IsDefault);
                }
            }
        }
Esempio n. 15
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();
        }
        public void TestMonitorAddFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int creates = 0;
                    monitor.FileCreated += _ => creates++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(name));
                    Assert.IsTrue(creates == 1);
                }
        }
Esempio n. 17
0
        public void TestSaveLoad()
        {
            const int change = 727;

            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
            {
                using (var manager = new TestConfigurationManager(storage))
                {
                    Assert.AreEqual(manager.TestNumber, default(int));
                    manager.TestNumber = change;
                    Assert.AreEqual(manager.TestNumber, change);
                }

                using (var manager = new TestConfigurationManager(storage))
                    Assert.AreEqual(manager.TestNumber, change);
            }
        }
Esempio n. 18
0
        public void TestDefaultOverrides()
        {
            const string test_locale = "override test";

            using (var storage = new TemporaryNativeStorage(new Guid().ToString()))
            {
                using (var configManager = new FrameworkConfigManager(storage, new Dictionary <FrameworkSetting, object> {
                    { FrameworkSetting.Locale, test_locale }
                }))
                {
                    var bindable = configManager.GetBindable <string>(FrameworkSetting.Locale);
                    Assert.AreEqual(test_locale, bindable.Value);
                    Assert.AreEqual(test_locale, bindable.Default);
                    Assert.IsTrue(bindable.IsDefault);

                    bindable.Value = string.Empty;
                    Assert.IsFalse(bindable.IsDefault);
                }

                // ensure correct after save
                using (var configManager = new FrameworkConfigManager(storage, new Dictionary <FrameworkSetting, object> {
                    { FrameworkSetting.Locale, test_locale }
                }))
                {
                    var bindable = configManager.GetBindable <string>(FrameworkSetting.Locale);
                    Assert.AreEqual(test_locale, bindable.Default);
                    Assert.AreEqual(string.Empty, bindable.Value);
                    Assert.IsFalse(bindable.IsDefault);

                    bindable.Value = test_locale;
                    Assert.IsTrue(bindable.IsDefault);
                }

                // ensure correct after save with default
                using (var configManager = new FrameworkConfigManager(storage, new Dictionary <FrameworkSetting, object> {
                    { FrameworkSetting.Locale, test_locale }
                }))
                {
                    var bindable = configManager.GetBindable <string>(FrameworkSetting.Locale);
                    Assert.AreEqual(test_locale, bindable.Value);
                    Assert.AreEqual(test_locale, bindable.Default);
                    Assert.IsTrue(bindable.IsDefault);
                }
            }
        }
        public void TestRelativePaths()
        {
            var guid = new Guid().ToString();

            using (var storage = new TemporaryNativeStorage(guid))
            {
                var basePath = storage.GetFullPath(string.Empty);

                Assert.IsTrue(basePath.EndsWith(guid));

                Assert.Throws <ArgumentException>(() => storage.GetFullPath("../"));
                Assert.Throws <ArgumentException>(() => storage.GetFullPath(".."));
                Assert.Throws <ArgumentException>(() => storage.GetFullPath("./../"));

                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")) + Path.DirectorySeparatorChar, storage.GetFullPath("sub/test/"));
                Assert.AreEqual(Path.GetFullPath(Path.Combine(basePath, "sub", "test")), storage.GetFullPath("sub/test"));
            }
        }
        public void TestMonitorRenameFile()
        {
            using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()))
                using (var monitor = new MonitoredStorage(storage))
                {
                    int renames = 0;
                    monitor.FileRenamed += (_, __) => renames++;

                    string name = Guid.NewGuid().ToString();
                    storage.GetStream(name, FileAccess.ReadWrite).Dispose();

                    Thread.Sleep(10);

                    string nameReplace = Guid.NewGuid().ToString();
                    var    fi          = new FileInfo(storage.GetFullPath(name));
                    fi.MoveTo(Path.Combine(storage.GetFullPath(string.Empty), nameReplace));

                    Thread.Sleep(10);

                    Assert.IsTrue(monitor.Files.Contains(nameReplace));
                    Assert.IsTrue(renames == 1);
                }
        }
Esempio n. 21
0
 static RealmTest()
 {
     storage = new TemporaryNativeStorage("realm-test");
     storage.DeleteDirectory(string.Empty);
 }
Esempio n. 22
0
 public void OneTimeSetUp()
 {
     storage           = new TemporaryNativeStorage("fontstore-test", createIfEmpty: true);
     fontResourceStore = new NamespacedResourceStore <byte[]>(new DllResourceStore(typeof(Drawable).Assembly), "Resources.Fonts.OpenSans");
 }
Esempio n. 23
0
 public void GlobalSetup()
 {
     storage = new TemporaryNativeStorage(new Guid().ToString());
     manager = new LocalisationManager(new FrameworkConfigManager(storage));
 }
 public void OneTimeSetUp()
 {
     storage           = new TemporaryNativeStorage("fontstore-test");
     fontResourceStore = new NamespacedResourceStore <byte[]>(new DllResourceStore(typeof(Drawable).Assembly), "Resources.Fonts.Roboto");
 }