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,380 +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
- // Authors: keith.ray@gmail.com (Keith Ray)
31
-
32
- #include "gtest/internal/gtest-filepath.h"
33
- #include "gtest/internal/gtest-port.h"
34
-
35
- #include <stdlib.h>
36
-
37
- #if GTEST_OS_WINDOWS_MOBILE
38
- # include <windows.h>
39
- #elif GTEST_OS_WINDOWS
40
- # include <direct.h>
41
- # include <io.h>
42
- #elif GTEST_OS_SYMBIAN || GTEST_OS_NACL
43
- // Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h
44
- # include <sys/syslimits.h>
45
- #else
46
- # include <limits.h>
47
- # include <climits> // Some Linux distributions define PATH_MAX here.
48
- #endif // GTEST_OS_WINDOWS_MOBILE
49
-
50
- #if GTEST_OS_WINDOWS
51
- # define GTEST_PATH_MAX_ _MAX_PATH
52
- #elif defined(PATH_MAX)
53
- # define GTEST_PATH_MAX_ PATH_MAX
54
- #elif defined(_XOPEN_PATH_MAX)
55
- # define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
56
- #else
57
- # define GTEST_PATH_MAX_ _POSIX_PATH_MAX
58
- #endif // GTEST_OS_WINDOWS
59
-
60
- #include "gtest/internal/gtest-string.h"
61
-
62
- namespace testing {
63
- namespace internal {
64
-
65
- #if GTEST_OS_WINDOWS
66
- // On Windows, '\\' is the standard path separator, but many tools and the
67
- // Windows API also accept '/' as an alternate path separator. Unless otherwise
68
- // noted, a file path can contain either kind of path separators, or a mixture
69
- // of them.
70
- const char kPathSeparator = '\\';
71
- const char kAlternatePathSeparator = '/';
72
- const char kPathSeparatorString[] = "\\";
73
- const char kAlternatePathSeparatorString[] = "/";
74
- # if GTEST_OS_WINDOWS_MOBILE
75
- // Windows CE doesn't have a current directory. You should not use
76
- // the current directory in tests on Windows CE, but this at least
77
- // provides a reasonable fallback.
78
- const char kCurrentDirectoryString[] = "\\";
79
- // Windows CE doesn't define INVALID_FILE_ATTRIBUTES
80
- const DWORD kInvalidFileAttributes = 0xffffffff;
81
- # else
82
- const char kCurrentDirectoryString[] = ".\\";
83
- # endif // GTEST_OS_WINDOWS_MOBILE
84
- #else
85
- const char kPathSeparator = '/';
86
- const char kPathSeparatorString[] = "/";
87
- const char kCurrentDirectoryString[] = "./";
88
- #endif // GTEST_OS_WINDOWS
89
-
90
- // Returns whether the given character is a valid path separator.
91
- static bool IsPathSeparator(char c) {
92
- #if GTEST_HAS_ALT_PATH_SEP_
93
- return (c == kPathSeparator) || (c == kAlternatePathSeparator);
94
- #else
95
- return c == kPathSeparator;
96
- #endif
97
- }
98
-
99
- // Returns the current working directory, or "" if unsuccessful.
100
- FilePath FilePath::GetCurrentDir() {
101
- #if GTEST_OS_WINDOWS_MOBILE
102
- // Windows CE doesn't have a current directory, so we just return
103
- // something reasonable.
104
- return FilePath(kCurrentDirectoryString);
105
- #elif GTEST_OS_WINDOWS
106
- char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
107
- return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
108
- #else
109
- char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
110
- return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
111
- #endif // GTEST_OS_WINDOWS_MOBILE
112
- }
113
-
114
- // Returns a copy of the FilePath with the case-insensitive extension removed.
115
- // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
116
- // FilePath("dir/file"). If a case-insensitive extension is not
117
- // found, returns a copy of the original FilePath.
118
- FilePath FilePath::RemoveExtension(const char* extension) const {
119
- String dot_extension(String::Format(".%s", extension));
120
- if (pathname_.EndsWithCaseInsensitive(dot_extension.c_str())) {
121
- return FilePath(String(pathname_.c_str(), pathname_.length() - 4));
122
- }
123
- return *this;
124
- }
125
-
126
- // Returns a pointer to the last occurence of a valid path separator in
127
- // the FilePath. On Windows, for example, both '/' and '\' are valid path
128
- // separators. Returns NULL if no path separator was found.
129
- const char* FilePath::FindLastPathSeparator() const {
130
- const char* const last_sep = strrchr(c_str(), kPathSeparator);
131
- #if GTEST_HAS_ALT_PATH_SEP_
132
- const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
133
- // Comparing two pointers of which only one is NULL is undefined.
134
- if (last_alt_sep != NULL &&
135
- (last_sep == NULL || last_alt_sep > last_sep)) {
136
- return last_alt_sep;
137
- }
138
- #endif
139
- return last_sep;
140
- }
141
-
142
- // Returns a copy of the FilePath with the directory part removed.
143
- // Example: FilePath("path/to/file").RemoveDirectoryName() returns
144
- // FilePath("file"). If there is no directory part ("just_a_file"), it returns
145
- // the FilePath unmodified. If there is no file part ("just_a_dir/") it
146
- // returns an empty FilePath ("").
147
- // On Windows platform, '\' is the path separator, otherwise it is '/'.
148
- FilePath FilePath::RemoveDirectoryName() const {
149
- const char* const last_sep = FindLastPathSeparator();
150
- return last_sep ? FilePath(String(last_sep + 1)) : *this;
151
- }
152
-
153
- // RemoveFileName returns the directory path with the filename removed.
154
- // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
155
- // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
156
- // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
157
- // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
158
- // On Windows platform, '\' is the path separator, otherwise it is '/'.
159
- FilePath FilePath::RemoveFileName() const {
160
- const char* const last_sep = FindLastPathSeparator();
161
- String dir;
162
- if (last_sep) {
163
- dir = String(c_str(), last_sep + 1 - c_str());
164
- } else {
165
- dir = kCurrentDirectoryString;
166
- }
167
- return FilePath(dir);
168
- }
169
-
170
- // Helper functions for naming files in a directory for xml output.
171
-
172
- // Given directory = "dir", base_name = "test", number = 0,
173
- // extension = "xml", returns "dir/test.xml". If number is greater
174
- // than zero (e.g., 12), returns "dir/test_12.xml".
175
- // On Windows platform, uses \ as the separator rather than /.
176
- FilePath FilePath::MakeFileName(const FilePath& directory,
177
- const FilePath& base_name,
178
- int number,
179
- const char* extension) {
180
- String file;
181
- if (number == 0) {
182
- file = String::Format("%s.%s", base_name.c_str(), extension);
183
- } else {
184
- file = String::Format("%s_%d.%s", base_name.c_str(), number, extension);
185
- }
186
- return ConcatPaths(directory, FilePath(file));
187
- }
188
-
189
- // Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
190
- // On Windows, uses \ as the separator rather than /.
191
- FilePath FilePath::ConcatPaths(const FilePath& directory,
192
- const FilePath& relative_path) {
193
- if (directory.IsEmpty())
194
- return relative_path;
195
- const FilePath dir(directory.RemoveTrailingPathSeparator());
196
- return FilePath(String::Format("%s%c%s", dir.c_str(), kPathSeparator,
197
- relative_path.c_str()));
198
- }
199
-
200
- // Returns true if pathname describes something findable in the file-system,
201
- // either a file, directory, or whatever.
202
- bool FilePath::FileOrDirectoryExists() const {
203
- #if GTEST_OS_WINDOWS_MOBILE
204
- LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
205
- const DWORD attributes = GetFileAttributes(unicode);
206
- delete [] unicode;
207
- return attributes != kInvalidFileAttributes;
208
- #else
209
- posix::StatStruct file_stat;
210
- return posix::Stat(pathname_.c_str(), &file_stat) == 0;
211
- #endif // GTEST_OS_WINDOWS_MOBILE
212
- }
213
-
214
- // Returns true if pathname describes a directory in the file-system
215
- // that exists.
216
- bool FilePath::DirectoryExists() const {
217
- bool result = false;
218
- #if GTEST_OS_WINDOWS
219
- // Don't strip off trailing separator if path is a root directory on
220
- // Windows (like "C:\\").
221
- const FilePath& path(IsRootDirectory() ? *this :
222
- RemoveTrailingPathSeparator());
223
- #else
224
- const FilePath& path(*this);
225
- #endif
226
-
227
- #if GTEST_OS_WINDOWS_MOBILE
228
- LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
229
- const DWORD attributes = GetFileAttributes(unicode);
230
- delete [] unicode;
231
- if ((attributes != kInvalidFileAttributes) &&
232
- (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
233
- result = true;
234
- }
235
- #else
236
- posix::StatStruct file_stat;
237
- result = posix::Stat(path.c_str(), &file_stat) == 0 &&
238
- posix::IsDir(file_stat);
239
- #endif // GTEST_OS_WINDOWS_MOBILE
240
-
241
- return result;
242
- }
243
-
244
- // Returns true if pathname describes a root directory. (Windows has one
245
- // root directory per disk drive.)
246
- bool FilePath::IsRootDirectory() const {
247
- #if GTEST_OS_WINDOWS
248
- // TODO(wan@google.com): on Windows a network share like
249
- // \\server\share can be a root directory, although it cannot be the
250
- // current directory. Handle this properly.
251
- return pathname_.length() == 3 && IsAbsolutePath();
252
- #else
253
- return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
254
- #endif
255
- }
256
-
257
- // Returns true if pathname describes an absolute path.
258
- bool FilePath::IsAbsolutePath() const {
259
- const char* const name = pathname_.c_str();
260
- #if GTEST_OS_WINDOWS
261
- return pathname_.length() >= 3 &&
262
- ((name[0] >= 'a' && name[0] <= 'z') ||
263
- (name[0] >= 'A' && name[0] <= 'Z')) &&
264
- name[1] == ':' &&
265
- IsPathSeparator(name[2]);
266
- #else
267
- return IsPathSeparator(name[0]);
268
- #endif
269
- }
270
-
271
- // Returns a pathname for a file that does not currently exist. The pathname
272
- // will be directory/base_name.extension or
273
- // directory/base_name_<number>.extension if directory/base_name.extension
274
- // already exists. The number will be incremented until a pathname is found
275
- // that does not already exist.
276
- // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
277
- // There could be a race condition if two or more processes are calling this
278
- // function at the same time -- they could both pick the same filename.
279
- FilePath FilePath::GenerateUniqueFileName(const FilePath& directory,
280
- const FilePath& base_name,
281
- const char* extension) {
282
- FilePath full_pathname;
283
- int number = 0;
284
- do {
285
- full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
286
- } while (full_pathname.FileOrDirectoryExists());
287
- return full_pathname;
288
- }
289
-
290
- // Returns true if FilePath ends with a path separator, which indicates that
291
- // it is intended to represent a directory. Returns false otherwise.
292
- // This does NOT check that a directory (or file) actually exists.
293
- bool FilePath::IsDirectory() const {
294
- return !pathname_.empty() &&
295
- IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
296
- }
297
-
298
- // Create directories so that path exists. Returns true if successful or if
299
- // the directories already exist; returns false if unable to create directories
300
- // for any reason.
301
- bool FilePath::CreateDirectoriesRecursively() const {
302
- if (!this->IsDirectory()) {
303
- return false;
304
- }
305
-
306
- if (pathname_.length() == 0 || this->DirectoryExists()) {
307
- return true;
308
- }
309
-
310
- const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
311
- return parent.CreateDirectoriesRecursively() && this->CreateFolder();
312
- }
313
-
314
- // Create the directory so that path exists. Returns true if successful or
315
- // if the directory already exists; returns false if unable to create the
316
- // directory for any reason, including if the parent directory does not
317
- // exist. Not named "CreateDirectory" because that's a macro on Windows.
318
- bool FilePath::CreateFolder() const {
319
- #if GTEST_OS_WINDOWS_MOBILE
320
- FilePath removed_sep(this->RemoveTrailingPathSeparator());
321
- LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
322
- int result = CreateDirectory(unicode, NULL) ? 0 : -1;
323
- delete [] unicode;
324
- #elif GTEST_OS_WINDOWS
325
- int result = _mkdir(pathname_.c_str());
326
- #else
327
- int result = mkdir(pathname_.c_str(), 0777);
328
- #endif // GTEST_OS_WINDOWS_MOBILE
329
-
330
- if (result == -1) {
331
- return this->DirectoryExists(); // An error is OK if the directory exists.
332
- }
333
- return true; // No error.
334
- }
335
-
336
- // If input name has a trailing separator character, remove it and return the
337
- // name, otherwise return the name string unmodified.
338
- // On Windows platform, uses \ as the separator, other platforms use /.
339
- FilePath FilePath::RemoveTrailingPathSeparator() const {
340
- return IsDirectory()
341
- ? FilePath(String(pathname_.c_str(), pathname_.length() - 1))
342
- : *this;
343
- }
344
-
345
- // Removes any redundant separators that might be in the pathname.
346
- // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
347
- // redundancies that might be in a pathname involving "." or "..".
348
- // TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
349
- void FilePath::Normalize() {
350
- if (pathname_.c_str() == NULL) {
351
- pathname_ = "";
352
- return;
353
- }
354
- const char* src = pathname_.c_str();
355
- char* const dest = new char[pathname_.length() + 1];
356
- char* dest_ptr = dest;
357
- memset(dest_ptr, 0, pathname_.length() + 1);
358
-
359
- while (*src != '\0') {
360
- *dest_ptr = *src;
361
- if (!IsPathSeparator(*src)) {
362
- src++;
363
- } else {
364
- #if GTEST_HAS_ALT_PATH_SEP_
365
- if (*dest_ptr == kAlternatePathSeparator) {
366
- *dest_ptr = kPathSeparator;
367
- }
368
- #endif
369
- while (IsPathSeparator(*src))
370
- src++;
371
- }
372
- dest_ptr++;
373
- }
374
- *dest_ptr = '\0';
375
- pathname_ = dest;
376
- delete[] dest;
377
- }
378
-
379
- } // namespace internal
380
- } // namespace testing
@@ -1,1038 +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
- // Utility functions and classes used by the Google C++ testing framework.
31
- //
32
- // Author: wan@google.com (Zhanyong Wan)
33
- //
34
- // This file contains purely Google Test's internal implementation. Please
35
- // DO NOT #INCLUDE IT IN A USER PROGRAM.
36
-
37
- #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
38
- #define GTEST_SRC_GTEST_INTERNAL_INL_H_
39
-
40
- // GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
41
- // part of Google Test's implementation; otherwise it's undefined.
42
- #if !GTEST_IMPLEMENTATION_
43
- // A user is trying to include this from his code - just say no.
44
- # error "gtest-internal-inl.h is part of Google Test's internal implementation."
45
- # error "It must not be included except by Google Test itself."
46
- #endif // GTEST_IMPLEMENTATION_
47
-
48
- #ifndef _WIN32_WCE
49
- # include <errno.h>
50
- #endif // !_WIN32_WCE
51
- #include <stddef.h>
52
- #include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
53
- #include <string.h> // For memmove.
54
-
55
- #include <algorithm>
56
- #include <string>
57
- #include <vector>
58
-
59
- #include "gtest/internal/gtest-port.h"
60
-
61
- #if GTEST_OS_WINDOWS
62
- # include <windows.h> // NOLINT
63
- #endif // GTEST_OS_WINDOWS
64
-
65
- #include "gtest/gtest.h" // NOLINT
66
- #include "gtest/gtest-spi.h"
67
-
68
- namespace testing {
69
-
70
- // Declares the flags.
71
- //
72
- // We don't want the users to modify this flag in the code, but want
73
- // Google Test's own unit tests to be able to access it. Therefore we
74
- // declare it here as opposed to in gtest.h.
75
- GTEST_DECLARE_bool_(death_test_use_fork);
76
-
77
- namespace internal {
78
-
79
- // The value of GetTestTypeId() as seen from within the Google Test
80
- // library. This is solely for testing GetTestTypeId().
81
- GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
82
-
83
- // Names of the flags (needed for parsing Google Test flags).
84
- const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
85
- const char kBreakOnFailureFlag[] = "break_on_failure";
86
- const char kCatchExceptionsFlag[] = "catch_exceptions";
87
- const char kColorFlag[] = "color";
88
- const char kFilterFlag[] = "filter";
89
- const char kListTestsFlag[] = "list_tests";
90
- const char kOutputFlag[] = "output";
91
- const char kPrintTimeFlag[] = "print_time";
92
- const char kRandomSeedFlag[] = "random_seed";
93
- const char kRepeatFlag[] = "repeat";
94
- const char kShuffleFlag[] = "shuffle";
95
- const char kStackTraceDepthFlag[] = "stack_trace_depth";
96
- const char kStreamResultToFlag[] = "stream_result_to";
97
- const char kThrowOnFailureFlag[] = "throw_on_failure";
98
-
99
- // A valid random seed must be in [1, kMaxRandomSeed].
100
- const int kMaxRandomSeed = 99999;
101
-
102
- // g_help_flag is true iff the --help flag or an equivalent form is
103
- // specified on the command line.
104
- GTEST_API_ extern bool g_help_flag;
105
-
106
- // Returns the current time in milliseconds.
107
- GTEST_API_ TimeInMillis GetTimeInMillis();
108
-
109
- // Returns true iff Google Test should use colors in the output.
110
- GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
111
-
112
- // Formats the given time in milliseconds as seconds.
113
- GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
114
-
115
- // Parses a string for an Int32 flag, in the form of "--flag=value".
116
- //
117
- // On success, stores the value of the flag in *value, and returns
118
- // true. On failure, returns false without changing *value.
119
- GTEST_API_ bool ParseInt32Flag(
120
- const char* str, const char* flag, Int32* value);
121
-
122
- // Returns a random seed in range [1, kMaxRandomSeed] based on the
123
- // given --gtest_random_seed flag value.
124
- inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
125
- const unsigned int raw_seed = (random_seed_flag == 0) ?
126
- static_cast<unsigned int>(GetTimeInMillis()) :
127
- static_cast<unsigned int>(random_seed_flag);
128
-
129
- // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
130
- // it's easy to type.
131
- const int normalized_seed =
132
- static_cast<int>((raw_seed - 1U) %
133
- static_cast<unsigned int>(kMaxRandomSeed)) + 1;
134
- return normalized_seed;
135
- }
136
-
137
- // Returns the first valid random seed after 'seed'. The behavior is
138
- // undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
139
- // considered to be 1.
140
- inline int GetNextRandomSeed(int seed) {
141
- GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
142
- << "Invalid random seed " << seed << " - must be in [1, "
143
- << kMaxRandomSeed << "].";
144
- const int next_seed = seed + 1;
145
- return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
146
- }
147
-
148
- // This class saves the values of all Google Test flags in its c'tor, and
149
- // restores them in its d'tor.
150
- class GTestFlagSaver {
151
- public:
152
- // The c'tor.
153
- GTestFlagSaver() {
154
- also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
155
- break_on_failure_ = GTEST_FLAG(break_on_failure);
156
- catch_exceptions_ = GTEST_FLAG(catch_exceptions);
157
- color_ = GTEST_FLAG(color);
158
- death_test_style_ = GTEST_FLAG(death_test_style);
159
- death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
160
- filter_ = GTEST_FLAG(filter);
161
- internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
162
- list_tests_ = GTEST_FLAG(list_tests);
163
- output_ = GTEST_FLAG(output);
164
- print_time_ = GTEST_FLAG(print_time);
165
- random_seed_ = GTEST_FLAG(random_seed);
166
- repeat_ = GTEST_FLAG(repeat);
167
- shuffle_ = GTEST_FLAG(shuffle);
168
- stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
169
- stream_result_to_ = GTEST_FLAG(stream_result_to);
170
- throw_on_failure_ = GTEST_FLAG(throw_on_failure);
171
- }
172
-
173
- // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
174
- ~GTestFlagSaver() {
175
- GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
176
- GTEST_FLAG(break_on_failure) = break_on_failure_;
177
- GTEST_FLAG(catch_exceptions) = catch_exceptions_;
178
- GTEST_FLAG(color) = color_;
179
- GTEST_FLAG(death_test_style) = death_test_style_;
180
- GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
181
- GTEST_FLAG(filter) = filter_;
182
- GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
183
- GTEST_FLAG(list_tests) = list_tests_;
184
- GTEST_FLAG(output) = output_;
185
- GTEST_FLAG(print_time) = print_time_;
186
- GTEST_FLAG(random_seed) = random_seed_;
187
- GTEST_FLAG(repeat) = repeat_;
188
- GTEST_FLAG(shuffle) = shuffle_;
189
- GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
190
- GTEST_FLAG(stream_result_to) = stream_result_to_;
191
- GTEST_FLAG(throw_on_failure) = throw_on_failure_;
192
- }
193
- private:
194
- // Fields for saving the original values of flags.
195
- bool also_run_disabled_tests_;
196
- bool break_on_failure_;
197
- bool catch_exceptions_;
198
- String color_;
199
- String death_test_style_;
200
- bool death_test_use_fork_;
201
- String filter_;
202
- String internal_run_death_test_;
203
- bool list_tests_;
204
- String output_;
205
- bool print_time_;
206
- bool pretty_;
207
- internal::Int32 random_seed_;
208
- internal::Int32 repeat_;
209
- bool shuffle_;
210
- internal::Int32 stack_trace_depth_;
211
- String stream_result_to_;
212
- bool throw_on_failure_;
213
- } GTEST_ATTRIBUTE_UNUSED_;
214
-
215
- // Converts a Unicode code point to a narrow string in UTF-8 encoding.
216
- // code_point parameter is of type UInt32 because wchar_t may not be
217
- // wide enough to contain a code point.
218
- // The output buffer str must containt at least 32 characters.
219
- // The function returns the address of the output buffer.
220
- // If the code_point is not a valid Unicode code point
221
- // (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
222
- // as '(Invalid Unicode 0xXXXXXXXX)'.
223
- GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
224
-
225
- // Converts a wide string to a narrow string in UTF-8 encoding.
226
- // The wide string is assumed to have the following encoding:
227
- // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
228
- // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
229
- // Parameter str points to a null-terminated wide string.
230
- // Parameter num_chars may additionally limit the number
231
- // of wchar_t characters processed. -1 is used when the entire string
232
- // should be processed.
233
- // If the string contains code points that are not valid Unicode code points
234
- // (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
235
- // as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
236
- // and contains invalid UTF-16 surrogate pairs, values in those pairs
237
- // will be encoded as individual Unicode characters from Basic Normal Plane.
238
- GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);
239
-
240
- // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
241
- // if the variable is present. If a file already exists at this location, this
242
- // function will write over it. If the variable is present, but the file cannot
243
- // be created, prints an error and exits.
244
- void WriteToShardStatusFileIfNeeded();
245
-
246
- // Checks whether sharding is enabled by examining the relevant
247
- // environment variable values. If the variables are present,
248
- // but inconsistent (e.g., shard_index >= total_shards), prints
249
- // an error and exits. If in_subprocess_for_death_test, sharding is
250
- // disabled because it must only be applied to the original test
251
- // process. Otherwise, we could filter out death tests we intended to execute.
252
- GTEST_API_ bool ShouldShard(const char* total_shards_str,
253
- const char* shard_index_str,
254
- bool in_subprocess_for_death_test);
255
-
256
- // Parses the environment variable var as an Int32. If it is unset,
257
- // returns default_val. If it is not an Int32, prints an error and
258
- // and aborts.
259
- GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
260
-
261
- // Given the total number of shards, the shard index, and the test id,
262
- // returns true iff the test should be run on this shard. The test id is
263
- // some arbitrary but unique non-negative integer assigned to each test
264
- // method. Assumes that 0 <= shard_index < total_shards.
265
- GTEST_API_ bool ShouldRunTestOnShard(
266
- int total_shards, int shard_index, int test_id);
267
-
268
- // STL container utilities.
269
-
270
- // Returns the number of elements in the given container that satisfy
271
- // the given predicate.
272
- template <class Container, typename Predicate>
273
- inline int CountIf(const Container& c, Predicate predicate) {
274
- // Implemented as an explicit loop since std::count_if () in libCstd on
275
- // Solaris has a non-standard signature.
276
- int count = 0;
277
- for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
278
- if (predicate(*it))
279
- ++count;
280
- }
281
- return count;
282
- }
283
-
284
- // Applies a function/functor to each element in the container.
285
- template <class Container, typename Functor>
286
- void ForEach(const Container& c, Functor functor) {
287
- std::for_each(c.begin(), c.end(), functor);
288
- }
289
-
290
- // Returns the i-th element of the vector, or default_value if i is not
291
- // in range [0, v.size()).
292
- template <typename E>
293
- inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
294
- return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
295
- }
296
-
297
- // Performs an in-place shuffle of a range of the vector's elements.
298
- // 'begin' and 'end' are element indices as an STL-style range;
299
- // i.e. [begin, end) are shuffled, where 'end' == size() means to
300
- // shuffle to the end of the vector.
301
- template <typename E>
302
- void ShuffleRange(internal::Random* random, int begin, int end,
303
- std::vector<E>* v) {
304
- const int size = static_cast<int>(v->size());
305
- GTEST_CHECK_(0 <= begin && begin <= size)
306
- << "Invalid shuffle range start " << begin << ": must be in range [0, "
307
- << size << "].";
308
- GTEST_CHECK_(begin <= end && end <= size)
309
- << "Invalid shuffle range finish " << end << ": must be in range ["
310
- << begin << ", " << size << "].";
311
-
312
- // Fisher-Yates shuffle, from
313
- // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
314
- for (int range_width = end - begin; range_width >= 2; range_width--) {
315
- const int last_in_range = begin + range_width - 1;
316
- const int selected = begin + random->Generate(range_width);
317
- std::swap((*v)[selected], (*v)[last_in_range]);
318
- }
319
- }
320
-
321
- // Performs an in-place shuffle of the vector's elements.
322
- template <typename E>
323
- inline void Shuffle(internal::Random* random, std::vector<E>* v) {
324
- ShuffleRange(random, 0, static_cast<int>(v->size()), v);
325
- }
326
-
327
- // A function for deleting an object. Handy for being used as a
328
- // functor.
329
- template <typename T>
330
- static void Delete(T* x) {
331
- delete x;
332
- }
333
-
334
- // A predicate that checks the key of a TestProperty against a known key.
335
- //
336
- // TestPropertyKeyIs is copyable.
337
- class TestPropertyKeyIs {
338
- public:
339
- // Constructor.
340
- //
341
- // TestPropertyKeyIs has NO default constructor.
342
- explicit TestPropertyKeyIs(const char* key)
343
- : key_(key) {}
344
-
345
- // Returns true iff the test name of test property matches on key_.
346
- bool operator()(const TestProperty& test_property) const {
347
- return String(test_property.key()).Compare(key_) == 0;
348
- }
349
-
350
- private:
351
- String key_;
352
- };
353
-
354
- // Class UnitTestOptions.
355
- //
356
- // This class contains functions for processing options the user
357
- // specifies when running the tests. It has only static members.
358
- //
359
- // In most cases, the user can specify an option using either an
360
- // environment variable or a command line flag. E.g. you can set the
361
- // test filter using either GTEST_FILTER or --gtest_filter. If both
362
- // the variable and the flag are present, the latter overrides the
363
- // former.
364
- class GTEST_API_ UnitTestOptions {
365
- public:
366
- // Functions for processing the gtest_output flag.
367
-
368
- // Returns the output format, or "" for normal printed output.
369
- static String GetOutputFormat();
370
-
371
- // Returns the absolute path of the requested output file, or the
372
- // default (test_detail.xml in the original working directory) if
373
- // none was explicitly specified.
374
- static String GetAbsolutePathToOutputFile();
375
-
376
- // Functions for processing the gtest_filter flag.
377
-
378
- // Returns true iff the wildcard pattern matches the string. The
379
- // first ':' or '\0' character in pattern marks the end of it.
380
- //
381
- // This recursive algorithm isn't very efficient, but is clear and
382
- // works well enough for matching test names, which are short.
383
- static bool PatternMatchesString(const char *pattern, const char *str);
384
-
385
- // Returns true iff the user-specified filter matches the test case
386
- // name and the test name.
387
- static bool FilterMatchesTest(const String &test_case_name,
388
- const String &test_name);
389
-
390
- #if GTEST_OS_WINDOWS
391
- // Function for supporting the gtest_catch_exception flag.
392
-
393
- // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
394
- // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
395
- // This function is useful as an __except condition.
396
- static int GTestShouldProcessSEH(DWORD exception_code);
397
- #endif // GTEST_OS_WINDOWS
398
-
399
- // Returns true if "name" matches the ':' separated list of glob-style
400
- // filters in "filter".
401
- static bool MatchesFilter(const String& name, const char* filter);
402
- };
403
-
404
- // Returns the current application's name, removing directory path if that
405
- // is present. Used by UnitTestOptions::GetOutputFile.
406
- GTEST_API_ FilePath GetCurrentExecutableName();
407
-
408
- // The role interface for getting the OS stack trace as a string.
409
- class OsStackTraceGetterInterface {
410
- public:
411
- OsStackTraceGetterInterface() {}
412
- virtual ~OsStackTraceGetterInterface() {}
413
-
414
- // Returns the current OS stack trace as a String. Parameters:
415
- //
416
- // max_depth - the maximum number of stack frames to be included
417
- // in the trace.
418
- // skip_count - the number of top frames to be skipped; doesn't count
419
- // against max_depth.
420
- virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;
421
-
422
- // UponLeavingGTest() should be called immediately before Google Test calls
423
- // user code. It saves some information about the current stack that
424
- // CurrentStackTrace() will use to find and hide Google Test stack frames.
425
- virtual void UponLeavingGTest() = 0;
426
-
427
- private:
428
- GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
429
- };
430
-
431
- // A working implementation of the OsStackTraceGetterInterface interface.
432
- class OsStackTraceGetter : public OsStackTraceGetterInterface {
433
- public:
434
- OsStackTraceGetter() : caller_frame_(NULL) {}
435
- virtual String CurrentStackTrace(int max_depth, int skip_count);
436
- virtual void UponLeavingGTest();
437
-
438
- // This string is inserted in place of stack frames that are part of
439
- // Google Test's implementation.
440
- static const char* const kElidedFramesMarker;
441
-
442
- private:
443
- Mutex mutex_; // protects all internal state
444
-
445
- // We save the stack frame below the frame that calls user code.
446
- // We do this because the address of the frame immediately below
447
- // the user code changes between the call to UponLeavingGTest()
448
- // and any calls to CurrentStackTrace() from within the user code.
449
- void* caller_frame_;
450
-
451
- GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
452
- };
453
-
454
- // Information about a Google Test trace point.
455
- struct TraceInfo {
456
- const char* file;
457
- int line;
458
- String message;
459
- };
460
-
461
- // This is the default global test part result reporter used in UnitTestImpl.
462
- // This class should only be used by UnitTestImpl.
463
- class DefaultGlobalTestPartResultReporter
464
- : public TestPartResultReporterInterface {
465
- public:
466
- explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
467
- // Implements the TestPartResultReporterInterface. Reports the test part
468
- // result in the current test.
469
- virtual void ReportTestPartResult(const TestPartResult& result);
470
-
471
- private:
472
- UnitTestImpl* const unit_test_;
473
-
474
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
475
- };
476
-
477
- // This is the default per thread test part result reporter used in
478
- // UnitTestImpl. This class should only be used by UnitTestImpl.
479
- class DefaultPerThreadTestPartResultReporter
480
- : public TestPartResultReporterInterface {
481
- public:
482
- explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
483
- // Implements the TestPartResultReporterInterface. The implementation just
484
- // delegates to the current global test part result reporter of *unit_test_.
485
- virtual void ReportTestPartResult(const TestPartResult& result);
486
-
487
- private:
488
- UnitTestImpl* const unit_test_;
489
-
490
- GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
491
- };
492
-
493
- // The private implementation of the UnitTest class. We don't protect
494
- // the methods under a mutex, as this class is not accessible by a
495
- // user and the UnitTest class that delegates work to this class does
496
- // proper locking.
497
- class GTEST_API_ UnitTestImpl {
498
- public:
499
- explicit UnitTestImpl(UnitTest* parent);
500
- virtual ~UnitTestImpl();
501
-
502
- // There are two different ways to register your own TestPartResultReporter.
503
- // You can register your own repoter to listen either only for test results
504
- // from the current thread or for results from all threads.
505
- // By default, each per-thread test result repoter just passes a new
506
- // TestPartResult to the global test result reporter, which registers the
507
- // test part result for the currently running test.
508
-
509
- // Returns the global test part result reporter.
510
- TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
511
-
512
- // Sets the global test part result reporter.
513
- void SetGlobalTestPartResultReporter(
514
- TestPartResultReporterInterface* reporter);
515
-
516
- // Returns the test part result reporter for the current thread.
517
- TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
518
-
519
- // Sets the test part result reporter for the current thread.
520
- void SetTestPartResultReporterForCurrentThread(
521
- TestPartResultReporterInterface* reporter);
522
-
523
- // Gets the number of successful test cases.
524
- int successful_test_case_count() const;
525
-
526
- // Gets the number of failed test cases.
527
- int failed_test_case_count() const;
528
-
529
- // Gets the number of all test cases.
530
- int total_test_case_count() const;
531
-
532
- // Gets the number of all test cases that contain at least one test
533
- // that should run.
534
- int test_case_to_run_count() const;
535
-
536
- // Gets the number of successful tests.
537
- int successful_test_count() const;
538
-
539
- // Gets the number of failed tests.
540
- int failed_test_count() const;
541
-
542
- // Gets the number of disabled tests.
543
- int disabled_test_count() const;
544
-
545
- // Gets the number of all tests.
546
- int total_test_count() const;
547
-
548
- // Gets the number of tests that should run.
549
- int test_to_run_count() const;
550
-
551
- // Gets the elapsed time, in milliseconds.
552
- TimeInMillis elapsed_time() const { return elapsed_time_; }
553
-
554
- // Returns true iff the unit test passed (i.e. all test cases passed).
555
- bool Passed() const { return !Failed(); }
556
-
557
- // Returns true iff the unit test failed (i.e. some test case failed
558
- // or something outside of all tests failed).
559
- bool Failed() const {
560
- return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
561
- }
562
-
563
- // Gets the i-th test case among all the test cases. i can range from 0 to
564
- // total_test_case_count() - 1. If i is not in that range, returns NULL.
565
- const TestCase* GetTestCase(int i) const {
566
- const int index = GetElementOr(test_case_indices_, i, -1);
567
- return index < 0 ? NULL : test_cases_[i];
568
- }
569
-
570
- // Gets the i-th test case among all the test cases. i can range from 0 to
571
- // total_test_case_count() - 1. If i is not in that range, returns NULL.
572
- TestCase* GetMutableTestCase(int i) {
573
- const int index = GetElementOr(test_case_indices_, i, -1);
574
- return index < 0 ? NULL : test_cases_[index];
575
- }
576
-
577
- // Provides access to the event listener list.
578
- TestEventListeners* listeners() { return &listeners_; }
579
-
580
- // Returns the TestResult for the test that's currently running, or
581
- // the TestResult for the ad hoc test if no test is running.
582
- TestResult* current_test_result();
583
-
584
- // Returns the TestResult for the ad hoc test.
585
- const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
586
-
587
- // Sets the OS stack trace getter.
588
- //
589
- // Does nothing if the input and the current OS stack trace getter
590
- // are the same; otherwise, deletes the old getter and makes the
591
- // input the current getter.
592
- void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
593
-
594
- // Returns the current OS stack trace getter if it is not NULL;
595
- // otherwise, creates an OsStackTraceGetter, makes it the current
596
- // getter, and returns it.
597
- OsStackTraceGetterInterface* os_stack_trace_getter();
598
-
599
- // Returns the current OS stack trace as a String.
600
- //
601
- // The maximum number of stack frames to be included is specified by
602
- // the gtest_stack_trace_depth flag. The skip_count parameter
603
- // specifies the number of top frames to be skipped, which doesn't
604
- // count against the number of frames to be included.
605
- //
606
- // For example, if Foo() calls Bar(), which in turn calls
607
- // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
608
- // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
609
- String CurrentOsStackTraceExceptTop(int skip_count);
610
-
611
- // Finds and returns a TestCase with the given name. If one doesn't
612
- // exist, creates one and returns it.
613
- //
614
- // Arguments:
615
- //
616
- // test_case_name: name of the test case
617
- // type_param: the name of the test's type parameter, or NULL if
618
- // this is not a typed or a type-parameterized test.
619
- // set_up_tc: pointer to the function that sets up the test case
620
- // tear_down_tc: pointer to the function that tears down the test case
621
- TestCase* GetTestCase(const char* test_case_name,
622
- const char* type_param,
623
- Test::SetUpTestCaseFunc set_up_tc,
624
- Test::TearDownTestCaseFunc tear_down_tc);
625
-
626
- // Adds a TestInfo to the unit test.
627
- //
628
- // Arguments:
629
- //
630
- // set_up_tc: pointer to the function that sets up the test case
631
- // tear_down_tc: pointer to the function that tears down the test case
632
- // test_info: the TestInfo object
633
- void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
634
- Test::TearDownTestCaseFunc tear_down_tc,
635
- TestInfo* test_info) {
636
- // In order to support thread-safe death tests, we need to
637
- // remember the original working directory when the test program
638
- // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
639
- // the user may have changed the current directory before calling
640
- // RUN_ALL_TESTS(). Therefore we capture the current directory in
641
- // AddTestInfo(), which is called to register a TEST or TEST_F
642
- // before main() is reached.
643
- if (original_working_dir_.IsEmpty()) {
644
- original_working_dir_.Set(FilePath::GetCurrentDir());
645
- GTEST_CHECK_(!original_working_dir_.IsEmpty())
646
- << "Failed to get the current working directory.";
647
- }
648
-
649
- GetTestCase(test_info->test_case_name(),
650
- test_info->type_param(),
651
- set_up_tc,
652
- tear_down_tc)->AddTestInfo(test_info);
653
- }
654
-
655
- #if GTEST_HAS_PARAM_TEST
656
- // Returns ParameterizedTestCaseRegistry object used to keep track of
657
- // value-parameterized tests and instantiate and register them.
658
- internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
659
- return parameterized_test_registry_;
660
- }
661
- #endif // GTEST_HAS_PARAM_TEST
662
-
663
- // Sets the TestCase object for the test that's currently running.
664
- void set_current_test_case(TestCase* a_current_test_case) {
665
- current_test_case_ = a_current_test_case;
666
- }
667
-
668
- // Sets the TestInfo object for the test that's currently running. If
669
- // current_test_info is NULL, the assertion results will be stored in
670
- // ad_hoc_test_result_.
671
- void set_current_test_info(TestInfo* a_current_test_info) {
672
- current_test_info_ = a_current_test_info;
673
- }
674
-
675
- // Registers all parameterized tests defined using TEST_P and
676
- // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
677
- // combination. This method can be called more then once; it has guards
678
- // protecting from registering the tests more then once. If
679
- // value-parameterized tests are disabled, RegisterParameterizedTests is
680
- // present but does nothing.
681
- void RegisterParameterizedTests();
682
-
683
- // Runs all tests in this UnitTest object, prints the result, and
684
- // returns true if all tests are successful. If any exception is
685
- // thrown during a test, this test is considered to be failed, but
686
- // the rest of the tests will still be run.
687
- bool RunAllTests();
688
-
689
- // Clears the results of all tests, except the ad hoc tests.
690
- void ClearNonAdHocTestResult() {
691
- ForEach(test_cases_, TestCase::ClearTestCaseResult);
692
- }
693
-
694
- // Clears the results of ad-hoc test assertions.
695
- void ClearAdHocTestResult() {
696
- ad_hoc_test_result_.Clear();
697
- }
698
-
699
- enum ReactionToSharding {
700
- HONOR_SHARDING_PROTOCOL,
701
- IGNORE_SHARDING_PROTOCOL
702
- };
703
-
704
- // Matches the full name of each test against the user-specified
705
- // filter to decide whether the test should run, then records the
706
- // result in each TestCase and TestInfo object.
707
- // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
708
- // based on sharding variables in the environment.
709
- // Returns the number of tests that should run.
710
- int FilterTests(ReactionToSharding shard_tests);
711
-
712
- // Prints the names of the tests matching the user-specified filter flag.
713
- void ListTestsMatchingFilter();
714
-
715
- const TestCase* current_test_case() const { return current_test_case_; }
716
- TestInfo* current_test_info() { return current_test_info_; }
717
- const TestInfo* current_test_info() const { return current_test_info_; }
718
-
719
- // Returns the vector of environments that need to be set-up/torn-down
720
- // before/after the tests are run.
721
- std::vector<Environment*>& environments() { return environments_; }
722
-
723
- // Getters for the per-thread Google Test trace stack.
724
- std::vector<TraceInfo>& gtest_trace_stack() {
725
- return *(gtest_trace_stack_.pointer());
726
- }
727
- const std::vector<TraceInfo>& gtest_trace_stack() const {
728
- return gtest_trace_stack_.get();
729
- }
730
-
731
- #if GTEST_HAS_DEATH_TEST
732
- void InitDeathTestSubprocessControlInfo() {
733
- internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
734
- }
735
- // Returns a pointer to the parsed --gtest_internal_run_death_test
736
- // flag, or NULL if that flag was not specified.
737
- // This information is useful only in a death test child process.
738
- // Must not be called before a call to InitGoogleTest.
739
- const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
740
- return internal_run_death_test_flag_.get();
741
- }
742
-
743
- // Returns a pointer to the current death test factory.
744
- internal::DeathTestFactory* death_test_factory() {
745
- return death_test_factory_.get();
746
- }
747
-
748
- void SuppressTestEventsIfInSubprocess();
749
-
750
- friend class ReplaceDeathTestFactory;
751
- #endif // GTEST_HAS_DEATH_TEST
752
-
753
- // Initializes the event listener performing XML output as specified by
754
- // UnitTestOptions. Must not be called before InitGoogleTest.
755
- void ConfigureXmlOutput();
756
-
757
- #if GTEST_CAN_STREAM_RESULTS_
758
- // Initializes the event listener for streaming test results to a socket.
759
- // Must not be called before InitGoogleTest.
760
- void ConfigureStreamingOutput();
761
- #endif
762
-
763
- // Performs initialization dependent upon flag values obtained in
764
- // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
765
- // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
766
- // this function is also called from RunAllTests. Since this function can be
767
- // called more than once, it has to be idempotent.
768
- void PostFlagParsingInit();
769
-
770
- // Gets the random seed used at the start of the current test iteration.
771
- int random_seed() const { return random_seed_; }
772
-
773
- // Gets the random number generator.
774
- internal::Random* random() { return &random_; }
775
-
776
- // Shuffles all test cases, and the tests within each test case,
777
- // making sure that death tests are still run first.
778
- void ShuffleTests();
779
-
780
- // Restores the test cases and tests to their order before the first shuffle.
781
- void UnshuffleTests();
782
-
783
- // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
784
- // UnitTest::Run() starts.
785
- bool catch_exceptions() const { return catch_exceptions_; }
786
-
787
- private:
788
- friend class ::testing::UnitTest;
789
-
790
- // Used by UnitTest::Run() to capture the state of
791
- // GTEST_FLAG(catch_exceptions) at the moment it starts.
792
- void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
793
-
794
- // The UnitTest object that owns this implementation object.
795
- UnitTest* const parent_;
796
-
797
- // The working directory when the first TEST() or TEST_F() was
798
- // executed.
799
- internal::FilePath original_working_dir_;
800
-
801
- // The default test part result reporters.
802
- DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
803
- DefaultPerThreadTestPartResultReporter
804
- default_per_thread_test_part_result_reporter_;
805
-
806
- // Points to (but doesn't own) the global test part result reporter.
807
- TestPartResultReporterInterface* global_test_part_result_repoter_;
808
-
809
- // Protects read and write access to global_test_part_result_reporter_.
810
- internal::Mutex global_test_part_result_reporter_mutex_;
811
-
812
- // Points to (but doesn't own) the per-thread test part result reporter.
813
- internal::ThreadLocal<TestPartResultReporterInterface*>
814
- per_thread_test_part_result_reporter_;
815
-
816
- // The vector of environments that need to be set-up/torn-down
817
- // before/after the tests are run.
818
- std::vector<Environment*> environments_;
819
-
820
- // The vector of TestCases in their original order. It owns the
821
- // elements in the vector.
822
- std::vector<TestCase*> test_cases_;
823
-
824
- // Provides a level of indirection for the test case list to allow
825
- // easy shuffling and restoring the test case order. The i-th
826
- // element of this vector is the index of the i-th test case in the
827
- // shuffled order.
828
- std::vector<int> test_case_indices_;
829
-
830
- #if GTEST_HAS_PARAM_TEST
831
- // ParameterizedTestRegistry object used to register value-parameterized
832
- // tests.
833
- internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
834
-
835
- // Indicates whether RegisterParameterizedTests() has been called already.
836
- bool parameterized_tests_registered_;
837
- #endif // GTEST_HAS_PARAM_TEST
838
-
839
- // Index of the last death test case registered. Initially -1.
840
- int last_death_test_case_;
841
-
842
- // This points to the TestCase for the currently running test. It
843
- // changes as Google Test goes through one test case after another.
844
- // When no test is running, this is set to NULL and Google Test
845
- // stores assertion results in ad_hoc_test_result_. Initially NULL.
846
- TestCase* current_test_case_;
847
-
848
- // This points to the TestInfo for the currently running test. It
849
- // changes as Google Test goes through one test after another. When
850
- // no test is running, this is set to NULL and Google Test stores
851
- // assertion results in ad_hoc_test_result_. Initially NULL.
852
- TestInfo* current_test_info_;
853
-
854
- // Normally, a user only writes assertions inside a TEST or TEST_F,
855
- // or inside a function called by a TEST or TEST_F. Since Google
856
- // Test keeps track of which test is current running, it can
857
- // associate such an assertion with the test it belongs to.
858
- //
859
- // If an assertion is encountered when no TEST or TEST_F is running,
860
- // Google Test attributes the assertion result to an imaginary "ad hoc"
861
- // test, and records the result in ad_hoc_test_result_.
862
- TestResult ad_hoc_test_result_;
863
-
864
- // The list of event listeners that can be used to track events inside
865
- // Google Test.
866
- TestEventListeners listeners_;
867
-
868
- // The OS stack trace getter. Will be deleted when the UnitTest
869
- // object is destructed. By default, an OsStackTraceGetter is used,
870
- // but the user can set this field to use a custom getter if that is
871
- // desired.
872
- OsStackTraceGetterInterface* os_stack_trace_getter_;
873
-
874
- // True iff PostFlagParsingInit() has been called.
875
- bool post_flag_parse_init_performed_;
876
-
877
- // The random number seed used at the beginning of the test run.
878
- int random_seed_;
879
-
880
- // Our random number generator.
881
- internal::Random random_;
882
-
883
- // How long the test took to run, in milliseconds.
884
- TimeInMillis elapsed_time_;
885
-
886
- #if GTEST_HAS_DEATH_TEST
887
- // The decomposed components of the gtest_internal_run_death_test flag,
888
- // parsed when RUN_ALL_TESTS is called.
889
- internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
890
- internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
891
- #endif // GTEST_HAS_DEATH_TEST
892
-
893
- // A per-thread stack of traces created by the SCOPED_TRACE() macro.
894
- internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
895
-
896
- // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
897
- // starts.
898
- bool catch_exceptions_;
899
-
900
- GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
901
- }; // class UnitTestImpl
902
-
903
- // Convenience function for accessing the global UnitTest
904
- // implementation object.
905
- inline UnitTestImpl* GetUnitTestImpl() {
906
- return UnitTest::GetInstance()->impl();
907
- }
908
-
909
- #if GTEST_USES_SIMPLE_RE
910
-
911
- // Internal helper functions for implementing the simple regular
912
- // expression matcher.
913
- GTEST_API_ bool IsInSet(char ch, const char* str);
914
- GTEST_API_ bool IsAsciiDigit(char ch);
915
- GTEST_API_ bool IsAsciiPunct(char ch);
916
- GTEST_API_ bool IsRepeat(char ch);
917
- GTEST_API_ bool IsAsciiWhiteSpace(char ch);
918
- GTEST_API_ bool IsAsciiWordChar(char ch);
919
- GTEST_API_ bool IsValidEscape(char ch);
920
- GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
921
- GTEST_API_ bool ValidateRegex(const char* regex);
922
- GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
923
- GTEST_API_ bool MatchRepetitionAndRegexAtHead(
924
- bool escaped, char ch, char repeat, const char* regex, const char* str);
925
- GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
926
-
927
- #endif // GTEST_USES_SIMPLE_RE
928
-
929
- // Parses the command line for Google Test flags, without initializing
930
- // other parts of Google Test.
931
- GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
932
- GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
933
-
934
- #if GTEST_HAS_DEATH_TEST
935
-
936
- // Returns the message describing the last system error, regardless of the
937
- // platform.
938
- GTEST_API_ String GetLastErrnoDescription();
939
-
940
- # if GTEST_OS_WINDOWS
941
- // Provides leak-safe Windows kernel handle ownership.
942
- class AutoHandle {
943
- public:
944
- AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
945
- explicit AutoHandle(HANDLE handle) : handle_(handle) {}
946
-
947
- ~AutoHandle() { Reset(); }
948
-
949
- HANDLE Get() const { return handle_; }
950
- void Reset() { Reset(INVALID_HANDLE_VALUE); }
951
- void Reset(HANDLE handle) {
952
- if (handle != handle_) {
953
- if (handle_ != INVALID_HANDLE_VALUE)
954
- ::CloseHandle(handle_);
955
- handle_ = handle;
956
- }
957
- }
958
-
959
- private:
960
- HANDLE handle_;
961
-
962
- GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
963
- };
964
- # endif // GTEST_OS_WINDOWS
965
-
966
- // Attempts to parse a string into a positive integer pointed to by the
967
- // number parameter. Returns true if that is possible.
968
- // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
969
- // it here.
970
- template <typename Integer>
971
- bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
972
- // Fail fast if the given string does not begin with a digit;
973
- // this bypasses strtoXXX's "optional leading whitespace and plus
974
- // or minus sign" semantics, which are undesirable here.
975
- if (str.empty() || !IsDigit(str[0])) {
976
- return false;
977
- }
978
- errno = 0;
979
-
980
- char* end;
981
- // BiggestConvertible is the largest integer type that system-provided
982
- // string-to-number conversion routines can return.
983
-
984
- # if GTEST_OS_WINDOWS && !defined(__GNUC__)
985
-
986
- // MSVC and C++ Builder define __int64 instead of the standard long long.
987
- typedef unsigned __int64 BiggestConvertible;
988
- const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
989
-
990
- # else
991
-
992
- typedef unsigned long long BiggestConvertible; // NOLINT
993
- const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
994
-
995
- # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
996
-
997
- const bool parse_success = *end == '\0' && errno == 0;
998
-
999
- // TODO(vladl@google.com): Convert this to compile time assertion when it is
1000
- // available.
1001
- GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
1002
-
1003
- const Integer result = static_cast<Integer>(parsed);
1004
- if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1005
- *number = result;
1006
- return true;
1007
- }
1008
- return false;
1009
- }
1010
- #endif // GTEST_HAS_DEATH_TEST
1011
-
1012
- // TestResult contains some private methods that should be hidden from
1013
- // Google Test user but are required for testing. This class allow our tests
1014
- // to access them.
1015
- //
1016
- // This class is supplied only for the purpose of testing Google Test's own
1017
- // constructs. Do not use it in user tests, either directly or indirectly.
1018
- class TestResultAccessor {
1019
- public:
1020
- static void RecordProperty(TestResult* test_result,
1021
- const TestProperty& property) {
1022
- test_result->RecordProperty(property);
1023
- }
1024
-
1025
- static void ClearTestPartResults(TestResult* test_result) {
1026
- test_result->ClearTestPartResults();
1027
- }
1028
-
1029
- static const std::vector<testing::TestPartResult>& test_part_results(
1030
- const TestResult& test_result) {
1031
- return test_result.test_part_results();
1032
- }
1033
- };
1034
-
1035
- } // namespace internal
1036
- } // namespace testing
1037
-
1038
- #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_