feat: Add ESP8266 support
* Added support for ESP8266 * Removed previous Arduino defines in favor of GTEST_OS_* syntax * Improved PlatformIO library file to be more stable when consumed in client applications.
This commit is contained in:
		| @@ -32,7 +32,10 @@ | |||||||
| #include "gmock/gmock.h" | #include "gmock/gmock.h" | ||||||
| #include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||||
|  |  | ||||||
| #ifdef ARDUINO | #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 | ||||||
|  | # if GTEST_OS_ESP8266 | ||||||
|  | extern "C" { | ||||||
|  | # endif | ||||||
| void setup() { | void setup() { | ||||||
|   // Since Google Mock depends on Google Test, InitGoogleMock() is |   // Since Google Mock depends on Google Test, InitGoogleMock() is | ||||||
|   // also responsible for initializing Google Test.  Therefore there's |   // also responsible for initializing Google Test.  Therefore there's | ||||||
| @@ -40,6 +43,10 @@ void setup() { | |||||||
|   testing::InitGoogleMock(); |   testing::InitGoogleMock(); | ||||||
| } | } | ||||||
| void loop() { RUN_ALL_TESTS(); } | void loop() { RUN_ALL_TESTS(); } | ||||||
|  | # if GTEST_OS_ESP8266 | ||||||
|  | } | ||||||
|  | # endif | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which | // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which | ||||||
|   | |||||||
| @@ -102,6 +102,10 @@ | |||||||
| # define GTEST_OS_QNX 1 | # define GTEST_OS_QNX 1 | ||||||
| #elif defined(__HAIKU__) | #elif defined(__HAIKU__) | ||||||
| #define GTEST_OS_HAIKU 1 | #define GTEST_OS_HAIKU 1 | ||||||
|  | #elif defined ESP8266 | ||||||
|  | # define GTEST_OS_ESP8266 1 | ||||||
|  | #elif defined  ESP32 | ||||||
|  | # define GTEST_OS_ESP32 1 | ||||||
| #endif  // __CYGWIN__ | #endif  // __CYGWIN__ | ||||||
|  |  | ||||||
| #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ | #endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ | ||||||
|   | |||||||
| @@ -449,7 +449,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; | |||||||
| // no support for it at least as recent as Froyo (2.2). | // no support for it at least as recent as Froyo (2.2). | ||||||
| #define GTEST_HAS_STD_WSTRING                                         \ | #define GTEST_HAS_STD_WSTRING                                         \ | ||||||
|   (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ |   (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ | ||||||
|      GTEST_OS_HAIKU)) |      GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266)) | ||||||
|  |  | ||||||
| #endif  // GTEST_HAS_STD_WSTRING | #endif  // GTEST_HAS_STD_WSTRING | ||||||
|  |  | ||||||
| @@ -573,7 +573,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; | |||||||
| #ifndef GTEST_HAS_STREAM_REDIRECTION | #ifndef GTEST_HAS_STREAM_REDIRECTION | ||||||
| // By default, we assume that stream redirection is supported on all | // By default, we assume that stream redirection is supported on all | ||||||
| // platforms except known mobile ones. | // platforms except known mobile ones. | ||||||
| # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT | # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 | ||||||
| #  define GTEST_HAS_STREAM_REDIRECTION 0 | #  define GTEST_HAS_STREAM_REDIRECTION 0 | ||||||
| # else | # else | ||||||
| #  define GTEST_HAS_STREAM_REDIRECTION 1 | #  define GTEST_HAS_STREAM_REDIRECTION 1 | ||||||
| @@ -1984,6 +1984,22 @@ inline bool IsDir(const StatStruct& st) { | |||||||
| } | } | ||||||
| # endif  // GTEST_OS_WINDOWS_MOBILE | # endif  // GTEST_OS_WINDOWS_MOBILE | ||||||
|  |  | ||||||
|  | #elif GTEST_OS_ESP8266 | ||||||
|  | typedef struct stat StatStruct; | ||||||
|  |  | ||||||
|  | inline int FileNo(FILE* file) { return fileno(file); } | ||||||
|  | inline int IsATTY(int fd) { return isatty(fd); } | ||||||
|  | inline int Stat(const char* path, StatStruct* buf) { | ||||||
|  |   // stat function not implemented on ESP8266 | ||||||
|  |   return 0; | ||||||
|  |   } | ||||||
|  | inline int StrCaseCmp(const char* s1, const char* s2) { | ||||||
|  |   return strcasecmp(s1, s2); | ||||||
|  | } | ||||||
|  | inline char* StrDup(const char* src) { return strdup(src); } | ||||||
|  | inline int RmDir(const char* dir) { return rmdir(dir); } | ||||||
|  | inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| typedef struct stat StatStruct; | typedef struct stat StatStruct; | ||||||
| @@ -2036,7 +2052,7 @@ inline int Close(int fd) { return close(fd); } | |||||||
| inline const char* StrError(int errnum) { return strerror(errnum); } | inline const char* StrError(int errnum) { return strerror(errnum); } | ||||||
| #endif | #endif | ||||||
| inline const char* GetEnv(const char* name) { | inline const char* GetEnv(const char* name) { | ||||||
| #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT | #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 | ||||||
|   // We are on Windows CE, which has no environment variables. |   // We are on Windows CE, which has no environment variables. | ||||||
|   static_cast<void>(name);  // To prevent 'unused argument' warning. |   static_cast<void>(name);  // To prevent 'unused argument' warning. | ||||||
|   return nullptr; |   return nullptr; | ||||||
|   | |||||||
| @@ -93,7 +93,7 @@ static bool IsPathSeparator(char c) { | |||||||
| // Returns the current working directory, or "" if unsuccessful. | // Returns the current working directory, or "" if unsuccessful. | ||||||
| FilePath FilePath::GetCurrentDir() { | FilePath FilePath::GetCurrentDir() { | ||||||
| #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ | #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ | ||||||
|     GTEST_OS_WINDOWS_RT || ARDUINO || defined(ESP_PLATFORM) |     GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 | ||||||
|   // These platforms do not have a current directory, so we just return |   // These platforms do not have a current directory, so we just return | ||||||
|   // something reasonable. |   // something reasonable. | ||||||
|   return FilePath(kCurrentDirectoryString); |   return FilePath(kCurrentDirectoryString); | ||||||
| @@ -236,7 +236,7 @@ bool FilePath::DirectoryExists() const { | |||||||
|     result = true; |     result = true; | ||||||
|   } |   } | ||||||
| #else | #else | ||||||
|   posix::StatStruct file_stat; |   posix::StatStruct file_stat = {}; | ||||||
|   result = posix::Stat(path.c_str(), &file_stat) == 0 && |   result = posix::Stat(path.c_str(), &file_stat) == 0 && | ||||||
|       posix::IsDir(file_stat); |       posix::IsDir(file_stat); | ||||||
| #endif  // GTEST_OS_WINDOWS_MOBILE | #endif  // GTEST_OS_WINDOWS_MOBILE | ||||||
| @@ -323,6 +323,9 @@ bool FilePath::CreateFolder() const { | |||||||
|   delete [] unicode; |   delete [] unicode; | ||||||
| #elif GTEST_OS_WINDOWS | #elif GTEST_OS_WINDOWS | ||||||
|   int result = _mkdir(pathname_.c_str()); |   int result = _mkdir(pathname_.c_str()); | ||||||
|  | #elif GTEST_OS_ESP8266 | ||||||
|  |   // do nothing | ||||||
|  |   int result = 0; | ||||||
| #else | #else | ||||||
|   int result = mkdir(pathname_.c_str(), 0777); |   int result = mkdir(pathname_.c_str(), 0777); | ||||||
| #endif  // GTEST_OS_WINDOWS_MOBILE | #endif  // GTEST_OS_WINDOWS_MOBILE | ||||||
|   | |||||||
| @@ -4508,6 +4508,7 @@ class ScopedPrematureExitFile { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   ~ScopedPrematureExitFile() { |   ~ScopedPrematureExitFile() { | ||||||
|  |     #if !defined GTEST_OS_ESP8266 | ||||||
|     if (!premature_exit_filepath_.empty()) { |     if (!premature_exit_filepath_.empty()) { | ||||||
|       int retval = remove(premature_exit_filepath_.c_str()); |       int retval = remove(premature_exit_filepath_.c_str()); | ||||||
|       if (retval) { |       if (retval) { | ||||||
| @@ -4516,6 +4517,7 @@ class ScopedPrematureExitFile { | |||||||
|                           << retval; |                           << retval; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |     #endif | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   | |||||||
| @@ -30,13 +30,20 @@ | |||||||
| #include <cstdio> | #include <cstdio> | ||||||
| #include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||||
|  |  | ||||||
| #ifdef ARDUINO | #if GTEST_OS_ESP8266 || GTEST_OS_ESP32 | ||||||
|  | # if GTEST_OS_ESP8266 | ||||||
|  | extern "C" { | ||||||
|  | # endif | ||||||
| void setup() { | void setup() { | ||||||
|   testing::InitGoogleTest(); |   testing::InitGoogleTest(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void loop() { RUN_ALL_TESTS(); } | void loop() { RUN_ALL_TESTS(); } | ||||||
|  |  | ||||||
|  | # if GTEST_OS_ESP8266 | ||||||
|  | } | ||||||
|  | # endif | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| GTEST_API_ int main(int argc, char **argv) { | GTEST_API_ int main(int argc, char **argv) { | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								library.json
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								library.json
									
									
									
									
									
								
							| @@ -11,7 +11,8 @@ | |||||||
|   "version": "1.8.1", |   "version": "1.8.1", | ||||||
|   "frameworks": "arduino", |   "frameworks": "arduino", | ||||||
|   "platforms": [ |   "platforms": [ | ||||||
|         "espressif32" |         "espressif32", | ||||||
|  |         "espressif8266" | ||||||
|   ], |   ], | ||||||
|   "export": { |   "export": { | ||||||
|         "include": [ |         "include": [ | ||||||
| @@ -38,6 +39,7 @@ | |||||||
|             "googletest/m4", |             "googletest/m4", | ||||||
|             "googletest/make", |             "googletest/make", | ||||||
|             "googletest/msvc", |             "googletest/msvc", | ||||||
|  |             "googletest/samples", | ||||||
|             "googletest/scripts", |             "googletest/scripts", | ||||||
|             "googletest/src/gtest-all.cc", |             "googletest/src/gtest-all.cc", | ||||||
|             "googletest/src/gtest_main.cc", |             "googletest/src/gtest_main.cc", | ||||||
| @@ -54,6 +56,24 @@ | |||||||
|             "-Igooglemock", |             "-Igooglemock", | ||||||
|             "-Igoogletest/include", |             "-Igoogletest/include", | ||||||
|             "-Igoogletest" |             "-Igoogletest" | ||||||
|  |         ], | ||||||
|  |         "srcFilter": [ | ||||||
|  |           "+<*>", | ||||||
|  |           "-<.git/>", | ||||||
|  |           "-<googlemock>", | ||||||
|  |           "-<googlemock/test/>", | ||||||
|  |           "-<googlemock/src>", | ||||||
|  |           "+<googlemock/src/gmock-all.cc>", | ||||||
|  |           "+<googletest/src/gtest-all.cc>", | ||||||
|  |           "+<googlemock/src/gmock_main.cc>", | ||||||
|  |           "-<googletest>", | ||||||
|  |           "-<googletest/codegear/>", | ||||||
|  |           "-<googletest/samples>", | ||||||
|  |           "-<googletest/test/>", | ||||||
|  |           "-<googletest/xcode>", | ||||||
|  |           "-<googletest/src>", | ||||||
|  |           "+<googletest/src/gtest-all.cc>", | ||||||
|  |           "+<googletest/src/gtest_main.cc>" | ||||||
|         ] |         ] | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -27,5 +27,21 @@ platform = espressif32 | |||||||
| board = esp32dev | board = esp32dev | ||||||
| framework = arduino | framework = arduino | ||||||
| build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock | build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock | ||||||
| src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googlemock/src/gmock_main.cc> +<googletest/src/gtest-all.cc> | src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc> | ||||||
|  | upload_speed = 921600 | ||||||
|  |  | ||||||
|  | [env:googletest_esp8266] | ||||||
|  | platform = espressif8266 | ||||||
|  | board = huzzah | ||||||
|  | framework = arduino | ||||||
|  | build_flags = -I./googletest/include -I./googletest | ||||||
|  | src_filter = +<*> -<.git/> -<googlemock> -<googletest/codegear/> -<googletest/samples> -<googletest/test/> -<googletest/xcode> -<googletest/src> +<googletest/src/gtest-all.cc> +<googletest/src/gtest_main.cc> | ||||||
|  | upload_speed = 921600 | ||||||
|  |  | ||||||
|  | [env:googlemock_esp8266] | ||||||
|  | platform = espressif8266 | ||||||
|  | board = huzzah | ||||||
|  | framework = arduino | ||||||
|  | build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock | ||||||
|  | src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc> | ||||||
| upload_speed = 921600 | upload_speed = 921600 | ||||||
		Reference in New Issue
	
	Block a user
	 Chris
					Chris