diff --git a/GLedApiDotNet/RGBFusionMotherboardImpl.cs b/GLedApiDotNet/RGBFusionMotherboardImpl.cs index e84830f..6c1f811 100644 --- a/GLedApiDotNet/RGBFusionMotherboardImpl.cs +++ b/GLedApiDotNet/RGBFusionMotherboardImpl.cs @@ -124,9 +124,9 @@ internal RGBFusionMotherboard(Raw.GLedAPIv1_0_0Wrapper wrapperAPI) api = wrapperAPI; string ver = api.GetSdkVersion(); - if (!("1.0.0".Equals(ver))) + if (string.IsNullOrEmpty(ver)) { - throw new GLedAPIException(string.Format("Unknown API version {0}. Expected 1.0.0", ver)); + throw new GLedAPIException(string.Format("GLedApi returned empty version")); } api.Initialize(); diff --git a/GLedApiDotNetTests/GLedApiv1_0_0Mock.cs b/GLedApiDotNetTests/GLedApiv1_0_0Mock.cs index e70ab29..114941d 100644 --- a/GLedApiDotNetTests/GLedApiv1_0_0Mock.cs +++ b/GLedApiDotNetTests/GLedApiv1_0_0Mock.cs @@ -34,7 +34,7 @@ public class Status public enum ControlState { Uninitialized = 1, - DoneInit, + DoneInitAPI, DoneGetMaxDivision, DoneGetLedLayout, DoneSetLedData @@ -57,10 +57,10 @@ public bool IsInitialized switch (state) { case ControlState.Uninitialized: - case ControlState.DoneGetLedLayout: + case ControlState.DoneInitAPI: case ControlState.DoneGetMaxDivision: return false; - case ControlState.DoneInit: + case ControlState.DoneGetLedLayout: case ControlState.DoneSetLedData: return true; default: @@ -150,7 +150,7 @@ public uint GetLedLayout(byte[] bytArray, int arySize) public int GetMaxDivision() { - AssertState(ControlState.DoneInit); + AssertState(ControlState.DoneInitAPI); state = ControlState.DoneGetMaxDivision; return maxDivisions; } @@ -176,7 +176,7 @@ public uint Get_IT8295_FwVer(byte[] bytArray, int arySize) public uint InitAPI() { AssertState(ControlState.Uninitialized); - state = ControlState.DoneInit; + state = ControlState.DoneInitAPI; return nextReturn; } diff --git a/GLedApiDotNetTests/Tests/RGBFusionMotherboardTests.cs b/GLedApiDotNetTests/Tests/RGBFusionMotherboardTests.cs index 3729414..182db95 100644 --- a/GLedApiDotNetTests/Tests/RGBFusionMotherboardTests.cs +++ b/GLedApiDotNetTests/Tests/RGBFusionMotherboardTests.cs @@ -37,6 +37,7 @@ public void TestBadDivisions() new RGBFusionMotherboard(new GLedApiDotNet.Raw.GLedAPIv1_0_0Wrapper(mock)); } + [Ignore] // This test is disabled until more rigorous version checking is implemented. [TestMethod] [ExpectedException(typeof(GLedAPIException))] public void TestBadVersion() diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs index 8e4e2ed..1ed9b66 100644 --- a/RGBFusionTool/Application.cs +++ b/RGBFusionTool/Application.cs @@ -41,6 +41,7 @@ public void Main(string[] args) string opt_ColorCycle = null; bool flag_DoCycle = false; bool flag_Help = false; + bool flag_List = false; string opt_Brightness = null; OptionSet options = new OptionSet @@ -51,7 +52,11 @@ public void Main(string[] args) {"cycle|colorcycle:", "cycle colors, changing color every {SECONDS}", v => { flag_DoCycle = true; opt_ColorCycle = v; } }, {"b|brightness=", "brightness (0-100)", v => opt_Brightness = v }, - {"?|h|help", "show help and exit", v => flag_Help = true } + {"l|list", "list zones", v => flag_List = true }, + + {"?|h|help", "show help and exit", v => flag_Help = true }, + + {"<>", v => { throw new OptionException(string.Format("Unexpected option \"{0}\"", v),"default"); } } }; try @@ -67,6 +72,15 @@ public void Main(string[] args) return; } + if (flag_List) + { + for (int i = 0; i < motherboardLEDs.Layout.Length; i++) + { + stdout.WriteLine("Zone {0}: {1}", i, motherboardLEDs.Layout[i]); + } + return; + } + if (!string.IsNullOrWhiteSpace(opt_Brightness)) { brightness = byte.Parse(opt_Brightness); @@ -91,6 +105,7 @@ public void Main(string[] args) } if (opt_Verbose > 0) { stdout.WriteLine("Static color: {0}", realColor.ToString()); } setting = new StaticLedSetting(realColor, brightness); + if (opt_Verbose > 0) { stdout.WriteLine("Brightness: {0}", brightness); } } if (setting != null) @@ -101,7 +116,8 @@ public void Main(string[] args) catch (Exception e) { ShowHelp(options, stderr); - stderr.WriteLine("Error: {0}", e.Message); + stderr.WriteLine(); + stderr.WriteLine("Error: {0}", e.ToString()); throw; } return; diff --git a/RGBFusionTool/Properties/AssemblyInfo.cs b/RGBFusionTool/Properties/AssemblyInfo.cs index cd40adc..1b269f6 100644 --- a/RGBFusionTool/Properties/AssemblyInfo.cs +++ b/RGBFusionTool/Properties/AssemblyInfo.cs @@ -40,5 +40,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.0.2")] -[assembly: AssemblyFileVersion("0.9.0.2")] +[assembly: AssemblyVersion("0.9.0.3")] +[assembly: AssemblyFileVersion("0.9.0.3")] diff --git a/RGBFusionTool/RGBFusionMain.cs b/RGBFusionTool/RGBFusionMain.cs index bcabe18..852ee3c 100644 --- a/RGBFusionTool/RGBFusionMain.cs +++ b/RGBFusionTool/RGBFusionMain.cs @@ -23,14 +23,24 @@ private class LazyMotherboard : IRGBFusionMotherboard public void SetAll(LedSetting ledSetting) => motherboard.Value.SetAll(ledSetting); } - private static void Main(string[] args) + private static int Main(string[] args) { Application application = new Application( new LazyMotherboard(), Console.Out, Console.Error ); - application.Main(args); + + try + { + application.Main(args); + } + catch + { + return 1; + } + + return 0; } } } \ No newline at end of file diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index a522aad..b9f7ce8 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -73,15 +73,26 @@ public void NoArgs() } // Color options - [DataRow(new string[] { "--color" }, DisplayName = "No value")] - [DataRow(new string[] { "--color=Invalid" }, DisplayName = "Bad name")] + [DataRow(new string[] { "--color" }, DisplayName = "--color")] + [DataRow(new string[] { "--color=Invalid" }, DisplayName = "--color=Invalid")] + [DataRow(new string[] { "--color", "--color=Red" }, DisplayName = "--color --color=Red")] // ColorCycle options - [DataRow(new string[] { "--colorcycle=Invalid" }, DisplayName = "Cycle, Bad name")] - [DataRow(new string[] { "--colorcycle=9999" }, DisplayName = "Cycle, Too high")] + [DataRow(new string[] { "--colorcycle=Invalid" }, DisplayName = "--colorcycle=Invalid")] + [DataRow(new string[] { "--colorcycle=9999" }, DisplayName = "--colorcycle=9999")] + [DataRow(new string[] { "--colorcycle=--colorcycle" }, DisplayName = "--colorcycle=--colorcycle")] // Brightness options - [DataRow(new string[] { "--color=Red", "--brightness" }, DisplayName = "Brightness, No value")] - [DataRow(new string[] { "--color=Red", "--brightness=Invalid" }, DisplayName = "Brightness, Bad name")] - [DataRow(new string[] { "--color=Red", "--brightness=101" }, DisplayName = "Brightness, Too high")] + [DataRow(new string[] { "--color=Red", "--brightness" }, DisplayName = "--color=Red --brightness")] + [DataRow(new string[] { "--color=Red", "--brightness=Invalid" }, DisplayName = "--color=Red --brightness=Invalid")] + [DataRow(new string[] { "--color=Red", "--brightness=101" }, DisplayName = "--color=Red --brightness=101")] + // Extra parameters + [DataRow(new string[] { "1" }, DisplayName = "1")] + [DataRow(new string[] { "0" }, DisplayName = "0")] + [DataRow(new string[] { "--badopt" }, DisplayName = "--badopt")] + [DataRow(new string[] { "badopt" }, DisplayName = "badopt")] + [DataRow(new string[] { "--", "badopt" }, DisplayName = "-- badopt")] + // Ambiguious options + [DataRow(new string[] { "--colorcycle", "4.0" }, DisplayName = "--colorcycle 4.0")] // Optional values expect explicit "=" + [DataRow(new string[] { "--colorcycle 4.0" }, DisplayName = "--colorcycle 4.0 (OneWord)")] // Optional values expect explicit "=" [DataTestMethod] public void BadOptions(string[] args) { @@ -131,6 +142,40 @@ public void Color(string[] args) GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); } + [DataRow(new string[] { "-v", "--color=DodgerBlue" }, DisplayName = "-v --color=DodgerBlue")] + [DataRow(new string[] { "-vv", "--color=DodgerBlue" }, DisplayName = "-vv --color=DodgerBlue")] + [DataRow(new string[] { "--verbose", "--color=DodgerBlue" }, DisplayName = "--verbose --color=DodgerBlue")] + [DataRow(new string[] { "--color=DodgerBlue", "--verbose" }, DisplayName = "--color=DodgerBlue --verbose")] + [DataTestMethod] + public void Color_verbose_name(string[] args) + { + rgbFusionTool.Main(args); + + StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty"); + StringAssert.Matches(stdout.ToString(), new Regex("color\\b.*dodgerblue", RegexOptions.IgnoreCase), "Expect stdout includes color name"); + + TestHelper.AssertAllLeds(mock, + GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.StaticDodgerBlue, + GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); + } + + [DataRow(new string[] { "-v", "--color=1E90FF" }, DisplayName = "-v --color=1E90FF")] + [DataRow(new string[] { "-vv", "--color=1E90FF" }, DisplayName = "-vv --color=1E90FF")] + [DataRow(new string[] { "--verbose", "--color=1E90FF" }, DisplayName = "--verbose --color=1E90FF")] + [DataRow(new string[] { "--color=1E90FF", "--verbose" }, DisplayName = "--color=1E90FF --verbose")] + [DataTestMethod] + public void Color_verbose_rgb(string[] args) + { + rgbFusionTool.Main(args); + + StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty"); + StringAssert.Matches(stdout.ToString(), new Regex("color\\b.*\\b30\\b.*\\b144\\b.*\\b255\\b", RegexOptions.IgnoreCase), "Expect stdout includes color values"); + + TestHelper.AssertAllLeds(mock, + GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.StaticDodgerBlue, + GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); + } + [DataRow(new string[] { "--color=Red", "-b50" }, DisplayName = "-b50")] [DataRow(new string[] { "--color=Red", "-b", "50" }, DisplayName = "-b 50")] [DataRow(new string[] { "--color=Red", "-b 50" }, DisplayName = "-b 50 (OneWord)")] @@ -149,6 +194,23 @@ public void Brightness(string[] args) GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); } + [DataRow(new string[] { "-v", "--color=Red", "--brightness=50" }, DisplayName = "-v --color=Red --brightness=50")] + [DataRow(new string[] { "-vv", "--color=Red", "--brightness=50" }, DisplayName = "-vv --color=Red --brightness=50")] + [DataRow(new string[] { "--verbose", "--color=Red", "--brightness=50" }, DisplayName = "--verbose --color=Red --brightness=50")] + [DataRow(new string[] { "--color=Red", "--brightness=50", "--verbose" }, DisplayName = "--color=Red --brightness=50 --verbose")] + [DataTestMethod] + public void Brightness_verbose(string[] args) + { + rgbFusionTool.Main(args); + + StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty"); + StringAssert.Matches(stdout.ToString(), new Regex("brightness\\b.*\\b50\\b", RegexOptions.IgnoreCase), "Expect stdout includes brightness value"); + + TestHelper.AssertAllLeds(mock, + GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.StaticRed50, + GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); + } + [DataRow(new string[] { "--colorcycle" }, DisplayName = "--colorcycle")] [DataRow(new string[] { "--cycle" }, DisplayName = "--cycle")] [DataRow(new string[] { "--colorcycle=1" }, DisplayName = "--colorcycle=1")] @@ -168,6 +230,23 @@ public void ColorCycle_1s(string[] args) GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); } + [DataRow(new string[] { "-v", "--colorcycle" }, DisplayName = "-v --colorcycle")] + [DataRow(new string[] { "-vv", "--colorcycle" }, DisplayName = "-vv --colorcycle")] + [DataRow(new string[] { "--verbose", "--colorcycle" }, DisplayName = "--verbose --colorcycle")] + [DataRow(new string[] { "--colorcycle", "--verbose" }, DisplayName = "--colorcycle --verbose")] + [DataTestMethod] + public void ColorCycle_verbose(string[] args) + { + rgbFusionTool.Main(args); + + StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty"); + StringAssert.Matches(stdout.ToString(), new Regex("(color\\w*)?cycle\\b.*\\b1(\\.0*)?\\b\\ss", RegexOptions.IgnoreCase), "Expect stdout includes mode and time"); + + TestHelper.AssertAllLeds(mock, + GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.ColorCycleA_1s, + GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); + } + [DataRow(new string[] { "--colorcycle=4" }, DisplayName = "--colorcycle=4")] [DataRow(new string[] { "--cycle=4" }, DisplayName = "--cycle=4")] [DataRow(new string[] { "--colorcycle=4.0" }, DisplayName = "--colorcycle=4.0")] @@ -201,5 +280,18 @@ public void ColorCycle_500ms(string[] args) GLedApiDotNetTests.Tests.LedSettingTests.SettingByteArrays.ColorCycleA_500ms, GLedApiv1_0_0Mock.DEFAULT_MAXDIVISIONS); } + + [DataRow(new string[] { "--list" }, DisplayName = "--list")] + [DataRow(new string[] { "-l" }, DisplayName = "-l")] + [DataTestMethod] + public void List(string[] args) + { + rgbFusionTool.Main(args); + + StringAssert.DoesNotMatch(stderr.ToString(), ANY, "Expect stderr is empty"); + StringAssert.Matches(stdout.ToString(), new Regex("zone \\d+", RegexOptions.IgnoreCase), "Expect stdout lists zones"); + + Assert.IsTrue(mock.IsInitialized, "Expect initialized"); + } } }