File indexing completed on 2024-04-28 16:08:40

0001 /***************************************************************************
0002  *   Copyright (C) 2013 by Linuxstopmotion contributors;                   *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef TESTUNDO_H_
0022 #define TESTUNDO_H_
0023 
0024 #include "hash.h"
0025 
0026 #include <string>
0027 
0028 class Executor;
0029 
0030 /**
0031  * Provides a way for test code to check the state of the model that is being
0032  * updated by commands in an Executor.
0033  */
0034 class ModelTestHelper {
0035 public:
0036     virtual ~ModelTestHelper() = 0;
0037     /**
0038      * Resets the model owned by an Executor to an empty state.
0039      * @param [in,out] e The executor whose model must be reset.
0040      */
0041     virtual void resetModel(Executor& e) = 0;
0042     /**
0043      * Returns a hash of the model. The hash of a model should be different
0044      * to the hash of similar models, so that hashes comparing equal very
0045      * probably means that the models are the same.
0046      * @param [in] The exector that owns the model to be hashed.
0047      */
0048     virtual Hash hashModel(const Executor& e) = 0;
0049     /**
0050      * Returns a text string describing the model.
0051      */
0052     virtual void dumpModel(std::string& out, const Executor& e) = 0;
0053 };
0054 
0055 /**
0056  * Tests that the commands in the executor {@a e} obey the following rules:
0057  * - Two identical commands executed on identical models must produce
0058  *    identical models.
0059  * - The execution of a string of commands followed by their inverses (in
0060  *    reverse order) must leave the model in an identical state.
0061  * - Under test conditions, only an out-of-memory exception may escape a
0062  *    command's execution.
0063  * - If an exception escapes a command's execution, it must not have affected
0064  *    the model at all.
0065  */
0066 void testUndo(Executor& e, ModelTestHelper& helper);
0067 
0068 #endif /* TESTUNDO_H_ */