15 #ifndef INCG_IRIS_IUTEST_PORT_HPP_7893F685_A1A9_477A_82E8_BF06237697FF_
16 #define INCG_IRIS_IUTEST_PORT_HPP_7893F685_A1A9_477A_82E8_BF06237697FF_
20 #if defined(__MWERKS__)
21 # define _MSL_USING_NAMESPACE
27 #if IUTEST_HAS_HDR_UNISTD
32 #if IUTEST_HAS_FILE_STAT
33 # include <sys/stat.h>
40 #if !defined(IUTEST_MAX_PATH)
41 # if defined(MAX_PATH) && MAX_PATH
42 # define IUTEST_MAX_PATH MAX_PATH
43 # elif defined(PATH_MAX) && PATH_MAX
44 # define IUTEST_MAX_PATH PATH_MAX
45 # elif defined(FILENAME_MAX) && FILENAME_MAX
46 # define IUTEST_MAX_PATH FILENAME_MAX
48 # define IUTEST_MAX_PATH 1024
55 #define IUTEST_LOG_(level) \
56 ::iutest::detail::IUTestLog( \
57 ::iutest::detail::IUTestLog::LOG_##level, __FILE__, __LINE__).GetStream()
62 #define IUTEST_CHECK_(condition) \
63 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
64 if( !::iutest::detail::IsTrue(condition) ) \
65 IUTEST_LOG_(FATAL) << "Condition " #condition " failed. "
70 #if !defined(IUTEST_ABORT)
71 # define IUTEST_ABORT() ::iutest::internal::posix::Abort()
83 void vprint_message(
const char *fmt, va_list va);
84 void print_message(
const char *fmt, ...);
93 const char* GetEnv(
const char* name);
94 int PutEnv(
const char* expr);
95 int SetEnv(
const char* name,
const char* value,
int overwrite);
97 const char* GetCWD(
char* buf,
size_t length);
98 ::std::string GetCWD();
100 void SleepMillisec(
unsigned int millisec);
103 #if !defined(IUTEST_OS_WINDOWS_MOBILE)
104 inline void Abort() { abort(); }
109 inline FILE* FileOpen(
const char* filename,
const char* mode)
111 #if defined(_MSC_VER)
112 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
113 return fopen(filename, mode);
114 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
115 #elif defined(_LARGEFILE64_SOURCE)
116 return fopen64(filename, mode);
118 return fopen(filename, mode);
122 inline int FileSeek(FILE* fp, iu_off_t pos,
int origin)
124 #if defined(_MSC_VER)
125 return _fseeki64(fp, pos, origin);
126 #elif defined(_LARGEFILE64_SOURCE)
127 return fseeko64(fp, pos, origin);
128 #elif IUTEST_HAS_LARGEFILE_API
129 return fseeko(fp, pos, origin);
131 return fseek(fp, pos, origin);
135 inline iu_off_t FileTell(FILE* fp)
137 #if defined(_MSC_VER)
138 return static_cast<iu_off_t
>(_ftelli64(fp));
139 #elif defined(_LARGEFILE64_SOURCE)
140 return static_cast<iu_off_t
>(ftello64(fp));
141 #elif IUTEST_HAS_LARGEFILE_API
142 return static_cast<iu_off_t
>(ftello(fp));
144 return static_cast<iu_off_t
>(ftell(fp));
150 #if IUTEST_HAS_HDR_UNISTD
152 #if defined(_MSC_VER) || defined(IUTEST_OS_WINDOWS_MINGW)
153 inline int FdClose(
int fd) {
return _close(fd); }
154 inline int FdFlush(
int fd) {
return _commit(fd); }
156 inline int FdClose(
int fd) {
return close(fd); }
157 inline int FdFlush(
int fd) {
return fsync(fd); }
160 inline int FdClose(
int) {
return -1; }
161 inline int FdFlush(
int) {
return -1; }
164 #if IUTEST_HAS_FD_OPEN
166 #if defined(_MSC_VER) || defined(__MINGW64__)
167 inline FILE* FdOpen(
int fd,
const char* mode) {
return _fdopen(fd, mode); }
169 inline FILE* FdOpen(
int fd,
const char* mode) {
return fdopen(fd, mode); }
174 inline FILE* FdOpen(
int,
const char*) {
return IUTEST_NULLPTR; }
179 #if IUTEST_HAS_FD_DUP
181 #if defined(_MSC_VER)
182 inline int Dup(
int fd) {
return _dup(fd); }
184 inline int Dup(
int fd) {
return dup(fd); }
187 #if defined(_MSC_VER)
188 inline int Dup2(
int fd1,
int fd2) {
return _dup2(fd1, fd2); }
190 inline int Dup2(
int fd1,
int fd2) {
return dup2(fd1, fd2); }
194 inline int Dup(
int) {
return -1; }
195 inline int Dup2(
int,
int) {
return -1; }
198 #if IUTEST_HAS_FILENO
200 #if defined(_MSC_VER)
201 inline int Fileno(FILE* fp) {
return _fileno(fp); }
203 inline int Fileno(FILE* fp) {
return fileno(fp); }
208 inline int Fileno(FILE*) {
return -1; }
212 #if IUTEST_HAS_FILE_STAT
214 #if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_WINE)
216 typedef struct __stat64 StatStruct;
218 inline int FileStat(
int fd, StatStruct* buf) {
return _fstat64(fd, buf); }
219 inline int Stat(
const char* path, StatStruct* buf) {
return _stat64(path, buf); }
220 inline bool IsDir(
const StatStruct& st) {
return (st.st_mode & _S_IFDIR) != 0; }
224 #if defined(_LARGEFILE64_SOURCE)
226 typedef struct stat64 StatStruct;
228 inline int FileStat(
int fd, StatStruct* buf) {
return fstat64(fd, buf); }
229 inline int Stat(
const char* path, StatStruct* buf) {
return stat64(path, buf); }
233 typedef struct stat StatStruct;
235 inline int FileStat(
int fd, StatStruct* buf) {
return fstat(fd, buf); }
236 inline int Stat(
const char* path, StatStruct* buf) {
return stat(path, buf); }
240 inline bool IsDir(
const StatStruct& st) {
return S_ISDIR(st.st_mode); }
244 inline int Stat(FILE* fp, StatStruct* buf)
247 return fd >= 0 ? FileStat(fd, buf) : fd;
254 inline iu_uint_max_t FileSizeBySeekSet(FILE* fp)
260 const iu_off_t pre = FileTell(fp);
261 if( (pre != -1) && (FileSeek(fp, 0, SEEK_END) == 0) )
263 const iu_off_t size = FileTell(fp);
264 IUTEST_UNUSED_RETURN(FileSeek(fp, pre, SEEK_SET));
265 return static_cast<iu_uint_max_t
>(size);
270 inline iu_uint_max_t FileSize(FILE* fp)
276 #if IUTEST_HAS_FILE_STAT
278 if (Stat(fp, &st) == 0)
280 return static_cast<iu_uint_max_t
>(st.st_size);
283 return FileSizeBySeekSet(fp);
288 inline iu_uint_max_t FdSize(
int fd)
294 #if IUTEST_HAS_FILE_STAT
296 if (FileStat(fd, &st) == 0)
298 return static_cast<iu_uint_max_t
>(st.st_size);
304 inline iu_uint_max_t FileSizeFromPath(
const char* filename)
306 #if IUTEST_HAS_STD_FILESYSTEM
307 return ::std::filesystem::file_size(filename);
310 #if IUTEST_HAS_FILE_STAT
312 if (Stat(filename, &st) == 0)
314 return static_cast<iu_uint_max_t
>(st.st_size);
322 #if IUTEST_HAS_MKSTEMP
324 #if defined(_MSC_VER)
325 inline int Mkstemp(
char* template_path) {
return _mkstemp(template_path); }
327 inline int Mkstemp(
char* template_path) {
return mkstemp(template_path); }
331 inline int Mkstemp(
char*) {
return -1; }
336 inline void SleepMilliseconds(
int n) { posix::SleepMillisec(
static_cast<unsigned int>(n)); }
343 namespace posix = internal::posix;
373 bool SetEnvironmentVariable(
const char* name,
const char* value);
382 bool GetEnvironmentVariable(
const char* name,
char* buf,
size_t size);
384 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
386 template<
size_t SIZE>
387 inline bool GetEnvironmentVariable(
const char* name,
char (&buf)[SIZE])
389 return GetEnvironmentVariable(name, buf, SIZE);
400 bool IUTEST_ATTRIBUTE_UNUSED_ GetEnvironmentVariable(
const char* name, ::std::string& var);
408 bool IUTEST_ATTRIBUTE_UNUSED_ GetEnvironmentInt(
const char* name,
int& var);
410 #if defined(IUTEST_OS_WINDOWS)
417 ::std::string IUTEST_ATTRIBUTE_UNUSED_ WideStringToMultiByteString(
const wchar_t* wide_c_str);
424 ::std::string IUTEST_ATTRIBUTE_UNUSED_ GetHResultString(HRESULT hr);
444 IUTestLog(Level level,
const char* file,
int line);
449 iu_stringstream& GetStream() {
return m_stream; }
452 static int GetCount(Level level) {
return GetCountTable().count[level]; }
453 static bool HasWarning() {
return GetCount(LOG_WARNING) > 0; }
454 static bool HasError() {
return GetCount(LOG_ERROR) > 0 || GetCount(LOG_FATAL) > 0; }
459 int count[LOG_LEVEL_NUM];
462 static Count& GetCountTable() {
static Count count = { {0} };
return count; }
463 static void CountUp(
int level);
467 iu_stringstream m_stream;
472 #if IUTEST_HAS_STREAM_BUFFER
474 #if defined(BUFSIZ) && BUFSIZ > 1024
475 # define IUTEST_DEFAULT_STREAM_BUFFER_SIZE BUFSIZ
477 # define IUTEST_DEFAULT_STREAM_BUFFER_SIZE 1024
483 template<
int SIZE=IUTEST_DEFAULT_STREAM_BUFFER_SIZE>
487 explicit IUStreamBuffer(FILE* fp)
492 const int r = setvbuf(fp, m_buf, _IOFBF, SIZE);
505 setvbuf(m_fp, NULL, _IONBF, 0);
510 ::std::string GetStreamString()
const
514 bool IsValid()
const {
return m_fp != NULL; }
527 # include "../impl/iutest_port.ipp"
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
#define IUTEST_ATTRIBUTE_NORETURN_
noreturn
Definition: iutest_compiler.hpp:1433
#define IUTEST_LOG_(level)
ログメッセージストリーム
Definition: iutest_port.hpp:56
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:31
iutest root namespace
Definition: iutest_charcode.hpp:33