~ubuntu-branches/ubuntu/raring/protobuf/raring

« back to all changes in this revision

Viewing changes to gtest/include/gtest/internal/gtest-port.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2010-02-11 11:13:19 UTC
  • mfrom: (2.2.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100211111319-zdn8hmw0gh8s4cf8
Tags: 2.2.0a-0.1ubuntu1
* Merge from Debian testing.
* Remaining Ubuntu changes:
  - Don't use python2.4.
* Ubuntu changes dropped:
  - Disable death tests on Itanium, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
//   GTEST_HAS_STD_WSTRING    - Define it to 1/0 to indicate that
59
59
//                              std::wstring does/doesn't work (Google Test can
60
60
//                              be used where std::wstring is unavailable).
61
 
//   GTEST_HAS_TR1_TUPLE 1    - Define it to 1/0 to indicate tr1::tuple
 
61
//   GTEST_HAS_TR1_TUPLE      - Define it to 1/0 to indicate tr1::tuple
62
62
//                              is/isn't available.
63
63
//   GTEST_HAS_SEH            - Define it to 1/0 to indicate whether the
64
64
//                              compiler supports Microsoft's "Structured
65
65
//                              Exception Handling".
 
66
//   GTEST_USE_OWN_TR1_TUPLE  - Define it to 1/0 to indicate whether Google
 
67
//                              Test's own tr1 tuple implementation should be
 
68
//                              used.  Unused when the user sets
 
69
//                              GTEST_HAS_TR1_TUPLE to 0.
66
70
 
67
71
// This header defines the following utilities:
68
72
//
150
154
//   Int32FromGTestEnv()  - parses an Int32 environment variable.
151
155
//   StringFromGTestEnv() - parses a string environment variable.
152
156
 
 
157
#include <stddef.h>  // For ptrdiff_t
153
158
#include <stdlib.h>
154
159
#include <stdio.h>
155
160
#include <string.h>
 
161
#ifndef _WIN32_WCE
156
162
#include <sys/stat.h>
 
163
#endif  // !_WIN32_WCE
157
164
 
158
165
#include <iostream>  // NOLINT
159
166
 
173
180
// Determines the platform on which Google Test is compiled.
174
181
#ifdef __CYGWIN__
175
182
#define GTEST_OS_CYGWIN 1
176
 
#elif __SYMBIAN32__
 
183
#elif defined __SYMBIAN32__
177
184
#define GTEST_OS_SYMBIAN 1
178
185
#elif defined _WIN32
179
186
#define GTEST_OS_WINDOWS 1
187
194
#define GTEST_OS_SOLARIS 1
188
195
#endif  // __CYGWIN__
189
196
 
190
 
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
 
197
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_SYMBIAN || \
 
198
    GTEST_OS_SOLARIS
191
199
 
192
200
// On some platforms, <regex.h> needs someone to define size_t, and
193
201
// won't compile otherwise.  We can #include it here as we already
202
210
 
203
211
#elif GTEST_OS_WINDOWS
204
212
 
 
213
#ifndef _WIN32_WCE
205
214
#include <direct.h>  // NOLINT
206
215
#include <io.h>  // NOLINT
 
216
#endif  // !_WIN32_WCE
207
217
 
208
218
// <regex.h> is not available on Windows.  Use our own simple regex
209
219
// implementation instead.
215
225
// simple regex implementation instead.
216
226
#define GTEST_USES_SIMPLE_RE 1
217
227
 
218
 
#endif  // GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC
 
228
#endif  // GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC ||
 
229
        // GTEST_OS_SYMBIAN || GTEST_OS_SOLARIS
219
230
 
220
231
// Defines GTEST_HAS_EXCEPTIONS to 1 if exceptions are enabled, or 0
221
232
// otherwise.
339
350
#define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC)
340
351
#endif  // GTEST_HAS_PTHREAD
341
352
 
342
 
// Determines whether tr1/tuple is available.  If you have tr1/tuple
343
 
// on your platform, define GTEST_HAS_TR1_TUPLE=1 for both the Google
344
 
// Test project and your tests. If you would like Google Test to detect
345
 
// tr1/tuple on your platform automatically, please open an issue
346
 
// ticket at http://code.google.com/p/googletest.
 
353
// Determines whether Google Test can use tr1/tuple.  You can define
 
354
// this macro to 0 to prevent Google Test from using tuple (any
 
355
// feature depending on tuple with be disabled in this mode).
347
356
#ifndef GTEST_HAS_TR1_TUPLE
348
 
// The user didn't tell us, so we need to figure it out.
349
 
 
350
 
// GCC provides <tr1/tuple> since 4.0.0.
351
 
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
 
357
// The user didn't tell us not to do it, so we assume it's OK.
352
358
#define GTEST_HAS_TR1_TUPLE 1
 
359
#endif  // GTEST_HAS_TR1_TUPLE
 
360
 
 
361
// Determines whether Google Test's own tr1 tuple implementation
 
362
// should be used.
 
363
#ifndef GTEST_USE_OWN_TR1_TUPLE
 
364
// The user didn't tell us, so we need to figure it out.
 
365
 
 
366
// We use our own tr1 tuple if we aren't sure the user has an
 
367
// implementation of it already.  At this time, GCC 4.0.0+ is the only
 
368
// mainstream compiler that comes with a TR1 tuple implementation.
 
369
// MSVC 2008 (9.0) provides TR1 tuple in a 323 MB Feature Pack
 
370
// download, which we cannot assume the user has.  MSVC 2010 isn't
 
371
// released yet.
 
372
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
 
373
#define GTEST_USE_OWN_TR1_TUPLE 0
353
374
#else
354
 
#define GTEST_HAS_TR1_TUPLE 0
355
 
#endif  // __GNUC__
356
 
#endif  // GTEST_HAS_TR1_TUPLE
 
375
#define GTEST_USE_OWN_TR1_TUPLE 1
 
376
#endif  // defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
 
377
 
 
378
#endif  // GTEST_USE_OWN_TR1_TUPLE
357
379
 
358
380
// To avoid conditional compilation everywhere, we make it
359
381
// gtest-port.h's responsibility to #include the header implementing
360
382
// tr1/tuple.
361
383
#if GTEST_HAS_TR1_TUPLE
362
 
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
 
384
 
 
385
#if GTEST_USE_OWN_TR1_TUPLE
 
386
#include <gtest/internal/gtest-tuple.h>
 
387
#elif GTEST_OS_SYMBIAN
 
388
 
 
389
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
 
390
// use STLport's tuple implementation, which unfortunately doesn't
 
391
// work as the copy of STLport distributed with Symbian is incomplete.
 
392
// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
 
393
// use its own tuple implementation.
 
394
#ifdef BOOST_HAS_TR1_TUPLE
 
395
#undef BOOST_HAS_TR1_TUPLE
 
396
#endif  // BOOST_HAS_TR1_TUPLE
 
397
 
 
398
// This prevents <boost/tr1/detail/config.hpp>, which defines
 
399
// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
 
400
#define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
 
401
#include <tuple>
 
402
 
 
403
#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
363
404
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header.  This does
364
405
// not conform to the TR1 spec, which requires the header to be <tuple>.
365
 
#include <tr1/tuple>
 
406
 
 
407
#if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
 
408
// Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
 
409
// which is #included by <tr1/tuple>, to not compile when RTTI is
 
410
// disabled.  _TR1_FUNCTIONAL is the header guard for
 
411
// <tr1/functional>.  Hence the following #define is a hack to prevent
 
412
// <tr1/functional> from being included.
 
413
#define _TR1_FUNCTIONAL 1
 
414
#include <tr1/tuple>
 
415
#undef _TR1_FUNCTIONAL  // Allows the user to #include
 
416
                        // <tr1/functional> if he chooses to.
 
417
#else
 
418
#include <tr1/tuple>
 
419
#endif  // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
 
420
 
366
421
#else
367
422
// If the compiler is not GCC 4.0+, we assume the user is using a
368
423
// spec-conforming TR1 implementation.
369
424
#include <tuple>
370
 
#endif  // __GNUC__
 
425
#endif  // GTEST_USE_OWN_TR1_TUPLE
 
426
 
371
427
#endif  // GTEST_HAS_TR1_TUPLE
372
428
 
373
429
// Determines whether clone(2) is supported.
396
452
#if GTEST_HAS_STD_STRING && (GTEST_OS_LINUX || \
397
453
                             GTEST_OS_MAC || \
398
454
                             GTEST_OS_CYGWIN || \
399
 
                             (GTEST_OS_WINDOWS && _MSC_VER >= 1400))
 
455
                             (GTEST_OS_WINDOWS && (_MSC_VER >= 1400) && \
 
456
                              !defined(_WIN32_WCE)))
400
457
#define GTEST_HAS_DEATH_TEST 1
401
458
#include <vector>  // NOLINT
402
459
#endif
641
698
//   CaptureStderr     - starts capturing stderr.
642
699
//   GetCapturedStderr - stops capturing stderr and returns the captured string.
643
700
 
644
 
#if GTEST_HAS_STD_STRING
645
701
void CaptureStderr();
646
 
::std::string GetCapturedStderr();
647
 
#endif  // GTEST_HAS_STD_STRING
 
702
String GetCapturedStderr();
648
703
 
649
704
#if GTEST_HAS_DEATH_TEST
650
705
 
764
819
  return stricmp(s1, s2);
765
820
}
766
821
inline char* StrDup(const char* src) { return strdup(src); }
767
 
#else
 
822
#else  // !__BORLANDC__
 
823
#ifdef _WIN32_WCE
 
824
inline int IsATTY(int /* fd */) { return 0; }
 
825
#else  // !_WIN32_WCE
768
826
inline int IsATTY(int fd) { return _isatty(fd); }
 
827
#endif  // _WIN32_WCE
769
828
inline int StrCaseCmp(const char* s1, const char* s2) {
770
829
  return _stricmp(s1, s2);
771
830
}
772
831
inline char* StrDup(const char* src) { return _strdup(src); }
773
832
#endif  // __BORLANDC__
774
833
 
 
834
#ifdef _WIN32_WCE
 
835
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
 
836
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
 
837
// time and thus not defined there.
 
838
#else  // !_WIN32_WCE
775
839
inline int FileNo(FILE* file) { return _fileno(file); }
776
840
inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
777
841
inline int RmDir(const char* dir) { return _rmdir(dir); }
778
842
inline bool IsDir(const StatStruct& st) {
779
843
  return (_S_IFDIR & st.st_mode) != 0;
780
844
}
 
845
#endif  // _WIN32_WCE
781
846
 
782
847
#else
783
848
 
806
871
inline const char* StrNCpy(char* dest, const char* src, size_t n) {
807
872
  return strncpy(dest, src, n);
808
873
}
 
874
 
 
875
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
 
876
// StrError() aren't needed on Windows CE at this time and thus not
 
877
// defined there.
 
878
 
 
879
#ifndef _WIN32_WCE
809
880
inline int ChDir(const char* dir) { return chdir(dir); }
 
881
#endif
810
882
inline FILE* FOpen(const char* path, const char* mode) {
811
883
  return fopen(path, mode);
812
884
}
 
885
#ifndef _WIN32_WCE
813
886
inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
814
887
  return freopen(path, mode, stream);
815
888
}
816
889
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
 
890
#endif
817
891
inline int FClose(FILE* fp) { return fclose(fp); }
 
892
#ifndef _WIN32_WCE
818
893
inline int Read(int fd, void* buf, unsigned int count) {
819
894
  return static_cast<int>(read(fd, buf, count));
820
895
}
823
898
}
824
899
inline int Close(int fd) { return close(fd); }
825
900
inline const char* StrError(int errnum) { return strerror(errnum); }
 
901
#endif
826
902
inline const char* GetEnv(const char* name) {
827
903
#ifdef _WIN32_WCE  // We are on Windows CE, which has no environment variables.
828
904
  return NULL;
943
1019
  }
944
1020
  ~GTestCheckProvider() {
945
1021
    ::std::cerr << ::std::endl;
946
 
    abort();
 
1022
    posix::Abort();
947
1023
  }
948
1024
  void FormatFileLocation(const char* file, int line) {
949
1025
    if (file == NULL)