Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2005, Google Inc. | 1 // Copyright 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 22 matching lines...) Expand all Loading... | |
33 // platforms. They are subject to change without notice. DO NOT USE | 33 // platforms. They are subject to change without notice. DO NOT USE |
34 // THEM IN USER CODE. | 34 // THEM IN USER CODE. |
35 | 35 |
36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | 36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ |
37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | 37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ |
38 | 38 |
39 // The user can define the following macros in the build script to | 39 // The user can define the following macros in the build script to |
40 // control Google Test's behavior. If the user doesn't define a macro | 40 // control Google Test's behavior. If the user doesn't define a macro |
41 // in this list, Google Test will define it. | 41 // in this list, Google Test will define it. |
42 // | 42 // |
43 // GTEST_HAS_CLONE - Define it to 1/0 to indicate clone(2) | |
chandlerc
2008/12/02 19:16:29
indicate _that_ clone(2) ...
Zhanyong
2008/12/02 20:01:46
I can fix this when I commit the patch.
Hobbes
2008/12/02 20:09:44
Thanks. You might wanna fix GTEST_HAS_TR1_TUPLE as
| |
44 // is/isn't available | |
45 // GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string | |
46 // is/isn't available (some systems define | |
47 // ::string, which is different to std::string). | |
48 // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string | |
49 // is/isn't available (some systems define | |
50 // ::wstring, which is different to std::wstring). | |
51 // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h> | |
52 // is/isn't available. | |
53 // GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't | |
54 // enabled. | |
43 // GTEST_HAS_STD_STRING - Define it to 1/0 to indicate that | 55 // GTEST_HAS_STD_STRING - Define it to 1/0 to indicate that |
44 // std::string does/doesn't work (Google Test can | 56 // std::string does/doesn't work (Google Test can |
45 // be used where std::string is unavailable). | 57 // be used where std::string is unavailable). |
46 // GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string | |
47 // is/isn't available (some systems define | |
48 // ::string, which is different to std::string). | |
49 // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that | 58 // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that |
50 // std::wstring does/doesn't work (Google Test can | 59 // std::wstring does/doesn't work (Google Test can |
51 // be used where std::wstring is unavailable). | 60 // be used where std::wstring is unavailable). |
52 // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string | |
53 // is/isn't available (some systems define | |
54 // ::wstring, which is different to std::wstring). | |
55 // GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't | |
56 // enabled. | |
57 // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h> | |
58 // is/isn't available. | |
59 // GTEST_HAS_TR1_TUPLE 1 - Define it to 1/0 to indicate tr1::tuple | 61 // GTEST_HAS_TR1_TUPLE 1 - Define it to 1/0 to indicate tr1::tuple |
60 // is/isn't available. | 62 // is/isn't available. |
61 | 63 |
62 // This header defines the following utilities: | 64 // This header defines the following utilities: |
63 // | 65 // |
64 // Macros indicating the name of the Google C++ Testing Framework project: | 66 // Macros indicating the name of the Google C++ Testing Framework project: |
65 // GTEST_NAME - a string literal of the project name. | 67 // GTEST_NAME - a string literal of the project name. |
66 // GTEST_FLAG_PREFIX - a string literal of the prefix all Google | 68 // GTEST_FLAG_PREFIX - a string literal of the prefix all Google |
67 // Test flag names share. | 69 // Test flag names share. |
68 // GTEST_FLAG_PREFIX_UPPER - a string literal of the prefix all Google | 70 // GTEST_FLAG_PREFIX_UPPER - a string literal of the prefix all Google |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 // <tr1/tuple> on your platform automatically, please open an issue | 307 // <tr1/tuple> on your platform automatically, please open an issue |
306 // ticket at http://code.google.com/p/googletest. | 308 // ticket at http://code.google.com/p/googletest. |
307 #ifndef GTEST_HAS_TR1_TUPLE | 309 #ifndef GTEST_HAS_TR1_TUPLE |
308 // The user didn't tell us, so we need to figure it out. | 310 // The user didn't tell us, so we need to figure it out. |
309 | 311 |
310 // GCC provides <tr1/tuple> since 4.0.0. | 312 // GCC provides <tr1/tuple> since 4.0.0. |
311 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) | 313 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) |
312 #define GTEST_HAS_TR1_TUPLE 1 | 314 #define GTEST_HAS_TR1_TUPLE 1 |
313 #else | 315 #else |
314 #define GTEST_HAS_TR1_TUPLE 0 | 316 #define GTEST_HAS_TR1_TUPLE 0 |
315 #endif // __GNUC__· | 317 #endif // __GNUC__ |
316 #endif // GTEST_HAS_TR1_TUPLE· | 318 #endif // GTEST_HAS_TR1_TUPLE |
317 · | 319 |
318 // Determines whether to support death tests.· | 320 // Determines whether clone(2) is supported. |
319 #if GTEST_HAS_STD_STRING && defined(GTEST_OS_LINUX)· | 321 // Usually it will only be available on Linux, excluding |
320 #define GTEST_HAS_DEATH_TEST· | 322 // Linux on the Itanium architecture. |
321 // On some platforms, <regex.h> needs someone to define size_t, and· | 323 // Also see http://linux.die.net/man/2/clone. |
322 // won't compile otherwise. We can #include it here as we already· | 324 #ifndef GTEST_HAS_CLONE |
325 // The user didn't tell us, so we need to figure it out. | |
326 | |
327 #if defined(GTEST_OS_LINUX) && !defined(__ia64__) | |
328 #define GTEST_HAS_CLONE 1 | |
329 #else | |
330 #define GTEST_HAS_CLONE 0 | |
331 #endif // defined(GTEST_OS_LINUX) && !defined(__ia64__) | |
332 | |
333 #endif // GTEST_HAS_CLONE | |
334 | |
335 // Determines whether to support death tests. | |
336 #if GTEST_HAS_STD_STRING && GTEST_HAS_CLONE | |
337 #define GTEST_HAS_DEATH_TEST | |
338 // On some platforms, <regex.h> needs someone to define size_t, and | |
339 // won't compile otherwise. We can #include it here as we already | |
340 // included <stdlib.h>, which is guaranteed to define size_t through | |
341 // <stddef.h>. | |
342 #include <regex.h> | |
343 #include <vector> | |
344 #include <fcntl.h> | |
345 #include <sys/mman.h> | |
346 #endif // GTEST_HAS_STD_STRING && GTEST_HAS_CLONE | |
347 | |
348 // Determines whether to support value-parameterized tests. | |
349 | |
350 #if defined(__GNUC__) || (_MSC_VER >= 1400) | |
351 // TODO(vladl@google.com): get the implementation rid of vector and list | |
352 // to compile on MSVC 7.1. | |
353 #define GTEST_HAS_PARAM_TEST | |
354 #endif // defined(__GNUC__) || (_MSC_VER >= 1400) | |
355 | |
356 // Determines whether to support type-driven tests. | |
357 | |
358 // Typed tests need <typeinfo> and variadic macros, which gcc and VC | |
359 // 8.0+ support. | |
360 #if defined(__GNUC__) || (_MSC_VER >= 1400) | |
361 #define GTEST_HAS_TYPED_TEST | |
362 #define GTEST_HAS_TYPED_TEST_P | |
363 #endif // defined(__GNUC__) || (_MSC_VER >= 1400) | |
364 | |
365 // Determines whether to support Combine(). This only makes sense when | |
366 // value-parameterized tests are enabled. | |
367 #if defined(GTEST_HAS_PARAM_TEST) && GTEST_HAS_TR1_TUPLE | |
368 #define GTEST_HAS_COMBINE | |
369 #endif // defined(GTEST_HAS_PARAM_TEST) && GTEST_HAS_TR1_TUPLE | |
370 | |
371 // Determines whether the system compiler uses UTF-16 for encoding wide strings. | |
372 #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \ | |
373 defined(GTEST_OS_SYMBIAN) | |
374 #define GTEST_WIDE_STRING_USES_UTF16_ 1 | |
375 #endif | |
376 | |
377 // Defines some utility macros. | |
378 | |
379 // The GNU compiler emits a warning if nested "if" statements are followed by | |
380 // an "else" statement and braces are not used to explicitly disambiguate the | |
381 // "else" binding. This leads to problems with code like: | |
382 // | |
383 // if (gate) | |
384 // ASSERT_*(condition) << "Some message"; | |
385 // | |
386 // The "switch (0) case 0:" idiom is used to suppress this. | |
387 #ifdef __INTEL_COMPILER | |
388 #define GTEST_AMBIGUOUS_ELSE_BLOCKER_ | |
389 #else | |
390 #define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: // NOLINT | |
391 #endif | |
392 | |
393 // Use this annotation at the end of a struct / class definition to | |
394 // prevent the compiler from optimizing away instances that are never | |
395 // used. This is useful when all interesting logic happens inside the | |
396 // c'tor and / or d'tor. Example: | |
397 // | |
398 // struct Foo { | |
399 // Foo() { ... } | |
400 // } GTEST_ATTRIBUTE_UNUSED_; | |
401 #if defined(__GNUC__) && !defined(COMPILER_ICC) | |
402 #define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) | |
403 #else | |
404 #define GTEST_ATTRIBUTE_UNUSED_ | |
405 #endif | |
406 | |
407 // A macro to disallow the evil copy constructor and operator= functions | |
408 // This should be used in the private: declarations for a class. | |
409 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\ | |
410 type(const type &);\ | |
411 void operator=(const type &) | |
412 | |
413 // Tell the compiler to warn about unused return values for functions declared | |
414 // with this macro. The macro should be used on function declarations | |
415 // following the argument list: | |
416 // | |
417 // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; | |
418 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) | |
419 #define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) | |
420 #else | |
421 #define GTEST_MUST_USE_RESULT_ | |
422 #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC | |
423 | |
424 namespace testing { | |
425 | |
426 class Message; | |
427 | |
428 namespace internal { | |
429 | |
430 class String; | |
431 | |
432 // std::strstream is deprecated. However, we have to use it on | |
433 // Windows as std::stringstream won't compile on Windows when | |
434 // exceptions are disabled. We use std::stringstream on other | |
435 // platforms to avoid compiler warnings there. | |
436 #if GTEST_HAS_STD_STRING | |
437 typedef ::std::stringstream StrStream; | |
438 #else | |
439 typedef ::std::strstream StrStream; | |
440 #endif // GTEST_HAS_STD_STRING | |
441 | |
442 // Defines scoped_ptr. | |
443 | |
444 // This implementation of scoped_ptr is PARTIAL - it only contains | |
445 // enough stuff to satisfy Google Test's need. | |
446 template <typename T> | |
447 class scoped_ptr { | |
448 public: | |
449 explicit scoped_ptr(T* p = NULL) : ptr_(p) {} | |
450 ~scoped_ptr() { reset(); } | |
451 | |
452 T& operator*() const { return *ptr_; } | |
453 T* operator->() const { return ptr_; } | |
454 T* get() const { return ptr_; } | |
455 | |
456 T* release() { | |
457 T* const ptr = ptr_; | |
458 ptr_ = NULL; | |
459 return ptr; | |
460 } | |
461 | |
462 void reset(T* p = NULL) { | |
463 if (p != ptr_) { | |
464 if (sizeof(T) > 0) { // Makes sure T is a complete type. | |
465 delete ptr_; | |
466 } | |
467 ptr_ = p; | |
468 } | |
469 } | |
470 private: | |
471 T* ptr_; | |
472 | |
473 GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr); | |
474 }; | |
475 | |
476 #ifdef GTEST_HAS_DEATH_TEST | |
477 | |
478 // Defines RE. | |
479 | |
480 // A simple C++ wrapper for <regex.h>. It uses the POSIX Enxtended | |
481 // Regular Expression syntax. | |
482 class RE { | |
483 public: | |
484 // Constructs an RE from a string. | |
485 #if GTEST_HAS_STD_STRING | |
486 RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT | |
487 #endif // GTEST_HAS_STD_STRING | |
488 | |
489 #if GTEST_HAS_GLOBAL_STRING | |
490 RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT | |
491 #endif // GTEST_HAS_GLOBAL_STRING | |
492 | |
493 RE(const char* regex) { Init(regex); } // NOLINT | |
494 ~RE(); | |
495 | |
496 // Returns the string representation of the regex. | |
497 const char* pattern() const { return pattern_; } | |
498 | |
499 // FullMatch(str, re) returns true iff regular expression re matches | |
500 // the entire str. | |
501 // PartialMatch(str, re) returns true iff regular expression re | |
502 // matches a substring of str (including str itself). | |
503 // | |
504 // TODO(wan@google.com): make FullMatch() and PartialMatch() work | |
505 // when str contains NUL characters. | |
506 #if GTEST_HAS_STD_STRING | |
507 static bool FullMatch(const ::std::string& str, const RE& re) { | |
508 return FullMatch(str.c_str(), re); | |
509 } | |
510 static bool PartialMatch(const ::std::string& str, const RE& re) { | |
511 return PartialMatch(str.c_str(), re); | |
512 } | |
513 #endif // GTEST_HAS_STD_STRING | |
514 | |
515 #if GTEST_HAS_GLOBAL_STRING | |
516 static bool FullMatch(const ::string& str, const RE& re) { | |
517 return FullMatch(str.c_str(), re); | |
518 } | |
519 static bool PartialMatch(const ::string& str, const RE& re) { | |
520 return PartialMatch(str.c_str(), re); | |
521 } | |
522 #endif // GTEST_HAS_GLOBAL_STRING | |
523 | |
524 static bool FullMatch(const char* str, const RE& re); | |
525 static bool PartialMatch(const char* str, const RE& re); | |
526 | |
527 private: | |
528 void Init(const char* regex); | |
529 | |
530 // We use a const char* instead of a string, as Google Test may be used | |
531 // where string is not available. We also do not use Google Test's own | |
532 // String type here, in order to simplify dependencies between the | |
533 // files. | |
534 const char* pattern_; | |
535 regex_t full_regex_; // For FullMatch(). | |
536 regex_t partial_regex_; // For PartialMatch(). | |
537 bool is_valid_; | |
538 }; | |
539 | |
540 #endif // GTEST_HAS_DEATH_TEST | |
541 | |
542 // Defines logging utilities: | |
543 // GTEST_LOG_() - logs messages at the specified severity level. | |
544 // LogToStderr() - directs all log messages to stderr. | |
545 // FlushInfoLog() - flushes informational log messages. | |
546 | |
547 enum GTestLogSeverity { | |
548 GTEST_INFO, | |
549 GTEST_WARNING, | |
550 GTEST_ERROR, | |
551 GTEST_FATAL | |
552 }; | |
553 | |
554 void GTestLog(GTestLogSeverity severity, const char* file, | |
555 int line, const char* msg); | |
556 | |
557 #define GTEST_LOG_(severity, msg)\ | |
558 ::testing::internal::GTestLog(\ | |
559 ::testing::internal::GTEST_##severity, __FILE__, __LINE__, \ | |
560 (::testing::Message() << (msg)).GetString().c_str()) | |
561 | |
562 inline void LogToStderr() {} | |
563 inline void FlushInfoLog() { fflush(NULL); } | |
564 | |
565 // Defines the stderr capturer: | |
566 // CaptureStderr - starts capturing stderr. | |
567 // GetCapturedStderr - stops capturing stderr and returns the captured string. | |
568 | |
569 #ifdef GTEST_HAS_DEATH_TEST | |
570 | |
571 // A copy of all command line arguments. Set by InitGoogleTest(). | |
572 extern ::std::vector<String> g_argvs; | |
573 | |
574 void CaptureStderr(); | |
575 // GTEST_HAS_DEATH_TEST implies we have ::std::string. | |
576 ::std::string GetCapturedStderr(); | |
577 const ::std::vector<String>& GetArgvs(); | |
578 | |
579 #endif // GTEST_HAS_DEATH_TEST | |
580 | |
581 // Defines synchronization primitives. | |
582 | |
583 // A dummy implementation of synchronization primitives (mutex, lock, | |
584 // and thread-local variable). Necessary for compiling Google Test where | |
585 // mutex is not supported - using Google Test in multiple threads is not | |
586 // supported on such platforms. | |
587 | |
588 class Mutex { | |
589 public: | |
590 Mutex() {} | |
591 explicit Mutex(int /*unused*/) {} | |
592 void AssertHeld() const {} | |
593 enum { NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX = 0 }; | |
594 }; | |
595 | |
596 // We cannot call it MutexLock directly as the ctor declaration would | |
597 // conflict with a macro named MutexLock, which is defined on some | |
598 // platforms. Hence the typedef trick below. | |
599 class GTestMutexLock { | |
600 public: | |
601 explicit GTestMutexLock(Mutex*) {} // NOLINT | |
602 }; | |
603 | |
604 typedef GTestMutexLock MutexLock; | |
605 | |
606 template <typename T> | |
607 class ThreadLocal { | |
608 public: | |
609 ThreadLocal() : value_() {} | |
610 explicit ThreadLocal(const T& value) : value_(value) {} | |
611 T* pointer() { return &value_; } | |
612 const T* pointer() const { return &value_; } | |
613 const T& get() const { return value_; } | |
614 void set(const T& value) { value_ = value; } | |
615 private: | |
616 T value_; | |
617 }; | |
618 | |
619 // There's no portable way to detect the number of threads, so we just | |
620 // return 0 to indicate that we cannot detect it. | |
621 inline size_t GetThreadCount() { return 0; } | |
622 | |
623 // The above synchronization primitives have dummy implementations. | |
624 // Therefore Google Test is not thread-safe. | |
625 #define GTEST_IS_THREADSAFE 0 | |
626 | |
627 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) | |
628 | |
629 // Passing non-POD classes through ellipsis (...) crashes the ARM | |
630 // compiler. The Nokia Symbian and the IBM XL C/C++ compiler try to | |
631 // instantiate a copy constructor for objects passed through ellipsis | |
632 // (...), failing for uncopyable objects. We define this to indicate | |
633 // the fact. | |
634 #define GTEST_ELLIPSIS_NEEDS_COPY_ 1 | |
635 | |
636 // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between | |
637 // const T& and const T* in a function template. These compilers | |
638 // _can_ decide between class template specializations for T and T*, | |
639 // so a tr1::type_traits-like is_pointer works. | |
640 #define GTEST_NEEDS_IS_POINTER_ 1 | |
641 | |
642 #endif // defined(__SYMBIAN32__) || defined(__IBMCPP__) | |
643 | |
644 template <bool bool_value> | |
645 struct bool_constant { | |
646 typedef bool_constant<bool_value> type; | |
647 static const bool value = bool_value; | |
648 }; | |
649 template <bool bool_value> const bool bool_constant<bool_value>::value; | |
650 | |
651 typedef bool_constant<false> false_type; | |
652 typedef bool_constant<true> true_type; | |
653 | |
654 template <typename T> | |
655 struct is_pointer : public false_type {}; | |
656 | |
657 template <typename T> | |
658 struct is_pointer<T*> : public true_type {}; | |
659 | |
660 // Defines BiggestInt as the biggest signed integer type the compiler | |
661 // supports. | |
662 | |
663 #ifdef GTEST_OS_WINDOWS | |
664 typedef __int64 BiggestInt; | |
665 #else | |
666 typedef long long BiggestInt; // NOLINT | |
667 #endif // GTEST_OS_WINDOWS | |
668 | |
669 // The maximum number a BiggestInt can represent. This definition | |
670 // works no matter BiggestInt is represented in one's complement or | |
671 // two's complement. | |
672 // | |
673 // We cannot rely on numeric_limits in STL, as __int64 and long long | |
674 // are not part of standard C++ and numeric_limits doesn't need to be | |
675 // defined for them. | |
676 const BiggestInt kMaxBiggestInt = | |
677 ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1)); | |
678 | |
679 // This template class serves as a compile-time function from size to | |
680 // type. It maps a size in bytes to a primitive type with that | |
681 // size. e.g. | |
682 // | |
683 // TypeWithSize<4>::UInt | |
684 // | |
685 // is typedef-ed to be unsigned int (unsigned integer made up of 4 | |
686 // bytes). | |
687 // | |
688 // Such functionality should belong to STL, but I cannot find it | |
689 // there. | |
690 // | |
691 // Google Test uses this class in the implementation of floating-point | |
692 // comparison. | |
693 // | |
694 // For now it only handles UInt (unsigned int) as that's all Google Test | |
695 // needs. Other types can be easily added in the future if need | |
696 // arises. | |
697 template <size_t size> | |
698 class TypeWithSize { | |
699 public: | |
700 // This prevents the user from using TypeWithSize<N> with incorrect | |
701 // values of N. | |
702 typedef void UInt; | |
703 }; | |
704 | |
705 // The specialization for size 4. | |
706 template <> | |
707 class TypeWithSize<4> { | |
708 public: | |
709 // unsigned int has size 4 in both gcc and MSVC. | |
710 // | |
711 // As base/basictypes.h doesn't compile on Windows, we cannot use | |
712 // uint32, uint64, and etc here. | |
713 typedef int Int; | |
714 typedef unsigned int UInt; | |
715 }; | |
716 | |
717 // The specialization for size 8. | |
718 template <> | |
719 class TypeWithSize<8> { | |
720 public: | |
721 #ifdef GTEST_OS_WINDOWS | |
722 typedef __int64 Int; | |
723 typedef unsigned __int64 UInt; | |
724 #else | |
725 typedef long long Int; // NOLINT | |
726 typedef unsigned long long UInt; // NOLINT | |
727 #endif // GTEST_OS_WINDOWS | |
728 }; | |
729 | |
730 // Integer types of known sizes. | |
731 typedef TypeWithSize<4>::Int Int32; | |
732 typedef TypeWithSize<4>::UInt UInt32; | |
733 typedef TypeWithSize<8>::Int Int64; | |
734 typedef TypeWithSize<8>::UInt UInt64; | |
735 typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. | |
736 | |
737 // Utilities for command line flags and environment variables. | |
738 | |
739 // A wrapper for getenv() that works on Linux, Windows, and Mac OS. | |
740 inline const char* GetEnv(const char* name) { | |
741 #ifdef _WIN32_WCE // We are on Windows CE. | |
742 // CE has no environment variables. | |
743 return NULL; | |
744 #elif defined(GTEST_OS_WINDOWS) // We are on Windows proper. | |
745 // MSVC 8 deprecates getenv(), so we want to suppress warning 4996 | |
746 // (deprecated function) there. | |
747 #pragma warning(push) // Saves the current warning state. | |
748 #pragma warning(disable:4996) // Temporarily disables warning 4996. | |
749 return getenv(name); | |
750 #pragma warning(pop) // Restores the warning state. | |
751 #else // We are on Linux or Mac OS. | |
752 return getenv(name); | |
753 #endif | |
754 } | |
755 | |
756 #ifdef _WIN32_WCE | |
757 // Windows CE has no C library. The abort() function is used in | |
758 // several places in Google Test. This implementation provides a reasonable | |
759 // imitation of standard behaviour. | |
760 void abort(); | |
761 #else | |
762 inline void abort() { ::abort(); } | |
763 #endif // _WIN32_WCE | |
764 | |
765 // INTERNAL IMPLEMENTATION - DO NOT USE. | |
766 // | |
767 // GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition | |
768 // is not satisfied. | |
769 // Synopsys: | |
770 // GTEST_CHECK_(boolean_condition); | |
771 // or | |
772 // GTEST_CHECK_(boolean_condition) << "Additional message"; | |
773 // | |
774 // This checks the condition and if the condition is not satisfied | |
775 // it prints message about the condition violation, including the | |
776 // condition itself, plus additional message streamed into it, if any, | |
777 // and then it aborts the program. It aborts the program irrespective of | |
778 // whether it is built in the debug mode or not. | |
779 class GTestCheckProvider { | |
780 public: | |
781 GTestCheckProvider(const char* condition, const char* file, int line) { | |
782 FormatFileLocation(file, line); | |
783 ::std::cerr << " ERROR: Condition " << condition << " failed. "; | |
784 } | |
785 ~GTestCheckProvider() { | |
786 ::std::cerr << ::std::endl; | |
787 abort(); | |
788 } | |
789 void FormatFileLocation(const char* file, int line) { | |
790 if (file == NULL) | |
791 file = "unknown file"; | |
792 if (line < 0) { | |
793 ::std::cerr << file << ":"; | |
794 } else { | |
795 #if _MSC_VER | |
796 ::std::cerr << file << "(" << line << "):"; | |
797 #else | |
798 ::std::cerr << file << ":" << line << ":"; | |
799 #endif | |
800 } | |
801 } | |
802 ::std::ostream& GetStream() { return ::std::cerr; } | |
803 }; | |
804 #define GTEST_CHECK_(condition) \ | |
805 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | |
806 if (condition) \ | |
807 ; \ | |
808 else \ | |
809 ::testing::internal::GTestCheckProvider(\ | |
810 #condition, __FILE__, __LINE__).GetStream() | |
811 | |
812 // Macro for referencing flags. | |
813 #define GTEST_FLAG(name) FLAGS_gtest_##name | |
814 | |
815 // Macros for declaring flags. | |
816 #define GTEST_DECLARE_bool_(name) extern bool GTEST_FLAG(name) | |
817 #define GTEST_DECLARE_int32_(name) \ | |
818 extern ::testing::internal::Int32 GTEST_FLAG(name) | |
819 #define GTEST_DECLARE_string_(name) \ | |
820 extern ::testing::internal::String GTEST_FLAG(name) | |
821 | |
822 // Macros for defining flags. | |
823 #define GTEST_DEFINE_bool_(name, default_val, doc) \ | |
824 bool GTEST_FLAG(name) = (default_val) | |
825 #define GTEST_DEFINE_int32_(name, default_val, doc) \ | |
826 ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) | |
827 #define GTEST_DEFINE_string_(name, default_val, doc) \ | |
828 ::testing::internal::String GTEST_FLAG(name) = (default_val) | |
829 | |
830 // Parses 'str' for a 32-bit signed integer. If successful, writes the result | |
831 // to *value and returns true; otherwise leaves *value unchanged and returns | |
832 // false. | |
833 // TODO(chandlerc): Find a better way to refactor flag and environment parsing | |
834 // out of both gtest-port.cc and gtest.cc to avoid exporting this utility | |
835 // function. | |
836 bool ParseInt32(const Message& src_text, const char* str, Int32* value); | |
837 | |
838 // Parses a bool/Int32/string from the environment variable | |
839 // corresponding to the given Google Test flag. | |
840 bool BoolFromGTestEnv(const char* flag, bool default_val); | |
841 Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); | |
842 const char* StringFromGTestEnv(const char* flag, const char* default_val); | |
843 | |
844 } // namespace internal | |
845 } // namespace testing | |
846 | |
847 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | |
LEFT | RIGHT |