public DoktorTest(string[] aArgs) { iMutex = new Mutex(); iHelper = new Helper(aArgs); iOptionShow = new OptionParser.OptionBool("-s", "--show", "Show tests"); OptionParser options = iHelper.OptionParser; options.Usage = "usage: DoktorTest [options] [test]\n"; options.AddOption(iOptionShow); string id = "DoktorTest"; iTests = Test.CreateTests(id); iSupplies = Supply.CreateSupplies(id); }
static void Main(string[] aArgs) { HelperVolkano helper = new HelperVolkano(aArgs); OptionParser optParser = helper.OptionParser; optParser.Usage = "usage: FacDef.exe [options] [target ugly name]"; OptionParser.OptionBool optNoExec = new OptionParser.OptionBool(null, "--noexec", "Do not reboot target after reprogramming"); OptionParser.OptionBool optWait = new OptionParser.OptionBool("-w", "--wait", "Wait to discover rebooted target after reprogramming (ignored with --noexec)"); optParser.AddOption(optNoExec); optParser.AddOption(optWait); helper.Start(); if (optParser.PosArgs.Count != 1) { Console.WriteLine(optParser.Help()); System.Environment.Exit(1); } string uglyname = optParser.PosArgs[0]; // create the console IConsole console = new FlashInfoConsole(); // create the reprogrammer FactoryDefaulter defaulter = new FactoryDefaulter(helper.IpAddress, console, uglyname); defaulter.NoExec = optNoExec.Value; defaulter.Wait = optWait.Value; if (!defaulter.Execute()) { defaulter.Close(); System.Environment.Exit(1); } defaulter.Close(); }
private void OptionBoolTests() { // bool option tests OptionParser optParser; OptionParser.OptionBool optBool1 = new OptionParser.OptionBool("-a", "--boola", "bool help"); OptionParser.OptionBool optBool2 = new OptionParser.OptionBool("-b", "--boolb", "bool help"); TEST(optBool1.ShortName == "-a"); TEST(optBool1.LongName == "--boola"); TEST(optBool1.Value == false); TEST(optBool2.ShortName == "-b"); TEST(optBool2.LongName == "--boolb"); TEST(optBool2.Value == false); // no args optParser = new OptionParser(new string[] {}); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 0); TEST(optBool1.Value == false); TEST(optBool2.Value == false); // positional args only optParser = new OptionParser(new string[] { "arg1", "arg2" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == false); TEST(optBool2.Value == false); // 1 good arg optParser = new OptionParser(new string[] { "-a", "arg1", "arg2" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == false); optParser = new OptionParser(new string[] { "--boola", "arg1", "arg2" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == false); optParser = new OptionParser(new string[] { "arg1", "-a", "arg2" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == false); optParser = new OptionParser(new string[] { "arg1", "arg2", "-a" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == false); // 2 good args optParser = new OptionParser(new string[] { "-b", "-a", "arg1", "arg2" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == true); optParser = new OptionParser(new string[] { "-b", "arg1", "arg2", "-a" }); optParser.AddOption(optBool1); optParser.AddOption(optBool2); optParser.Parse(); TEST(optParser.PosArgs.Count == 2); TEST(optParser.PosArgs[0] == "arg1"); TEST(optParser.PosArgs[1] == "arg2"); TEST(optBool1.Value == true); TEST(optBool2.Value == true); // help tests OptionParser.OptionHelp help; help = new OptionParser.OptionHelp(); optBool1 = new OptionParser.OptionBool("-a", null, "bool help"); optBool1.AppendHelp(help); TEST(help.ToString() == "options:\n -a bool help\n"); help = new OptionParser.OptionHelp(); optBool1 = new OptionParser.OptionBool(null, "--boola", "bool help"); optBool1.AppendHelp(help); TEST(help.ToString() == "options:\n --boola bool help\n"); help = new OptionParser.OptionHelp(); optBool1 = new OptionParser.OptionBool("-a", "--boola", "bool help"); optBool1.AppendHelp(help); TEST(help.ToString() == "options:\n -a, --boola bool help\n"); help = new OptionParser.OptionHelp(); optBool1 = new OptionParser.OptionBool("-a", "--boolaaaaaaaaaa", "bool help"); optBool1.AppendHelp(help); TEST(help.ToString() == "options:\n -a, --boolaaaaaaaaaa bool help\n"); help = new OptionParser.OptionHelp(); optBool1 = new OptionParser.OptionBool("-a", "--boolaaaaaaaaaaa", "bool help"); optBool1.AppendHelp(help); TEST(help.ToString() == "options:\n -a, --boolaaaaaaaaaaa\n bool help\n"); }
public override void Test() { // Option creation tests // no option names TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, null, "defaultstring", "test string help", "STRING"); // bad short option names TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "", null, "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "s", null, "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "-", null, "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "--", null, "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "-sd", null, "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), "--sd", null, "defaultstring", "test string help", "STRING"); // bad long option names TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "", "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "s", "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "-", "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "-s", "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "--", "defaultstring", "test string help", "STRING"); TEST_THROWS_NEW(typeof(AssertionError), typeof(OptionParser.OptionString), null, "-sd", "defaultstring", "test string help", "STRING"); // Some tests for different option types OptionStringTests(); OptionIntTests(); OptionBoolTests(); // Parsing tests OptionParser optParser = new OptionParser(new string[] { "-a", "aval", "--bc", "bcval" }); OptionParser.OptionString optString1 = new OptionParser.OptionString("-a", null, "defaultstring", "string help", "STRING"); OptionParser.OptionString optString2 = new OptionParser.OptionString(null, "--bc", "defaultstring", "string help", "STRING"); OptionParser.OptionString optString3 = new OptionParser.OptionString("-a", "--bc", "defaultstring", "string help", "STRING"); OptionParser.OptionInt optInt4 = new OptionParser.OptionInt("-a", null, 123, "int help", "INT"); OptionParser.OptionBool optBool5 = new OptionParser.OptionBool(null, "--bc", "bool help"); // test adding already existing options optParser.AddOption(optString1); optParser.AddOption(optString2); TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString1); TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString2); TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optString3); TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optInt4); TEST_THROWS(typeof(AssertionError), optParser, "AddOption", optBool5); optParser.Parse(); TEST(optParser.PosArgs.Count == 0); TEST(optString1.Value == "aval"); TEST(optString2.Value == "bcval"); TEST(optString3.Value == "defaultstring"); TEST(optInt4.Value == 123); TEST(optBool5.Value == false); // test undefined options optParser = new OptionParser(new string[] { "-d" }); TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse"); TEST(optParser.PosArgs.Count == 0); optParser = new OptionParser(new string[] { "--de" }); TEST_THROWS(typeof(OptionParser.OptionParserError), optParser, "Parse"); TEST(optParser.PosArgs.Count == 0); }
static void Main(string[] aArgs) { HelperVolkano helper = new HelperVolkano(aArgs); OptionParser optParser = helper.OptionParser; optParser.Usage = "usage: Reprog.exe [options] [target ugly name] [rom file | bundle file]"; OptionParser.OptionBool optFallback = new OptionParser.OptionBool("-f", "--fallback", "Target fallback rather than main"); OptionParser.OptionBool optNoExec = new OptionParser.OptionBool(null, "--noexec", "Do not reboot target after reprogramming"); OptionParser.OptionBool optWait = new OptionParser.OptionBool("-w", "--wait", "Wait to discover rebooted target after reprogramming (ignored with --noexec)"); OptionParser.OptionBool optNoTrust = new OptionParser.OptionBool(null, "--notrust", "Reprogram to factory fresh paying no attention to current flash contents"); OptionParser.OptionBool optBootstrap = new OptionParser.OptionBool(null, "--bootstrap", "Additionally reprogram the boostrap"); OptionParser.OptionBool optUnsafe = new OptionParser.OptionBool(null, "--unsafe", "Program directly to flash / no 2 phase programming."); OptionParser.OptionString optEmulator = new OptionParser.OptionString("-e", "--emulator", "", "Flash emulator name (SrecA)", "Emulator name"); OptionParser.OptionString optOutput = new OptionParser.OptionString("-o", "--output", "", "Flash emulator output filename", "Output filename"); optParser.AddOption(optFallback); optParser.AddOption(optNoExec); optParser.AddOption(optWait); optParser.AddOption(optNoTrust); optParser.AddOption(optBootstrap); optParser.AddOption(optUnsafe); optParser.AddOption(optEmulator); optParser.AddOption(optOutput); helper.Start(); if (optParser.PosArgs.Count != 2) { Console.WriteLine(optParser.Help()); System.Environment.Exit(1); } string uglyname = optParser.PosArgs[0]; string xmlfile = optParser.PosArgs[1]; // create the console IConsole console = new FlashInfoConsole(); // create the reprogrammer Reprogrammer reprog = new Reprogrammer(helper.IpAddress, console, uglyname, xmlfile); reprog.Fallback = optFallback.Value; reprog.NoExec = optNoExec.Value; reprog.Wait = optWait.Value; reprog.NoTrust = optNoTrust.Value; reprog.Bootstrap = optBootstrap.Value; reprog.Emulator = optEmulator.Value; reprog.Output = optOutput.Value; reprog.Unsafe = optUnsafe.Value; // reprog if (!reprog.Execute()) { reprog.Close(); System.Environment.Exit(1); } reprog.Close(); System.Environment.Exit(0); }