public static SettingsBag ReadSettings(XElement node) { if (!node.Name.LocalName.Equals("Settings")) { throw new InternalErrorException(); } var settings = SettingsBag.CreateDefault(); foreach (var element in node.Elements("Setting")) { var key = element.Attribute("Key"); var value = element.Attribute("Value"); settings.Add(key.Value, value.Value); } return(settings); }
void Initialize() { serverModeArray = new NSMutableArray(); if (MacUI.AppDelegate.HasBuiltinFramework) { serverModeArray.Add(new ServerModeModel(ServerMode.Builtin, "Builtin test framework")); } else { serverModeArray.Add(new ServerModeModel(ServerMode.WaitForConnection, "Wait for connection")); serverModeArray.Add(new ServerModeModel(ServerMode.Local, "Run locally")); serverModeArray.Add(new ServerModeModel(ServerMode.Android, "Connect to Android")); serverModeArray.Add(new ServerModeModel(ServerMode.iOS, "Connect to iOS")); } string currentMode; if (!SettingsBag.TryGetValue("ServerMode", out currentMode)) { currentMode = MacUI.AppDelegate.HasBuiltinFramework ? "Builtin" : "WaitForConnection"; } SettingsBag.DisableTimeouts = SettingsBag.LogLevel > SettingsBag.DisableTimeoutsAtLogLevel; for (nuint i = 0; i < serverModeArray.Count; i++) { var model = serverModeArray.GetItem <ServerModeModel> (i); if (currentServerMode == null || model.Mode.ToString().Equals(currentMode)) { currentServerMode = model; } } testCategoriesArray = new NSMutableArray(); allCategory = new TestCategoryModel(TestCategory.All); globalCategory = new TestCategoryModel(TestCategory.Global); martinCategory = new TestCategoryModel(TestCategory.Martin); currentCategory = allCategory; testCategoriesArray.Add(allCategory); testCategoriesArray.Add(globalCategory); testCategoriesArray.Add(martinCategory); testFeaturesArray = new NSMutableArray(); }
Program(string[] args) { rng = RandomNumberGenerator.Create(); DependencyInjector.Register <ICryptoProvider> (this); DependencyInjector.Register <IConnectionProvider> (this); MonoTlsProviderFactory.InstallProvider(new NewTlsProvider()); LogLevel = -1; var p = new OptionSet(); p.Add("settings=", v => SettingsFile = v); p.Add("server", v => Server = true); p.Add("noxml", v => NoXml = true); p.Add("log-level=", v => LogLevel = int.Parse(v)); var remaining = p.Parse(args); settings = LoadSettings(SettingsFile); Assembly assembly; if (remaining.Count == 1) { assembly = Assembly.LoadFile(remaining [0]); } else if (remaining.Count == 0) { assembly = typeof(NewTlsTestFeatures).Assembly; } else { throw new InvalidOperationException(); } logger = new TestLogger(new ConsoleLogger(this)); logger.LogLevel = LogLevel; framework = TestFramework.GetLocalFramework(assembly); }
void Initialize() { CheckSettingsFile(); settings = LoadSettings(SettingsFile); if (customSettings != null) { ParseSettings(customSettings); } if (DebugMode) { settings.LogLevel = -1; settings.LocalLogLevel = -1; settings.DisableTimeouts = true; } if (LogLevel != null) { settings.LogLevel = LogLevel.Value; } if (LocalLogLevel != null) { settings.LocalLogLevel = LocalLogLevel.Value; } logger = new TestLogger(new ConsoleLogger(this)); if (Launcher != null) { LauncherOptions = new LauncherOptions { Category = category, Features = features }; } }
private void AddField(FieldInfo fieldInfo, SettingsBag obj) { GameObject newField; SettingsField uiField; if (fieldInfo.FieldType == typeof(bool)) { newField = Instantiate(BoolFieldPrefab, _scrollView.content); var f = newField.GetComponent <BoolSettingField>(); f.CheckBox.isOn = (bool)fieldInfo.GetValue(obj); uiField = f; } else //(fieldInfo.FieldType == typeof(string)) { // Anything except bool is string for now if (Attribute.GetCustomAttribute(fieldInfo, typeof(PathAttribute)) != null) { newField = Instantiate(BrowseFieldPrefab, _scrollView.content); } else { newField = Instantiate(StringFieldPrefab, _scrollView.content); } var f = newField.GetComponent <StringSettingsField>(); f.Field.text = fieldInfo.GetValue(obj)?.ToString() ?? ""; uiField = f; } newField.name = $"{fieldInfo.Name}"; uiField.SettingsBag = obj; var tooltip = (TooltipAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(TooltipAttribute)); uiField.FieldToolTip = tooltip?.tooltip ?? fieldInfo.Name; uiField.FieldName = fieldInfo.Name; uiField.FieldType = fieldInfo.FieldType; _fields.Add(uiField); }
private bool IsDirectory() { var attr = SettingsBag.GetType().GetField(FieldName).GetCustomAttribute <PathAttribute>(); return(attr != null && attr.PathType == PathAttribute.PathTypes.Directory); }
public ProgramOptions(Assembly assembly, string[] args) { Assembly = assembly; var dependencies = new List <string> (); var resultOutput = "TestResult.xml"; var junitResultOutput = "JUnitTestResult.xml"; string packageName = null; string outputDir = null, stdout = null; string customSettings = null; string sdkRoot = null, iosDeviceType = null, iosRuntime = null; string androidSdkRoot = null; int? repeat = null; bool debugMode = false; bool noJUnit = false; bool dontSaveLogging = false; string logLevel = null; int? localLogLevel = null; var p = new OptionSet(); p.Add("settings=", v => settingsFile = v); p.Add("endpoint=", v => EndPoint = Program.GetEndPoint(v)); p.Add("extra-launcher-args=", v => ExtraLauncherArgs = v); p.Add("gui=", v => GuiEndPoint = Program.GetEndPoint(v)); p.Add("no-result", v => resultOutput = junitResultOutput = null); p.Add("package-name=", v => packageName = v); p.Add("result=", v => resultOutput = v); p.Add("junit-result=", v => junitResultOutput = v); p.Add("log-level=", v => logLevel = v); p.Add("local-log-level=", v => localLogLevel = int.Parse(v)); p.Add("dependency=", v => dependencies.Add(v)); p.Add("optional-gui", v => OptionalGui = true); p.Add("no-junit", v => noJUnit = true); p.Add("set=", v => customSettings = v); p.Add("category=", v => Category = v); p.Add("features=", v => Features = v); p.Add("martin=", v => MartinTest = v); p.Add("debug", v => debugMode = true); p.Add("save-options", v => saveSettings = true); p.Add("show-categories", v => ShowCategories = true); p.Add("show-features", v => ShowFeatures = true); p.Add("show-config", v => ShowCategories = ShowFeatures = true); p.Add("ios-device-type=", v => iosDeviceType = v); p.Add("ios-runtime=", v => iosRuntime = v); p.Add("android-activity=", v => AndroidActivity = v); p.Add("android-serial=", v => AndroidSerial = v); p.Add("stdout=", v => stdout = v); p.Add("sdkroot=", v => sdkRoot = v); p.Add("android-sdkroot=", v => androidSdkRoot = v); p.Add("save-logcat=", v => SaveLogCat = v); p.Add("jenkins", v => Jenkins = true); p.Add("jenkins-html=", v => JenkinsHtml = v); p.Add("output-dir=", v => outputDir = v); p.Add("repeat=", v => repeat = int.Parse(v)); p.Add("dont-save-logging", v => dontSaveLogging = true); p.Add("jenkins-job=", "Jenkins Job Path", v => JenkinsJobPath = v); var arguments = p.Parse(args); PackageName = packageName; if (assembly != null) { Command = Command.Local; if (arguments.Count > 0 && arguments[0].Equals("local")) { arguments.RemoveAt(0); } } else { if (arguments.Count < 1) { throw new ProgramException("Missing argument."); } Command command; if (!Enum.TryParse(arguments[0], true, out command)) { throw new ProgramException("Unknown command."); } arguments.RemoveAt(0); Command = command; } Arguments = arguments; var dependencyAssemblies = new Assembly[dependencies.Count]; for (int i = 0; i < dependencyAssemblies.Length; i++) { dependencyAssemblies[i] = Assembly.LoadFile(dependencies[i]); } Dependencies = dependencyAssemblies; switch (Command) { case Command.Listen: if (EndPoint == null) { EndPoint = Program.GetLocalEndPoint(); } break; case Command.Local: if (assembly != null) { if (arguments.Count != 0) { arguments.ForEach(a => Program.PrintError($"Unexpected remaining argument: {a}")); throw new ProgramException("Unexpected extra argument."); } Assembly = assembly; } else if (arguments.Count == 1) { Application = arguments[0]; Assembly = Assembly.LoadFile(arguments[0]); arguments.RemoveAt(0); } else if (EndPoint == null) { throw new ProgramException("Missing endpoint"); } break; case Command.Connect: if (assembly != null) { throw new ProgramException("Cannot use 'connect' with assembly."); } if (arguments.Count == 1) { EndPoint = Program.GetEndPoint(arguments[0]); arguments.RemoveAt(0); } else if (arguments.Count == 0) { if (EndPoint == null) { throw new ProgramException("Missing endpoint"); } } else { arguments.ForEach(a => Program.PrintError($"Unexpected remaining argument: {a}")); throw new ProgramException("Unexpected extra argument."); } break; case Command.Simulator: case Command.Device: case Command.TVOS: if (arguments.Count < 1) { throw new ProgramException("Expected .app argument"); } Application = arguments[0]; arguments.RemoveAt(0); if (EndPoint == null) { EndPoint = Program.GetLocalEndPoint(); } break; case Command.Mac: if (arguments.Count < 1) { throw new ProgramException("Expected .app argument"); } Application = arguments[0]; arguments.RemoveAt(0); if (EndPoint == null) { EndPoint = Program.GetLocalEndPoint(); } break; case Command.Android: if (arguments.Count != 0) { throw new ProgramException("Unexpected extra arguments"); } if (EndPoint == null) { EndPoint = Program.GetLocalEndPoint(); } break; case Command.Avd: case Command.Emulator: if (arguments.Count != 0) { throw new ProgramException("Unexpected extra arguments"); } break; case Command.Apk: if (arguments.Count != 1) { throw new ProgramException("Expected .apk argument"); } Application = arguments[0]; arguments.RemoveAt(0); break; case Command.Result: if (arguments.Count != 1) { throw new ProgramException("Expected TestResult.xml argument"); } resultOutput = arguments[0]; arguments.RemoveAt(0); break; default: throw new ProgramException("Unknown command '{0}'.", Command); } OutputDirectory = outputDir; if (!string.IsNullOrEmpty(OutputDirectory) && !Directory.Exists(OutputDirectory)) { Directory.CreateDirectory(OutputDirectory); } if (stdout != null) { var fullPath = Path.Combine("artifact", stdout); if (JenkinsJobPath != null) { fullPath = Path.Combine(JenkinsJobPath, fullPath); } JenkinsStdOutLink = $"<a href=\"{fullPath}\">{stdout}</a>"; } StdOut = MakeAbsolute(OutputDirectory, stdout); ResultOutput = MakeAbsolute(OutputDirectory, resultOutput); if (!noJUnit) { JUnitResultOutput = MakeAbsolute(OutputDirectory, junitResultOutput); } JenkinsHtml = MakeAbsolute(OutputDirectory, JenkinsHtml); if (settingsFile != null) { if (saveSettings == null) { saveSettings = true; } } else if (Assembly != null) { var name = Assembly.GetName().Name; var path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); path = Path.Combine(path, "Xamarin", "AsyncTests"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } settingsFile = Path.Combine(path, name + ".xml"); } if (settingsFile == null || !File.Exists(settingsFile)) { Settings = SettingsBag.CreateDefault(); } else { Settings = LoadSettings(settingsFile); } if (repeat != null) { Settings.Repeat = true; Settings.RepeatCount = repeat.Value; } if (customSettings != null) { ParseSettings(Settings, customSettings); if (saveSettings ?? false) { SaveSettings(Settings, settingsFile); } } if (debugMode) { Settings.LogLevel = -1; Settings.LocalLogLevel = -1; Settings.DisableTimeouts = true; } if (logLevel != null) { var(defaultLevel, categories) = ParseLogLevel(logLevel); Settings.LogLevel = defaultLevel; foreach (var entry in categories) { Settings.SetLogLevel(entry.Key, entry.Value); } } if (localLogLevel != null) { Settings.LocalLogLevel = localLogLevel.Value; } if (!debugMode) { Settings.DisableTimeouts = Settings.LogLevel > SettingsBag.DisableTimeoutsAtLogLevel; } if (dontSaveLogging) { Settings.DontSaveLogging = true; } if (MartinTest != null) { if (Category != null) { throw new ProgramException("Cannot use both --category and --martin"); } Category = "martin"; Settings.MartinTest = MartinTest; } bool needSdk = false, needAndroidSdk = false; switch (Command) { case Command.Device: case Command.Simulator: IOSDeviceType = iosDeviceType ?? GetEnvironmentVariable("IOS_DEVICE_TYPE", "iPhone-5s"); IOSRuntime = iosRuntime ?? GetEnvironmentVariable("IOS_RUNTIME", "iOS-10-3"); needSdk = true; break; case Command.TVOS: IOSDeviceType = iosDeviceType ?? GetEnvironmentVariable("IOS_DEVICE_TYPE", "Apple-TV-1080p"); IOSRuntime = iosRuntime ?? GetEnvironmentVariable("IOS_RUNTIME", "tvOS-9-2"); needSdk = true; break; case Command.Android: case Command.Avd: case Command.Emulator: case Command.Apk: needAndroidSdk = true; break; } if (needSdk) { SdkRoot = sdkRoot ?? GetEnvironmentVariable("XCODE_DEVELOPER_ROOT", "/Applications/Xcode.app/Contents/Developer"); } if (needAndroidSdk) { AndroidSdkRoot = androidSdkRoot ?? Environment.GetEnvironmentVariable("ANDROID_SDK_PATH"); if (String.IsNullOrEmpty(AndroidSdkRoot)) { var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal); AndroidSdkRoot = Path.Combine(home, "Library", "Developer", "Xamarin", "android-sdk"); } } }
public MobileTestOptions(string options) { Settings = SettingsBag.CreateDefault(); Settings.LocalLogLevel = -1; if (string.IsNullOrEmpty(options)) { Settings.LogLevel = 0; Settings.LocalLogLevel = 0; Settings.DisableTimeouts = false; SessionMode = MobileSessionMode.Local; return; } int? logLevel = null; bool debugMode = false; string category = null; string features = null; string packageName = null; string customSettings = null; var p = new NDesk.Options.OptionSet(); p.Add("debug", v => debugMode = true); p.Add("log-level=", v => logLevel = int.Parse(v)); p.Add("category=", v => category = v); p.Add("features=", v => features = v); p.Add("package-name=", v => packageName = v); p.Add("set=", v => customSettings = v); var optArray = options.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var args = p.Parse(optArray); Category = category; Features = features; PackageName = packageName; if (debugMode) { Settings.LogLevel = -1; Settings.LocalLogLevel = -1; Settings.DisableTimeouts = true; } else { Settings.DisableTimeouts = false; } if (logLevel != null) { Settings.LogLevel = logLevel.Value; } if (customSettings != null) { ParseSettings(customSettings); } if (args.Count == 0) { SessionMode = MobileSessionMode.Local; return; } if (args [0] == "server") { SessionMode = MobileSessionMode.Server; if (args.Count == 2) { EndPoint = DependencyInjector.Get <IPortableEndPointSupport> ().ParseEndpoint(args [1]); } else if (args.Count == 1) { EndPoint = GetEndPoint(); } else { throw new InvalidOperationException("Invalid 'XAMARIN_ASYNCTESTS_OPTIONS' argument."); } } else if (args [0] == "connect") { SessionMode = MobileSessionMode.Connect; if (args.Count != 2) { throw new InvalidOperationException("Invalid 'XAMARIN_ASYNCTESTS_OPTIONS' argument."); } EndPoint = DependencyInjector.Get <IPortableEndPointSupport> ().ParseEndpoint(args [1]); } else if (args [0] == "local") { SessionMode = MobileSessionMode.Local; if (args.Count != 1) { throw new InvalidOperationException("Invalid 'XAMARIN_ASYNCTESTS_OPTIONS' argument."); } return; } else { throw new InvalidOperationException("Invalid 'XAMARIN_ASYNCTESTS_OPTIONS' argument."); } }
public void Add(SettingsBag recent) { Add((T)recent); }