cppjieba_rb 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +26 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +81 -0
  8. data/Rakefile +20 -0
  9. data/cppjieba_rb.gemspec +50 -0
  10. data/ext/cppjieba/.gitignore +17 -0
  11. data/ext/cppjieba/.travis.yml +22 -0
  12. data/ext/cppjieba/CMakeLists.txt +28 -0
  13. data/ext/cppjieba/ChangeLog.md +236 -0
  14. data/ext/cppjieba/README.md +285 -0
  15. data/ext/cppjieba/README_EN.md +111 -0
  16. data/ext/cppjieba/appveyor.yml +32 -0
  17. data/ext/cppjieba/deps/CMakeLists.txt +1 -0
  18. data/ext/cppjieba/deps/gtest/CMakeLists.txt +5 -0
  19. data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +283 -0
  20. data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +230 -0
  21. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +1421 -0
  22. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +487 -0
  23. data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +796 -0
  24. data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +232 -0
  25. data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +176 -0
  26. data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +259 -0
  27. data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +2155 -0
  28. data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +358 -0
  29. data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +58 -0
  30. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +308 -0
  31. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +210 -0
  32. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +1226 -0
  33. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +233 -0
  34. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +4822 -0
  35. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  36. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +619 -0
  37. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +1788 -0
  38. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +350 -0
  39. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +968 -0
  40. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +336 -0
  41. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +3330 -0
  42. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +296 -0
  43. data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
  44. data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +681 -0
  45. data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +509 -0
  46. data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
  47. data/ext/cppjieba/deps/gtest/src/gtest-all.cc +48 -0
  48. data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +1234 -0
  49. data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +380 -0
  50. data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +1038 -0
  51. data/ext/cppjieba/deps/gtest/src/gtest-port.cc +746 -0
  52. data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +356 -0
  53. data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +110 -0
  54. data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +110 -0
  55. data/ext/cppjieba/deps/gtest/src/gtest.cc +4898 -0
  56. data/ext/cppjieba/deps/gtest/src/gtest_main.cc +39 -0
  57. data/ext/cppjieba/deps/limonp/ArgvContext.hpp +70 -0
  58. data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +49 -0
  59. data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +67 -0
  60. data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +65 -0
  61. data/ext/cppjieba/deps/limonp/Closure.hpp +206 -0
  62. data/ext/cppjieba/deps/limonp/Colors.hpp +31 -0
  63. data/ext/cppjieba/deps/limonp/Condition.hpp +38 -0
  64. data/ext/cppjieba/deps/limonp/Config.hpp +103 -0
  65. data/ext/cppjieba/deps/limonp/FileLock.hpp +74 -0
  66. data/ext/cppjieba/deps/limonp/ForcePublic.hpp +7 -0
  67. data/ext/cppjieba/deps/limonp/LocalVector.hpp +139 -0
  68. data/ext/cppjieba/deps/limonp/Logging.hpp +76 -0
  69. data/ext/cppjieba/deps/limonp/Md5.hpp +411 -0
  70. data/ext/cppjieba/deps/limonp/MutexLock.hpp +51 -0
  71. data/ext/cppjieba/deps/limonp/NonCopyable.hpp +21 -0
  72. data/ext/cppjieba/deps/limonp/StdExtension.hpp +159 -0
  73. data/ext/cppjieba/deps/limonp/StringUtil.hpp +365 -0
  74. data/ext/cppjieba/deps/limonp/Thread.hpp +44 -0
  75. data/ext/cppjieba/deps/limonp/ThreadPool.hpp +86 -0
  76. data/ext/cppjieba/dict/README.md +31 -0
  77. data/ext/cppjieba/dict/hmm_model.utf8 +34 -0
  78. data/ext/cppjieba/dict/idf.utf8 +258826 -0
  79. data/ext/cppjieba/dict/jieba.dict.utf8 +348982 -0
  80. data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
  81. data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
  82. data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
  83. data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
  84. data/ext/cppjieba/dict/stop_words.utf8 +1534 -0
  85. data/ext/cppjieba/dict/user.dict.utf8 +4 -0
  86. data/ext/cppjieba/include/cppjieba/DictTrie.hpp +227 -0
  87. data/ext/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
  88. data/ext/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
  89. data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
  90. data/ext/cppjieba/include/cppjieba/Jieba.hpp +108 -0
  91. data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
  92. data/ext/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
  93. data/ext/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
  94. data/ext/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
  95. data/ext/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
  96. data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +90 -0
  97. data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
  98. data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
  99. data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
  100. data/ext/cppjieba/include/cppjieba/Trie.hpp +174 -0
  101. data/ext/cppjieba/include/cppjieba/Unicode.hpp +215 -0
  102. data/ext/cppjieba/test/CMakeLists.txt +5 -0
  103. data/ext/cppjieba/test/demo.cpp +80 -0
  104. data/ext/cppjieba/test/load_test.cpp +54 -0
  105. data/ext/cppjieba/test/testdata/curl.res +1 -0
  106. data/ext/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +109750 -0
  107. data/ext/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +34 -0
  108. data/ext/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +348982 -0
  109. data/ext/cppjieba/test/testdata/jieba.dict.0.1.utf8 +93 -0
  110. data/ext/cppjieba/test/testdata/jieba.dict.0.utf8 +93 -0
  111. data/ext/cppjieba/test/testdata/jieba.dict.1.utf8 +67 -0
  112. data/ext/cppjieba/test/testdata/jieba.dict.2.utf8 +64 -0
  113. data/ext/cppjieba/test/testdata/load_test.urls +2 -0
  114. data/ext/cppjieba/test/testdata/review.100 +100 -0
  115. data/ext/cppjieba/test/testdata/review.100.res +200 -0
  116. data/ext/cppjieba/test/testdata/server.conf +19 -0
  117. data/ext/cppjieba/test/testdata/testlines.gbk +9 -0
  118. data/ext/cppjieba/test/testdata/testlines.utf8 +8 -0
  119. data/ext/cppjieba/test/testdata/userdict.2.utf8 +1 -0
  120. data/ext/cppjieba/test/testdata/userdict.english +2 -0
  121. data/ext/cppjieba/test/testdata/userdict.utf8 +8 -0
  122. data/ext/cppjieba/test/testdata/weicheng.utf8 +247 -0
  123. data/ext/cppjieba/test/unittest/CMakeLists.txt +24 -0
  124. data/ext/cppjieba/test/unittest/gtest_main.cpp +39 -0
  125. data/ext/cppjieba/test/unittest/jieba_test.cpp +133 -0
  126. data/ext/cppjieba/test/unittest/keyword_extractor_test.cpp +79 -0
  127. data/ext/cppjieba/test/unittest/pos_tagger_test.cpp +41 -0
  128. data/ext/cppjieba/test/unittest/pre_filter_test.cpp +43 -0
  129. data/ext/cppjieba/test/unittest/segments_test.cpp +256 -0
  130. data/ext/cppjieba/test/unittest/textrank_test.cpp +86 -0
  131. data/ext/cppjieba/test/unittest/trie_test.cpp +177 -0
  132. data/ext/cppjieba/test/unittest/unicode_test.cpp +43 -0
  133. data/ext/cppjieba_rb/cppjieba_rb.c +10 -0
  134. data/ext/cppjieba_rb/extconf.rb +26 -0
  135. data/ext/cppjieba_rb/internal.cc +148 -0
  136. data/lib/cppjieba_rb/segment.rb +20 -0
  137. data/lib/cppjieba_rb/version.rb +3 -0
  138. data/lib/cppjieba_rb.rb +34 -0
  139. data/test/test_keyword.rb +17 -0
  140. data/test/test_segment.rb +24 -0
  141. data/test/test_tagging.rb +19 -0
  142. metadata +244 -0
@@ -0,0 +1,356 @@
1
+ // Copyright 2007, 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: wan@google.com (Zhanyong Wan)
31
+
32
+ // Google Test - The Google C++ Testing Framework
33
+ //
34
+ // This file implements a universal value printer that can print a
35
+ // value of any type T:
36
+ //
37
+ // void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
38
+ //
39
+ // It uses the << operator when possible, and prints the bytes in the
40
+ // object otherwise. A user can override its behavior for a class
41
+ // type Foo by defining either operator<<(::std::ostream&, const Foo&)
42
+ // or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
43
+ // defines Foo.
44
+
45
+ #include "gtest/gtest-printers.h"
46
+ #include <ctype.h>
47
+ #include <stdio.h>
48
+ #include <ostream> // NOLINT
49
+ #include <string>
50
+ #include "gtest/internal/gtest-port.h"
51
+
52
+ namespace testing {
53
+
54
+ namespace {
55
+
56
+ using ::std::ostream;
57
+
58
+ #if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
59
+ # define snprintf _snprintf
60
+ #elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
61
+ # define snprintf _snprintf_s
62
+ #elif _MSC_VER
63
+ # define snprintf _snprintf
64
+ #endif // GTEST_OS_WINDOWS_MOBILE
65
+
66
+ // Prints a segment of bytes in the given object.
67
+ void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
68
+ size_t count, ostream* os) {
69
+ char text[5] = "";
70
+ for (size_t i = 0; i != count; i++) {
71
+ const size_t j = start + i;
72
+ if (i != 0) {
73
+ // Organizes the bytes into groups of 2 for easy parsing by
74
+ // human.
75
+ if ((j % 2) == 0)
76
+ *os << ' ';
77
+ else
78
+ *os << '-';
79
+ }
80
+ snprintf(text, sizeof(text), "%02X", obj_bytes[j]);
81
+ *os << text;
82
+ }
83
+ }
84
+
85
+ // Prints the bytes in the given value to the given ostream.
86
+ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
87
+ ostream* os) {
88
+ // Tells the user how big the object is.
89
+ *os << count << "-byte object <";
90
+
91
+ const size_t kThreshold = 132;
92
+ const size_t kChunkSize = 64;
93
+ // If the object size is bigger than kThreshold, we'll have to omit
94
+ // some details by printing only the first and the last kChunkSize
95
+ // bytes.
96
+ // TODO(wan): let the user control the threshold using a flag.
97
+ if (count < kThreshold) {
98
+ PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
99
+ } else {
100
+ PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
101
+ *os << " ... ";
102
+ // Rounds up to 2-byte boundary.
103
+ const size_t resume_pos = (count - kChunkSize + 1)/2*2;
104
+ PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
105
+ }
106
+ *os << ">";
107
+ }
108
+
109
+ } // namespace
110
+
111
+ namespace internal2 {
112
+
113
+ // Delegates to PrintBytesInObjectToImpl() to print the bytes in the
114
+ // given object. The delegation simplifies the implementation, which
115
+ // uses the << operator and thus is easier done outside of the
116
+ // ::testing::internal namespace, which contains a << operator that
117
+ // sometimes conflicts with the one in STL.
118
+ void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
119
+ ostream* os) {
120
+ PrintBytesInObjectToImpl(obj_bytes, count, os);
121
+ }
122
+
123
+ } // namespace internal2
124
+
125
+ namespace internal {
126
+
127
+ // Depending on the value of a char (or wchar_t), we print it in one
128
+ // of three formats:
129
+ // - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
130
+ // - as a hexidecimal escape sequence (e.g. '\x7F'), or
131
+ // - as a special escape sequence (e.g. '\r', '\n').
132
+ enum CharFormat {
133
+ kAsIs,
134
+ kHexEscape,
135
+ kSpecialEscape
136
+ };
137
+
138
+ // Returns true if c is a printable ASCII character. We test the
139
+ // value of c directly instead of calling isprint(), which is buggy on
140
+ // Windows Mobile.
141
+ inline bool IsPrintableAscii(wchar_t c) {
142
+ return 0x20 <= c && c <= 0x7E;
143
+ }
144
+
145
+ // Prints a wide or narrow char c as a character literal without the
146
+ // quotes, escaping it when necessary; returns how c was formatted.
147
+ // The template argument UnsignedChar is the unsigned version of Char,
148
+ // which is the type of c.
149
+ template <typename UnsignedChar, typename Char>
150
+ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
151
+ switch (static_cast<wchar_t>(c)) {
152
+ case L'\0':
153
+ *os << "\\0";
154
+ break;
155
+ case L'\'':
156
+ *os << "\\'";
157
+ break;
158
+ case L'\\':
159
+ *os << "\\\\";
160
+ break;
161
+ case L'\a':
162
+ *os << "\\a";
163
+ break;
164
+ case L'\b':
165
+ *os << "\\b";
166
+ break;
167
+ case L'\f':
168
+ *os << "\\f";
169
+ break;
170
+ case L'\n':
171
+ *os << "\\n";
172
+ break;
173
+ case L'\r':
174
+ *os << "\\r";
175
+ break;
176
+ case L'\t':
177
+ *os << "\\t";
178
+ break;
179
+ case L'\v':
180
+ *os << "\\v";
181
+ break;
182
+ default:
183
+ if (IsPrintableAscii(c)) {
184
+ *os << static_cast<char>(c);
185
+ return kAsIs;
186
+ } else {
187
+ *os << String::Format("\\x%X", static_cast<UnsignedChar>(c));
188
+ return kHexEscape;
189
+ }
190
+ }
191
+ return kSpecialEscape;
192
+ }
193
+
194
+ // Prints a char c as if it's part of a string literal, escaping it when
195
+ // necessary; returns how c was formatted.
196
+ static CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {
197
+ switch (c) {
198
+ case L'\'':
199
+ *os << "'";
200
+ return kAsIs;
201
+ case L'"':
202
+ *os << "\\\"";
203
+ return kSpecialEscape;
204
+ default:
205
+ return PrintAsCharLiteralTo<wchar_t>(c, os);
206
+ }
207
+ }
208
+
209
+ // Prints a char c as if it's part of a string literal, escaping it when
210
+ // necessary; returns how c was formatted.
211
+ static CharFormat PrintAsNarrowStringLiteralTo(char c, ostream* os) {
212
+ return PrintAsWideStringLiteralTo(static_cast<unsigned char>(c), os);
213
+ }
214
+
215
+ // Prints a wide or narrow character c and its code. '\0' is printed
216
+ // as "'\\0'", other unprintable characters are also properly escaped
217
+ // using the standard C++ escape sequence. The template argument
218
+ // UnsignedChar is the unsigned version of Char, which is the type of c.
219
+ template <typename UnsignedChar, typename Char>
220
+ void PrintCharAndCodeTo(Char c, ostream* os) {
221
+ // First, print c as a literal in the most readable form we can find.
222
+ *os << ((sizeof(c) > 1) ? "L'" : "'");
223
+ const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
224
+ *os << "'";
225
+
226
+ // To aid user debugging, we also print c's code in decimal, unless
227
+ // it's 0 (in which case c was printed as '\\0', making the code
228
+ // obvious).
229
+ if (c == 0)
230
+ return;
231
+ *os << " (" << String::Format("%d", c).c_str();
232
+
233
+ // For more convenience, we print c's code again in hexidecimal,
234
+ // unless c was already printed in the form '\x##' or the code is in
235
+ // [1, 9].
236
+ if (format == kHexEscape || (1 <= c && c <= 9)) {
237
+ // Do nothing.
238
+ } else {
239
+ *os << String::Format(", 0x%X",
240
+ static_cast<UnsignedChar>(c)).c_str();
241
+ }
242
+ *os << ")";
243
+ }
244
+
245
+ void PrintTo(unsigned char c, ::std::ostream* os) {
246
+ PrintCharAndCodeTo<unsigned char>(c, os);
247
+ }
248
+ void PrintTo(signed char c, ::std::ostream* os) {
249
+ PrintCharAndCodeTo<unsigned char>(c, os);
250
+ }
251
+
252
+ // Prints a wchar_t as a symbol if it is printable or as its internal
253
+ // code otherwise and also as its code. L'\0' is printed as "L'\\0'".
254
+ void PrintTo(wchar_t wc, ostream* os) {
255
+ PrintCharAndCodeTo<wchar_t>(wc, os);
256
+ }
257
+
258
+ // Prints the given array of characters to the ostream.
259
+ // The array starts at *begin, the length is len, it may include '\0' characters
260
+ // and may not be null-terminated.
261
+ static void PrintCharsAsStringTo(const char* begin, size_t len, ostream* os) {
262
+ *os << "\"";
263
+ bool is_previous_hex = false;
264
+ for (size_t index = 0; index < len; ++index) {
265
+ const char cur = begin[index];
266
+ if (is_previous_hex && IsXDigit(cur)) {
267
+ // Previous character is of '\x..' form and this character can be
268
+ // interpreted as another hexadecimal digit in its number. Break string to
269
+ // disambiguate.
270
+ *os << "\" \"";
271
+ }
272
+ is_previous_hex = PrintAsNarrowStringLiteralTo(cur, os) == kHexEscape;
273
+ }
274
+ *os << "\"";
275
+ }
276
+
277
+ // Prints a (const) char array of 'len' elements, starting at address 'begin'.
278
+ void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
279
+ PrintCharsAsStringTo(begin, len, os);
280
+ }
281
+
282
+ // Prints the given array of wide characters to the ostream.
283
+ // The array starts at *begin, the length is len, it may include L'\0'
284
+ // characters and may not be null-terminated.
285
+ static void PrintWideCharsAsStringTo(const wchar_t* begin, size_t len,
286
+ ostream* os) {
287
+ *os << "L\"";
288
+ bool is_previous_hex = false;
289
+ for (size_t index = 0; index < len; ++index) {
290
+ const wchar_t cur = begin[index];
291
+ if (is_previous_hex && isascii(cur) && IsXDigit(static_cast<char>(cur))) {
292
+ // Previous character is of '\x..' form and this character can be
293
+ // interpreted as another hexadecimal digit in its number. Break string to
294
+ // disambiguate.
295
+ *os << "\" L\"";
296
+ }
297
+ is_previous_hex = PrintAsWideStringLiteralTo(cur, os) == kHexEscape;
298
+ }
299
+ *os << "\"";
300
+ }
301
+
302
+ // Prints the given C string to the ostream.
303
+ void PrintTo(const char* s, ostream* os) {
304
+ if (s == NULL) {
305
+ *os << "NULL";
306
+ } else {
307
+ *os << ImplicitCast_<const void*>(s) << " pointing to ";
308
+ PrintCharsAsStringTo(s, strlen(s), os);
309
+ }
310
+ }
311
+
312
+ // MSVC compiler can be configured to define whar_t as a typedef
313
+ // of unsigned short. Defining an overload for const wchar_t* in that case
314
+ // would cause pointers to unsigned shorts be printed as wide strings,
315
+ // possibly accessing more memory than intended and causing invalid
316
+ // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
317
+ // wchar_t is implemented as a native type.
318
+ #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
319
+ // Prints the given wide C string to the ostream.
320
+ void PrintTo(const wchar_t* s, ostream* os) {
321
+ if (s == NULL) {
322
+ *os << "NULL";
323
+ } else {
324
+ *os << ImplicitCast_<const void*>(s) << " pointing to ";
325
+ PrintWideCharsAsStringTo(s, wcslen(s), os);
326
+ }
327
+ }
328
+ #endif // wchar_t is native
329
+
330
+ // Prints a ::string object.
331
+ #if GTEST_HAS_GLOBAL_STRING
332
+ void PrintStringTo(const ::string& s, ostream* os) {
333
+ PrintCharsAsStringTo(s.data(), s.size(), os);
334
+ }
335
+ #endif // GTEST_HAS_GLOBAL_STRING
336
+
337
+ void PrintStringTo(const ::std::string& s, ostream* os) {
338
+ PrintCharsAsStringTo(s.data(), s.size(), os);
339
+ }
340
+
341
+ // Prints a ::wstring object.
342
+ #if GTEST_HAS_GLOBAL_WSTRING
343
+ void PrintWideStringTo(const ::wstring& s, ostream* os) {
344
+ PrintWideCharsAsStringTo(s.data(), s.size(), os);
345
+ }
346
+ #endif // GTEST_HAS_GLOBAL_WSTRING
347
+
348
+ #if GTEST_HAS_STD_WSTRING
349
+ void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
350
+ PrintWideCharsAsStringTo(s.data(), s.size(), os);
351
+ }
352
+ #endif // GTEST_HAS_STD_WSTRING
353
+
354
+ } // namespace internal
355
+
356
+ } // namespace testing
@@ -0,0 +1,110 @@
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: mheule@google.com (Markus Heule)
31
+ //
32
+ // The Google C++ Testing Framework (Google Test)
33
+
34
+ #include "gtest/gtest-test-part.h"
35
+
36
+ // Indicates that this translation unit is part of Google Test's
37
+ // implementation. It must come before gtest-internal-inl.h is
38
+ // included, or there will be a compiler error. This trick is to
39
+ // prevent a user from accidentally including gtest-internal-inl.h in
40
+ // his code.
41
+ #define GTEST_IMPLEMENTATION_ 1
42
+ #include "src/gtest-internal-inl.h"
43
+ #undef GTEST_IMPLEMENTATION_
44
+
45
+ namespace testing {
46
+
47
+ using internal::GetUnitTestImpl;
48
+
49
+ // Gets the summary of the failure message by omitting the stack trace
50
+ // in it.
51
+ internal::String TestPartResult::ExtractSummary(const char* message) {
52
+ const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
53
+ return stack_trace == NULL ? internal::String(message) :
54
+ internal::String(message, stack_trace - message);
55
+ }
56
+
57
+ // Prints a TestPartResult object.
58
+ std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
59
+ return os
60
+ << result.file_name() << ":" << result.line_number() << ": "
61
+ << (result.type() == TestPartResult::kSuccess ? "Success" :
62
+ result.type() == TestPartResult::kFatalFailure ? "Fatal failure" :
63
+ "Non-fatal failure") << ":\n"
64
+ << result.message() << std::endl;
65
+ }
66
+
67
+ // Appends a TestPartResult to the array.
68
+ void TestPartResultArray::Append(const TestPartResult& result) {
69
+ array_.push_back(result);
70
+ }
71
+
72
+ // Returns the TestPartResult at the given index (0-based).
73
+ const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
74
+ if (index < 0 || index >= size()) {
75
+ printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
76
+ internal::posix::Abort();
77
+ }
78
+
79
+ return array_[index];
80
+ }
81
+
82
+ // Returns the number of TestPartResult objects in the array.
83
+ int TestPartResultArray::size() const {
84
+ return static_cast<int>(array_.size());
85
+ }
86
+
87
+ namespace internal {
88
+
89
+ HasNewFatalFailureHelper::HasNewFatalFailureHelper()
90
+ : has_new_fatal_failure_(false),
91
+ original_reporter_(GetUnitTestImpl()->
92
+ GetTestPartResultReporterForCurrentThread()) {
93
+ GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
94
+ }
95
+
96
+ HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
97
+ GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
98
+ original_reporter_);
99
+ }
100
+
101
+ void HasNewFatalFailureHelper::ReportTestPartResult(
102
+ const TestPartResult& result) {
103
+ if (result.fatally_failed())
104
+ has_new_fatal_failure_ = true;
105
+ original_reporter_->ReportTestPartResult(result);
106
+ }
107
+
108
+ } // namespace internal
109
+
110
+ } // namespace testing
@@ -0,0 +1,110 @@
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: wan@google.com (Zhanyong Wan)
31
+
32
+ #include "gtest/gtest-typed-test.h"
33
+ #include "gtest/gtest.h"
34
+
35
+ namespace testing {
36
+ namespace internal {
37
+
38
+ #if GTEST_HAS_TYPED_TEST_P
39
+
40
+ // Skips to the first non-space char in str. Returns an empty string if str
41
+ // contains only whitespace characters.
42
+ static const char* SkipSpaces(const char* str) {
43
+ while (IsSpace(*str))
44
+ str++;
45
+ return str;
46
+ }
47
+
48
+ // Verifies that registered_tests match the test names in
49
+ // defined_test_names_; returns registered_tests if successful, or
50
+ // aborts the program otherwise.
51
+ const char* TypedTestCasePState::VerifyRegisteredTestNames(
52
+ const char* file, int line, const char* registered_tests) {
53
+ typedef ::std::set<const char*>::const_iterator DefinedTestIter;
54
+ registered_ = true;
55
+
56
+ // Skip initial whitespace in registered_tests since some
57
+ // preprocessors prefix stringizied literals with whitespace.
58
+ registered_tests = SkipSpaces(registered_tests);
59
+
60
+ Message errors;
61
+ ::std::set<String> tests;
62
+ for (const char* names = registered_tests; names != NULL;
63
+ names = SkipComma(names)) {
64
+ const String name = GetPrefixUntilComma(names);
65
+ if (tests.count(name) != 0) {
66
+ errors << "Test " << name << " is listed more than once.\n";
67
+ continue;
68
+ }
69
+
70
+ bool found = false;
71
+ for (DefinedTestIter it = defined_test_names_.begin();
72
+ it != defined_test_names_.end();
73
+ ++it) {
74
+ if (name == *it) {
75
+ found = true;
76
+ break;
77
+ }
78
+ }
79
+
80
+ if (found) {
81
+ tests.insert(name);
82
+ } else {
83
+ errors << "No test named " << name
84
+ << " can be found in this test case.\n";
85
+ }
86
+ }
87
+
88
+ for (DefinedTestIter it = defined_test_names_.begin();
89
+ it != defined_test_names_.end();
90
+ ++it) {
91
+ if (tests.count(*it) == 0) {
92
+ errors << "You forgot to list test " << *it << ".\n";
93
+ }
94
+ }
95
+
96
+ const String& errors_str = errors.GetString();
97
+ if (errors_str != "") {
98
+ fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
99
+ errors_str.c_str());
100
+ fflush(stderr);
101
+ posix::Abort();
102
+ }
103
+
104
+ return registered_tests;
105
+ }
106
+
107
+ #endif // GTEST_HAS_TYPED_TEST_P
108
+
109
+ } // namespace internal
110
+ } // namespace testing