Files

54 lines
2.2 KiB
C#

using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using SbLauncher;
public static class ProfileSmoke
{
[STAThread]
public static int Main()
{
string root = Path.Combine(Path.GetTempPath(), "SbLauncherRev2-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
try
{
var app = new Application();
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
var vm = new MainVm();
vm.Load(new Paths(root));
string vless = "vless://58863334-3b8a-4c81-9145-a18311621a7f@localhost:443?security=reality&pbk=test&sni=example.com#Smoke";
string trojan = "trojan://password@example.com:443?sni=example.com#Second";
Task<bool> added = vm.AddFromLinkAsync(vless + "\n" + trojan + "\n" + vless);
var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(20) };
var started = DateTime.UtcNow;
timer.Tick += delegate
{
if (added.IsCompleted || (DateTime.UtcNow - started).TotalSeconds > 5)
{
timer.Stop();
app.Shutdown();
}
};
timer.Start();
app.Run();
vm.DisposeTimers();
Profiles stored = Profiles.Load(Path.Combine(root, "profiles.json"));
bool ok = added.IsCompleted && added.Result && stored.Servers.Count == 2 &&
vm.Servers.Count == 3 && stored.Servers[0].Outbound != null &&
stored.Servers[1].Outbound != null &&
stored.Servers[0].Protocol == "vless" && stored.Servers[1].Protocol == "trojan" &&
stored.Servers[0].Code != stored.Servers[1].Code;
Console.WriteLine(ok ? "batch import, deduplication and roundtrip: ok" :
"batch import, deduplication and roundtrip: failed");
return ok ? 0 : 1;
}
finally
{
if (root.StartsWith(Path.GetTempPath(), StringComparison.OrdinalIgnoreCase))
Directory.Delete(root, true);
}
}
}