>From bf68d3191e96bdd5860507ae366c440c6d51b010 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Dec 2014 15:00:37 +0100 Subject: [PATCH] Don't overwrite user file history with the files opened during testing. Avoid the problem with the files in user history (a.k.a. MRU files list) being replaced with the test files after running the unattended test. Do this by creating a special version of DocManagerEx for the tests, which doesn't save (nor load, for symmetry) the file history, unlike the normal one. --- main_wx_test.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/main_wx_test.cpp b/main_wx_test.cpp index 4166bd9..26df872 100644 --- a/main_wx_test.cpp +++ b/main_wx_test.cpp @@ -27,6 +27,7 @@ #endif #include "alert.hpp" +#include "docmanager_ex.hpp" #include "force_linking.hpp" #include "handle_exceptions.hpp" // stealth_exception #include "main_common.hpp" // initialize_application() @@ -522,6 +523,9 @@ class SkeletonTest : public Skeleton } protected: + // Override base class virtual method. + virtual DocManagerEx* CreateDocManager(); + // wxApp overrides. virtual bool OnInit (); virtual bool OnExceptionInMainLoop (); @@ -545,6 +549,36 @@ class SkeletonTest : public Skeleton IMPLEMENT_APP_NO_MAIN(SkeletonTest) IMPLEMENT_WX_THEME_SUPPORT +DocManagerEx* SkeletonTest::CreateDocManager() +{ + // Custom document manager allowing to intercept the behaviour of the + // program for testing purposes. + // + // Currently it is used to prevent the files opened during testing from + // being saved. + class DocManagerTest : public DocManagerEx + { + public: + virtual void FileHistoryLoad(wxConfigBase const&) + { + // We could call the base class method here, but it doesn't seem + // useful to do it and doing nothing here makes it more symmetric + // with FileHistorySave(). + } + + virtual void FileHistorySave(wxConfigBase&) + { + // Do not save the history to persistent storage: we don't want the + // files opened during testing replace the files actually opened by + // the user interactively. + } + }; + + // As in the base class version, notice that we must not use 'new(wx)' here + // as this object is deleted by wxWidgets itself. + return new DocManagerTest; +} + bool SkeletonTest::OnInit() { // The test output should be reproducible, so disable the time -- 1.7.9