// The ctor redirects the stream to a temporary file. explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { # if GTEST_OS_WINDOWS char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path); const UINT success = ::GetTempFileNameA(temp_dir_path, "gtest_redir", 0, // Generate unique file name. temp_file_path); GTEST_CHECK_(success != 0) << "Unable to create a temporary file in " << temp_dir_path; const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file " << temp_file_path; filename_ = temp_file_path; # else // There's no guarantee that a test has write access to the current // directory, so we create the temporary file in the /tmp directory // instead. We use /tmp on most systems, and /sdcard on Android. // That's because Android doesn't have /tmp. # if GTEST_OS_LINUX_ANDROID // Note: Android applications are expected to call the framework's // Context.getExternalStorageDirectory() method through JNI to get // the location of the world-writable SD Card directory. However, // this requires a Context handle, which cannot be retrieved // globally from native code. Doing so also precludes running the // code as part of a regular standalone executable, which doesn't // run in a Dalvik process (e.g. when running it through 'adb shell'). // // The location /sdcard is directly accessible from native code // and is the only location (unofficially) supported by the Android // team. It's generally a symlink to the real SD Card mount point // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or // other OEM-customized locations. Never rely on these, and always // use /sdcard. char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX"; # else char name_template[] = "/tmp/captured_stream.XXXXXX"; # endif // GTEST_OS_LINUX_ANDROID const int captured_fd = mkstemp(name_template); filename_ = name_template; # endif // GTEST_OS_WINDOWS fflush(NULL); dup2(captured_fd, fd_); close(captured_fd); }
void registerTestWithParameter(const ParameterType& parameter) { GTEST_CHECK_(parameterNames.hasMore()) << "Parameter list parse error"; const auto parameterName = *parameterNames; registerTestWithParameterNamed(parameterName, parameter); ++parameterNames; }
template <class T> void ASSERT_ARRAY_EQ(T* actual, T* expected, size_t n) { int fails = 0; #pragma omp for schedule(dynamic, 1024) for(intptr_t i = 0; i < n; i++) if(actual[i] != expected[i]) #pragma omp atomic fails++; if(fails > 0) GTEST_CHECK_(false) << fails << " out of " << n << " elements were not equal to expected"; }
void ASSERT_ARRAY_ABSOLUTE_RANGE(tfloat* expected, tfloat* actual, size_t n, tfloat range) { int fails = 0; #pragma omp for schedule(dynamic, 1024) for(int i = 0; i < n; i++) if(abs(expected[i] - actual[i]) > range) #pragma omp atomic fails++; if(fails > 0) GTEST_CHECK_(false) << fails << " out of " << n << " elements had an absolute error of over " << range; }
void ASSERT_ARRAY_RELATIVE_RANGE(tfloat* expected, tfloat* actual, size_t n, tfloat range) { int fails = 0; #pragma omp for schedule(dynamic, 1024) for(int i = 0; i < n; i++) if(expected[i] == 0.0f && actual[i] == 0.0f) #pragma omp atomic fails++; else if(expected[i] != 0.0f && actual[i] != 0.0f && abs((actual[i] - expected[i]) / expected[i]) > range) #pragma omp atomic fails++; if(fails > 0) GTEST_CHECK_(false) << fails << " out of " << n << " elements had a relative error of over " << range; }