cppjieba_rb 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cppjieba/.gitignore +17 -0
  3. data/ext/cppjieba/.travis.yml +21 -0
  4. data/ext/cppjieba/CMakeLists.txt +28 -0
  5. data/ext/cppjieba/ChangeLog.md +249 -0
  6. data/ext/cppjieba/README.md +289 -0
  7. data/ext/cppjieba/README_EN.md +115 -0
  8. data/ext/cppjieba/appveyor.yml +32 -0
  9. data/ext/cppjieba/deps/CMakeLists.txt +1 -0
  10. data/ext/cppjieba/deps/gtest/CMakeLists.txt +5 -0
  11. data/ext/cppjieba/deps/gtest/include/gtest/gtest-death-test.h +283 -0
  12. data/ext/cppjieba/deps/gtest/include/gtest/gtest-message.h +230 -0
  13. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h +1421 -0
  14. data/ext/cppjieba/deps/gtest/include/gtest/gtest-param-test.h.pump +487 -0
  15. data/ext/cppjieba/deps/gtest/include/gtest/gtest-printers.h +796 -0
  16. data/ext/cppjieba/deps/gtest/include/gtest/gtest-spi.h +232 -0
  17. data/ext/cppjieba/deps/gtest/include/gtest/gtest-test-part.h +176 -0
  18. data/ext/cppjieba/deps/gtest/include/gtest/gtest-typed-test.h +259 -0
  19. data/ext/cppjieba/deps/gtest/include/gtest/gtest.h +2155 -0
  20. data/ext/cppjieba/deps/gtest/include/gtest/gtest_pred_impl.h +358 -0
  21. data/ext/cppjieba/deps/gtest/include/gtest/gtest_prod.h +58 -0
  22. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-death-test-internal.h +308 -0
  23. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-filepath.h +210 -0
  24. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-internal.h +1226 -0
  25. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-linked_ptr.h +233 -0
  26. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h +4822 -0
  27. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  28. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-param-util.h +619 -0
  29. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-port.h +1788 -0
  30. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-string.h +350 -0
  31. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h +968 -0
  32. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-tuple.h.pump +336 -0
  33. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h +3330 -0
  34. data/ext/cppjieba/deps/gtest/include/gtest/internal/gtest-type-util.h.pump +296 -0
  35. data/ext/cppjieba/deps/gtest/src/.deps/.dirstamp +0 -0
  36. data/ext/cppjieba/deps/gtest/src/.deps/gtest-all.Plo +681 -0
  37. data/ext/cppjieba/deps/gtest/src/.deps/gtest_main.Plo +509 -0
  38. data/ext/cppjieba/deps/gtest/src/.dirstamp +0 -0
  39. data/ext/cppjieba/deps/gtest/src/gtest-all.cc +48 -0
  40. data/ext/cppjieba/deps/gtest/src/gtest-death-test.cc +1234 -0
  41. data/ext/cppjieba/deps/gtest/src/gtest-filepath.cc +380 -0
  42. data/ext/cppjieba/deps/gtest/src/gtest-internal-inl.h +1038 -0
  43. data/ext/cppjieba/deps/gtest/src/gtest-port.cc +746 -0
  44. data/ext/cppjieba/deps/gtest/src/gtest-printers.cc +356 -0
  45. data/ext/cppjieba/deps/gtest/src/gtest-test-part.cc +110 -0
  46. data/ext/cppjieba/deps/gtest/src/gtest-typed-test.cc +110 -0
  47. data/ext/cppjieba/deps/gtest/src/gtest.cc +4898 -0
  48. data/ext/cppjieba/deps/gtest/src/gtest_main.cc +39 -0
  49. data/ext/cppjieba/deps/limonp/ArgvContext.hpp +70 -0
  50. data/ext/cppjieba/deps/limonp/BlockingQueue.hpp +49 -0
  51. data/ext/cppjieba/deps/limonp/BoundedBlockingQueue.hpp +67 -0
  52. data/ext/cppjieba/deps/limonp/BoundedQueue.hpp +65 -0
  53. data/ext/cppjieba/deps/limonp/Closure.hpp +206 -0
  54. data/ext/cppjieba/deps/limonp/Colors.hpp +31 -0
  55. data/ext/cppjieba/deps/limonp/Condition.hpp +38 -0
  56. data/ext/cppjieba/deps/limonp/Config.hpp +103 -0
  57. data/ext/cppjieba/deps/limonp/FileLock.hpp +74 -0
  58. data/ext/cppjieba/deps/limonp/ForcePublic.hpp +7 -0
  59. data/ext/cppjieba/deps/limonp/LocalVector.hpp +139 -0
  60. data/ext/cppjieba/deps/limonp/Logging.hpp +76 -0
  61. data/ext/cppjieba/deps/limonp/Md5.hpp +411 -0
  62. data/ext/cppjieba/deps/limonp/MutexLock.hpp +51 -0
  63. data/ext/cppjieba/deps/limonp/NonCopyable.hpp +21 -0
  64. data/ext/cppjieba/deps/limonp/StdExtension.hpp +157 -0
  65. data/ext/cppjieba/deps/limonp/StringUtil.hpp +365 -0
  66. data/ext/cppjieba/deps/limonp/Thread.hpp +44 -0
  67. data/ext/cppjieba/deps/limonp/ThreadPool.hpp +86 -0
  68. data/ext/cppjieba/dict/README.md +31 -0
  69. data/ext/cppjieba/dict/hmm_model.utf8 +34 -0
  70. data/ext/cppjieba/dict/idf.utf8 +258826 -0
  71. data/ext/cppjieba/dict/jieba.dict.utf8 +348982 -0
  72. data/ext/cppjieba/dict/pos_dict/char_state_tab.utf8 +6653 -0
  73. data/ext/cppjieba/dict/pos_dict/prob_emit.utf8 +166 -0
  74. data/ext/cppjieba/dict/pos_dict/prob_start.utf8 +259 -0
  75. data/ext/cppjieba/dict/pos_dict/prob_trans.utf8 +5222 -0
  76. data/ext/cppjieba/dict/stop_words.utf8 +1534 -0
  77. data/ext/cppjieba/dict/user.dict.utf8 +4 -0
  78. data/ext/cppjieba/include/cppjieba/DictTrie.hpp +277 -0
  79. data/ext/cppjieba/include/cppjieba/FullSegment.hpp +93 -0
  80. data/ext/cppjieba/include/cppjieba/HMMModel.hpp +129 -0
  81. data/ext/cppjieba/include/cppjieba/HMMSegment.hpp +190 -0
  82. data/ext/cppjieba/include/cppjieba/Jieba.hpp +130 -0
  83. data/ext/cppjieba/include/cppjieba/KeywordExtractor.hpp +153 -0
  84. data/ext/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
  85. data/ext/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
  86. data/ext/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
  87. data/ext/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
  88. data/ext/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
  89. data/ext/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
  90. data/ext/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
  91. data/ext/cppjieba/include/cppjieba/TextRankExtractor.hpp +190 -0
  92. data/ext/cppjieba/include/cppjieba/Trie.hpp +174 -0
  93. data/ext/cppjieba/include/cppjieba/Unicode.hpp +227 -0
  94. data/ext/cppjieba/test/CMakeLists.txt +5 -0
  95. data/ext/cppjieba/test/demo.cpp +80 -0
  96. data/ext/cppjieba/test/load_test.cpp +54 -0
  97. data/ext/cppjieba/test/testdata/curl.res +1 -0
  98. data/ext/cppjieba/test/testdata/extra_dict/jieba.dict.small.utf8 +109750 -0
  99. data/ext/cppjieba/test/testdata/gbk_dict/hmm_model.gbk +34 -0
  100. data/ext/cppjieba/test/testdata/gbk_dict/jieba.dict.gbk +348982 -0
  101. data/ext/cppjieba/test/testdata/jieba.dict.0.1.utf8 +93 -0
  102. data/ext/cppjieba/test/testdata/jieba.dict.0.utf8 +93 -0
  103. data/ext/cppjieba/test/testdata/jieba.dict.1.utf8 +67 -0
  104. data/ext/cppjieba/test/testdata/jieba.dict.2.utf8 +64 -0
  105. data/ext/cppjieba/test/testdata/load_test.urls +2 -0
  106. data/ext/cppjieba/test/testdata/review.100 +100 -0
  107. data/ext/cppjieba/test/testdata/review.100.res +200 -0
  108. data/ext/cppjieba/test/testdata/server.conf +19 -0
  109. data/ext/cppjieba/test/testdata/testlines.gbk +9 -0
  110. data/ext/cppjieba/test/testdata/testlines.utf8 +8 -0
  111. data/ext/cppjieba/test/testdata/userdict.2.utf8 +1 -0
  112. data/ext/cppjieba/test/testdata/userdict.english +2 -0
  113. data/ext/cppjieba/test/testdata/userdict.utf8 +8 -0
  114. data/ext/cppjieba/test/testdata/weicheng.utf8 +247 -0
  115. data/ext/cppjieba/test/unittest/CMakeLists.txt +24 -0
  116. data/ext/cppjieba/test/unittest/gtest_main.cpp +39 -0
  117. data/ext/cppjieba/test/unittest/jieba_test.cpp +133 -0
  118. data/ext/cppjieba/test/unittest/keyword_extractor_test.cpp +79 -0
  119. data/ext/cppjieba/test/unittest/pos_tagger_test.cpp +41 -0
  120. data/ext/cppjieba/test/unittest/pre_filter_test.cpp +43 -0
  121. data/ext/cppjieba/test/unittest/segments_test.cpp +256 -0
  122. data/ext/cppjieba/test/unittest/textrank_test.cpp +86 -0
  123. data/ext/cppjieba/test/unittest/trie_test.cpp +177 -0
  124. data/ext/cppjieba/test/unittest/unicode_test.cpp +43 -0
  125. data/lib/cppjieba_rb/version.rb +1 -1
  126. metadata +125 -2
@@ -0,0 +1,115 @@
1
+ # CppJieba [简体中文](README.md)
2
+
3
+ [![Build Status](https://travis-ci.org/yanyiwu/cppjieba.png?branch=master)](https://travis-ci.org/yanyiwu/cppjieba)
4
+ [![Author](https://img.shields.io/badge/author-@yanyiwu-blue.svg?style=flat)](http://yanyiwu.com/)
5
+ [![Platform](https://img.shields.io/badge/platform-Linux,%20OS%20X,%20Windows-green.svg?style=flat)](https://github.com/yanyiwu/cppjieba)
6
+ [![Performance](https://img.shields.io/badge/performance-excellent-brightgreen.svg?style=flat)](http://yanyiwu.com/work/2015/06/14/jieba-series-performance-test.html)
7
+ [![License](https://img.shields.io/badge/license-MIT-yellow.svg?style=flat)](http://yanyiwu.mit-license.org)
8
+ [![Build status](https://ci.appveyor.com/api/projects/status/wl30fjnm2rhft6ta/branch/master?svg=true)](https://ci.appveyor.com/project/yanyiwu/cppjieba/branch/master)
9
+
10
+ [![logo](http://7viirv.com1.z0.glb.clouddn.com/CppJiebaLogo-v1.png)](https://github.com/yanyiwu/cppjieba)
11
+
12
+ ## Introduction
13
+
14
+ The Jieba Chinese Word Segmentation Implemented By C++ .
15
+
16
+ ## Usage
17
+
18
+ ### Dependencies
19
+
20
+ + `g++ (version >= 4.1 is recommended) or clang++`;
21
+ + `cmake (version >= 2.6 is recommended)`;
22
+
23
+ ### Download & Compile
24
+
25
+ ```sh
26
+ git clone --depth=10 --branch=master git://github.com/yanyiwu/cppjieba.git
27
+ cd cppjieba
28
+ mkdir build
29
+ cd build
30
+ cmake ..
31
+ make
32
+ ```
33
+
34
+ ### Unit Testing
35
+
36
+ ```
37
+ make test
38
+ ```
39
+
40
+ ## Demo
41
+
42
+ ```
43
+ ./demo
44
+ ```
45
+
46
+ Output:
47
+
48
+ ```
49
+ [demo] Cut With HMM
50
+ 他/来到/了/网易/杭研/大厦
51
+ [demo] Cut Without HMM
52
+ 他/来到/了/网易/杭/研/大厦
53
+ 我来到北京清华大学
54
+ [demo] CutAll
55
+ 我/来到/北京/清华/清华大学/华大/大学
56
+ 小明硕士毕业于中国科学院计算所,后在日本京都大学深造
57
+ [demo] CutForSearch
58
+ 小明/硕士/毕业/于/中国/科学/学院/科学院/中国科学院/计算/计算所/,/后/在/日本/京都/大学/日本京都大学/深造
59
+ [demo] Insert User Word
60
+ 男默/女泪
61
+ 男默女泪
62
+ [demo] CutForSearch Word With Offset
63
+ [{"word": "小明", "offset": 0}, {"word": "硕士", "offset": 6}, {"word": "毕业", "offset": 12}, {"word": "于", "offset": 18}, {"word": "中国", "offset": 21}, {"word": "科学", "offset": 27}, {"word": "学院", "offset": 30}, {"word": "科学院", "offset": 27}, {"word": "中国科学院", "offset": 21}, {"word": "计算", "offset": 36}, {"word": "计算所", "offset": 36}, {"word": ",", "offset": 45}, {"word": "后", "offset": 48}, {"word": "在", "offset": 51}, {"word": "日本", "offset": 54}, {"word": "京都", "offset": 60}, {"word": "大学", "offset": 66}, {"word": "日本京都大学", "offset": 54}, {"word": "深造", "offset": 72}]
64
+ [demo] Tagging
65
+ 我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。
66
+ [我:r, 是:v, 拖拉机:n, 学院:n, 手扶拖拉机:n, 专业:n, 的:uj, 。:x, 不用:v, 多久:m, ,:x, 我:r, 就:d, 会:v, 升职:v, 加薪:nr, ,:x, 当上:t, CEO:eng, ,:x, 走上:v, 人生:n, 巅峰:n, 。:x]
67
+ [demo] Keyword Extraction
68
+ 我是拖拉机学院手扶拖拉机专业的。不用多久,我就会升职加薪,当上CEO,走上人生巅峰。
69
+ [{"word": "CEO", "offset": [93], "weight": 11.7392}, {"word": "升职", "offset": [72], "weight": 10.8562}, {"word": "加薪", "offset": [78], "weight": 10.6426}, {"word": "手扶拖拉机", "offset": [21], "weight": 10.0089}, {"word": "巅峰", "offset": [111], "weight": 9.49396}]
70
+ ```
71
+
72
+ Please see details in `test/demo.cpp`.
73
+
74
+ ## Cases
75
+
76
+ + [GoJieba]
77
+ + [NodeJieba]
78
+ + [simhash]
79
+ + [exjieba]
80
+ + [jiebaR]
81
+ + [cjieba]
82
+ + [jieba_rb]
83
+ + [iosjieba]
84
+ + [SqlJieba]
85
+ + [pg_jieba]
86
+ + [ngx_http_cppjieba_module]
87
+ + [gitbook-plugin-search-pro]
88
+ + [cppjieba-server]
89
+ + [perl5-jieba]
90
+ + [jieba-dlang]
91
+
92
+ ## Contact
93
+
94
+ + Email: `i@yanyiwu.com`
95
+ + QQ: 64162451
96
+ + WeChat: ![image](http://7viirv.com1.z0.glb.clouddn.com/5a7d1b5c0d_yanyiwu_personal_qrcodes.jpg)
97
+
98
+ [GoJieba]:https://github.com/yanyiwu/gojieba
99
+ [CppJieba]:https://github.com/yanyiwu/cppjieba
100
+ [jannson]:https://github.com/jannson
101
+ [cppjiebapy]:https://github.com/jannson/cppjiebapy
102
+ [cppjiebapy_discussion]:https://github.com/yanyiwu/cppjieba/issues/1
103
+ [NodeJieba]:https://github.com/yanyiwu/nodejieba
104
+ [jiebaR]:https://github.com/qinwf/jiebaR
105
+ [simhash]:https://github.com/yanyiwu/simhash
106
+ [exjieba]:https://github.com/falood/exjieba
107
+ [cjieba]:http://github.com/yanyiwu/cjieba
108
+ [jieba_rb]:https://github.com/altkatz/jieba_rb
109
+ [iosjieba]:https://github.com/yanyiwu/iosjieba
110
+ [SqlJieba]:https://github.com/yanyiwu/sqljieba
111
+ [pg_jieba]:https://github.com/jaiminpan/pg_jieba
112
+ [gitbook-plugin-search-pro]:https://plugins.gitbook.com/plugin/search-pro
113
+ [cppjieba-server]:https://github.com/yanyiwu/cppjieba-server
114
+ [perl5-jieba]:https://metacpan.org/pod/distribution/Lingua-ZH-Jieba/lib/Lingua/ZH/Jieba.pod
115
+ [jieba-dlang]:https://github.com/shove70/jieba
@@ -0,0 +1,32 @@
1
+ os: Visual Studio 2015
2
+
3
+ platform: x64
4
+
5
+ # clone directory
6
+ clone_folder: c:\projects\cppjieba
7
+
8
+ # scripts to run before build
9
+ before_build:
10
+ - echo Running cmake...
11
+ - cd c:\projects\cppjieba
12
+ - cmake .
13
+
14
+ build:
15
+ project: ALL_BUILD.vcxproj # path to Visual Studio solution or project
16
+
17
+ # scripts to run after build
18
+ after_build:
19
+ - cd Debug
20
+ - demo.exe
21
+ - load_test.exe
22
+ - cd ..
23
+ - COPY .\test\Debug\test.run.exe .\test\test.run.exe
24
+ - cd test
25
+ - test.run.exe
26
+ - cd ..
27
+ - 7z a c:\projects\all.zip * -tzip
28
+ - cd c:\projects
29
+
30
+ artifacts:
31
+ - path: all.zip
32
+ name: all.zip
@@ -0,0 +1 @@
1
+ ADD_SUBDIRECTORY(gtest)
@@ -0,0 +1,5 @@
1
+ INCLUDE_DIRECTORIES(./ include)
2
+ ADD_LIBRARY(gtest STATIC src/gtest-all.cc)
3
+ if(NOT MSVC)
4
+ TARGET_LINK_LIBRARIES(gtest pthread)
5
+ endif()
@@ -0,0 +1,283 @@
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
+ // Author: wan@google.com (Zhanyong Wan)
31
+ //
32
+ // The Google C++ Testing Framework (Google Test)
33
+ //
34
+ // This header file defines the public API for death tests. It is
35
+ // #included by gtest.h so a user doesn't need to include this
36
+ // directly.
37
+
38
+ #ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
39
+ #define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
40
+
41
+ #include "gtest/internal/gtest-death-test-internal.h"
42
+
43
+ namespace testing {
44
+
45
+ // This flag controls the style of death tests. Valid values are "threadsafe",
46
+ // meaning that the death test child process will re-execute the test binary
47
+ // from the start, running only a single death test, or "fast",
48
+ // meaning that the child process will execute the test logic immediately
49
+ // after forking.
50
+ GTEST_DECLARE_string_(death_test_style);
51
+
52
+ #if GTEST_HAS_DEATH_TEST
53
+
54
+ // The following macros are useful for writing death tests.
55
+
56
+ // Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
57
+ // executed:
58
+ //
59
+ // 1. It generates a warning if there is more than one active
60
+ // thread. This is because it's safe to fork() or clone() only
61
+ // when there is a single thread.
62
+ //
63
+ // 2. The parent process clone()s a sub-process and runs the death
64
+ // test in it; the sub-process exits with code 0 at the end of the
65
+ // death test, if it hasn't exited already.
66
+ //
67
+ // 3. The parent process waits for the sub-process to terminate.
68
+ //
69
+ // 4. The parent process checks the exit code and error message of
70
+ // the sub-process.
71
+ //
72
+ // Examples:
73
+ //
74
+ // ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number");
75
+ // for (int i = 0; i < 5; i++) {
76
+ // EXPECT_DEATH(server.ProcessRequest(i),
77
+ // "Invalid request .* in ProcessRequest()")
78
+ // << "Failed to die on request " << i);
79
+ // }
80
+ //
81
+ // ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
82
+ //
83
+ // bool KilledBySIGHUP(int exit_code) {
84
+ // return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;
85
+ // }
86
+ //
87
+ // ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
88
+ //
89
+ // On the regular expressions used in death tests:
90
+ //
91
+ // On POSIX-compliant systems (*nix), we use the <regex.h> library,
92
+ // which uses the POSIX extended regex syntax.
93
+ //
94
+ // On other platforms (e.g. Windows), we only support a simple regex
95
+ // syntax implemented as part of Google Test. This limited
96
+ // implementation should be enough most of the time when writing
97
+ // death tests; though it lacks many features you can find in PCRE
98
+ // or POSIX extended regex syntax. For example, we don't support
99
+ // union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and
100
+ // repetition count ("x{5,7}"), among others.
101
+ //
102
+ // Below is the syntax that we do support. We chose it to be a
103
+ // subset of both PCRE and POSIX extended regex, so it's easy to
104
+ // learn wherever you come from. In the following: 'A' denotes a
105
+ // literal character, period (.), or a single \\ escape sequence;
106
+ // 'x' and 'y' denote regular expressions; 'm' and 'n' are for
107
+ // natural numbers.
108
+ //
109
+ // c matches any literal character c
110
+ // \\d matches any decimal digit
111
+ // \\D matches any character that's not a decimal digit
112
+ // \\f matches \f
113
+ // \\n matches \n
114
+ // \\r matches \r
115
+ // \\s matches any ASCII whitespace, including \n
116
+ // \\S matches any character that's not a whitespace
117
+ // \\t matches \t
118
+ // \\v matches \v
119
+ // \\w matches any letter, _, or decimal digit
120
+ // \\W matches any character that \\w doesn't match
121
+ // \\c matches any literal character c, which must be a punctuation
122
+ // . matches any single character except \n
123
+ // A? matches 0 or 1 occurrences of A
124
+ // A* matches 0 or many occurrences of A
125
+ // A+ matches 1 or many occurrences of A
126
+ // ^ matches the beginning of a string (not that of each line)
127
+ // $ matches the end of a string (not that of each line)
128
+ // xy matches x followed by y
129
+ //
130
+ // If you accidentally use PCRE or POSIX extended regex features
131
+ // not implemented by us, you will get a run-time failure. In that
132
+ // case, please try to rewrite your regular expression within the
133
+ // above syntax.
134
+ //
135
+ // This implementation is *not* meant to be as highly tuned or robust
136
+ // as a compiled regex library, but should perform well enough for a
137
+ // death test, which already incurs significant overhead by launching
138
+ // a child process.
139
+ //
140
+ // Known caveats:
141
+ //
142
+ // A "threadsafe" style death test obtains the path to the test
143
+ // program from argv[0] and re-executes it in the sub-process. For
144
+ // simplicity, the current implementation doesn't search the PATH
145
+ // when launching the sub-process. This means that the user must
146
+ // invoke the test program via a path that contains at least one
147
+ // path separator (e.g. path/to/foo_test and
148
+ // /absolute/path/to/bar_test are fine, but foo_test is not). This
149
+ // is rarely a problem as people usually don't put the test binary
150
+ // directory in PATH.
151
+ //
152
+ // TODO(wan@google.com): make thread-safe death tests search the PATH.
153
+
154
+ // Asserts that a given statement causes the program to exit, with an
155
+ // integer exit status that satisfies predicate, and emitting error output
156
+ // that matches regex.
157
+ # define ASSERT_EXIT(statement, predicate, regex) \
158
+ GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
159
+
160
+ // Like ASSERT_EXIT, but continues on to successive tests in the
161
+ // test case, if any:
162
+ # define EXPECT_EXIT(statement, predicate, regex) \
163
+ GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
164
+
165
+ // Asserts that a given statement causes the program to exit, either by
166
+ // explicitly exiting with a nonzero exit code or being killed by a
167
+ // signal, and emitting error output that matches regex.
168
+ # define ASSERT_DEATH(statement, regex) \
169
+ ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
170
+
171
+ // Like ASSERT_DEATH, but continues on to successive tests in the
172
+ // test case, if any:
173
+ # define EXPECT_DEATH(statement, regex) \
174
+ EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
175
+
176
+ // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
177
+
178
+ // Tests that an exit code describes a normal exit with a given exit code.
179
+ class GTEST_API_ ExitedWithCode {
180
+ public:
181
+ explicit ExitedWithCode(int exit_code);
182
+ bool operator()(int exit_status) const;
183
+ private:
184
+ // No implementation - assignment is unsupported.
185
+ void operator=(const ExitedWithCode& other);
186
+
187
+ const int exit_code_;
188
+ };
189
+
190
+ # if !GTEST_OS_WINDOWS
191
+ // Tests that an exit code describes an exit due to termination by a
192
+ // given signal.
193
+ class GTEST_API_ KilledBySignal {
194
+ public:
195
+ explicit KilledBySignal(int signum);
196
+ bool operator()(int exit_status) const;
197
+ private:
198
+ const int signum_;
199
+ };
200
+ # endif // !GTEST_OS_WINDOWS
201
+
202
+ // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
203
+ // The death testing framework causes this to have interesting semantics,
204
+ // since the sideeffects of the call are only visible in opt mode, and not
205
+ // in debug mode.
206
+ //
207
+ // In practice, this can be used to test functions that utilize the
208
+ // LOG(DFATAL) macro using the following style:
209
+ //
210
+ // int DieInDebugOr12(int* sideeffect) {
211
+ // if (sideeffect) {
212
+ // *sideeffect = 12;
213
+ // }
214
+ // LOG(DFATAL) << "death";
215
+ // return 12;
216
+ // }
217
+ //
218
+ // TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {
219
+ // int sideeffect = 0;
220
+ // // Only asserts in dbg.
221
+ // EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
222
+ //
223
+ // #ifdef NDEBUG
224
+ // // opt-mode has sideeffect visible.
225
+ // EXPECT_EQ(12, sideeffect);
226
+ // #else
227
+ // // dbg-mode no visible sideeffect.
228
+ // EXPECT_EQ(0, sideeffect);
229
+ // #endif
230
+ // }
231
+ //
232
+ // This will assert that DieInDebugReturn12InOpt() crashes in debug
233
+ // mode, usually due to a DCHECK or LOG(DFATAL), but returns the
234
+ // appropriate fallback value (12 in this case) in opt mode. If you
235
+ // need to test that a function has appropriate side-effects in opt
236
+ // mode, include assertions against the side-effects. A general
237
+ // pattern for this is:
238
+ //
239
+ // EXPECT_DEBUG_DEATH({
240
+ // // Side-effects here will have an effect after this statement in
241
+ // // opt mode, but none in debug mode.
242
+ // EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
243
+ // }, "death");
244
+ //
245
+ # ifdef NDEBUG
246
+
247
+ # define EXPECT_DEBUG_DEATH(statement, regex) \
248
+ do { statement; } while (::testing::internal::AlwaysFalse())
249
+
250
+ # define ASSERT_DEBUG_DEATH(statement, regex) \
251
+ do { statement; } while (::testing::internal::AlwaysFalse())
252
+
253
+ # else
254
+
255
+ # define EXPECT_DEBUG_DEATH(statement, regex) \
256
+ EXPECT_DEATH(statement, regex)
257
+
258
+ # define ASSERT_DEBUG_DEATH(statement, regex) \
259
+ ASSERT_DEATH(statement, regex)
260
+
261
+ # endif // NDEBUG for EXPECT_DEBUG_DEATH
262
+ #endif // GTEST_HAS_DEATH_TEST
263
+
264
+ // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
265
+ // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
266
+ // death tests are supported; otherwise they just issue a warning. This is
267
+ // useful when you are combining death test assertions with normal test
268
+ // assertions in one test.
269
+ #if GTEST_HAS_DEATH_TEST
270
+ # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
271
+ EXPECT_DEATH(statement, regex)
272
+ # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
273
+ ASSERT_DEATH(statement, regex)
274
+ #else
275
+ # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
276
+ GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )
277
+ # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
278
+ GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)
279
+ #endif
280
+
281
+ } // namespace testing
282
+
283
+ #endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
@@ -0,0 +1,230 @@
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
+ // Author: wan@google.com (Zhanyong Wan)
31
+ //
32
+ // The Google C++ Testing Framework (Google Test)
33
+ //
34
+ // This header file defines the Message class.
35
+ //
36
+ // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
37
+ // leave some internal implementation details in this header file.
38
+ // They are clearly marked by comments like this:
39
+ //
40
+ // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
41
+ //
42
+ // Such code is NOT meant to be used by a user directly, and is subject
43
+ // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
44
+ // program!
45
+
46
+ #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
47
+ #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
48
+
49
+ #include <limits>
50
+
51
+ #include "gtest/internal/gtest-string.h"
52
+ #include "gtest/internal/gtest-internal.h"
53
+
54
+ namespace testing {
55
+
56
+ // The Message class works like an ostream repeater.
57
+ //
58
+ // Typical usage:
59
+ //
60
+ // 1. You stream a bunch of values to a Message object.
61
+ // It will remember the text in a stringstream.
62
+ // 2. Then you stream the Message object to an ostream.
63
+ // This causes the text in the Message to be streamed
64
+ // to the ostream.
65
+ //
66
+ // For example;
67
+ //
68
+ // testing::Message foo;
69
+ // foo << 1 << " != " << 2;
70
+ // std::cout << foo;
71
+ //
72
+ // will print "1 != 2".
73
+ //
74
+ // Message is not intended to be inherited from. In particular, its
75
+ // destructor is not virtual.
76
+ //
77
+ // Note that stringstream behaves differently in gcc and in MSVC. You
78
+ // can stream a NULL char pointer to it in the former, but not in the
79
+ // latter (it causes an access violation if you do). The Message
80
+ // class hides this difference by treating a NULL char pointer as
81
+ // "(null)".
82
+ class GTEST_API_ Message {
83
+ private:
84
+ // The type of basic IO manipulators (endl, ends, and flush) for
85
+ // narrow streams.
86
+ typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
87
+
88
+ public:
89
+ // Constructs an empty Message.
90
+ // We allocate the stringstream separately because otherwise each use of
91
+ // ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
92
+ // stack frame leading to huge stack frames in some cases; gcc does not reuse
93
+ // the stack space.
94
+ Message() : ss_(new ::std::stringstream) {
95
+ // By default, we want there to be enough precision when printing
96
+ // a double to a Message.
97
+ *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
98
+ }
99
+
100
+ // Copy constructor.
101
+ Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
102
+ *ss_ << msg.GetString();
103
+ }
104
+
105
+ // Constructs a Message from a C-string.
106
+ explicit Message(const char* str) : ss_(new ::std::stringstream) {
107
+ *ss_ << str;
108
+ }
109
+
110
+ #if GTEST_OS_SYMBIAN
111
+ // Streams a value (either a pointer or not) to this object.
112
+ template <typename T>
113
+ inline Message& operator <<(const T& value) {
114
+ StreamHelper(typename internal::is_pointer<T>::type(), value);
115
+ return *this;
116
+ }
117
+ #else
118
+ // Streams a non-pointer value to this object.
119
+ template <typename T>
120
+ inline Message& operator <<(const T& val) {
121
+ ::GTestStreamToHelper(ss_.get(), val);
122
+ return *this;
123
+ }
124
+
125
+ // Streams a pointer value to this object.
126
+ //
127
+ // This function is an overload of the previous one. When you
128
+ // stream a pointer to a Message, this definition will be used as it
129
+ // is more specialized. (The C++ Standard, section
130
+ // [temp.func.order].) If you stream a non-pointer, then the
131
+ // previous definition will be used.
132
+ //
133
+ // The reason for this overload is that streaming a NULL pointer to
134
+ // ostream is undefined behavior. Depending on the compiler, you
135
+ // may get "0", "(nil)", "(null)", or an access violation. To
136
+ // ensure consistent result across compilers, we always treat NULL
137
+ // as "(null)".
138
+ template <typename T>
139
+ inline Message& operator <<(T* const& pointer) { // NOLINT
140
+ if (pointer == NULL) {
141
+ *ss_ << "(null)";
142
+ } else {
143
+ ::GTestStreamToHelper(ss_.get(), pointer);
144
+ }
145
+ return *this;
146
+ }
147
+ #endif // GTEST_OS_SYMBIAN
148
+
149
+ // Since the basic IO manipulators are overloaded for both narrow
150
+ // and wide streams, we have to provide this specialized definition
151
+ // of operator <<, even though its body is the same as the
152
+ // templatized version above. Without this definition, streaming
153
+ // endl or other basic IO manipulators to Message will confuse the
154
+ // compiler.
155
+ Message& operator <<(BasicNarrowIoManip val) {
156
+ *ss_ << val;
157
+ return *this;
158
+ }
159
+
160
+ // Instead of 1/0, we want to see true/false for bool values.
161
+ Message& operator <<(bool b) {
162
+ return *this << (b ? "true" : "false");
163
+ }
164
+
165
+ // These two overloads allow streaming a wide C string to a Message
166
+ // using the UTF-8 encoding.
167
+ Message& operator <<(const wchar_t* wide_c_str) {
168
+ return *this << internal::String::ShowWideCString(wide_c_str);
169
+ }
170
+ Message& operator <<(wchar_t* wide_c_str) {
171
+ return *this << internal::String::ShowWideCString(wide_c_str);
172
+ }
173
+
174
+ #if GTEST_HAS_STD_WSTRING
175
+ // Converts the given wide string to a narrow string using the UTF-8
176
+ // encoding, and streams the result to this Message object.
177
+ Message& operator <<(const ::std::wstring& wstr);
178
+ #endif // GTEST_HAS_STD_WSTRING
179
+
180
+ #if GTEST_HAS_GLOBAL_WSTRING
181
+ // Converts the given wide string to a narrow string using the UTF-8
182
+ // encoding, and streams the result to this Message object.
183
+ Message& operator <<(const ::wstring& wstr);
184
+ #endif // GTEST_HAS_GLOBAL_WSTRING
185
+
186
+ // Gets the text streamed to this object so far as a String.
187
+ // Each '\0' character in the buffer is replaced with "\\0".
188
+ //
189
+ // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
190
+ internal::String GetString() const {
191
+ return internal::StringStreamToString(ss_.get());
192
+ }
193
+
194
+ private:
195
+
196
+ #if GTEST_OS_SYMBIAN
197
+ // These are needed as the Nokia Symbian Compiler cannot decide between
198
+ // const T& and const T* in a function template. The Nokia compiler _can_
199
+ // decide between class template specializations for T and T*, so a
200
+ // tr1::type_traits-like is_pointer works, and we can overload on that.
201
+ template <typename T>
202
+ inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {
203
+ if (pointer == NULL) {
204
+ *ss_ << "(null)";
205
+ } else {
206
+ ::GTestStreamToHelper(ss_.get(), pointer);
207
+ }
208
+ }
209
+ template <typename T>
210
+ inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {
211
+ ::GTestStreamToHelper(ss_.get(), value);
212
+ }
213
+ #endif // GTEST_OS_SYMBIAN
214
+
215
+ // We'll hold the text streamed to this object here.
216
+ const internal::scoped_ptr< ::std::stringstream> ss_;
217
+
218
+ // We declare (but don't implement) this to prevent the compiler
219
+ // from implementing the assignment operator.
220
+ void operator=(const Message&);
221
+ };
222
+
223
+ // Streams a Message to an ostream.
224
+ inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
225
+ return os << sb.GetString();
226
+ }
227
+
228
+ } // namespace testing
229
+
230
+ #endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_