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 OOMTESTUTIL_H_ 0022 #define OOMTESTUTIL_H_ 0023 0024 // sadly, can't simply forward-declare FILE 0025 #include <stdio.h> 0026 0027 /** 0028 * Interface class for mock file systems, and the facade for the real file 0029 * system. 0030 */ 0031 class MockableFileSystem { 0032 public: 0033 virtual ~MockableFileSystem(); 0034 virtual void setDelegate(MockableFileSystem* mfs) = 0; 0035 virtual FILE* fopen(const char* filename, const char* mode) = 0; 0036 virtual FILE* freopen(const char* filename, const char* mode, FILE* fh) = 0; 0037 virtual int fclose(FILE*) = 0; 0038 virtual int fflush(FILE*) = 0; 0039 virtual size_t fread (void *out, size_t blockSize, 0040 size_t blockCount, FILE *fh) = 0; 0041 virtual size_t fwrite (const void *in, size_t blockSize, 0042 size_t blockCount, FILE *fh) = 0; 0043 virtual int access (const char *name, int type) = 0; 0044 virtual int ferror(FILE*) = 0; 0045 virtual int unlink(const char *name) = 0; 0046 virtual char* getenv(const char *name) = 0; 0047 }; 0048 0049 extern "C" { 0050 0051 /** 0052 * Installs the SetMallocsUntilFailure function. 0053 * Returns 1 on success, 0 on failure. 0054 * @ref SetMallocsUntilFailure will not work unless this function has been 0055 * called and has returned 1. 0056 */ 0057 int loadOomTestUtil(); 0058 0059 /** 0060 * Sets the number of successful memory allocations until one will fail. 0061 * Will not work unless @ref LoadOomTestUtil has been called and returned 1. 0062 */ 0063 void setMallocsUntilFailure(int successes); 0064 0065 /** 0066 * Sets that there will be no artificial memory allocation failures. 0067 */ 0068 void cancelAnyMallocFailure(); 0069 0070 /** 0071 * Returns a counter of the number of (successful or unsuccessful) calls to 0072 * @c malloc so far. Will not work unless @ref LoadOomTestUtil has been called 0073 * and returned 1. 0074 */ 0075 long mallocsSoFar(); 0076 0077 /** 0078 * Wraps the mock file system object. 0079 * @param mfs The new object with which to wrap the file system. 0080 * {@c setDelegate} will be called on {@a mfs} with an object representing the 0081 * current versions of these functions which can be used as a delegate. If 0 is 0082 * passed the file system will be returned to its natural unwrapped state. 0083 */ 0084 void wrapFileSystem(MockableFileSystem* mfs); 0085 0086 } 0087 0088 #endif