public static void Add(State state, string description, string name, string args, ref RegState final, ref bool pass, RegState?initial = null, bool noWipe = false) { state.AddReport(description); if (initial != null) { ((RegState)initial).Zap(Const.TestExt); } var result = InvokeFileMetaAssoc(state, "-a " + args); if (result != 0) { state.AddReport(String.Format("FileMetaAssoc -a failed for {0}", name)); pass = false; } if (pass) { var outcome = new RegState(); outcome.Read(Const.TestExt); // Verify that we got the final state if (outcome != final) { state.AddReport(String.Format("Add did not produce the expected final registry state for {0}", name)); pass = false; } } // Clean up after ourselves if (!noWipe) { RegState.Wipe(Const.TestExt); } }
public static RegState AddExtend(State state, string description, string ext, string args, ref RegState final, ref bool pass) { state.AddReport(description); var initial = new RegState(); initial.Read(ext); var result = InvokeFileMetaAssoc(state, "-a " + args, true, ext); if (result != 0) { state.AddReport(String.Format("FileMetaAssoc -a failed for {0}", ext)); pass = false; } if (pass) { var outcome = new RegState(); outcome.Read(ext); // Verify that we got the final state if (outcome != final) { state.AddReport(String.Format("Add did not produce the expected final registry state for {0}", ext)); pass = false; } } return(initial); }
private static bool VerifyRegistryState(string ext, ref RegState expected) { var outcome = new RegState(); outcome.Read(Const.TestExt); // Verify that we got the final state return(outcome == expected); }
private void scan_Click(object sender, RoutedEventArgs e) { // get all the current handlers using (RegistryKey handlers = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PropertySystem\PropertyHandlers", false)) { foreach (string name in handlers.GetSubKeyNames()) { using (RegistryKey key = handlers.OpenSubKey(name, false)) { string handlerGuid = (string)key.GetValue(null); if (handlerGuid == Const.OurPropertyHandlerGuid) { RegState s = new RegState(); s.Read(name); regStates.Add(name, s); } } } } }
public static void RemoveExtend(State state, string description, string ext, ref RegState final, ref bool pass) { state.AddReport(description); var result = InvokeFileMetaAssoc(state, "-r", true, ext); if (result != 0) { state.AddReport(String.Format("FileMetaAssoc -r failed for {0}", ext)); pass = false; } var outcome = new RegState(); outcome.Read(ext); // If the final state was specified, verify that we got it if (outcome != final) { state.AddReport(String.Format("Remove did not produce the expected final registry state for {0}", ext)); pass = false; } }
public static void Remove(State state, string description, string name, ref RegState source, ref bool pass, RegState?final = null) { state.AddReport(description); source.Zap(Const.TestExt); var result = InvokeFileMetaAssoc(state, "-r"); if (result != 0) { state.AddReport(String.Format("FileMetaAssoc -r failed for {0}", name)); pass = false; } var outcome = new RegState(); outcome.Read(Const.TestExt); if (final == null) { // Usually, the expected final state is an empty registry if (outcome != new RegState()) { state.AddReport(String.Format("Remove did not completely clean up for {0}", name)); pass = false; } } else { // If the final state was specified, verify that we got it if (outcome != final) { state.AddReport(String.Format("Remove did not produce the expected final registry state for {0}", name)); pass = false; } } // Clean up after ourselves RegState.Wipe(Const.TestExt); }
private static void RoundTrip(State state, string name, ref RegState source, ref bool pass) { source.Zap(Const.TestExt); var read = new RegState(); read.Read(Const.TestExt); if (read != source) { state.AddReport(String.Format("Round-trip failed for {0}", name)); pass = false; } RegState.Wipe(Const.TestExt); var clear = new RegState(); clear.Read(Const.TestExt); if (clear != new RegState()) { state.AddReport(String.Format("Wipe failed for {0}", name)); pass = false; } }
/// <summary> /// /// </summary> /// <param name="obj"></param> public static void Run(Object obj) { State state = (State)obj; state.TestCounter = 1; bool overallPass = true; // Backup any saved state file because some add operations update it if (!Common.SetupProfileForTestRun(state)) { return; } state.AddReport(""); state.AddReport(String.Format("Run {0}", state.RunCounter)); state.AddReport(""); try { bool pass = true; // This is an internal test to verify that we are writing and reading all the registry settings that we use accurately // Otherwise, we might get false negatives when we run our real tests state.AddReport(String.Format("#{0}: Registry settings round trips", state.TestCounter)); RoundTrip(state, "V13BuiltIn", ref Const.V13BuiltIn, ref pass); RoundTrip(state, "V13Custom", ref Const.V13CustomTest, ref pass); RoundTrip(state, "V14BuiltIn", ref Const.V14BuiltIn, ref pass); RoundTrip(state, "V14Custom", ref Const.V14CustomTest, ref pass); RoundTrip(state, "V14Extended", ref Const.V14ExtendedBmp, ref pass); RoundTrip(state, "V14UnExtended", ref Const.V14UnExtended, ref pass); RoundTrip(state, "V15BuiltIn", ref Const.V15BuiltIn, ref pass); RoundTrip(state, "V15Custom", ref Const.V15CustomTest, ref pass); RoundTrip(state, "V15CustomOther32", ref Const.V15CustomTestOther32, ref pass); RoundTrip(state, "V15CustomOther64", ref Const.V15CustomTestOther64, ref pass); RoundTrip(state, "V15Extended", ref Const.V15ExtendedBmp, ref pass); #if x64 RoundTrip(state, "V15InitialOther32", ref Const.V15InitialOther32, ref pass); #endif RoundTrip(state, "V15UnExtended", ref Const.V15UnExtended, ref pass); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; // Test command line utility's ability to remove handlers set up by various versions // Since upgrading is always a matter of remove then re-add, this is all we need to do to check old version handling pass = true; state.AddReport(""); state.AddReport(String.Format("#{0}: Remove handlers set up by various versions", state.TestCounter)); Remove(state, "Version 1.3 with Simple profile", "V13BuiltIn", ref Const.V13BuiltIn, ref pass); Remove(state, "Version 1.3 with custom profile", "V13Custom", ref Const.V13CustomTest, ref pass); Remove(state, "Version 1.4 with Simple profile", "V14BuiltIn", ref Const.V14BuiltIn, ref pass); Remove(state, "Version 1.4 with custom profile", "V14Custom", ref Const.V14CustomTest, ref pass); Remove(state, "Version 1.4 with extended handler", "V14Extended", ref Const.V14ExtendedBmp, ref pass, Const.V14UnExtended); Remove(state, "Version 1.5 with Simple profile", "V15BuiltIn", ref Const.V15BuiltIn, ref pass); Remove(state, "Version 1.5 with custom profile", "V15Custom", ref Const.V15CustomTest, ref pass); #if x64 Remove(state, "Version 1.5 with custom profile and existing 32 bit handler", "V15CustomOther32", ref Const.V15CustomTestOther32, ref pass, Const.V15InitialOther32); Remove(state, "Version 1.5 with custom profile and existing 64 bit handler", "V15CustomOther64", ref Const.V15CustomTestOther64, ref pass, Const.V15InitialOther64); #endif Remove(state, "Version 1.5 with extended handler", "V15Extended", ref Const.V15ExtendedBmp, ref pass, Const.V15UnExtended); Remove(state, "Version 1.5 with extended handler and CLSID settings", "V15ExtendedClsid", ref Const.V15ExtendedBmpClsid, ref pass, Const.V15UnExtendedClsid); Remove(state, "Version 1.5 with extended handler and both settings", "V15ExtendedBoth", ref Const.V15ExtendedBmpBoth, ref pass, Const.V15UnExtendedBoth); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; // Test command line utility's ability to add handlers with various arguments pass = true; state.AddReport(""); state.AddReport(String.Format("#{0}: Add handlers with various arguments", state.TestCounter)); Add(state, "Extension does not exist, Simple profile", "V15BuiltIn", "-p=simple", ref Const.V15BuiltIn, ref pass); RegState.CreateMinimalExtension(Const.TestExt); Add(state, "Minimal extension, Simple profile", "V15BuiltIn", "-p=simple", ref Const.V15BuiltIn, ref pass); Add(state, "Extension does not exist, custom profile 'test'", "V15CustomTest", "-p=test -d=SavedState.xml", ref Const.V15CustomTest, ref pass); #if x64 Add(state, "Extension does not exist, 32 bit handler does, custom profile 'test'", "V15CustomTestOther32", "-p=test -d=SavedState.xml", ref Const.V15CustomTestOther32, ref pass, Const.V15InitialOther32); Add(state, "Extension does not exist, 64 bit handler does, custom profile 'test'", "V15CustomTestOther64", "-p=test -d=SavedState.xml", ref Const.V15CustomTestOther64, ref pass, Const.V15InitialOther64); #endif Common.ClearProfile(); Add(state, "Extend existing .bmp property handler", "V15ExtendedBmp", "-p=.bmp -d=SavedState.xml", ref Const.V15ExtendedBmp, ref pass, Const.V15UnExtended); if (!TestGUI.VerifySavedState("SavedStateBmpOnly.xml")) { state.AddReport(String.Format("Add did not produce the expected saved state file for {0}", Const.TestExt)); pass = false; } Add(state, "Extend existing .bmp property handler with CLSID settings", "V15ExtendedBmpClsid", "-p=.bmp -d=SavedState.xml", ref Const.V15ExtendedBmpClsid, ref pass, Const.V15UnExtendedClsid); Add(state, "Extend existing .bmp property handler with both settings", "V15ExtendedBmpBoth", "-p=.bmp -d=SavedState.xml", ref Const.V15ExtendedBmpBoth, ref pass, Const.V15UnExtendedBoth); Common.ResetProfile(); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; // Test command line utility's ability to handle various error conditions pass = true; state.AddReport(""); state.AddReport(String.Format("#{0}: Test various error conditions", state.TestCounter)); Error(state, "No arguments at all", "", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Bad command", "-x", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Two commands", "-a -r", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Remove without an extension", "-r", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Remove with a bad extension", "-r nosuch", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Remove with a non-existent extension", "-r", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, false); Error(state, "Add without an extension", "-a", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, true); Error(state, "Add without a profile", "-a", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, false); Error(state, "Add with a bad profile", "-a -p=nosuch", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, false); Error(state, "Add with a data file and a bad profile", "-a -p=nosuch -d=SavedState.xml", WindowsErrorCode.ERROR_INVALID_PARAMETER, ref pass, false); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; } catch (Exception ex) { state.AddReport(String.Format("Run failed with unexpected exception '{0}'", ex.Message)); } finally { Common.RestoreProfileAfterTestRun(state); } state.AddReport(""); state.AddReport(String.Format("Run {0} completed {1}", state.RunCounter++, overallPass ? "with no failures" : "with some failures")); }
public static void Run(Object obj) { State state = (State)obj; state.TestCounter = 1; bool overallPass = true; // Backup any saved state file because some add operations update it if (!Common.SetupProfileForTestRun(state)) { return; } state.AddReport(""); state.AddReport(String.Format("Run {0}", state.RunCounter)); state.AddReport(""); try { bool pass = true; RegState.Wipe(Const.TestExt); // Ensure that we start clean state.AddReport(String.Format("#{0}: Add a handler with Simple profile for the minimal extension {1}, then remove it again", state.TestCounter, Const.TestExt)); RegState.CreateMinimalExtension(Const.TestExt); OpenAssociationManager(state); ScrollAndSelectExtension(state.extensions, Const.TestExt); SelectProfile(state.profiles, "Simple"); state.addButton.GetInvokePattern().Invoke(); CloseAssociationManager(state); // Need to do this before verifying the registry state as it seems to flush the changes through pass = VerifyRegistryState(Const.TestExt, ref Const.V15BuiltIn); if (!pass) { state.AddReport(String.Format("Add did not produce the expected final registry state for {0}", Const.TestExt)); } else { OpenAssociationManager(state); ScrollAndSelectExtension(state.extensions, Const.TestExt); state.removeButton.GetInvokePattern().Invoke(); CloseAssociationManager(state); var clear = new RegState(); pass = VerifyRegistryState(Const.TestExt, ref clear); if (!pass) { state.AddReport(String.Format("Remove did not produce the expected final registry state for {0}", Const.TestExt)); } } RegState.Wipe(Const.TestExt); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; pass = true; state.AddReport(String.Format("#{0}: Extend a handler for {1} with Tiny profile, then remove it again", state.TestCounter, Const.TestExt)); Const.V15UnExtendedTiny.Zap(Const.TestExt); OpenAssociationManager(state); ScrollAndSelectExtension(state.extensions, Const.TestExt); SelectProfile(state.profiles, "tiny"); state.addButton.GetInvokePattern().Invoke(); DismissDialog(state.mainWindow, "Handler addition", "Yes"); CloseAssociationManager(state); pass = VerifyRegistryState(Const.TestExt, ref Const.V15ExtendedTiny); if (!pass) { state.AddReport(String.Format("Add did not produce the expected final registry state for {0}", Const.TestExt)); } else { // Check that saved state is as expected pass = VerifySavedState("SavedStatePlus.xml"); if (!pass) { state.AddReport(String.Format("Add did not produce the expected saved state file for {0}", Const.TestExt)); } else { OpenAssociationManager(state); ScrollAndSelectExtension(state.extensions, Const.TestExt); state.removeButton.GetInvokePattern().Invoke(); CloseAssociationManager(state); pass = VerifyRegistryState(Const.TestExt, ref Const.V15UnExtendedTiny); if (!pass) { state.AddReport(String.Format("Remove did not produce the expected final registry state for {0}", Const.TestExt)); } } } RegState.Wipe(Const.TestExt); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; pass = true; state.AddReport(String.Format("#{0}: Set up a 1.3 handler for extension {1}, and verify that it is upgraded correctly", state.TestCounter, Const.TestExt)); var result = MessageBox.Show( "This test presses the Update Registry button, which updates all File Meta registry entries, as well as the test target. Are you happy to run this test?", "Do you want to run this one?", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { Const.V13BuiltIn.Zap(Const.TestExt); OpenAssociationManager(state); state.updateButton.GetInvokePattern().Invoke(); CloseAssociationManager(state); // Need to do this before verifying the registry state as it seems to flush the changes through pass = VerifyRegistryState(Const.TestExt, ref Const.V15BuiltIn); if (!pass) { state.AddReport(String.Format("Upgrade did not produce the expected final registry state for {0}", Const.TestExt)); } RegState.Wipe(Const.TestExt); state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, pass ? "Passed" : "Failed")); overallPass &= pass; } else { state.AddReport(String.Format("#{0}: {1}", state.TestCounter++, "Skipped")); } RegState.Wipe(Const.TestExt); } catch (Exception ex) { state.AddReport(String.Format("Run failed with unexpected exception '{0}'", ex.Message)); } finally { RegState.Wipe(Const.TestExt); Common.RestoreProfileAfterTestRun(state); } state.AddReport(""); state.AddReport(String.Format("Run {0} completed {1}", state.RunCounter++, overallPass ? "with no failures" : "with some failures")); }