From f0b0366bbc26f42d099b1d04dc08067963616053 Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Sun, 18 Feb 2018 18:12:35 -0800 Subject: [PATCH 1/9] Error on unexpected options --- RGBFusionTool/Application.cs | 4 +++- RGBFusionToolTests/RGBFusionToolExeTests.cs | 23 ++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs index 8e4e2ed..6574f4c 100644 --- a/RGBFusionTool/Application.cs +++ b/RGBFusionTool/Application.cs @@ -51,7 +51,9 @@ 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 } + {"?|h|help", "show help and exit", v => flag_Help = true }, + + {"<>", v => { throw new OptionException(string.Format("Unexpected option \"{0}\"", v),"default"); } } }; try diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index a522aad..82957fb 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -73,15 +73,24 @@ 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 = "--batopt")] + // 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) { From 874e6a6666bdee80cbaafc3937dbaf4649f16fbc Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Sun, 18 Feb 2018 23:57:30 -0800 Subject: [PATCH 2/9] Improve exception display behavior --- RGBFusionTool/Application.cs | 3 ++- RGBFusionTool/RGBFusionMain.cs | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs index 6574f4c..9c0d34b 100644 --- a/RGBFusionTool/Application.cs +++ b/RGBFusionTool/Application.cs @@ -103,7 +103,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/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 From 30c09f9c1339d04b4ea95e5139137f842861e32f Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Mon, 19 Feb 2018 00:21:35 -0800 Subject: [PATCH 3/9] Add additional negative tests --- RGBFusionToolTests/RGBFusionToolExeTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index 82957fb..8b69e28 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -87,7 +87,9 @@ public void NoArgs() // Extra parameters [DataRow(new string[] { "1" }, DisplayName = "1")] [DataRow(new string[] { "0" }, DisplayName = "0")] - [DataRow(new string[] { "--badopt" }, DisplayName = "--batopt")] + [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 "=" From 85313cbafd2c189500ef4a3a503606a28825c98a Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Mon, 19 Feb 2018 00:53:24 -0800 Subject: [PATCH 4/9] Add coverage for verbose --- RGBFusionToolTests/RGBFusionToolExeTests.cs | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index 8b69e28..59bb36f 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -142,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)")] @@ -179,6 +213,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")] From 73fe8646d4e25d392904f5131490f526422cd8ba Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Mon, 19 Feb 2018 00:56:45 -0800 Subject: [PATCH 5/9] Add brightness output to verbose --- RGBFusionTool/Application.cs | 1 + RGBFusionToolTests/RGBFusionToolExeTests.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs index 9c0d34b..66ca39b 100644 --- a/RGBFusionTool/Application.cs +++ b/RGBFusionTool/Application.cs @@ -93,6 +93,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) diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index 59bb36f..cca7639 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -194,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")] From e2d93ff3bf436af26616023af787c9abdda3cf69 Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Wed, 21 Feb 2018 00:00:19 -0800 Subject: [PATCH 6/9] Correct test checks for proper initialization --- GLedApiDotNetTests/GLedApiv1_0_0Mock.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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; } From dece62584e733a213745e6ca8c46f934afe2d36e Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Wed, 21 Feb 2018 00:01:00 -0800 Subject: [PATCH 7/9] Add --list option to list zones --- RGBFusionTool/Application.cs | 12 ++++++++++++ RGBFusionToolTests/RGBFusionToolExeTests.cs | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/RGBFusionTool/Application.cs b/RGBFusionTool/Application.cs index 66ca39b..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,6 +52,8 @@ 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 }, + {"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"); } } @@ -69,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); diff --git a/RGBFusionToolTests/RGBFusionToolExeTests.cs b/RGBFusionToolTests/RGBFusionToolExeTests.cs index cca7639..b9f7ce8 100644 --- a/RGBFusionToolTests/RGBFusionToolExeTests.cs +++ b/RGBFusionToolTests/RGBFusionToolExeTests.cs @@ -280,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"); + } } } From 9b304530c3949c10dcd413e97ab860bedb9347d0 Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Sat, 14 Apr 2018 18:05:13 -0700 Subject: [PATCH 8/9] Disable explicit version checking --- GLedApiDotNet/RGBFusionMotherboardImpl.cs | 4 ++-- GLedApiDotNetTests/Tests/RGBFusionMotherboardTests.cs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) 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/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() From 437138ec067f899b8d74091b7f014a63c977d253 Mon Sep 17 00:00:00 2001 From: Tyler Szabo Date: Sat, 14 Apr 2018 18:06:48 -0700 Subject: [PATCH 9/9] Increase version to 0.9.0.3 --- RGBFusionTool/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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")]