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,308 @@
1
+ // Copyright 2005, Google Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ //
30
+ // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
31
+ //
32
+ // The Google C++ Testing Framework (Google Test)
33
+ //
34
+ // This header file defines internal utilities needed for implementing
35
+ // death tests. They are subject to change without notice.
36
+
37
+ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
38
+ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
39
+
40
+ #include "gtest/internal/gtest-internal.h"
41
+
42
+ #include <stdio.h>
43
+
44
+ namespace testing {
45
+ namespace internal {
46
+
47
+ GTEST_DECLARE_string_(internal_run_death_test);
48
+
49
+ // Names of the flags (needed for parsing Google Test flags).
50
+ const char kDeathTestStyleFlag[] = "death_test_style";
51
+ const char kDeathTestUseFork[] = "death_test_use_fork";
52
+ const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
53
+
54
+ #if GTEST_HAS_DEATH_TEST
55
+
56
+ // DeathTest is a class that hides much of the complexity of the
57
+ // GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
58
+ // returns a concrete class that depends on the prevailing death test
59
+ // style, as defined by the --gtest_death_test_style and/or
60
+ // --gtest_internal_run_death_test flags.
61
+
62
+ // In describing the results of death tests, these terms are used with
63
+ // the corresponding definitions:
64
+ //
65
+ // exit status: The integer exit information in the format specified
66
+ // by wait(2)
67
+ // exit code: The integer code passed to exit(3), _exit(2), or
68
+ // returned from main()
69
+ class GTEST_API_ DeathTest {
70
+ public:
71
+ // Create returns false if there was an error determining the
72
+ // appropriate action to take for the current death test; for example,
73
+ // if the gtest_death_test_style flag is set to an invalid value.
74
+ // The LastMessage method will return a more detailed message in that
75
+ // case. Otherwise, the DeathTest pointer pointed to by the "test"
76
+ // argument is set. If the death test should be skipped, the pointer
77
+ // is set to NULL; otherwise, it is set to the address of a new concrete
78
+ // DeathTest object that controls the execution of the current test.
79
+ static bool Create(const char* statement, const RE* regex,
80
+ const char* file, int line, DeathTest** test);
81
+ DeathTest();
82
+ virtual ~DeathTest() { }
83
+
84
+ // A helper class that aborts a death test when it's deleted.
85
+ class ReturnSentinel {
86
+ public:
87
+ explicit ReturnSentinel(DeathTest* test) : test_(test) { }
88
+ ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
89
+ private:
90
+ DeathTest* const test_;
91
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
92
+ } GTEST_ATTRIBUTE_UNUSED_;
93
+
94
+ // An enumeration of possible roles that may be taken when a death
95
+ // test is encountered. EXECUTE means that the death test logic should
96
+ // be executed immediately. OVERSEE means that the program should prepare
97
+ // the appropriate environment for a child process to execute the death
98
+ // test, then wait for it to complete.
99
+ enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
100
+
101
+ // An enumeration of the three reasons that a test might be aborted.
102
+ enum AbortReason {
103
+ TEST_ENCOUNTERED_RETURN_STATEMENT,
104
+ TEST_THREW_EXCEPTION,
105
+ TEST_DID_NOT_DIE
106
+ };
107
+
108
+ // Assumes one of the above roles.
109
+ virtual TestRole AssumeRole() = 0;
110
+
111
+ // Waits for the death test to finish and returns its status.
112
+ virtual int Wait() = 0;
113
+
114
+ // Returns true if the death test passed; that is, the test process
115
+ // exited during the test, its exit status matches a user-supplied
116
+ // predicate, and its stderr output matches a user-supplied regular
117
+ // expression.
118
+ // The user-supplied predicate may be a macro expression rather
119
+ // than a function pointer or functor, or else Wait and Passed could
120
+ // be combined.
121
+ virtual bool Passed(bool exit_status_ok) = 0;
122
+
123
+ // Signals that the death test did not die as expected.
124
+ virtual void Abort(AbortReason reason) = 0;
125
+
126
+ // Returns a human-readable outcome message regarding the outcome of
127
+ // the last death test.
128
+ static const char* LastMessage();
129
+
130
+ static void set_last_death_test_message(const String& message);
131
+
132
+ private:
133
+ // A string containing a description of the outcome of the last death test.
134
+ static String last_death_test_message_;
135
+
136
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
137
+ };
138
+
139
+ // Factory interface for death tests. May be mocked out for testing.
140
+ class DeathTestFactory {
141
+ public:
142
+ virtual ~DeathTestFactory() { }
143
+ virtual bool Create(const char* statement, const RE* regex,
144
+ const char* file, int line, DeathTest** test) = 0;
145
+ };
146
+
147
+ // A concrete DeathTestFactory implementation for normal use.
148
+ class DefaultDeathTestFactory : public DeathTestFactory {
149
+ public:
150
+ virtual bool Create(const char* statement, const RE* regex,
151
+ const char* file, int line, DeathTest** test);
152
+ };
153
+
154
+ // Returns true if exit_status describes a process that was terminated
155
+ // by a signal, or exited normally with a nonzero exit code.
156
+ GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
157
+
158
+ // Traps C++ exceptions escaping statement and reports them as test
159
+ // failures. Note that trapping SEH exceptions is not implemented here.
160
+ # if GTEST_HAS_EXCEPTIONS
161
+ # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
162
+ try { \
163
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
164
+ } catch (const ::std::exception& gtest_exception) { \
165
+ fprintf(\
166
+ stderr, \
167
+ "\n%s: Caught std::exception-derived exception escaping the " \
168
+ "death test statement. Exception message: %s\n", \
169
+ ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
170
+ gtest_exception.what()); \
171
+ fflush(stderr); \
172
+ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
173
+ } catch (...) { \
174
+ death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
175
+ }
176
+
177
+ # else
178
+ # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
179
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
180
+
181
+ # endif
182
+
183
+ // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
184
+ // ASSERT_EXIT*, and EXPECT_EXIT*.
185
+ # define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
186
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
187
+ if (::testing::internal::AlwaysTrue()) { \
188
+ const ::testing::internal::RE& gtest_regex = (regex); \
189
+ ::testing::internal::DeathTest* gtest_dt; \
190
+ if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \
191
+ __FILE__, __LINE__, &gtest_dt)) { \
192
+ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
193
+ } \
194
+ if (gtest_dt != NULL) { \
195
+ ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
196
+ gtest_dt_ptr(gtest_dt); \
197
+ switch (gtest_dt->AssumeRole()) { \
198
+ case ::testing::internal::DeathTest::OVERSEE_TEST: \
199
+ if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
200
+ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
201
+ } \
202
+ break; \
203
+ case ::testing::internal::DeathTest::EXECUTE_TEST: { \
204
+ ::testing::internal::DeathTest::ReturnSentinel \
205
+ gtest_sentinel(gtest_dt); \
206
+ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
207
+ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
208
+ break; \
209
+ } \
210
+ default: \
211
+ break; \
212
+ } \
213
+ } \
214
+ } else \
215
+ GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
216
+ fail(::testing::internal::DeathTest::LastMessage())
217
+ // The symbol "fail" here expands to something into which a message
218
+ // can be streamed.
219
+
220
+ // A class representing the parsed contents of the
221
+ // --gtest_internal_run_death_test flag, as it existed when
222
+ // RUN_ALL_TESTS was called.
223
+ class InternalRunDeathTestFlag {
224
+ public:
225
+ InternalRunDeathTestFlag(const String& a_file,
226
+ int a_line,
227
+ int an_index,
228
+ int a_write_fd)
229
+ : file_(a_file), line_(a_line), index_(an_index),
230
+ write_fd_(a_write_fd) {}
231
+
232
+ ~InternalRunDeathTestFlag() {
233
+ if (write_fd_ >= 0)
234
+ posix::Close(write_fd_);
235
+ }
236
+
237
+ String file() const { return file_; }
238
+ int line() const { return line_; }
239
+ int index() const { return index_; }
240
+ int write_fd() const { return write_fd_; }
241
+
242
+ private:
243
+ String file_;
244
+ int line_;
245
+ int index_;
246
+ int write_fd_;
247
+
248
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
249
+ };
250
+
251
+ // Returns a newly created InternalRunDeathTestFlag object with fields
252
+ // initialized from the GTEST_FLAG(internal_run_death_test) flag if
253
+ // the flag is specified; otherwise returns NULL.
254
+ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
255
+
256
+ #else // GTEST_HAS_DEATH_TEST
257
+
258
+ // This macro is used for implementing macros such as
259
+ // EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
260
+ // death tests are not supported. Those macros must compile on such systems
261
+ // iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
262
+ // systems that support death tests. This allows one to write such a macro
263
+ // on a system that does not support death tests and be sure that it will
264
+ // compile on a death-test supporting system.
265
+ //
266
+ // Parameters:
267
+ // statement - A statement that a macro such as EXPECT_DEATH would test
268
+ // for program termination. This macro has to make sure this
269
+ // statement is compiled but not executed, to ensure that
270
+ // EXPECT_DEATH_IF_SUPPORTED compiles with a certain
271
+ // parameter iff EXPECT_DEATH compiles with it.
272
+ // regex - A regex that a macro such as EXPECT_DEATH would use to test
273
+ // the output of statement. This parameter has to be
274
+ // compiled but not evaluated by this macro, to ensure that
275
+ // this macro only accepts expressions that a macro such as
276
+ // EXPECT_DEATH would accept.
277
+ // terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
278
+ // and a return statement for ASSERT_DEATH_IF_SUPPORTED.
279
+ // This ensures that ASSERT_DEATH_IF_SUPPORTED will not
280
+ // compile inside functions where ASSERT_DEATH doesn't
281
+ // compile.
282
+ //
283
+ // The branch that has an always false condition is used to ensure that
284
+ // statement and regex are compiled (and thus syntactically correct) but
285
+ // never executed. The unreachable code macro protects the terminator
286
+ // statement from generating an 'unreachable code' warning in case
287
+ // statement unconditionally returns or throws. The Message constructor at
288
+ // the end allows the syntax of streaming additional messages into the
289
+ // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
290
+ # define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
291
+ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
292
+ if (::testing::internal::AlwaysTrue()) { \
293
+ GTEST_LOG_(WARNING) \
294
+ << "Death tests are not supported on this platform.\n" \
295
+ << "Statement '" #statement "' cannot be verified."; \
296
+ } else if (::testing::internal::AlwaysFalse()) { \
297
+ ::testing::internal::RE::PartialMatch(".*", (regex)); \
298
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
299
+ terminator; \
300
+ } else \
301
+ ::testing::Message()
302
+
303
+ #endif // GTEST_HAS_DEATH_TEST
304
+
305
+ } // namespace internal
306
+ } // namespace testing
307
+
308
+ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
@@ -0,0 +1,210 @@
1
+ // Copyright 2008, Google Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ //
30
+ // Author: keith.ray@gmail.com (Keith Ray)
31
+ //
32
+ // Google Test filepath utilities
33
+ //
34
+ // This header file declares classes and functions used internally by
35
+ // Google Test. They are subject to change without notice.
36
+ //
37
+ // This file is #included in <gtest/internal/gtest-internal.h>.
38
+ // Do not include this header file separately!
39
+
40
+ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
41
+ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
42
+
43
+ #include "gtest/internal/gtest-string.h"
44
+
45
+ namespace testing {
46
+ namespace internal {
47
+
48
+ // FilePath - a class for file and directory pathname manipulation which
49
+ // handles platform-specific conventions (like the pathname separator).
50
+ // Used for helper functions for naming files in a directory for xml output.
51
+ // Except for Set methods, all methods are const or static, which provides an
52
+ // "immutable value object" -- useful for peace of mind.
53
+ // A FilePath with a value ending in a path separator ("like/this/") represents
54
+ // a directory, otherwise it is assumed to represent a file. In either case,
55
+ // it may or may not represent an actual file or directory in the file system.
56
+ // Names are NOT checked for syntax correctness -- no checking for illegal
57
+ // characters, malformed paths, etc.
58
+
59
+ class GTEST_API_ FilePath {
60
+ public:
61
+ FilePath() : pathname_("") { }
62
+ FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
63
+
64
+ explicit FilePath(const char* pathname) : pathname_(pathname) {
65
+ Normalize();
66
+ }
67
+
68
+ explicit FilePath(const String& pathname) : pathname_(pathname) {
69
+ Normalize();
70
+ }
71
+
72
+ FilePath& operator=(const FilePath& rhs) {
73
+ Set(rhs);
74
+ return *this;
75
+ }
76
+
77
+ void Set(const FilePath& rhs) {
78
+ pathname_ = rhs.pathname_;
79
+ }
80
+
81
+ String ToString() const { return pathname_; }
82
+ const char* c_str() const { return pathname_.c_str(); }
83
+
84
+ // Returns the current working directory, or "" if unsuccessful.
85
+ static FilePath GetCurrentDir();
86
+
87
+ // Given directory = "dir", base_name = "test", number = 0,
88
+ // extension = "xml", returns "dir/test.xml". If number is greater
89
+ // than zero (e.g., 12), returns "dir/test_12.xml".
90
+ // On Windows platform, uses \ as the separator rather than /.
91
+ static FilePath MakeFileName(const FilePath& directory,
92
+ const FilePath& base_name,
93
+ int number,
94
+ const char* extension);
95
+
96
+ // Given directory = "dir", relative_path = "test.xml",
97
+ // returns "dir/test.xml".
98
+ // On Windows, uses \ as the separator rather than /.
99
+ static FilePath ConcatPaths(const FilePath& directory,
100
+ const FilePath& relative_path);
101
+
102
+ // Returns a pathname for a file that does not currently exist. The pathname
103
+ // will be directory/base_name.extension or
104
+ // directory/base_name_<number>.extension if directory/base_name.extension
105
+ // already exists. The number will be incremented until a pathname is found
106
+ // that does not already exist.
107
+ // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
108
+ // There could be a race condition if two or more processes are calling this
109
+ // function at the same time -- they could both pick the same filename.
110
+ static FilePath GenerateUniqueFileName(const FilePath& directory,
111
+ const FilePath& base_name,
112
+ const char* extension);
113
+
114
+ // Returns true iff the path is NULL or "".
115
+ bool IsEmpty() const { return c_str() == NULL || *c_str() == '\0'; }
116
+
117
+ // If input name has a trailing separator character, removes it and returns
118
+ // the name, otherwise return the name string unmodified.
119
+ // On Windows platform, uses \ as the separator, other platforms use /.
120
+ FilePath RemoveTrailingPathSeparator() const;
121
+
122
+ // Returns a copy of the FilePath with the directory part removed.
123
+ // Example: FilePath("path/to/file").RemoveDirectoryName() returns
124
+ // FilePath("file"). If there is no directory part ("just_a_file"), it returns
125
+ // the FilePath unmodified. If there is no file part ("just_a_dir/") it
126
+ // returns an empty FilePath ("").
127
+ // On Windows platform, '\' is the path separator, otherwise it is '/'.
128
+ FilePath RemoveDirectoryName() const;
129
+
130
+ // RemoveFileName returns the directory path with the filename removed.
131
+ // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
132
+ // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
133
+ // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
134
+ // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
135
+ // On Windows platform, '\' is the path separator, otherwise it is '/'.
136
+ FilePath RemoveFileName() const;
137
+
138
+ // Returns a copy of the FilePath with the case-insensitive extension removed.
139
+ // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
140
+ // FilePath("dir/file"). If a case-insensitive extension is not
141
+ // found, returns a copy of the original FilePath.
142
+ FilePath RemoveExtension(const char* extension) const;
143
+
144
+ // Creates directories so that path exists. Returns true if successful or if
145
+ // the directories already exist; returns false if unable to create
146
+ // directories for any reason. Will also return false if the FilePath does
147
+ // not represent a directory (that is, it doesn't end with a path separator).
148
+ bool CreateDirectoriesRecursively() const;
149
+
150
+ // Create the directory so that path exists. Returns true if successful or
151
+ // if the directory already exists; returns false if unable to create the
152
+ // directory for any reason, including if the parent directory does not
153
+ // exist. Not named "CreateDirectory" because that's a macro on Windows.
154
+ bool CreateFolder() const;
155
+
156
+ // Returns true if FilePath describes something in the file-system,
157
+ // either a file, directory, or whatever, and that something exists.
158
+ bool FileOrDirectoryExists() const;
159
+
160
+ // Returns true if pathname describes a directory in the file-system
161
+ // that exists.
162
+ bool DirectoryExists() const;
163
+
164
+ // Returns true if FilePath ends with a path separator, which indicates that
165
+ // it is intended to represent a directory. Returns false otherwise.
166
+ // This does NOT check that a directory (or file) actually exists.
167
+ bool IsDirectory() const;
168
+
169
+ // Returns true if pathname describes a root directory. (Windows has one
170
+ // root directory per disk drive.)
171
+ bool IsRootDirectory() const;
172
+
173
+ // Returns true if pathname describes an absolute path.
174
+ bool IsAbsolutePath() const;
175
+
176
+ private:
177
+ // Replaces multiple consecutive separators with a single separator.
178
+ // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
179
+ // redundancies that might be in a pathname involving "." or "..".
180
+ //
181
+ // A pathname with multiple consecutive separators may occur either through
182
+ // user error or as a result of some scripts or APIs that generate a pathname
183
+ // with a trailing separator. On other platforms the same API or script
184
+ // may NOT generate a pathname with a trailing "/". Then elsewhere that
185
+ // pathname may have another "/" and pathname components added to it,
186
+ // without checking for the separator already being there.
187
+ // The script language and operating system may allow paths like "foo//bar"
188
+ // but some of the functions in FilePath will not handle that correctly. In
189
+ // particular, RemoveTrailingPathSeparator() only removes one separator, and
190
+ // it is called in CreateDirectoriesRecursively() assuming that it will change
191
+ // a pathname from directory syntax (trailing separator) to filename syntax.
192
+ //
193
+ // On Windows this method also replaces the alternate path separator '/' with
194
+ // the primary path separator '\\', so that for example "bar\\/\\foo" becomes
195
+ // "bar\\foo".
196
+
197
+ void Normalize();
198
+
199
+ // Returns a pointer to the last occurence of a valid path separator in
200
+ // the FilePath. On Windows, for example, both '/' and '\' are valid path
201
+ // separators. Returns NULL if no path separator was found.
202
+ const char* FindLastPathSeparator() const;
203
+
204
+ String pathname_;
205
+ }; // class FilePath
206
+
207
+ } // namespace internal
208
+ } // namespace testing
209
+
210
+ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_