cppjieba_rb 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +3 -0
  3. data/README.md +1 -1
  4. data/Rakefile +2 -2
  5. data/cppjieba_rb.gemspec +4 -4
  6. data/lib/cppjieba_rb/version.rb +1 -1
  7. metadata +17 -135
  8. data/ext/cppjieba/.gitignore +0 -17
  9. data/ext/cppjieba/.travis.yml +0 -21
  10. data/ext/cppjieba/CMakeLists.txt +0 -28
  11. data/ext/cppjieba/ChangeLog.md +0 -236
  12. data/ext/cppjieba/README.md +0 -292
  13. data/ext/cppjieba/README_EN.md +0 -113
  14. data/ext/cppjieba/appveyor.yml +0 -32
  15. data/ext/cppjieba/deps/CMakeLists.txt +0 -1
  16. data/ext/cppjieba/deps/gtest/CMakeLists.txt +0 -5
  17. data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +0 -283
  18. data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +0 -230
  19. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +0 -1421
  20. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +0 -487
  21. data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +0 -796
  22. data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +0 -232
  23. data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +0 -176
  24. data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +0 -259
  25. data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +0 -2155
  26. data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +0 -358
  27. data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +0 -58
  28. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +0 -308
  29. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +0 -210
  30. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +0 -1226
  31. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +0 -233
  32. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +0 -4822
  33. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +0 -301
  34. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +0 -619
  35. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +0 -1788
  36. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +0 -350
  37. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +0 -968
  38. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +0 -336
  39. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +0 -3330
  40. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +0 -296
  41. data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
  42. data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +0 -681
  43. data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +0 -509
  44. data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
  45. data/ext/cppjieba/deps/gtest/src/gtest-all.cc +0 -48
  46. data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +0 -1234
  47. data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +0 -380
  48. data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +0 -1038
  49. data/ext/cppjieba/deps/gtest/src/gtest-port.cc +0 -746
  50. data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +0 -356
  51. data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +0 -110
  52. data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +0 -110
  53. data/ext/cppjieba/deps/gtest/src/gtest.cc +0 -4898
  54. data/ext/cppjieba/deps/gtest/src/gtest_main.cc +0 -39
  55. data/ext/cppjieba/deps/limonp/ArgvContext.hpp +0 -70
  56. data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +0 -49
  57. data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +0 -67
  58. data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +0 -65
  59. data/ext/cppjieba/deps/limonp/Closure.hpp +0 -206
  60. data/ext/cppjieba/deps/limonp/Colors.hpp +0 -31
  61. data/ext/cppjieba/deps/limonp/Condition.hpp +0 -38
  62. data/ext/cppjieba/deps/limonp/Config.hpp +0 -103
  63. data/ext/cppjieba/deps/limonp/FileLock.hpp +0 -74
  64. data/ext/cppjieba/deps/limonp/ForcePublic.hpp +0 -7
  65. data/ext/cppjieba/deps/limonp/LocalVector.hpp +0 -139
  66. data/ext/cppjieba/deps/limonp/Logging.hpp +0 -76
  67. data/ext/cppjieba/deps/limonp/Md5.hpp +0 -411
  68. data/ext/cppjieba/deps/limonp/MutexLock.hpp +0 -51
  69. data/ext/cppjieba/deps/limonp/NonCopyable.hpp +0 -21
  70. data/ext/cppjieba/deps/limonp/StdExtension.hpp +0 -159
  71. data/ext/cppjieba/deps/limonp/StringUtil.hpp +0 -365
  72. data/ext/cppjieba/deps/limonp/Thread.hpp +0 -44
  73. data/ext/cppjieba/deps/limonp/ThreadPool.hpp +0 -86
  74. data/ext/cppjieba/dict/README.md +0 -31
  75. data/ext/cppjieba/dict/hmm_model.utf8 +0 -34
  76. data/ext/cppjieba/dict/idf.utf8 +0 -258826
  77. data/ext/cppjieba/dict/jieba.dict.utf8 +0 -348982
  78. data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +0 -6653
  79. data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +0 -166
  80. data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +0 -259
  81. data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +0 -5222
  82. data/ext/cppjieba/dict/stop_words.utf8 +0 -1534
  83. data/ext/cppjieba/dict/user.dict.utf8 +0 -4
  84. data/ext/cppjieba/include/cppjieba/DictTrie.hpp +0 -277
  85. data/ext/cppjieba/include/cppjieba/FullSegment.hpp +0 -93
  86. data/ext/cppjieba/include/cppjieba/HMMModel.hpp +0 -129
  87. data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +0 -190
  88. data/ext/cppjieba/include/cppjieba/Jieba.hpp +0 -130
  89. data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +0 -153
  90. data/ext/cppjieba/include/cppjieba/MPSegment.hpp +0 -137
  91. data/ext/cppjieba/include/cppjieba/MixSegment.hpp +0 -109
  92. data/ext/cppjieba/include/cppjieba/PosTagger.hpp +0 -77
  93. data/ext/cppjieba/include/cppjieba/PreFilter.hpp +0 -54
  94. data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +0 -90
  95. data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +0 -46
  96. data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +0 -23
  97. data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +0 -190
  98. data/ext/cppjieba/include/cppjieba/Trie.hpp +0 -174
  99. data/ext/cppjieba/include/cppjieba/Unicode.hpp +0 -227
  100. data/ext/cppjieba/test/CMakeLists.txt +0 -5
  101. data/ext/cppjieba/test/demo.cpp +0 -80
  102. data/ext/cppjieba/test/load_test.cpp +0 -54
  103. data/ext/cppjieba/test/testdata/curl.res +0 -1
  104. data/ext/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +0 -109750
  105. data/ext/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +0 -34
  106. data/ext/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +0 -348982
  107. data/ext/cppjieba/test/testdata/jieba.dict.0.1.utf8 +0 -93
  108. data/ext/cppjieba/test/testdata/jieba.dict.0.utf8 +0 -93
  109. data/ext/cppjieba/test/testdata/jieba.dict.1.utf8 +0 -67
  110. data/ext/cppjieba/test/testdata/jieba.dict.2.utf8 +0 -64
  111. data/ext/cppjieba/test/testdata/load_test.urls +0 -2
  112. data/ext/cppjieba/test/testdata/review.100 +0 -100
  113. data/ext/cppjieba/test/testdata/review.100.res +0 -200
  114. data/ext/cppjieba/test/testdata/server.conf +0 -19
  115. data/ext/cppjieba/test/testdata/testlines.gbk +0 -9
  116. data/ext/cppjieba/test/testdata/testlines.utf8 +0 -8
  117. data/ext/cppjieba/test/testdata/userdict.2.utf8 +0 -1
  118. data/ext/cppjieba/test/testdata/userdict.english +0 -2
  119. data/ext/cppjieba/test/testdata/userdict.utf8 +0 -8
  120. data/ext/cppjieba/test/testdata/weicheng.utf8 +0 -247
  121. data/ext/cppjieba/test/unittest/CMakeLists.txt +0 -24
  122. data/ext/cppjieba/test/unittest/gtest_main.cpp +0 -39
  123. data/ext/cppjieba/test/unittest/jieba_test.cpp +0 -133
  124. data/ext/cppjieba/test/unittest/keyword_extractor_test.cpp +0 -79
  125. data/ext/cppjieba/test/unittest/pos_tagger_test.cpp +0 -41
  126. data/ext/cppjieba/test/unittest/pre_filter_test.cpp +0 -43
  127. data/ext/cppjieba/test/unittest/segments_test.cpp +0 -256
  128. data/ext/cppjieba/test/unittest/textrank_test.cpp +0 -86
  129. data/ext/cppjieba/test/unittest/trie_test.cpp +0 -177
  130. data/ext/cppjieba/test/unittest/unicode_test.cpp +0 -43
@@ -1,210 +0,0 @@
1
- // Copyright 2008, Google Inc.
2
- // All rights reserved.
3
- //
4
- // Redistribution and use in source and binary forms, with or without
5
- // modification, are permitted provided that the following conditions are
6
- // met:
7
- //
8
- // * Redistributions of source code must retain the above copyright
9
- // notice, this list of conditions and the following disclaimer.
10
- // * Redistributions in binary form must reproduce the above
11
- // copyright notice, this list of conditions and the following disclaimer
12
- // in the documentation and/or other materials provided with the
13
- // distribution.
14
- // * Neither the name of Google Inc. nor the names of its
15
- // contributors may be used to endorse or promote products derived from
16
- // this software without specific prior written permission.
17
- //
18
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- //
30
- // Author: keith.ray@gmail.com (Keith Ray)
31
- //
32
- // Google Test filepath utilities
33
- //
34
- // This header file declares classes and functions used internally by
35
- // Google Test. They are subject to change without notice.
36
- //
37
- // This file is #included in <gtest/internal/gtest-internal.h>.
38
- // Do not include this header file separately!
39
-
40
- #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
41
- #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
42
-
43
- #include "gtest/internal/gtest-string.h"
44
-
45
- namespace testing {
46
- namespace internal {
47
-
48
- // FilePath - a class for file and directory pathname manipulation which
49
- // handles platform-specific conventions (like the pathname separator).
50
- // Used for helper functions for naming files in a directory for xml output.
51
- // Except for Set methods, all methods are const or static, which provides an
52
- // "immutable value object" -- useful for peace of mind.
53
- // A FilePath with a value ending in a path separator ("like/this/") represents
54
- // a directory, otherwise it is assumed to represent a file. In either case,
55
- // it may or may not represent an actual file or directory in the file system.
56
- // Names are NOT checked for syntax correctness -- no checking for illegal
57
- // characters, malformed paths, etc.
58
-
59
- class GTEST_API_ FilePath {
60
- public:
61
- FilePath() : pathname_("") { }
62
- FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
63
-
64
- explicit FilePath(const char* pathname) : pathname_(pathname) {
65
- Normalize();
66
- }
67
-
68
- explicit FilePath(const String& pathname) : pathname_(pathname) {
69
- Normalize();
70
- }
71
-
72
- FilePath& operator=(const FilePath& rhs) {
73
- Set(rhs);
74
- return *this;
75
- }
76
-
77
- void Set(const FilePath& rhs) {
78
- pathname_ = rhs.pathname_;
79
- }
80
-
81
- String ToString() const { return pathname_; }
82
- const char* c_str() const { return pathname_.c_str(); }
83
-
84
- // Returns the current working directory, or "" if unsuccessful.
85
- static FilePath GetCurrentDir();
86
-
87
- // Given directory = "dir", base_name = "test", number = 0,
88
- // extension = "xml", returns "dir/test.xml". If number is greater
89
- // than zero (e.g., 12), returns "dir/test_12.xml".
90
- // On Windows platform, uses \ as the separator rather than /.
91
- static FilePath MakeFileName(const FilePath& directory,
92
- const FilePath& base_name,
93
- int number,
94
- const char* extension);
95
-
96
- // Given directory = "dir", relative_path = "test.xml",
97
- // returns "dir/test.xml".
98
- // On Windows, uses \ as the separator rather than /.
99
- static FilePath ConcatPaths(const FilePath& directory,
100
- const FilePath& relative_path);
101
-
102
- // Returns a pathname for a file that does not currently exist. The pathname
103
- // will be directory/base_name.extension or
104
- // directory/base_name_<number>.extension if directory/base_name.extension
105
- // already exists. The number will be incremented until a pathname is found
106
- // that does not already exist.
107
- // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
108
- // There could be a race condition if two or more processes are calling this
109
- // function at the same time -- they could both pick the same filename.
110
- static FilePath GenerateUniqueFileName(const FilePath& directory,
111
- const FilePath& base_name,
112
- const char* extension);
113
-
114
- // Returns true iff the path is NULL or "".
115
- bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; }
116
-
117
- // If input name has a trailing separator character, removes it and returns
118
- // the name, otherwise return the name string unmodified.
119
- // On Windows platform, uses \ as the separator, other platforms use /.
120
- FilePath RemoveTrailingPathSeparator() const;
121
-
122
- // Returns a copy of the FilePath with the directory part removed.
123
- // Example: FilePath("path/to/file").RemoveDirectoryName() returns
124
- // FilePath("file"). If there is no directory part ("just_a_file"), it returns
125
- // the FilePath unmodified. If there is no file part ("just_a_dir/") it
126
- // returns an empty FilePath ("").
127
- // On Windows platform, '\' is the path separator, otherwise it is '/'.
128
- FilePath RemoveDirectoryName() const;
129
-
130
- // RemoveFileName returns the directory path with the filename removed.
131
- // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
132
- // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
133
- // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
134
- // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
135
- // On Windows platform, '\' is the path separator, otherwise it is '/'.
136
- FilePath RemoveFileName() const;
137
-
138
- // Returns a copy of the FilePath with the case-insensitive extension removed.
139
- // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
140
- // FilePath("dir/file"). If a case-insensitive extension is not
141
- // found, returns a copy of the original FilePath.
142
- FilePath RemoveExtension(const char* extension) const;
143
-
144
- // Creates directories so that path exists. Returns true if successful or if
145
- // the directories already exist; returns false if unable to create
146
- // directories for any reason. Will also return false if the FilePath does
147
- // not represent a directory (that is, it doesn't end with a path separator).
148
- bool CreateDirectoriesRecursively() const;
149
-
150
- // Create the directory so that path exists. Returns true if successful or
151
- // if the directory already exists; returns false if unable to create the
152
- // directory for any reason, including if the parent directory does not
153
- // exist. Not named "CreateDirectory" because that's a macro on Windows.
154
- bool CreateFolder() const;
155
-
156
- // Returns true if FilePath describes something in the file-system,
157
- // either a file, directory, or whatever, and that something exists.
158
- bool FileOrDirectoryExists() const;
159
-
160
- // Returns true if pathname describes a directory in the file-system
161
- // that exists.
162
- bool DirectoryExists() const;
163
-
164
- // Returns true if FilePath ends with a path separator, which indicates that
165
- // it is intended to represent a directory. Returns false otherwise.
166
- // This does NOT check that a directory (or file) actually exists.
167
- bool IsDirectory() const;
168
-
169
- // Returns true if pathname describes a root directory. (Windows has one
170
- // root directory per disk drive.)
171
- bool IsRootDirectory() const;
172
-
173
- // Returns true if pathname describes an absolute path.
174
- bool IsAbsolutePath() const;
175
-
176
- private:
177
- // Replaces multiple consecutive separators with a single separator.
178
- // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
179
- // redundancies that might be in a pathname involving "." or "..".
180
- //
181
- // A pathname with multiple consecutive separators may occur either through
182
- // user error or as a result of some scripts or APIs that generate a pathname
183
- // with a trailing separator. On other platforms the same API or script
184
- // may NOT generate a pathname with a trailing "/". Then elsewhere that
185
- // pathname may have another "/" and pathname components added to it,
186
- // without checking for the separator already being there.
187
- // The script language and operating system may allow paths like "foo//bar"
188
- // but some of the functions in FilePath will not handle that correctly. In
189
- // particular, RemoveTrailingPathSeparator() only removes one separator, and
190
- // it is called in CreateDirectoriesRecursively() assuming that it will change
191
- // a pathname from directory syntax (trailing separator) to filename syntax.
192
- //
193
- // On Windows this method also replaces the alternate path separator '/' with
194
- // the primary path separator '\\', so that for example "bar\\/\\foo" becomes
195
- // "bar\\foo".
196
-
197
- void Normalize();
198
-
199
- // Returns a pointer to the last occurence of a valid path separator in
200
- // the FilePath. On Windows, for example, both '/' and '\' are valid path
201
- // separators. Returns NULL if no path separator was found.
202
- const char* FindLastPathSeparator() const;
203
-
204
- String pathname_;
205
- }; // class FilePath
206
-
207
- } // namespace internal
208
- } // namespace testing
209
-
210
- #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
@@ -1,1226 +0,0 @@
1
- // Copyright 2005, Google Inc.
2
- // All rights reserved.
3
- //
4
- // Redistribution and use in source and binary forms, with or without
5
- // modification, are permitted provided that the following conditions are
6
- // met:
7
- //
8
- // * Redistributions of source code must retain the above copyright
9
- // notice, this list of conditions and the following disclaimer.
10
- // * Redistributions in binary form must reproduce the above
11
- // copyright notice, this list of conditions and the following disclaimer
12
- // in the documentation and/or other materials provided with the
13
- // distribution.
14
- // * Neither the name of Google Inc. nor the names of its
15
- // contributors may be used to endorse or promote products derived from
16
- // this software without specific prior written permission.
17
- //
18
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- //
30
- // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
31
- //
32
- // The Google C++ Testing Framework (Google Test)
33
- //
34
- // This header file declares functions and macros used internally by
35
- // Google Test. They are subject to change without notice.
36
-
37
- #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
38
- #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
39
-
40
- #include "gtest/internal/gtest-port.h"
41
-
42
- #if GTEST_OS_LINUX
43
- # include <stdlib.h>
44
- # include <sys/types.h>
45
- # include <sys/wait.h>
46
- # include <unistd.h>
47
- #endif // GTEST_OS_LINUX
48
-
49
- #include <ctype.h>
50
- #include <string.h>
51
- #include <iomanip>
52
- #include <limits>
53
- #include <set>
54
-
55
- #include "gtest/internal/gtest-string.h"
56
- #include "gtest/internal/gtest-filepath.h"
57
- #include "gtest/internal/gtest-type-util.h"
58
-
59
- // Due to C++ preprocessor weirdness, we need double indirection to
60
- // concatenate two tokens when one of them is __LINE__. Writing
61
- //
62
- // foo ## __LINE__
63
- //
64
- // will result in the token foo__LINE__, instead of foo followed by
65
- // the current line number. For more details, see
66
- // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
67
- #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
68
- #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
69
-
70
- // Google Test defines the testing::Message class to allow construction of
71
- // test messages via the << operator. The idea is that anything
72
- // streamable to std::ostream can be streamed to a testing::Message.
73
- // This allows a user to use his own types in Google Test assertions by
74
- // overloading the << operator.
75
- //
76
- // util/gtl/stl_logging-inl.h overloads << for STL containers. These
77
- // overloads cannot be defined in the std namespace, as that will be
78
- // undefined behavior. Therefore, they are defined in the global
79
- // namespace instead.
80
- //
81
- // C++'s symbol lookup rule (i.e. Koenig lookup) says that these
82
- // overloads are visible in either the std namespace or the global
83
- // namespace, but not other namespaces, including the testing
84
- // namespace which Google Test's Message class is in.
85
- //
86
- // To allow STL containers (and other types that has a << operator
87
- // defined in the global namespace) to be used in Google Test assertions,
88
- // testing::Message must access the custom << operator from the global
89
- // namespace. Hence this helper function.
90
- //
91
- // Note: Jeffrey Yasskin suggested an alternative fix by "using
92
- // ::operator<<;" in the definition of Message's operator<<. That fix
93
- // doesn't require a helper function, but unfortunately doesn't
94
- // compile with MSVC.
95
- template <typename T>
96
- inline void GTestStreamToHelper(std::ostream* os, const T& val) {
97
- *os << val;
98
- }
99
-
100
- class ProtocolMessage;
101
- namespace proto2 { class Message; }
102
-
103
- namespace testing {
104
-
105
- // Forward declarations.
106
-
107
- class AssertionResult; // Result of an assertion.
108
- class Message; // Represents a failure message.
109
- class Test; // Represents a test.
110
- class TestInfo; // Information about a test.
111
- class TestPartResult; // Result of a test part.
112
- class UnitTest; // A collection of test cases.
113
-
114
- template <typename T>
115
- ::std::string PrintToString(const T& value);
116
-
117
- namespace internal {
118
-
119
- struct TraceInfo; // Information about a trace point.
120
- class ScopedTrace; // Implements scoped trace.
121
- class TestInfoImpl; // Opaque implementation of TestInfo
122
- class UnitTestImpl; // Opaque implementation of UnitTest
123
-
124
- // How many times InitGoogleTest() has been called.
125
- extern int g_init_gtest_count;
126
-
127
- // The text used in failure messages to indicate the start of the
128
- // stack trace.
129
- GTEST_API_ extern const char kStackTraceMarker[];
130
-
131
- // A secret type that Google Test users don't know about. It has no
132
- // definition on purpose. Therefore it's impossible to create a
133
- // Secret object, which is what we want.
134
- class Secret;
135
-
136
- // Two overloaded helpers for checking at compile time whether an
137
- // expression is a null pointer literal (i.e. NULL or any 0-valued
138
- // compile-time integral constant). Their return values have
139
- // different sizes, so we can use sizeof() to test which version is
140
- // picked by the compiler. These helpers have no implementations, as
141
- // we only need their signatures.
142
- //
143
- // Given IsNullLiteralHelper(x), the compiler will pick the first
144
- // version if x can be implicitly converted to Secret*, and pick the
145
- // second version otherwise. Since Secret is a secret and incomplete
146
- // type, the only expression a user can write that has type Secret* is
147
- // a null pointer literal. Therefore, we know that x is a null
148
- // pointer literal if and only if the first version is picked by the
149
- // compiler.
150
- char IsNullLiteralHelper(Secret* p);
151
- char (&IsNullLiteralHelper(...))[2]; // NOLINT
152
-
153
- // A compile-time bool constant that is true if and only if x is a
154
- // null pointer literal (i.e. NULL or any 0-valued compile-time
155
- // integral constant).
156
- #ifdef GTEST_ELLIPSIS_NEEDS_POD_
157
- // We lose support for NULL detection where the compiler doesn't like
158
- // passing non-POD classes through ellipsis (...).
159
- # define GTEST_IS_NULL_LITERAL_(x) false
160
- #else
161
- # define GTEST_IS_NULL_LITERAL_(x) \
162
- (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
163
- #endif // GTEST_ELLIPSIS_NEEDS_POD_
164
-
165
- // Appends the user-supplied message to the Google-Test-generated message.
166
- GTEST_API_ String AppendUserMessage(const String& gtest_msg,
167
- const Message& user_msg);
168
-
169
- // A helper class for creating scoped traces in user programs.
170
- class GTEST_API_ ScopedTrace {
171
- public:
172
- // The c'tor pushes the given source file location and message onto
173
- // a trace stack maintained by Google Test.
174
- ScopedTrace(const char* file, int line, const Message& message);
175
-
176
- // The d'tor pops the info pushed by the c'tor.
177
- //
178
- // Note that the d'tor is not virtual in order to be efficient.
179
- // Don't inherit from ScopedTrace!
180
- ~ScopedTrace();
181
-
182
- private:
183
- GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
184
- } GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its
185
- // c'tor and d'tor. Therefore it doesn't
186
- // need to be used otherwise.
187
-
188
- // Converts a streamable value to a String. A NULL pointer is
189
- // converted to "(null)". When the input value is a ::string,
190
- // ::std::string, ::wstring, or ::std::wstring object, each NUL
191
- // character in it is replaced with "\\0".
192
- // Declared here but defined in gtest.h, so that it has access
193
- // to the definition of the Message class, required by the ARM
194
- // compiler.
195
- template <typename T>
196
- String StreamableToString(const T& streamable);
197
-
198
- // The Symbian compiler has a bug that prevents it from selecting the
199
- // correct overload of FormatForComparisonFailureMessage (see below)
200
- // unless we pass the first argument by reference. If we do that,
201
- // however, Visual Age C++ 10.1 generates a compiler error. Therefore
202
- // we only apply the work-around for Symbian.
203
- #if defined(__SYMBIAN32__)
204
- # define GTEST_CREF_WORKAROUND_ const&
205
- #else
206
- # define GTEST_CREF_WORKAROUND_
207
- #endif
208
-
209
- // When this operand is a const char* or char*, if the other operand
210
- // is a ::std::string or ::string, we print this operand as a C string
211
- // rather than a pointer (we do the same for wide strings); otherwise
212
- // we print it as a pointer to be safe.
213
-
214
- // This internal macro is used to avoid duplicated code.
215
- #define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\
216
- inline String FormatForComparisonFailureMessage(\
217
- operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
218
- const operand2_type& /*operand2*/) {\
219
- return operand1_printer(str);\
220
- }\
221
- inline String FormatForComparisonFailureMessage(\
222
- const operand2_type::value_type* GTEST_CREF_WORKAROUND_ str, \
223
- const operand2_type& /*operand2*/) {\
224
- return operand1_printer(str);\
225
- }
226
-
227
- GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)
228
- #if GTEST_HAS_STD_WSTRING
229
- GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted)
230
- #endif // GTEST_HAS_STD_WSTRING
231
-
232
- #if GTEST_HAS_GLOBAL_STRING
233
- GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted)
234
- #endif // GTEST_HAS_GLOBAL_STRING
235
- #if GTEST_HAS_GLOBAL_WSTRING
236
- GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)
237
- #endif // GTEST_HAS_GLOBAL_WSTRING
238
-
239
- #undef GTEST_FORMAT_IMPL_
240
-
241
- // The next four overloads handle the case where the operand being
242
- // printed is a char/wchar_t pointer and the other operand is not a
243
- // string/wstring object. In such cases, we just print the operand as
244
- // a pointer to be safe.
245
- #define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \
246
- template <typename T> \
247
- String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_ p, \
248
- const T&) { \
249
- return PrintToString(static_cast<const void*>(p)); \
250
- }
251
-
252
- GTEST_FORMAT_CHAR_PTR_IMPL_(char)
253
- GTEST_FORMAT_CHAR_PTR_IMPL_(const char)
254
- GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t)
255
- GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)
256
-
257
- #undef GTEST_FORMAT_CHAR_PTR_IMPL_
258
-
259
- // Constructs and returns the message for an equality assertion
260
- // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
261
- //
262
- // The first four parameters are the expressions used in the assertion
263
- // and their values, as strings. For example, for ASSERT_EQ(foo, bar)
264
- // where foo is 5 and bar is 6, we have:
265
- //
266
- // expected_expression: "foo"
267
- // actual_expression: "bar"
268
- // expected_value: "5"
269
- // actual_value: "6"
270
- //
271
- // The ignoring_case parameter is true iff the assertion is a
272
- // *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
273
- // be inserted into the message.
274
- GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
275
- const char* actual_expression,
276
- const String& expected_value,
277
- const String& actual_value,
278
- bool ignoring_case);
279
-
280
- // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
281
- GTEST_API_ String GetBoolAssertionFailureMessage(
282
- const AssertionResult& assertion_result,
283
- const char* expression_text,
284
- const char* actual_predicate_value,
285
- const char* expected_predicate_value);
286
-
287
- // This template class represents an IEEE floating-point number
288
- // (either single-precision or double-precision, depending on the
289
- // template parameters).
290
- //
291
- // The purpose of this class is to do more sophisticated number
292
- // comparison. (Due to round-off error, etc, it's very unlikely that
293
- // two floating-points will be equal exactly. Hence a naive
294
- // comparison by the == operation often doesn't work.)
295
- //
296
- // Format of IEEE floating-point:
297
- //
298
- // The most-significant bit being the leftmost, an IEEE
299
- // floating-point looks like
300
- //
301
- // sign_bit exponent_bits fraction_bits
302
- //
303
- // Here, sign_bit is a single bit that designates the sign of the
304
- // number.
305
- //
306
- // For float, there are 8 exponent bits and 23 fraction bits.
307
- //
308
- // For double, there are 11 exponent bits and 52 fraction bits.
309
- //
310
- // More details can be found at
311
- // http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
312
- //
313
- // Template parameter:
314
- //
315
- // RawType: the raw floating-point type (either float or double)
316
- template <typename RawType>
317
- class FloatingPoint {
318
- public:
319
- // Defines the unsigned integer type that has the same size as the
320
- // floating point number.
321
- typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
322
-
323
- // Constants.
324
-
325
- // # of bits in a number.
326
- static const size_t kBitCount = 8*sizeof(RawType);
327
-
328
- // # of fraction bits in a number.
329
- static const size_t kFractionBitCount =
330
- std::numeric_limits<RawType>::digits - 1;
331
-
332
- // # of exponent bits in a number.
333
- static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
334
-
335
- // The mask for the sign bit.
336
- static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
337
-
338
- // The mask for the fraction bits.
339
- static const Bits kFractionBitMask =
340
- ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
341
-
342
- // The mask for the exponent bits.
343
- static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
344
-
345
- // How many ULP's (Units in the Last Place) we want to tolerate when
346
- // comparing two numbers. The larger the value, the more error we
347
- // allow. A 0 value means that two numbers must be exactly the same
348
- // to be considered equal.
349
- //
350
- // The maximum error of a single floating-point operation is 0.5
351
- // units in the last place. On Intel CPU's, all floating-point
352
- // calculations are done with 80-bit precision, while double has 64
353
- // bits. Therefore, 4 should be enough for ordinary use.
354
- //
355
- // See the following article for more details on ULP:
356
- // http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm.
357
- static const size_t kMaxUlps = 4;
358
-
359
- // Constructs a FloatingPoint from a raw floating-point number.
360
- //
361
- // On an Intel CPU, passing a non-normalized NAN (Not a Number)
362
- // around may change its bits, although the new value is guaranteed
363
- // to be also a NAN. Therefore, don't expect this constructor to
364
- // preserve the bits in x when x is a NAN.
365
- explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
366
-
367
- // Static methods
368
-
369
- // Reinterprets a bit pattern as a floating-point number.
370
- //
371
- // This function is needed to test the AlmostEquals() method.
372
- static RawType ReinterpretBits(const Bits bits) {
373
- FloatingPoint fp(0);
374
- fp.u_.bits_ = bits;
375
- return fp.u_.value_;
376
- }
377
-
378
- // Returns the floating-point number that represent positive infinity.
379
- static RawType Infinity() {
380
- return ReinterpretBits(kExponentBitMask);
381
- }
382
-
383
- // Non-static methods
384
-
385
- // Returns the bits that represents this number.
386
- const Bits &bits() const { return u_.bits_; }
387
-
388
- // Returns the exponent bits of this number.
389
- Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
390
-
391
- // Returns the fraction bits of this number.
392
- Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
393
-
394
- // Returns the sign bit of this number.
395
- Bits sign_bit() const { return kSignBitMask & u_.bits_; }
396
-
397
- // Returns true iff this is NAN (not a number).
398
- bool is_nan() const {
399
- // It's a NAN if the exponent bits are all ones and the fraction
400
- // bits are not entirely zeros.
401
- return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
402
- }
403
-
404
- // Returns true iff this number is at most kMaxUlps ULP's away from
405
- // rhs. In particular, this function:
406
- //
407
- // - returns false if either number is (or both are) NAN.
408
- // - treats really large numbers as almost equal to infinity.
409
- // - thinks +0.0 and -0.0 are 0 DLP's apart.
410
- bool AlmostEquals(const FloatingPoint& rhs) const {
411
- // The IEEE standard says that any comparison operation involving
412
- // a NAN must return false.
413
- if (is_nan() || rhs.is_nan()) return false;
414
-
415
- return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
416
- <= kMaxUlps;
417
- }
418
-
419
- private:
420
- // The data type used to store the actual floating-point number.
421
- union FloatingPointUnion {
422
- RawType value_; // The raw floating-point number.
423
- Bits bits_; // The bits that represent the number.
424
- };
425
-
426
- // Converts an integer from the sign-and-magnitude representation to
427
- // the biased representation. More precisely, let N be 2 to the
428
- // power of (kBitCount - 1), an integer x is represented by the
429
- // unsigned number x + N.
430
- //
431
- // For instance,
432
- //
433
- // -N + 1 (the most negative number representable using
434
- // sign-and-magnitude) is represented by 1;
435
- // 0 is represented by N; and
436
- // N - 1 (the biggest number representable using
437
- // sign-and-magnitude) is represented by 2N - 1.
438
- //
439
- // Read http://en.wikipedia.org/wiki/Signed_number_representations
440
- // for more details on signed number representations.
441
- static Bits SignAndMagnitudeToBiased(const Bits &sam) {
442
- if (kSignBitMask & sam) {
443
- // sam represents a negative number.
444
- return ~sam + 1;
445
- } else {
446
- // sam represents a positive number.
447
- return kSignBitMask | sam;
448
- }
449
- }
450
-
451
- // Given two numbers in the sign-and-magnitude representation,
452
- // returns the distance between them as an unsigned number.
453
- static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
454
- const Bits &sam2) {
455
- const Bits biased1 = SignAndMagnitudeToBiased(sam1);
456
- const Bits biased2 = SignAndMagnitudeToBiased(sam2);
457
- return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
458
- }
459
-
460
- FloatingPointUnion u_;
461
- };
462
-
463
- // Typedefs the instances of the FloatingPoint template class that we
464
- // care to use.
465
- typedef FloatingPoint<float> Float;
466
- typedef FloatingPoint<double> Double;
467
-
468
- // In order to catch the mistake of putting tests that use different
469
- // test fixture classes in the same test case, we need to assign
470
- // unique IDs to fixture classes and compare them. The TypeId type is
471
- // used to hold such IDs. The user should treat TypeId as an opaque
472
- // type: the only operation allowed on TypeId values is to compare
473
- // them for equality using the == operator.
474
- typedef const void* TypeId;
475
-
476
- template <typename T>
477
- class TypeIdHelper {
478
- public:
479
- // dummy_ must not have a const type. Otherwise an overly eager
480
- // compiler (e.g. MSVC 7.1 & 8.0) may try to merge
481
- // TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
482
- static bool dummy_;
483
- };
484
-
485
- template <typename T>
486
- bool TypeIdHelper<T>::dummy_ = false;
487
-
488
- // GetTypeId<T>() returns the ID of type T. Different values will be
489
- // returned for different types. Calling the function twice with the
490
- // same type argument is guaranteed to return the same ID.
491
- template <typename T>
492
- TypeId GetTypeId() {
493
- // The compiler is required to allocate a different
494
- // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
495
- // the template. Therefore, the address of dummy_ is guaranteed to
496
- // be unique.
497
- return &(TypeIdHelper<T>::dummy_);
498
- }
499
-
500
- // Returns the type ID of ::testing::Test. Always call this instead
501
- // of GetTypeId< ::testing::Test>() to get the type ID of
502
- // ::testing::Test, as the latter may give the wrong result due to a
503
- // suspected linker bug when compiling Google Test as a Mac OS X
504
- // framework.
505
- GTEST_API_ TypeId GetTestTypeId();
506
-
507
- // Defines the abstract factory interface that creates instances
508
- // of a Test object.
509
- class TestFactoryBase {
510
- public:
511
- virtual ~TestFactoryBase() {}
512
-
513
- // Creates a test instance to run. The instance is both created and destroyed
514
- // within TestInfoImpl::Run()
515
- virtual Test* CreateTest() = 0;
516
-
517
- protected:
518
- TestFactoryBase() {}
519
-
520
- private:
521
- GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
522
- };
523
-
524
- // This class provides implementation of TeastFactoryBase interface.
525
- // It is used in TEST and TEST_F macros.
526
- template <class TestClass>
527
- class TestFactoryImpl : public TestFactoryBase {
528
- public:
529
- virtual Test* CreateTest() { return new TestClass; }
530
- };
531
-
532
- #if GTEST_OS_WINDOWS
533
-
534
- // Predicate-formatters for implementing the HRESULT checking macros
535
- // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
536
- // We pass a long instead of HRESULT to avoid causing an
537
- // include dependency for the HRESULT type.
538
- GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
539
- long hr); // NOLINT
540
- GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
541
- long hr); // NOLINT
542
-
543
- #endif // GTEST_OS_WINDOWS
544
-
545
- // Types of SetUpTestCase() and TearDownTestCase() functions.
546
- typedef void (*SetUpTestCaseFunc)();
547
- typedef void (*TearDownTestCaseFunc)();
548
-
549
- // Creates a new TestInfo object and registers it with Google Test;
550
- // returns the created object.
551
- //
552
- // Arguments:
553
- //
554
- // test_case_name: name of the test case
555
- // name: name of the test
556
- // type_param the name of the test's type parameter, or NULL if
557
- // this is not a typed or a type-parameterized test.
558
- // value_param text representation of the test's value parameter,
559
- // or NULL if this is not a type-parameterized test.
560
- // fixture_class_id: ID of the test fixture class
561
- // set_up_tc: pointer to the function that sets up the test case
562
- // tear_down_tc: pointer to the function that tears down the test case
563
- // factory: pointer to the factory that creates a test object.
564
- // The newly created TestInfo instance will assume
565
- // ownership of the factory object.
566
- GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
567
- const char* test_case_name, const char* name,
568
- const char* type_param,
569
- const char* value_param,
570
- TypeId fixture_class_id,
571
- SetUpTestCaseFunc set_up_tc,
572
- TearDownTestCaseFunc tear_down_tc,
573
- TestFactoryBase* factory);
574
-
575
- // If *pstr starts with the given prefix, modifies *pstr to be right
576
- // past the prefix and returns true; otherwise leaves *pstr unchanged
577
- // and returns false. None of pstr, *pstr, and prefix can be NULL.
578
- GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
579
-
580
- #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
581
-
582
- // State of the definition of a type-parameterized test case.
583
- class GTEST_API_ TypedTestCasePState {
584
- public:
585
- TypedTestCasePState() : registered_(false) {}
586
-
587
- // Adds the given test name to defined_test_names_ and return true
588
- // if the test case hasn't been registered; otherwise aborts the
589
- // program.
590
- bool AddTestName(const char* file, int line, const char* case_name,
591
- const char* test_name) {
592
- if (registered_) {
593
- fprintf(stderr, "%s Test %s must be defined before "
594
- "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
595
- FormatFileLocation(file, line).c_str(), test_name, case_name);
596
- fflush(stderr);
597
- posix::Abort();
598
- }
599
- defined_test_names_.insert(test_name);
600
- return true;
601
- }
602
-
603
- // Verifies that registered_tests match the test names in
604
- // defined_test_names_; returns registered_tests if successful, or
605
- // aborts the program otherwise.
606
- const char* VerifyRegisteredTestNames(
607
- const char* file, int line, const char* registered_tests);
608
-
609
- private:
610
- bool registered_;
611
- ::std::set<const char*> defined_test_names_;
612
- };
613
-
614
- // Skips to the first non-space char after the first comma in 'str';
615
- // returns NULL if no comma is found in 'str'.
616
- inline const char* SkipComma(const char* str) {
617
- const char* comma = strchr(str, ',');
618
- if (comma == NULL) {
619
- return NULL;
620
- }
621
- while (IsSpace(*(++comma))) {}
622
- return comma;
623
- }
624
-
625
- // Returns the prefix of 'str' before the first comma in it; returns
626
- // the entire string if it contains no comma.
627
- inline String GetPrefixUntilComma(const char* str) {
628
- const char* comma = strchr(str, ',');
629
- return comma == NULL ? String(str) : String(str, comma - str);
630
- }
631
-
632
- // TypeParameterizedTest<Fixture, TestSel, Types>::Register()
633
- // registers a list of type-parameterized tests with Google Test. The
634
- // return value is insignificant - we just need to return something
635
- // such that we can call this function in a namespace scope.
636
- //
637
- // Implementation note: The GTEST_TEMPLATE_ macro declares a template
638
- // template parameter. It's defined in gtest-type-util.h.
639
- template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
640
- class TypeParameterizedTest {
641
- public:
642
- // 'index' is the index of the test in the type list 'Types'
643
- // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
644
- // Types). Valid values for 'index' are [0, N - 1] where N is the
645
- // length of Types.
646
- static bool Register(const char* prefix, const char* case_name,
647
- const char* test_names, int index) {
648
- typedef typename Types::Head Type;
649
- typedef Fixture<Type> FixtureClass;
650
- typedef typename GTEST_BIND_(TestSel, Type) TestClass;
651
-
652
- // First, registers the first type-parameterized test in the type
653
- // list.
654
- MakeAndRegisterTestInfo(
655
- String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/",
656
- case_name, index).c_str(),
657
- GetPrefixUntilComma(test_names).c_str(),
658
- GetTypeName<Type>().c_str(),
659
- NULL, // No value parameter.
660
- GetTypeId<FixtureClass>(),
661
- TestClass::SetUpTestCase,
662
- TestClass::TearDownTestCase,
663
- new TestFactoryImpl<TestClass>);
664
-
665
- // Next, recurses (at compile time) with the tail of the type list.
666
- return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
667
- ::Register(prefix, case_name, test_names, index + 1);
668
- }
669
- };
670
-
671
- // The base case for the compile time recursion.
672
- template <GTEST_TEMPLATE_ Fixture, class TestSel>
673
- class TypeParameterizedTest<Fixture, TestSel, Types0> {
674
- public:
675
- static bool Register(const char* /*prefix*/, const char* /*case_name*/,
676
- const char* /*test_names*/, int /*index*/) {
677
- return true;
678
- }
679
- };
680
-
681
- // TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
682
- // registers *all combinations* of 'Tests' and 'Types' with Google
683
- // Test. The return value is insignificant - we just need to return
684
- // something such that we can call this function in a namespace scope.
685
- template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
686
- class TypeParameterizedTestCase {
687
- public:
688
- static bool Register(const char* prefix, const char* case_name,
689
- const char* test_names) {
690
- typedef typename Tests::Head Head;
691
-
692
- // First, register the first test in 'Test' for each type in 'Types'.
693
- TypeParameterizedTest<Fixture, Head, Types>::Register(
694
- prefix, case_name, test_names, 0);
695
-
696
- // Next, recurses (at compile time) with the tail of the test list.
697
- return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
698
- ::Register(prefix, case_name, SkipComma(test_names));
699
- }
700
- };
701
-
702
- // The base case for the compile time recursion.
703
- template <GTEST_TEMPLATE_ Fixture, typename Types>
704
- class TypeParameterizedTestCase<Fixture, Templates0, Types> {
705
- public:
706
- static bool Register(const char* /*prefix*/, const char* /*case_name*/,
707
- const char* /*test_names*/) {
708
- return true;
709
- }
710
- };
711
-
712
- #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
713
-
714
- // Returns the current OS stack trace as a String.
715
- //
716
- // The maximum number of stack frames to be included is specified by
717
- // the gtest_stack_trace_depth flag. The skip_count parameter
718
- // specifies the number of top frames to be skipped, which doesn't
719
- // count against the number of frames to be included.
720
- //
721
- // For example, if Foo() calls Bar(), which in turn calls
722
- // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
723
- // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
724
- GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,
725
- int skip_count);
726
-
727
- // Helpers for suppressing warnings on unreachable code or constant
728
- // condition.
729
-
730
- // Always returns true.
731
- GTEST_API_ bool AlwaysTrue();
732
-
733
- // Always returns false.
734
- inline bool AlwaysFalse() { return !AlwaysTrue(); }
735
-
736
- // Helper for suppressing false warning from Clang on a const char*
737
- // variable declared in a conditional expression always being NULL in
738
- // the else branch.
739
- struct GTEST_API_ ConstCharPtr {
740
- ConstCharPtr(const char* str) : value(str) {}
741
- operator bool() const { return true; }
742
- const char* value;
743
- };
744
-
745
- // A simple Linear Congruential Generator for generating random
746
- // numbers with a uniform distribution. Unlike rand() and srand(), it
747
- // doesn't use global state (and therefore can't interfere with user
748
- // code). Unlike rand_r(), it's portable. An LCG isn't very random,
749
- // but it's good enough for our purposes.
750
- class GTEST_API_ Random {
751
- public:
752
- static const UInt32 kMaxRange = 1u << 31;
753
-
754
- explicit Random(UInt32 seed) : state_(seed) {}
755
-
756
- void Reseed(UInt32 seed) { state_ = seed; }
757
-
758
- // Generates a random number from [0, range). Crashes if 'range' is
759
- // 0 or greater than kMaxRange.
760
- UInt32 Generate(UInt32 range);
761
-
762
- private:
763
- UInt32 state_;
764
- GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
765
- };
766
-
767
- // Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
768
- // compiler error iff T1 and T2 are different types.
769
- template <typename T1, typename T2>
770
- struct CompileAssertTypesEqual;
771
-
772
- template <typename T>
773
- struct CompileAssertTypesEqual<T, T> {
774
- };
775
-
776
- // Removes the reference from a type if it is a reference type,
777
- // otherwise leaves it unchanged. This is the same as
778
- // tr1::remove_reference, which is not widely available yet.
779
- template <typename T>
780
- struct RemoveReference { typedef T type; }; // NOLINT
781
- template <typename T>
782
- struct RemoveReference<T&> { typedef T type; }; // NOLINT
783
-
784
- // A handy wrapper around RemoveReference that works when the argument
785
- // T depends on template parameters.
786
- #define GTEST_REMOVE_REFERENCE_(T) \
787
- typename ::testing::internal::RemoveReference<T>::type
788
-
789
- // Removes const from a type if it is a const type, otherwise leaves
790
- // it unchanged. This is the same as tr1::remove_const, which is not
791
- // widely available yet.
792
- template <typename T>
793
- struct RemoveConst { typedef T type; }; // NOLINT
794
- template <typename T>
795
- struct RemoveConst<const T> { typedef T type; }; // NOLINT
796
-
797
- // MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
798
- // definition to fail to remove the const in 'const int[3]' and 'const
799
- // char[3][4]'. The following specialization works around the bug.
800
- // However, it causes trouble with GCC and thus needs to be
801
- // conditionally compiled.
802
- #if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
803
- template <typename T, size_t N>
804
- struct RemoveConst<const T[N]> {
805
- typedef typename RemoveConst<T>::type type[N];
806
- };
807
- #endif
808
-
809
- // A handy wrapper around RemoveConst that works when the argument
810
- // T depends on template parameters.
811
- #define GTEST_REMOVE_CONST_(T) \
812
- typename ::testing::internal::RemoveConst<T>::type
813
-
814
- // Turns const U&, U&, const U, and U all into U.
815
- #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
816
- GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
817
-
818
- // Adds reference to a type if it is not a reference type,
819
- // otherwise leaves it unchanged. This is the same as
820
- // tr1::add_reference, which is not widely available yet.
821
- template <typename T>
822
- struct AddReference { typedef T& type; }; // NOLINT
823
- template <typename T>
824
- struct AddReference<T&> { typedef T& type; }; // NOLINT
825
-
826
- // A handy wrapper around AddReference that works when the argument T
827
- // depends on template parameters.
828
- #define GTEST_ADD_REFERENCE_(T) \
829
- typename ::testing::internal::AddReference<T>::type
830
-
831
- // Adds a reference to const on top of T as necessary. For example,
832
- // it transforms
833
- //
834
- // char ==> const char&
835
- // const char ==> const char&
836
- // char& ==> const char&
837
- // const char& ==> const char&
838
- //
839
- // The argument T must depend on some template parameters.
840
- #define GTEST_REFERENCE_TO_CONST_(T) \
841
- GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
842
-
843
- // ImplicitlyConvertible<From, To>::value is a compile-time bool
844
- // constant that's true iff type From can be implicitly converted to
845
- // type To.
846
- template <typename From, typename To>
847
- class ImplicitlyConvertible {
848
- private:
849
- // We need the following helper functions only for their types.
850
- // They have no implementations.
851
-
852
- // MakeFrom() is an expression whose type is From. We cannot simply
853
- // use From(), as the type From may not have a public default
854
- // constructor.
855
- static From MakeFrom();
856
-
857
- // These two functions are overloaded. Given an expression
858
- // Helper(x), the compiler will pick the first version if x can be
859
- // implicitly converted to type To; otherwise it will pick the
860
- // second version.
861
- //
862
- // The first version returns a value of size 1, and the second
863
- // version returns a value of size 2. Therefore, by checking the
864
- // size of Helper(x), which can be done at compile time, we can tell
865
- // which version of Helper() is used, and hence whether x can be
866
- // implicitly converted to type To.
867
- static char Helper(To);
868
- static char (&Helper(...))[2]; // NOLINT
869
-
870
- // We have to put the 'public' section after the 'private' section,
871
- // or MSVC refuses to compile the code.
872
- public:
873
- // MSVC warns about implicitly converting from double to int for
874
- // possible loss of data, so we need to temporarily disable the
875
- // warning.
876
- #ifdef _MSC_VER
877
- # pragma warning(push) // Saves the current warning state.
878
- # pragma warning(disable:4244) // Temporarily disables warning 4244.
879
-
880
- static const bool value =
881
- sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
882
- # pragma warning(pop) // Restores the warning state.
883
- #elif defined(__BORLANDC__)
884
- // C++Builder cannot use member overload resolution during template
885
- // instantiation. The simplest workaround is to use its C++0x type traits
886
- // functions (C++Builder 2009 and above only).
887
- static const bool value = __is_convertible(From, To);
888
- #else
889
- static const bool value =
890
- sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
891
- #endif // _MSV_VER
892
- };
893
- template <typename From, typename To>
894
- const bool ImplicitlyConvertible<From, To>::value;
895
-
896
- // IsAProtocolMessage<T>::value is a compile-time bool constant that's
897
- // true iff T is type ProtocolMessage, proto2::Message, or a subclass
898
- // of those.
899
- template <typename T>
900
- struct IsAProtocolMessage
901
- : public bool_constant<
902
- ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
903
- ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
904
- };
905
-
906
- // When the compiler sees expression IsContainerTest<C>(0), if C is an
907
- // STL-style container class, the first overload of IsContainerTest
908
- // will be viable (since both C::iterator* and C::const_iterator* are
909
- // valid types and NULL can be implicitly converted to them). It will
910
- // be picked over the second overload as 'int' is a perfect match for
911
- // the type of argument 0. If C::iterator or C::const_iterator is not
912
- // a valid type, the first overload is not viable, and the second
913
- // overload will be picked. Therefore, we can determine whether C is
914
- // a container class by checking the type of IsContainerTest<C>(0).
915
- // The value of the expression is insignificant.
916
- //
917
- // Note that we look for both C::iterator and C::const_iterator. The
918
- // reason is that C++ injects the name of a class as a member of the
919
- // class itself (e.g. you can refer to class iterator as either
920
- // 'iterator' or 'iterator::iterator'). If we look for C::iterator
921
- // only, for example, we would mistakenly think that a class named
922
- // iterator is an STL container.
923
- //
924
- // Also note that the simpler approach of overloading
925
- // IsContainerTest(typename C::const_iterator*) and
926
- // IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
927
- typedef int IsContainer;
928
- template <class C>
929
- IsContainer IsContainerTest(int /* dummy */,
930
- typename C::iterator* /* it */ = NULL,
931
- typename C::const_iterator* /* const_it */ = NULL) {
932
- return 0;
933
- }
934
-
935
- typedef char IsNotContainer;
936
- template <class C>
937
- IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
938
-
939
- // EnableIf<condition>::type is void when 'Cond' is true, and
940
- // undefined when 'Cond' is false. To use SFINAE to make a function
941
- // overload only apply when a particular expression is true, add
942
- // "typename EnableIf<expression>::type* = 0" as the last parameter.
943
- template<bool> struct EnableIf;
944
- template<> struct EnableIf<true> { typedef void type; }; // NOLINT
945
-
946
- // Utilities for native arrays.
947
-
948
- // ArrayEq() compares two k-dimensional native arrays using the
949
- // elements' operator==, where k can be any integer >= 0. When k is
950
- // 0, ArrayEq() degenerates into comparing a single pair of values.
951
-
952
- template <typename T, typename U>
953
- bool ArrayEq(const T* lhs, size_t size, const U* rhs);
954
-
955
- // This generic version is used when k is 0.
956
- template <typename T, typename U>
957
- inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
958
-
959
- // This overload is used when k >= 1.
960
- template <typename T, typename U, size_t N>
961
- inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
962
- return internal::ArrayEq(lhs, N, rhs);
963
- }
964
-
965
- // This helper reduces code bloat. If we instead put its logic inside
966
- // the previous ArrayEq() function, arrays with different sizes would
967
- // lead to different copies of the template code.
968
- template <typename T, typename U>
969
- bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
970
- for (size_t i = 0; i != size; i++) {
971
- if (!internal::ArrayEq(lhs[i], rhs[i]))
972
- return false;
973
- }
974
- return true;
975
- }
976
-
977
- // Finds the first element in the iterator range [begin, end) that
978
- // equals elem. Element may be a native array type itself.
979
- template <typename Iter, typename Element>
980
- Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
981
- for (Iter it = begin; it != end; ++it) {
982
- if (internal::ArrayEq(*it, elem))
983
- return it;
984
- }
985
- return end;
986
- }
987
-
988
- // CopyArray() copies a k-dimensional native array using the elements'
989
- // operator=, where k can be any integer >= 0. When k is 0,
990
- // CopyArray() degenerates into copying a single value.
991
-
992
- template <typename T, typename U>
993
- void CopyArray(const T* from, size_t size, U* to);
994
-
995
- // This generic version is used when k is 0.
996
- template <typename T, typename U>
997
- inline void CopyArray(const T& from, U* to) { *to = from; }
998
-
999
- // This overload is used when k >= 1.
1000
- template <typename T, typename U, size_t N>
1001
- inline void CopyArray(const T(&from)[N], U(*to)[N]) {
1002
- internal::CopyArray(from, N, *to);
1003
- }
1004
-
1005
- // This helper reduces code bloat. If we instead put its logic inside
1006
- // the previous CopyArray() function, arrays with different sizes
1007
- // would lead to different copies of the template code.
1008
- template <typename T, typename U>
1009
- void CopyArray(const T* from, size_t size, U* to) {
1010
- for (size_t i = 0; i != size; i++) {
1011
- internal::CopyArray(from[i], to + i);
1012
- }
1013
- }
1014
-
1015
- // The relation between an NativeArray object (see below) and the
1016
- // native array it represents.
1017
- enum RelationToSource {
1018
- kReference, // The NativeArray references the native array.
1019
- kCopy // The NativeArray makes a copy of the native array and
1020
- // owns the copy.
1021
- };
1022
-
1023
- // Adapts a native array to a read-only STL-style container. Instead
1024
- // of the complete STL container concept, this adaptor only implements
1025
- // members useful for Google Mock's container matchers. New members
1026
- // should be added as needed. To simplify the implementation, we only
1027
- // support Element being a raw type (i.e. having no top-level const or
1028
- // reference modifier). It's the client's responsibility to satisfy
1029
- // this requirement. Element can be an array type itself (hence
1030
- // multi-dimensional arrays are supported).
1031
- template <typename Element>
1032
- class NativeArray {
1033
- public:
1034
- // STL-style container typedefs.
1035
- typedef Element value_type;
1036
- typedef Element* iterator;
1037
- typedef const Element* const_iterator;
1038
-
1039
- // Constructs from a native array.
1040
- NativeArray(const Element* array, size_t count, RelationToSource relation) {
1041
- Init(array, count, relation);
1042
- }
1043
-
1044
- // Copy constructor.
1045
- NativeArray(const NativeArray& rhs) {
1046
- Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
1047
- }
1048
-
1049
- ~NativeArray() {
1050
- // Ensures that the user doesn't instantiate NativeArray with a
1051
- // const or reference type.
1052
- static_cast<void>(StaticAssertTypeEqHelper<Element,
1053
- GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
1054
- if (relation_to_source_ == kCopy)
1055
- delete[] array_;
1056
- }
1057
-
1058
- // STL-style container methods.
1059
- size_t size() const { return size_; }
1060
- const_iterator begin() const { return array_; }
1061
- const_iterator end() const { return array_ + size_; }
1062
- bool operator==(const NativeArray& rhs) const {
1063
- return size() == rhs.size() &&
1064
- ArrayEq(begin(), size(), rhs.begin());
1065
- }
1066
-
1067
- private:
1068
- // Initializes this object; makes a copy of the input array if
1069
- // 'relation' is kCopy.
1070
- void Init(const Element* array, size_t a_size, RelationToSource relation) {
1071
- if (relation == kReference) {
1072
- array_ = array;
1073
- } else {
1074
- Element* const copy = new Element[a_size];
1075
- CopyArray(array, a_size, copy);
1076
- array_ = copy;
1077
- }
1078
- size_ = a_size;
1079
- relation_to_source_ = relation;
1080
- }
1081
-
1082
- const Element* array_;
1083
- size_t size_;
1084
- RelationToSource relation_to_source_;
1085
-
1086
- GTEST_DISALLOW_ASSIGN_(NativeArray);
1087
- };
1088
-
1089
- } // namespace internal
1090
- } // namespace testing
1091
-
1092
- #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1093
- ::testing::internal::AssertHelper(result_type, file, line, message) \
1094
- = ::testing::Message()
1095
-
1096
- #define GTEST_MESSAGE_(message, result_type) \
1097
- GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1098
-
1099
- #define GTEST_FATAL_FAILURE_(message) \
1100
- return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1101
-
1102
- #define GTEST_NONFATAL_FAILURE_(message) \
1103
- GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1104
-
1105
- #define GTEST_SUCCESS_(message) \
1106
- GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1107
-
1108
- // Suppresses MSVC warnings 4072 (unreachable code) for the code following
1109
- // statement if it returns or throws (or doesn't return or throw in some
1110
- // situations).
1111
- #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1112
- if (::testing::internal::AlwaysTrue()) { statement; }
1113
-
1114
- #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1115
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1116
- if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1117
- bool gtest_caught_expected = false; \
1118
- try { \
1119
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1120
- } \
1121
- catch (expected_exception const&) { \
1122
- gtest_caught_expected = true; \
1123
- } \
1124
- catch (...) { \
1125
- gtest_msg.value = \
1126
- "Expected: " #statement " throws an exception of type " \
1127
- #expected_exception ".\n Actual: it throws a different type."; \
1128
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1129
- } \
1130
- if (!gtest_caught_expected) { \
1131
- gtest_msg.value = \
1132
- "Expected: " #statement " throws an exception of type " \
1133
- #expected_exception ".\n Actual: it throws nothing."; \
1134
- goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1135
- } \
1136
- } else \
1137
- GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1138
- fail(gtest_msg.value)
1139
-
1140
- #define GTEST_TEST_NO_THROW_(statement, fail) \
1141
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1142
- if (::testing::internal::AlwaysTrue()) { \
1143
- try { \
1144
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1145
- } \
1146
- catch (...) { \
1147
- goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1148
- } \
1149
- } else \
1150
- GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1151
- fail("Expected: " #statement " doesn't throw an exception.\n" \
1152
- " Actual: it throws.")
1153
-
1154
- #define GTEST_TEST_ANY_THROW_(statement, fail) \
1155
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1156
- if (::testing::internal::AlwaysTrue()) { \
1157
- bool gtest_caught_any = false; \
1158
- try { \
1159
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1160
- } \
1161
- catch (...) { \
1162
- gtest_caught_any = true; \
1163
- } \
1164
- if (!gtest_caught_any) { \
1165
- goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1166
- } \
1167
- } else \
1168
- GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1169
- fail("Expected: " #statement " throws an exception.\n" \
1170
- " Actual: it doesn't.")
1171
-
1172
-
1173
- // Implements Boolean test assertions such as EXPECT_TRUE. expression can be
1174
- // either a boolean expression or an AssertionResult. text is a textual
1175
- // represenation of expression as it was passed into the EXPECT_TRUE.
1176
- #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1177
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1178
- if (const ::testing::AssertionResult gtest_ar_ = \
1179
- ::testing::AssertionResult(expression)) \
1180
- ; \
1181
- else \
1182
- fail(::testing::internal::GetBoolAssertionFailureMessage(\
1183
- gtest_ar_, text, #actual, #expected).c_str())
1184
-
1185
- #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1186
- GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1187
- if (::testing::internal::AlwaysTrue()) { \
1188
- ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1189
- GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1190
- if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1191
- goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1192
- } \
1193
- } else \
1194
- GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1195
- fail("Expected: " #statement " doesn't generate new fatal " \
1196
- "failures in the current thread.\n" \
1197
- " Actual: it does.")
1198
-
1199
- // Expands to the name of the class that implements the given test.
1200
- #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1201
- test_case_name##_##test_name##_Test
1202
-
1203
- // Helper macro for defining tests.
1204
- #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
1205
- class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
1206
- public:\
1207
- GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
1208
- private:\
1209
- virtual void TestBody();\
1210
- static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
1211
- GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1212
- GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
1213
- };\
1214
- \
1215
- ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
1216
- ::test_info_ =\
1217
- ::testing::internal::MakeAndRegisterTestInfo(\
1218
- #test_case_name, #test_name, NULL, NULL, \
1219
- (parent_id), \
1220
- parent_class::SetUpTestCase, \
1221
- parent_class::TearDownTestCase, \
1222
- new ::testing::internal::TestFactoryImpl<\
1223
- GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
1224
- void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
1225
-
1226
- #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_