cppjieba_rb 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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,232 @@
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
+ // Utilities for testing Google Test itself and code that uses Google Test
33
+ // (e.g. frameworks built on top of Google Test).
34
+
35
+ #ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
36
+ #define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
37
+
38
+ #include "gtest/gtest.h"
39
+
40
+ namespace testing {
41
+
42
+ // This helper class can be used to mock out Google Test failure reporting
43
+ // so that we can test Google Test or code that builds on Google Test.
44
+ //
45
+ // An object of this class appends a TestPartResult object to the
46
+ // TestPartResultArray object given in the constructor whenever a Google Test
47
+ // failure is reported. It can either intercept only failures that are
48
+ // generated in the same thread that created this object or it can intercept
49
+ // all generated failures. The scope of this mock object can be controlled with
50
+ // the second argument to the two arguments constructor.
51
+ class GTEST_API_ ScopedFakeTestPartResultReporter
52
+ : public TestPartResultReporterInterface {
53
+ public:
54
+ // The two possible mocking modes of this object.
55
+ enum InterceptMode {
56
+ INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
57
+ INTERCEPT_ALL_THREADS // Intercepts all failures.
58
+ };
59
+
60
+ // The c'tor sets this object as the test part result reporter used
61
+ // by Google Test. The 'result' parameter specifies where to report the
62
+ // results. This reporter will only catch failures generated in the current
63
+ // thread. DEPRECATED
64
+ explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
65
+
66
+ // Same as above, but you can choose the interception scope of this object.
67
+ ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
68
+ TestPartResultArray* result);
69
+
70
+ // The d'tor restores the previous test part result reporter.
71
+ virtual ~ScopedFakeTestPartResultReporter();
72
+
73
+ // Appends the TestPartResult object to the TestPartResultArray
74
+ // received in the constructor.
75
+ //
76
+ // This method is from the TestPartResultReporterInterface
77
+ // interface.
78
+ virtual void ReportTestPartResult(const TestPartResult& result);
79
+ private:
80
+ void Init();
81
+
82
+ const InterceptMode intercept_mode_;
83
+ TestPartResultReporterInterface* old_reporter_;
84
+ TestPartResultArray* const result_;
85
+
86
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
87
+ };
88
+
89
+ namespace internal {
90
+
91
+ // A helper class for implementing EXPECT_FATAL_FAILURE() and
92
+ // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
93
+ // TestPartResultArray contains exactly one failure that has the given
94
+ // type and contains the given substring. If that's not the case, a
95
+ // non-fatal failure will be generated.
96
+ class GTEST_API_ SingleFailureChecker {
97
+ public:
98
+ // The constructor remembers the arguments.
99
+ SingleFailureChecker(const TestPartResultArray* results,
100
+ TestPartResult::Type type,
101
+ const string& substr);
102
+ ~SingleFailureChecker();
103
+ private:
104
+ const TestPartResultArray* const results_;
105
+ const TestPartResult::Type type_;
106
+ const string substr_;
107
+
108
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
109
+ };
110
+
111
+ } // namespace internal
112
+
113
+ } // namespace testing
114
+
115
+ // A set of macros for testing Google Test assertions or code that's expected
116
+ // to generate Google Test fatal failures. It verifies that the given
117
+ // statement will cause exactly one fatal Google Test failure with 'substr'
118
+ // being part of the failure message.
119
+ //
120
+ // There are two different versions of this macro. EXPECT_FATAL_FAILURE only
121
+ // affects and considers failures generated in the current thread and
122
+ // EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
123
+ //
124
+ // The verification of the assertion is done correctly even when the statement
125
+ // throws an exception or aborts the current function.
126
+ //
127
+ // Known restrictions:
128
+ // - 'statement' cannot reference local non-static variables or
129
+ // non-static members of the current object.
130
+ // - 'statement' cannot return a value.
131
+ // - You cannot stream a failure message to this macro.
132
+ //
133
+ // Note that even though the implementations of the following two
134
+ // macros are much alike, we cannot refactor them to use a common
135
+ // helper macro, due to some peculiarity in how the preprocessor
136
+ // works. The AcceptsMacroThatExpandsToUnprotectedComma test in
137
+ // gtest_unittest.cc will fail to compile if we do that.
138
+ #define EXPECT_FATAL_FAILURE(statement, substr) \
139
+ do { \
140
+ class GTestExpectFatalFailureHelper {\
141
+ public:\
142
+ static void Execute() { statement; }\
143
+ };\
144
+ ::testing::TestPartResultArray gtest_failures;\
145
+ ::testing::internal::SingleFailureChecker gtest_checker(\
146
+ &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
147
+ {\
148
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
149
+ ::testing::ScopedFakeTestPartResultReporter:: \
150
+ INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
151
+ GTestExpectFatalFailureHelper::Execute();\
152
+ }\
153
+ } while (::testing::internal::AlwaysFalse())
154
+
155
+ #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
156
+ do { \
157
+ class GTestExpectFatalFailureHelper {\
158
+ public:\
159
+ static void Execute() { statement; }\
160
+ };\
161
+ ::testing::TestPartResultArray gtest_failures;\
162
+ ::testing::internal::SingleFailureChecker gtest_checker(\
163
+ &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
164
+ {\
165
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
166
+ ::testing::ScopedFakeTestPartResultReporter:: \
167
+ INTERCEPT_ALL_THREADS, &gtest_failures);\
168
+ GTestExpectFatalFailureHelper::Execute();\
169
+ }\
170
+ } while (::testing::internal::AlwaysFalse())
171
+
172
+ // A macro for testing Google Test assertions or code that's expected to
173
+ // generate Google Test non-fatal failures. It asserts that the given
174
+ // statement will cause exactly one non-fatal Google Test failure with 'substr'
175
+ // being part of the failure message.
176
+ //
177
+ // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
178
+ // affects and considers failures generated in the current thread and
179
+ // EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
180
+ //
181
+ // 'statement' is allowed to reference local variables and members of
182
+ // the current object.
183
+ //
184
+ // The verification of the assertion is done correctly even when the statement
185
+ // throws an exception or aborts the current function.
186
+ //
187
+ // Known restrictions:
188
+ // - You cannot stream a failure message to this macro.
189
+ //
190
+ // Note that even though the implementations of the following two
191
+ // macros are much alike, we cannot refactor them to use a common
192
+ // helper macro, due to some peculiarity in how the preprocessor
193
+ // works. If we do that, the code won't compile when the user gives
194
+ // EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
195
+ // expands to code containing an unprotected comma. The
196
+ // AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
197
+ // catches that.
198
+ //
199
+ // For the same reason, we have to write
200
+ // if (::testing::internal::AlwaysTrue()) { statement; }
201
+ // instead of
202
+ // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
203
+ // to avoid an MSVC warning on unreachable code.
204
+ #define EXPECT_NONFATAL_FAILURE(statement, substr) \
205
+ do {\
206
+ ::testing::TestPartResultArray gtest_failures;\
207
+ ::testing::internal::SingleFailureChecker gtest_checker(\
208
+ &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
209
+ (substr));\
210
+ {\
211
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
212
+ ::testing::ScopedFakeTestPartResultReporter:: \
213
+ INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
214
+ if (::testing::internal::AlwaysTrue()) { statement; }\
215
+ }\
216
+ } while (::testing::internal::AlwaysFalse())
217
+
218
+ #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
219
+ do {\
220
+ ::testing::TestPartResultArray gtest_failures;\
221
+ ::testing::internal::SingleFailureChecker gtest_checker(\
222
+ &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
223
+ (substr));\
224
+ {\
225
+ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
226
+ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
227
+ &gtest_failures);\
228
+ if (::testing::internal::AlwaysTrue()) { statement; }\
229
+ }\
230
+ } while (::testing::internal::AlwaysFalse())
231
+
232
+ #endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
@@ -0,0 +1,176 @@
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
+
33
+ #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
34
+ #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
35
+
36
+ #include <iosfwd>
37
+ #include <vector>
38
+ #include "gtest/internal/gtest-internal.h"
39
+ #include "gtest/internal/gtest-string.h"
40
+
41
+ namespace testing {
42
+
43
+ // A copyable object representing the result of a test part (i.e. an
44
+ // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
45
+ //
46
+ // Don't inherit from TestPartResult as its destructor is not virtual.
47
+ class GTEST_API_ TestPartResult {
48
+ public:
49
+ // The possible outcomes of a test part (i.e. an assertion or an
50
+ // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
51
+ enum Type {
52
+ kSuccess, // Succeeded.
53
+ kNonFatalFailure, // Failed but the test can continue.
54
+ kFatalFailure // Failed and the test should be terminated.
55
+ };
56
+
57
+ // C'tor. TestPartResult does NOT have a default constructor.
58
+ // Always use this constructor (with parameters) to create a
59
+ // TestPartResult object.
60
+ TestPartResult(Type a_type,
61
+ const char* a_file_name,
62
+ int a_line_number,
63
+ const char* a_message)
64
+ : type_(a_type),
65
+ file_name_(a_file_name),
66
+ line_number_(a_line_number),
67
+ summary_(ExtractSummary(a_message)),
68
+ message_(a_message) {
69
+ }
70
+
71
+ // Gets the outcome of the test part.
72
+ Type type() const { return type_; }
73
+
74
+ // Gets the name of the source file where the test part took place, or
75
+ // NULL if it's unknown.
76
+ const char* file_name() const { return file_name_.c_str(); }
77
+
78
+ // Gets the line in the source file where the test part took place,
79
+ // or -1 if it's unknown.
80
+ int line_number() const { return line_number_; }
81
+
82
+ // Gets the summary of the failure message.
83
+ const char* summary() const { return summary_.c_str(); }
84
+
85
+ // Gets the message associated with the test part.
86
+ const char* message() const { return message_.c_str(); }
87
+
88
+ // Returns true iff the test part passed.
89
+ bool passed() const { return type_ == kSuccess; }
90
+
91
+ // Returns true iff the test part failed.
92
+ bool failed() const { return type_ != kSuccess; }
93
+
94
+ // Returns true iff the test part non-fatally failed.
95
+ bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
96
+
97
+ // Returns true iff the test part fatally failed.
98
+ bool fatally_failed() const { return type_ == kFatalFailure; }
99
+ private:
100
+ Type type_;
101
+
102
+ // Gets the summary of the failure message by omitting the stack
103
+ // trace in it.
104
+ static internal::String ExtractSummary(const char* message);
105
+
106
+ // The name of the source file where the test part took place, or
107
+ // NULL if the source file is unknown.
108
+ internal::String file_name_;
109
+ // The line in the source file where the test part took place, or -1
110
+ // if the line number is unknown.
111
+ int line_number_;
112
+ internal::String summary_; // The test failure summary.
113
+ internal::String message_; // The test failure message.
114
+ };
115
+
116
+ // Prints a TestPartResult object.
117
+ std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
118
+
119
+ // An array of TestPartResult objects.
120
+ //
121
+ // Don't inherit from TestPartResultArray as its destructor is not
122
+ // virtual.
123
+ class GTEST_API_ TestPartResultArray {
124
+ public:
125
+ TestPartResultArray() {}
126
+
127
+ // Appends the given TestPartResult to the array.
128
+ void Append(const TestPartResult& result);
129
+
130
+ // Returns the TestPartResult at the given index (0-based).
131
+ const TestPartResult& GetTestPartResult(int index) const;
132
+
133
+ // Returns the number of TestPartResult objects in the array.
134
+ int size() const;
135
+
136
+ private:
137
+ std::vector<TestPartResult> array_;
138
+
139
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
140
+ };
141
+
142
+ // This interface knows how to report a test part result.
143
+ class TestPartResultReporterInterface {
144
+ public:
145
+ virtual ~TestPartResultReporterInterface() {}
146
+
147
+ virtual void ReportTestPartResult(const TestPartResult& result) = 0;
148
+ };
149
+
150
+ namespace internal {
151
+
152
+ // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
153
+ // statement generates new fatal failures. To do so it registers itself as the
154
+ // current test part result reporter. Besides checking if fatal failures were
155
+ // reported, it only delegates the reporting to the former result reporter.
156
+ // The original result reporter is restored in the destructor.
157
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
158
+ class GTEST_API_ HasNewFatalFailureHelper
159
+ : public TestPartResultReporterInterface {
160
+ public:
161
+ HasNewFatalFailureHelper();
162
+ virtual ~HasNewFatalFailureHelper();
163
+ virtual void ReportTestPartResult(const TestPartResult& result);
164
+ bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
165
+ private:
166
+ bool has_new_fatal_failure_;
167
+ TestPartResultReporterInterface* original_reporter_;
168
+
169
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
170
+ };
171
+
172
+ } // namespace internal
173
+
174
+ } // namespace testing
175
+
176
+ #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
@@ -0,0 +1,259 @@
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
+ #ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
33
+ #define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
34
+
35
+ // This header implements typed tests and type-parameterized tests.
36
+
37
+ // Typed (aka type-driven) tests repeat the same test for types in a
38
+ // list. You must know which types you want to test with when writing
39
+ // typed tests. Here's how you do it:
40
+
41
+ #if 0
42
+
43
+ // First, define a fixture class template. It should be parameterized
44
+ // by a type. Remember to derive it from testing::Test.
45
+ template <typename T>
46
+ class FooTest : public testing::Test {
47
+ public:
48
+ ...
49
+ typedef std::list<T> List;
50
+ static T shared_;
51
+ T value_;
52
+ };
53
+
54
+ // Next, associate a list of types with the test case, which will be
55
+ // repeated for each type in the list. The typedef is necessary for
56
+ // the macro to parse correctly.
57
+ typedef testing::Types<char, int, unsigned int> MyTypes;
58
+ TYPED_TEST_CASE(FooTest, MyTypes);
59
+
60
+ // If the type list contains only one type, you can write that type
61
+ // directly without Types<...>:
62
+ // TYPED_TEST_CASE(FooTest, int);
63
+
64
+ // Then, use TYPED_TEST() instead of TEST_F() to define as many typed
65
+ // tests for this test case as you want.
66
+ TYPED_TEST(FooTest, DoesBlah) {
67
+ // Inside a test, refer to TypeParam to get the type parameter.
68
+ // Since we are inside a derived class template, C++ requires use to
69
+ // visit the members of FooTest via 'this'.
70
+ TypeParam n = this->value_;
71
+
72
+ // To visit static members of the fixture, add the TestFixture::
73
+ // prefix.
74
+ n += TestFixture::shared_;
75
+
76
+ // To refer to typedefs in the fixture, add the "typename
77
+ // TestFixture::" prefix.
78
+ typename TestFixture::List values;
79
+ values.push_back(n);
80
+ ...
81
+ }
82
+
83
+ TYPED_TEST(FooTest, HasPropertyA) { ... }
84
+
85
+ #endif // 0
86
+
87
+ // Type-parameterized tests are abstract test patterns parameterized
88
+ // by a type. Compared with typed tests, type-parameterized tests
89
+ // allow you to define the test pattern without knowing what the type
90
+ // parameters are. The defined pattern can be instantiated with
91
+ // different types any number of times, in any number of translation
92
+ // units.
93
+ //
94
+ // If you are designing an interface or concept, you can define a
95
+ // suite of type-parameterized tests to verify properties that any
96
+ // valid implementation of the interface/concept should have. Then,
97
+ // each implementation can easily instantiate the test suite to verify
98
+ // that it conforms to the requirements, without having to write
99
+ // similar tests repeatedly. Here's an example:
100
+
101
+ #if 0
102
+
103
+ // First, define a fixture class template. It should be parameterized
104
+ // by a type. Remember to derive it from testing::Test.
105
+ template <typename T>
106
+ class FooTest : public testing::Test {
107
+ ...
108
+ };
109
+
110
+ // Next, declare that you will define a type-parameterized test case
111
+ // (the _P suffix is for "parameterized" or "pattern", whichever you
112
+ // prefer):
113
+ TYPED_TEST_CASE_P(FooTest);
114
+
115
+ // Then, use TYPED_TEST_P() to define as many type-parameterized tests
116
+ // for this type-parameterized test case as you want.
117
+ TYPED_TEST_P(FooTest, DoesBlah) {
118
+ // Inside a test, refer to TypeParam to get the type parameter.
119
+ TypeParam n = 0;
120
+ ...
121
+ }
122
+
123
+ TYPED_TEST_P(FooTest, HasPropertyA) { ... }
124
+
125
+ // Now the tricky part: you need to register all test patterns before
126
+ // you can instantiate them. The first argument of the macro is the
127
+ // test case name; the rest are the names of the tests in this test
128
+ // case.
129
+ REGISTER_TYPED_TEST_CASE_P(FooTest,
130
+ DoesBlah, HasPropertyA);
131
+
132
+ // Finally, you are free to instantiate the pattern with the types you
133
+ // want. If you put the above code in a header file, you can #include
134
+ // it in multiple C++ source files and instantiate it multiple times.
135
+ //
136
+ // To distinguish different instances of the pattern, the first
137
+ // argument to the INSTANTIATE_* macro is a prefix that will be added
138
+ // to the actual test case name. Remember to pick unique prefixes for
139
+ // different instances.
140
+ typedef testing::Types<char, int, unsigned int> MyTypes;
141
+ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
142
+
143
+ // If the type list contains only one type, you can write that type
144
+ // directly without Types<...>:
145
+ // INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
146
+
147
+ #endif // 0
148
+
149
+ #include "gtest/internal/gtest-port.h"
150
+ #include "gtest/internal/gtest-type-util.h"
151
+
152
+ // Implements typed tests.
153
+
154
+ #if GTEST_HAS_TYPED_TEST
155
+
156
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
157
+ //
158
+ // Expands to the name of the typedef for the type parameters of the
159
+ // given test case.
160
+ # define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
161
+
162
+ // The 'Types' template argument below must have spaces around it
163
+ // since some compilers may choke on '>>' when passing a template
164
+ // instance (e.g. Types<int>)
165
+ # define TYPED_TEST_CASE(CaseName, Types) \
166
+ typedef ::testing::internal::TypeList< Types >::type \
167
+ GTEST_TYPE_PARAMS_(CaseName)
168
+
169
+ # define TYPED_TEST(CaseName, TestName) \
170
+ template <typename gtest_TypeParam_> \
171
+ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
172
+ : public CaseName<gtest_TypeParam_> { \
173
+ private: \
174
+ typedef CaseName<gtest_TypeParam_> TestFixture; \
175
+ typedef gtest_TypeParam_ TypeParam; \
176
+ virtual void TestBody(); \
177
+ }; \
178
+ bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
179
+ ::testing::internal::TypeParameterizedTest< \
180
+ CaseName, \
181
+ ::testing::internal::TemplateSel< \
182
+ GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
183
+ GTEST_TYPE_PARAMS_(CaseName)>::Register(\
184
+ "", #CaseName, #TestName, 0); \
185
+ template <typename gtest_TypeParam_> \
186
+ void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()
187
+
188
+ #endif // GTEST_HAS_TYPED_TEST
189
+
190
+ // Implements type-parameterized tests.
191
+
192
+ #if GTEST_HAS_TYPED_TEST_P
193
+
194
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
195
+ //
196
+ // Expands to the namespace name that the type-parameterized tests for
197
+ // the given type-parameterized test case are defined in. The exact
198
+ // name of the namespace is subject to change without notice.
199
+ # define GTEST_CASE_NAMESPACE_(TestCaseName) \
200
+ gtest_case_##TestCaseName##_
201
+
202
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
203
+ //
204
+ // Expands to the name of the variable used to remember the names of
205
+ // the defined tests in the given test case.
206
+ # define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
207
+ gtest_typed_test_case_p_state_##TestCaseName##_
208
+
209
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
210
+ //
211
+ // Expands to the name of the variable used to remember the names of
212
+ // the registered tests in the given test case.
213
+ # define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
214
+ gtest_registered_test_names_##TestCaseName##_
215
+
216
+ // The variables defined in the type-parameterized test macros are
217
+ // static as typically these macros are used in a .h file that can be
218
+ // #included in multiple translation units linked together.
219
+ # define TYPED_TEST_CASE_P(CaseName) \
220
+ static ::testing::internal::TypedTestCasePState \
221
+ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
222
+
223
+ # define TYPED_TEST_P(CaseName, TestName) \
224
+ namespace GTEST_CASE_NAMESPACE_(CaseName) { \
225
+ template <typename gtest_TypeParam_> \
226
+ class TestName : public CaseName<gtest_TypeParam_> { \
227
+ private: \
228
+ typedef CaseName<gtest_TypeParam_> TestFixture; \
229
+ typedef gtest_TypeParam_ TypeParam; \
230
+ virtual void TestBody(); \
231
+ }; \
232
+ static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
233
+ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
234
+ __FILE__, __LINE__, #CaseName, #TestName); \
235
+ } \
236
+ template <typename gtest_TypeParam_> \
237
+ void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
238
+
239
+ # define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
240
+ namespace GTEST_CASE_NAMESPACE_(CaseName) { \
241
+ typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
242
+ } \
243
+ static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
244
+ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
245
+ __FILE__, __LINE__, #__VA_ARGS__)
246
+
247
+ // The 'Types' template argument below must have spaces around it
248
+ // since some compilers may choke on '>>' when passing a template
249
+ // instance (e.g. Types<int>)
250
+ # define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
251
+ bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
252
+ ::testing::internal::TypeParameterizedTestCase<CaseName, \
253
+ GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
254
+ ::testing::internal::TypeList< Types >::type>::Register(\
255
+ #Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
256
+
257
+ #endif // GTEST_HAS_TYPED_TEST_P
258
+
259
+ #endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_