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
26 #if defined(IUTEST_OS_LINUX) || defined(IUTEST_OS_CYGWIN) || defined(IUTEST_OS_MAC) || defined(IUTEST_OS_FREEBSD)
31 #if IUTEST_HAS_FILE_STAT
32 # include <sys/stat.h>
37 #if !defined(IUTEST_MAX_PATH)
38 # if defined(MAX_PATH) && MAX_PATH
39 # define IUTEST_MAX_PATH MAX_PATH
40 # elif defined(PATH_MAX) && PATH_MAX
41 # define IUTEST_MAX_PATH PATH_MAX
42 # elif defined(FILENAME_MAX) && FILENAME_MAX
43 # define IUTEST_MAX_PATH FILENAME_MAX
45 # define IUTEST_MAX_PATH 1024
52 #define IUTEST_LOG_(level) \
53 ::iutest::detail::IUTestLog( \
54 ::iutest::detail::IUTestLog::LOG_##level, __FILE__, __LINE__).GetStream()
59 #define IUTEST_CHECK_(condition) \
60 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
61 if( !::iutest::detail::IsTrue(condition) ) \
62 IUTEST_LOG_(FATAL) << "Condition " #condition " failed. "
73 void vprint_message(
const char *fmt, va_list va);
74 void print_message(
const char *fmt, ...);
83 const char* GetEnv(
const char* name);
84 int PutEnv(
const char* expr);
85 int SetEnv(
const char* name,
const char* value,
int overwrite);
87 const char* GetCWD(
char* buf,
size_t length);
88 ::std::string GetCWD();
90 void SleepMillisec(
unsigned int millisec);
92 #if defined(IUTEST_OS_WINDOWS_MOBILE)
96 inline void Abort() { abort(); }
101 #if defined(_MSC_VER)
102 inline int Fileno(FILE* fp) {
return _fileno(fp); }
104 inline int Fileno(FILE* fp) {
return fileno(fp); }
109 inline int Fileno(FILE*) {
return -1; }
113 #if IUTEST_HAS_FILE_STAT
115 #if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_WINE)
117 typedef struct _stat StatStruct;
119 inline int FileStat(
int fd, StatStruct* buf) {
return _fstat(fd, buf); }
120 inline int Stat(
const char* path, StatStruct* buf) {
return _stat(path, buf); }
121 inline bool IsDir(
const StatStruct& st) {
return (st.st_mode & _S_IFDIR) != 0; }
125 typedef struct stat StatStruct;
127 inline int FileStat(
int fd, StatStruct* buf) {
return fstat(fd, buf); }
128 inline int Stat(
const char* path, StatStruct* buf) {
return stat(path, buf); }
129 inline bool IsDir(
const StatStruct& st) {
return S_ISDIR(st.st_mode); }
133 inline int Stat(FILE* fp, StatStruct* buf)
136 return fd >= 0 ? FileStat(fd, buf) : fd;
143 inline void SleepMilliseconds(
int n) { posix::SleepMillisec(
static_cast<unsigned int>(n)); }
150 namespace posix = internal::posix;
180 bool SetEnvironmentVariable(
const char* name,
const char* value);
189 bool GetEnvironmentVariable(
const char* name,
char* buf,
size_t size);
191 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
193 template<
size_t SIZE>
194 inline bool GetEnvironmentVariable(
const char* name,
char (&buf)[SIZE])
196 return GetEnvironmentVariable(name, buf, SIZE);
207 bool IUTEST_ATTRIBUTE_UNUSED_ GetEnvironmentVariable(
const char* name, ::std::string& var);
215 bool IUTEST_ATTRIBUTE_UNUSED_ GetEnvironmentInt(
const char* name,
int& var);
217 #if defined(IUTEST_OS_WINDOWS)
224 ::std::string IUTEST_ATTRIBUTE_UNUSED_ WideStringToMultiByteString(
const wchar_t* wide_c_str);
231 ::std::string IUTEST_ATTRIBUTE_UNUSED_ GetHResultString(HRESULT hr);
251 IUTestLog(Level level,
const char* file,
int line);
256 iu_stringstream& GetStream() {
return m_stream; }
259 static int GetCount(Level level) {
return GetCountTable().count[level]; }
260 static bool HasWarning() {
return GetCount(LOG_WARNING) > 0; }
261 static bool HasError() {
return GetCount(LOG_ERROR) > 0 || GetCount(LOG_FATAL) > 0; }
266 int count[LOG_LEVEL_NUM];
269 static Count& GetCountTable() {
static Count count = { {0} };
return count; }
270 static void CountUp(
int level);
274 iu_stringstream m_stream;
279 #if IUTEST_HAS_STREAM_BUFFER
284 template<
int SIZE=BUFSIZ>
288 explicit IUStreamBuffer(FILE* fp)
293 setvbuf(fp, m_buf, _IOFBF, SIZE);
299 setvbuf(m_fp, NULL, _IONBF, 0);
303 ::std::string GetStreamString() {
return m_buf; }
321 # include "../impl/iutest_port.ipp"
324 #endif // INCG_IRIS_IUTEST_PORT_HPP_7893F685_A1A9_477A_82E8_BF06237697FF_