| 1 | /* |
| 2 | * Copyright (c) 2007, Michael Feathers, James Grenning, Bas Vodde and Timo Puronen |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the <organization> nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY |
| 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
| 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | #include "CppUTest/TestHarness.h" |
| 28 | |
| 29 | #include <e32def.h> |
| 30 | #include <e32std.h> |
| 31 | #include <sys/time.h> |
| 32 | #include <stdio.h> |
| 33 | #include <stdarg.h> |
| 34 | #include <string.h> |
| 35 | #include <math.h> |
| 36 | #include <stdlib.h> |
| 37 | #include "CppUTest/PlatformSpecificFunctions.h" |
| 38 | |
| 39 | static jmp_buf test_exit_jmp_buf[10]; |
| 40 | static int jmp_buf_index = 0; |
| 41 | |
| 42 | int PlatformSpecificSetJmp(void (*function) (void* data), void* data) |
| 43 | { |
| 44 | if (0 == setjmp(test_exit_jmp_buf[jmp_buf_index])) { |
| 45 | jmp_buf_index++; |
| 46 | function(data); |
| 47 | jmp_buf_index--; |
| 48 | return 1; |
| 49 | } |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | void PlatformSpecificLongJmp() |
| 54 | { |
| 55 | jmp_buf_index--; |
| 56 | longjmp(test_exit_jmp_buf[jmp_buf_index], 1); |
| 57 | } |
| 58 | |
| 59 | void PlatformSpecificRestoreJumpBuffer() |
| 60 | { |
| 61 | jmp_buf_index--; |
| 62 | } |
| 63 | |
| 64 | void PlatformSpecificRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result) |
| 65 | { |
| 66 | printf("-p doesn't work on this platform as it is not implemented. Running inside the process\b"); |
| 67 | shell->runOneTest(plugin, *result); |
| 68 | } |
| 69 | |
| 70 | static long TimeInMillisImplementation() { |
| 71 | struct timeval tv; |
| 72 | struct timezone tz; |
| 73 | ::gettimeofday(&tv, &tz); |
| 74 | return (tv.tv_sec * 1000) + (long)(tv.tv_usec * 0.001); |
| 75 | } |
| 76 | |
| 77 | long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation; |
| 78 | |
| 79 | TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment() |
| 80 | { |
| 81 | return TestOutput::eclipse; |
| 82 | } |
| 83 | |
| 84 | static SimpleString TimeStringImplementation() { |
| 85 | time_t tm = time(NULL); |
| 86 | return ctime(&tm); |
| 87 | } |
| 88 | |
| 89 | SimpleString GetPlatformSpecificTimeString() = TimeStringImplementation; |
| 90 | |
| 91 | int PlatformSpecificVSNprintf(char* str, size_t size, const char* format, va_list args) { |
| 92 | return vsnprintf(str, size, format, args); |
| 93 | } |
| 94 | |
| 95 | void PlatformSpecificFlush() { |
| 96 | fflush(stdout); |
| 97 | } |
| 98 | |
| 99 | int PlatformSpecificPutchar(int c) { |
| 100 | return putchar(c); |
| 101 | } |
| 102 | |
| 103 | double PlatformSpecificFabs(double d) { |
| 104 | return fabs(d); |
| 105 | } |
| 106 | |
| 107 | void* PlatformSpecificMalloc(size_t size) { |
| 108 | return malloc(size); |
| 109 | } |
| 110 | |
| 111 | void* PlatformSpecificRealloc (void* memory, size_t size) { |
| 112 | return realloc(memory, size); |
| 113 | } |
| 114 | |
| 115 | void PlatformSpecificFree(void* memory) { |
| 116 | free(memory); |
| 117 | } |
| 118 | |
| 119 | void* PlatformSpecificMemCpy(void* s1, const void* s2, size_t size) { |
| 120 | return memcpy(s1, s2, size); |
| 121 | } |
| 122 | |
| 123 | void* PlatformSpecificMemset(void* mem, int c, size_t size) |
| 124 | { |
| 125 | return memset(mem, c, size); |
| 126 | } |
| 127 | |
| 128 | PlatformSpecificFile PlatformSpecificFOpen(const char* filename, const char* flag) { |
| 129 | return fopen(filename, flag); |
| 130 | } |
| 131 | |
| 132 | void PlatformSpecificFPuts(const char* str, PlatformSpecificFile file) { |
| 133 | fputs(str, (FILE*)file); |
| 134 | } |
| 135 | |
| 136 | void PlatformSpecificFClose(PlatformSpecificFile file) { |
| 137 | fclose((FILE*)file); |
| 138 | } |
| 139 | |
| 140 | extern "C" { |
| 141 | |
| 142 | static int IsNanImplementation(double d) |
| 143 | { |
| 144 | return isnan(d); |
| 145 | } |
| 146 | |
| 147 | static int IsInfImplementation(double d) |
| 148 | { |
| 149 | return isinf(d); |
| 150 | } |
| 151 | |
| 152 | int (*PlatformSpecificIsNan)(double) = IsNanImplementation; |
| 153 | int (*PlatformSpecificIsInf)(double) = IsInfImplementation; |
| 154 | |
| 155 | } |
| 156 | |
| 157 | static PlatformSpecificMutex DummyMutexCreate(void) |
| 158 | { |
| 159 | FAIL("PlatformSpecificMutexCreate is not implemented"); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static void DummyMutexLock(PlatformSpecificMutex mtx) |
| 164 | { |
| 165 | FAIL("PlatformSpecificMutexLock is not implemented"); |
| 166 | } |
| 167 | |
| 168 | static void DummyMutexUnlock(PlatformSpecificMutex mtx) |
| 169 | { |
| 170 | FAIL("PlatformSpecificMutexUnlock is not implemented"); |
| 171 | } |
| 172 | |
| 173 | static void DummyMutexDestroy(PlatformSpecificMutex mtx) |
| 174 | { |
| 175 | FAIL("PlatformSpecificMutexDestroy is not implemented"); |
| 176 | } |
| 177 | |
| 178 | PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void) = DummyMutexCreate; |
| 179 | void (*PlatformSpecificMutexLock)(PlatformSpecificMutex) = DummyMutexLock; |
| 180 | void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex) = DummyMutexUnlock; |
| 181 | void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex) = DummyMutexDestroy; |
| 182 |