ooxml_crypt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +58 -0
  5. data/Rakefile +12 -0
  6. data/bin/console +15 -0
  7. data/bin/setup +8 -0
  8. data/ext/ooxml_crypt/extconf.rb +18 -0
  9. data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
  10. data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
  11. data/lib/ooxml_crypt/version.rb +5 -0
  12. data/lib/ooxml_crypt.rb +75 -0
  13. data/vendor/cybozulib/.github/workflows/main.yml +12 -0
  14. data/vendor/cybozulib/.gitignore +5 -0
  15. data/vendor/cybozulib/CMakeLists.txt +6 -0
  16. data/vendor/cybozulib/COPYRIGHT +27 -0
  17. data/vendor/cybozulib/Makefile +26 -0
  18. data/vendor/cybozulib/bin/libeay32.dll +0 -0
  19. data/vendor/cybozulib/bin/libmecab.dll +0 -0
  20. data/vendor/cybozulib/bin/ssleay32.dll +0 -0
  21. data/vendor/cybozulib/common.mk +116 -0
  22. data/vendor/cybozulib/common.props +25 -0
  23. data/vendor/cybozulib/cybozulib.sln +286 -0
  24. data/vendor/cybozulib/debug.props +14 -0
  25. data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
  26. data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
  27. data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
  28. data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
  29. data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
  30. data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
  31. data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
  32. data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
  33. data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
  34. data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
  35. data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
  36. data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
  37. data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
  38. data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
  39. data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
  40. data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
  41. data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
  42. data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
  43. data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
  44. data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
  45. data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
  46. data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
  47. data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
  48. data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
  49. data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
  50. data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
  51. data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
  52. data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
  53. data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
  54. data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
  55. data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
  56. data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
  57. data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
  58. data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
  59. data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
  60. data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
  61. data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
  62. data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
  63. data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
  64. data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
  65. data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
  66. data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
  67. data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
  68. data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
  69. data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
  70. data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
  71. data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
  72. data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
  73. data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
  74. data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
  75. data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
  76. data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
  77. data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
  78. data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
  79. data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
  80. data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
  81. data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
  82. data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
  83. data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
  84. data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
  85. data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
  86. data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
  87. data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
  88. data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
  89. data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
  90. data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
  91. data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
  92. data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
  93. data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
  94. data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
  95. data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
  96. data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
  97. data/vendor/cybozulib/include/sais.hxx +364 -0
  98. data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
  99. data/vendor/cybozulib/mk.bat +37 -0
  100. data/vendor/cybozulib/readme.md +29 -0
  101. data/vendor/cybozulib/release.props +12 -0
  102. data/vendor/cybozulib/sample/Makefile +30 -0
  103. data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
  104. data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
  105. data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
  106. data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
  107. data/vendor/cybozulib/sample/data/svd/test1 +4 -0
  108. data/vendor/cybozulib/sample/data/svd/test2 +4 -0
  109. data/vendor/cybozulib/sample/desymbol.cpp +127 -0
  110. data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
  111. data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
  112. data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
  113. data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
  114. data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
  115. data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
  116. data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
  117. data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
  118. data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
  119. data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
  120. data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
  121. data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
  122. data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
  123. data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
  124. data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
  125. data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
  126. data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
  127. data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
  128. data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
  129. data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
  130. data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
  131. data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
  132. data/vendor/cybozulib/src/Makefile +8 -0
  133. data/vendor/cybozulib/src/base/Makefile +19 -0
  134. data/vendor/cybozulib/test/Makefile +12 -0
  135. data/vendor/cybozulib/test/base/Makefile +37 -0
  136. data/vendor/cybozulib/test/base/array_test.cpp +173 -0
  137. data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
  138. data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
  139. data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
  140. data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
  141. data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
  142. data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
  143. data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
  144. data/vendor/cybozulib/test/base/config_test.cpp +236 -0
  145. data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
  146. data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
  147. data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
  148. data/vendor/cybozulib/test/base/data/a.xml +26 -0
  149. data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
  150. data/vendor/cybozulib/test/base/env_test.cpp +22 -0
  151. data/vendor/cybozulib/test/base/event_test.cpp +41 -0
  152. data/vendor/cybozulib/test/base/file_test.cpp +233 -0
  153. data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
  154. data/vendor/cybozulib/test/base/format_test.cpp +12 -0
  155. data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
  156. data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
  157. data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
  158. data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
  159. data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
  160. data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
  161. data/vendor/cybozulib/test/base/option_test.cpp +487 -0
  162. data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
  163. data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
  164. data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
  165. data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
  166. data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
  167. data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
  168. data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
  169. data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
  170. data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
  171. data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
  172. data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
  173. data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
  174. data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
  175. data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
  176. data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
  177. data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
  178. data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
  179. data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
  180. data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
  181. data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
  182. data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
  183. data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
  184. data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
  185. data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
  186. data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
  187. data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
  188. data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
  189. data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
  190. data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
  191. data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
  192. data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
  193. data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
  194. data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
  195. data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
  196. data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
  197. data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
  198. data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
  199. data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
  200. data/vendor/cybozulib/test/base/time_test.cpp +164 -0
  201. data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
  202. data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
  203. data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
  204. data/vendor/cybozulib/test/nlp/Makefile +27 -0
  205. data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
  206. data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
  207. data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
  208. data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
  209. data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
  210. data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
  211. data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
  212. data/vendor/cybozulib/tool/create_vcproj.py +186 -0
  213. data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
  214. data/vendor/msoffice/COPYRIGHT +27 -0
  215. data/vendor/msoffice/Makefile +29 -0
  216. data/vendor/msoffice/bin/64/msoc.dll +0 -0
  217. data/vendor/msoffice/bin/64/msocsample.exe +0 -0
  218. data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
  219. data/vendor/msoffice/bin/msoc.dll +0 -0
  220. data/vendor/msoffice/bin/msocsample.exe +0 -0
  221. data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
  222. data/vendor/msoffice/common.mk +71 -0
  223. data/vendor/msoffice/common.props +26 -0
  224. data/vendor/msoffice/debug.props +14 -0
  225. data/vendor/msoffice/include/attack.hpp +211 -0
  226. data/vendor/msoffice/include/cfb.hpp +777 -0
  227. data/vendor/msoffice/include/crypto_util.hpp +450 -0
  228. data/vendor/msoffice/include/custom_sha1.hpp +342 -0
  229. data/vendor/msoffice/include/decode.hpp +240 -0
  230. data/vendor/msoffice/include/encode.hpp +221 -0
  231. data/vendor/msoffice/include/make_dataspace.hpp +316 -0
  232. data/vendor/msoffice/include/msoc.h +129 -0
  233. data/vendor/msoffice/include/resource.hpp +7 -0
  234. data/vendor/msoffice/include/standard_encryption.hpp +145 -0
  235. data/vendor/msoffice/include/uint32vec.hpp +179 -0
  236. data/vendor/msoffice/include/util.hpp +212 -0
  237. data/vendor/msoffice/lib/.emptydir +0 -0
  238. data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
  239. data/vendor/msoffice/mk.bat +1 -0
  240. data/vendor/msoffice/mkdll.bat +3 -0
  241. data/vendor/msoffice/msoc.def +13 -0
  242. data/vendor/msoffice/msocsample.py +178 -0
  243. data/vendor/msoffice/msoffice12.sln +31 -0
  244. data/vendor/msoffice/readme.md +110 -0
  245. data/vendor/msoffice/release.props +28 -0
  246. data/vendor/msoffice/src/Makefile +19 -0
  247. data/vendor/msoffice/src/attack.cpp +124 -0
  248. data/vendor/msoffice/src/cfb_test.cpp +77 -0
  249. data/vendor/msoffice/src/minisample.c +54 -0
  250. data/vendor/msoffice/src/msocdll.cpp +276 -0
  251. data/vendor/msoffice/src/msocsample.c +136 -0
  252. data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
  253. data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
  254. data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
  255. data/vendor/msoffice/src/sha1.cpp +234 -0
  256. data/vendor/msoffice/test/Makefile +20 -0
  257. data/vendor/msoffice/test/cfb_test.cpp +74 -0
  258. data/vendor/msoffice/test/hash_test.cpp +59 -0
  259. data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
  260. data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
  261. data/vendor/msoffice/test/sampl.bat +8 -0
  262. data/vendor/msoffice/test_all.py +46 -0
  263. data/vendor/update +4 -0
  264. metadata +351 -0
@@ -0,0 +1,56 @@
1
+ #include <stdio.h>
2
+ #include <memory.h>
3
+ #include <cybozu/endian.hpp>
4
+ #include <cybozu/test.hpp>
5
+
6
+ #ifdef _WIN32
7
+ #pragma warning(disable : 4309) /* trivial cast */
8
+ #endif
9
+
10
+ CYBOZU_TEST_AUTO(endian_test)
11
+ {
12
+ uint8_t buf[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff };
13
+ {
14
+ uint64_t x;
15
+ x = cybozu::Get64bitAsLE(buf);
16
+ CYBOZU_TEST_EQUAL(x, uint64_t(0xffdebc9a78563412LL));
17
+
18
+ x = cybozu::Get64bitAsBE(buf);
19
+ CYBOZU_TEST_EQUAL(x, uint64_t(0x123456789abcdeffLL));
20
+ }
21
+ {
22
+ uint32_t x;
23
+ x = cybozu::Get32bitAsLE(buf);
24
+ CYBOZU_TEST_EQUAL(x, 0x78563412U);
25
+
26
+ x = cybozu::Get32bitAsBE(buf);
27
+ CYBOZU_TEST_EQUAL(x, 0x12345678U);
28
+ }
29
+ char buf2[8];
30
+ cybozu::Set32bitAsLE(buf2, 0x78563412);
31
+ CYBOZU_TEST_ASSERT(memcmp(buf2, buf, 4) == 0);
32
+
33
+ cybozu::Set32bitAsBE(buf2, 0x12345678);
34
+ CYBOZU_TEST_ASSERT(memcmp(buf2, buf, 4) == 0);
35
+
36
+ cybozu::Set64bitAsLE(buf2, uint64_t(0xffdebc9a78563412LL));
37
+ CYBOZU_TEST_ASSERT(memcmp(buf2, buf, 8) == 0);
38
+
39
+ cybozu::Set64bitAsBE(buf2, uint64_t(0x123456789abcdeffLL));
40
+ CYBOZU_TEST_ASSERT(memcmp(buf2, buf, 8) == 0);
41
+
42
+ {
43
+ unsigned short x;
44
+ x = cybozu::Get16bitAsLE(buf);
45
+ CYBOZU_TEST_EQUAL(x, 0x3412);
46
+ x = cybozu::Get16bitAsBE(buf);
47
+ CYBOZU_TEST_EQUAL(x, 0x1234);
48
+ }
49
+ {
50
+ char buf3[2];
51
+ cybozu::Set16bitAsLE(buf3, 0x3456);
52
+ CYBOZU_TEST_ASSERT(memcmp(buf3, "\x56\x34", 2) == 0);
53
+ cybozu::Set16bitAsBE(buf3, 0x3456);
54
+ CYBOZU_TEST_ASSERT(memcmp(buf3, "\x34\x56", 2) == 0);
55
+ }
56
+ }
@@ -0,0 +1,22 @@
1
+ #include <stdio.h>
2
+ #include <cybozu/env.hpp>
3
+ #include <cybozu/test.hpp>
4
+
5
+ CYBOZU_TEST_AUTO(env)
6
+ {
7
+ std::string val;
8
+ CYBOZU_TEST_ASSERT(!cybozu::QueryEnv(val, "aw3vraw3vasv"));
9
+ #ifdef _WIN32
10
+ const char *key = "SystemDrive";
11
+ const char *assumeVal = "C:";
12
+ #elif defined(__APPLE__)
13
+ const char *key = "OSTYPE";
14
+ const char *assumeVal = "darwin";
15
+ #else
16
+ const char *key = "OSTYPE";
17
+ const char *assumeVal = "linux";
18
+ #endif
19
+ val = cybozu::GetEnv(key);
20
+ CYBOZU_TEST_EQUAL(val, assumeVal);
21
+ CYBOZU_TEST_EQUAL(cybozu::GetEnv("asvrifansevjase", "default"), "default");
22
+ }
@@ -0,0 +1,41 @@
1
+ #include <stdio.h>
2
+ #include <cybozu/thread.hpp>
3
+ #include <cybozu/event.hpp>
4
+ #include <cybozu/test.hpp>
5
+
6
+ class Thread : public cybozu::ThreadBase {
7
+ cybozu::Event& ev_;
8
+ public:
9
+ bool done_;
10
+ Thread(cybozu::Event& ev)
11
+ : ev_(ev)
12
+ , done_(false)
13
+ {
14
+ }
15
+
16
+ void threadEntry()
17
+ {
18
+ puts("thread");
19
+ puts("sleep 100msec");
20
+ cybozu::Sleep(100);
21
+ puts("wakeup");
22
+ ev_.wakeup();
23
+ cybozu::Sleep(100);
24
+ ev_.wakeup();
25
+ }
26
+ };
27
+
28
+ CYBOZU_TEST_AUTO(event_test)
29
+ {
30
+ cybozu::Event ev;
31
+
32
+ Thread th(ev);
33
+ th.beginThread();
34
+
35
+ ev.wait();
36
+ puts("done");
37
+ ev.wait();
38
+ puts("done");
39
+
40
+ th.joinThread();
41
+ }
@@ -0,0 +1,233 @@
1
+ #include <cybozu/file.hpp>
2
+ #include <cybozu/test.hpp>
3
+ #include <memory.h>
4
+ #include <stdlib.h>
5
+ #include <vector>
6
+
7
+ static const std::string fileName = "test.tmp";
8
+ static const std::string fileName2 = "test2.tmp";
9
+ static const char testBuf[] = { 1, 2, 5, 4, 3, 2, 1 };
10
+
11
+ CYBOZU_TEST_AUTO(open_and_write)
12
+ {
13
+ cybozu::File f;
14
+ CYBOZU_TEST_ASSERT(!f.isOpen());
15
+ f.open(fileName, std::ios::out | std::ios::trunc);
16
+ CYBOZU_TEST_ASSERT(f.isOpen());
17
+ f.write(testBuf, sizeof(testBuf));
18
+ f.close();
19
+ }
20
+
21
+ CYBOZU_TEST_AUTO(read)
22
+ {
23
+ cybozu::File f;
24
+ f.open(fileName, std::ios::in);
25
+ CYBOZU_TEST_ASSERT(f.isOpen());
26
+ char buf[sizeof(testBuf)] = {};
27
+ f.read(buf, sizeof(buf));
28
+ CYBOZU_TEST_ASSERT(memcmp(buf, testBuf, sizeof(buf)) == 0);
29
+ CYBOZU_TEST_EQUAL(f.getSize(), sizeof(testBuf));
30
+ }
31
+
32
+ CYBOZU_TEST_AUTO(readSome)
33
+ {
34
+ cybozu::File f;
35
+ f.open(fileName, std::ios::in);
36
+ CYBOZU_TEST_ASSERT(f.isOpen());
37
+ char buf[1024] = {};
38
+ size_t readSize = f.readSome(buf, sizeof(buf));
39
+ CYBOZU_TEST_EQUAL(f.getSize(), readSize);
40
+ CYBOZU_TEST_ASSERT(memcmp(buf, testBuf, readSize) == 0);
41
+ }
42
+
43
+ CYBOZU_TEST_AUTO(size)
44
+ {
45
+ CYBOZU_TEST_EQUAL(cybozu::GetFileSize(fileName), sizeof(testBuf));
46
+ }
47
+
48
+ CYBOZU_TEST_AUTO(append)
49
+ {
50
+ cybozu::File f;
51
+ CYBOZU_TEST_ASSERT(!f.isOpen());
52
+ f.open(fileName, std::ios::out | std::ios::app);
53
+ CYBOZU_TEST_ASSERT(f.isOpen());
54
+ f.write(testBuf, sizeof(testBuf));
55
+ }
56
+
57
+ CYBOZU_TEST_AUTO(read2)
58
+ {
59
+ cybozu::File f;
60
+ f.open(fileName, std::ios::in);
61
+ const size_t size = sizeof(testBuf);
62
+ char buf[size * 2];
63
+ f.read(buf, size * 2);
64
+ CYBOZU_TEST_ASSERT(memcmp(buf, testBuf, size) == 0);
65
+ CYBOZU_TEST_ASSERT(memcmp(buf + size, testBuf, size) == 0);
66
+ CYBOZU_TEST_EQUAL(f.getSize(), size * 2);
67
+ }
68
+
69
+ CYBOZU_TEST_AUTO(badmode)
70
+ {
71
+ cybozu::File f;
72
+ CYBOZU_TEST_EXCEPTION(f.open("test", std::ios::in | std::ios::out), cybozu::Exception);
73
+ CYBOZU_TEST_EXCEPTION(f.open("test", std::ios::in | std::ios::trunc), cybozu::Exception);
74
+ CYBOZU_TEST_EXCEPTION(f.open("test", std::ios::in | std::ios::app), cybozu::Exception);
75
+ CYBOZU_TEST_EXCEPTION(f.open("test", std::ios::out | std::ios::trunc | std::ios::app), cybozu::Exception);
76
+ }
77
+
78
+ CYBOZU_TEST_AUTO(move_and_remove)
79
+ {
80
+ {
81
+ cybozu::File f;
82
+ f.open(fileName, std::ios::out | std::ios::trunc);
83
+ CYBOZU_TEST_ASSERT(f.isOpen());
84
+ f.write(testBuf, sizeof(testBuf));
85
+ }
86
+ {
87
+ /*
88
+ remove fileName2 if exists and move fileName to fileName2
89
+ */
90
+ if (cybozu::DoesFileExist(fileName2)) {
91
+ cybozu::RemoveFile(fileName2);
92
+ }
93
+ CYBOZU_TEST_ASSERT(!cybozu::DoesFileExist(fileName2));
94
+ cybozu::RenameFile(fileName, fileName2);
95
+ CYBOZU_TEST_ASSERT(cybozu::DoesFileExist(fileName2));
96
+ cybozu::RemoveFile(fileName2);
97
+ }
98
+ {
99
+ CYBOZU_TEST_EXCEPTION_MESSAGE(cybozu::RemoveFile(fileName2), cybozu::Exception, fileName2);
100
+ CYBOZU_TEST_EXCEPTION_MESSAGE(cybozu::RenameFile(fileName, fileName2), cybozu::Exception, fileName2);
101
+ }
102
+ }
103
+
104
+ CYBOZU_TEST_AUTO(path)
105
+ {
106
+ {
107
+ std::string a = "abc\\def\\defg\\\\";
108
+ std::string b = "abc/def/defg//";
109
+ cybozu::ReplaceBackSlash(a);
110
+ CYBOZU_TEST_EQUAL(a, b);
111
+ }
112
+
113
+ std::string path, baseName;
114
+ path = cybozu::GetExePath(&baseName);
115
+ #ifdef NDEBUG
116
+ const std::string cBaseName = "file_test";
117
+ #else
118
+ const std::string cBaseName = "file_testd";
119
+ #endif
120
+ CYBOZU_TEST_EQUAL(baseName, cBaseName);
121
+ std::string cPath = "/cybozulib/bin/";
122
+ if (path.size() >= cPath.size()) path = path.substr(path.size() - cPath.size(), std::string::npos);
123
+ CYBOZU_TEST_EQUAL(path, cPath);
124
+ }
125
+
126
+ template<size_t N>
127
+ bool findIn(const std::string& name, const char (&tbl)[N][16])
128
+ {
129
+ for (size_t i = 0; i < N; i++) {
130
+ if (name == tbl[i]) return true;
131
+ }
132
+ return false;
133
+ }
134
+
135
+ CYBOZU_TEST_AUTO(GetFilesInDir1)
136
+ {
137
+ std::string path = cybozu::GetExePath() + "../include/cybozu/";
138
+ cybozu::FileList list;
139
+ CYBOZU_TEST_ASSERT(cybozu::GetFileList(list, path, "hpp"));
140
+
141
+ const char fileTbl[][16] = {
142
+ "inttype.hpp",
143
+ "file.hpp",
144
+ "exception.hpp",
145
+ "atoi.hpp",
146
+ "stacktrace.hpp",
147
+ "mutex.hpp",
148
+ };
149
+ size_t foundFileNum = 0;
150
+ for (size_t i = 0; i < list.size(); i++) {
151
+ const std::string& name = list[i].name;
152
+ if (findIn(name, fileTbl)) {
153
+ CYBOZU_TEST_ASSERT(list[i].isFile());
154
+ foundFileNum++;
155
+ }
156
+ }
157
+ CYBOZU_TEST_EQUAL(CYBOZU_NUM_OF_ARRAY(fileTbl), foundFileNum);
158
+ }
159
+
160
+ CYBOZU_TEST_AUTO(GetFilesInDir2)
161
+ {
162
+ std::string path = cybozu::GetExePath() + "../include/cybozu/";
163
+ cybozu::FileList list = cybozu::GetFileList(path);
164
+
165
+ const char fileTbl[][16] = {
166
+ "inttype.hpp",
167
+ "file.hpp",
168
+ "exception.hpp",
169
+ "atoi.hpp",
170
+ "stacktrace.hpp",
171
+ "mutex.hpp",
172
+ };
173
+ const char dirTbl[][16] = {
174
+ "nlp",
175
+ };
176
+
177
+ size_t foundFileNum = 0;
178
+ size_t foundDirNum = 0;
179
+ for (size_t i = 0; i < list.size(); i++) {
180
+ const std::string& name = list[i].name;
181
+ if (findIn(name, fileTbl)) {
182
+ CYBOZU_TEST_ASSERT(list[i].isFile());
183
+ foundFileNum++;
184
+ }
185
+ if (findIn(name, dirTbl)) {
186
+ CYBOZU_TEST_ASSERT(list[i].isDirectory());
187
+ foundDirNum++;
188
+ }
189
+ }
190
+ CYBOZU_TEST_EQUAL(CYBOZU_NUM_OF_ARRAY(fileTbl), foundFileNum);
191
+ CYBOZU_TEST_EQUAL(CYBOZU_NUM_OF_ARRAY(dirTbl), foundDirNum);
192
+ }
193
+
194
+ CYBOZU_TEST_AUTO(GetBaseName)
195
+ {
196
+ const struct {
197
+ const char *name;
198
+ const char *base;
199
+ const char *suf;
200
+ } tbl[] = {
201
+ { "test", "test", "" },
202
+ { "test.abc", "test", "abc" },
203
+ { "test.abc.def", "test.abc", "def" },
204
+ { ".abc", "", "abc" },
205
+ { "abc.", "abc", "" },
206
+ };
207
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
208
+ const std::string name = tbl[i].name;
209
+ CYBOZU_TEST_EQUAL(cybozu::GetBaseName(name), tbl[i].base);
210
+ std::string suf;
211
+ CYBOZU_TEST_EQUAL(cybozu::GetBaseName(name, &suf), tbl[i].base);
212
+ CYBOZU_TEST_EQUAL(suf, tbl[i].suf);
213
+
214
+ }
215
+ }
216
+
217
+ CYBOZU_TEST_AUTO(HasExtension)
218
+ {
219
+ const struct {
220
+ const char *name;
221
+ const char *suf;
222
+ bool has;
223
+ } tbl[] = {
224
+ { "test.txt", "txt", true },
225
+ { "test.txa", "txt", false },
226
+ { ".txt", "txt", true },
227
+ { "asbc", "", true },
228
+ { "", "a", false },
229
+ };
230
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
231
+ CYBOZU_TEST_EQUAL(cybozu::HasExtension(tbl[i].name, tbl[i].suf), tbl[i].has);
232
+ }
233
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+ don't remove the top of BOM for VC
3
+ */
4
+ #include <cybozu/test.hpp>
5
+ #include <cybozu/fmindex.hpp>
6
+ #include <cybozu/file.hpp>
7
+ #include <cybozu/mmap.hpp>
8
+ #include <cybozu/string.hpp>
9
+ #include <set>
10
+
11
+ typedef std::set<int> Set;
12
+
13
+ std::string g_textTbl[] = {
14
+ "",
15
+ "abracatabra",
16
+ "cybozuabcabcintint}}",
17
+ };
18
+
19
+ struct Init {
20
+ Init()
21
+ {
22
+ std::string path = cybozu::GetExePath();
23
+ size_t pos = path.find("cybozulib");
24
+ CYBOZU_TEST_ASSERT(pos != std::string::npos);
25
+ path = path.substr(0, pos + 9) + "/include/cybozu/fmindex.hpp";
26
+ cybozu::Mmap mmap(path);
27
+ g_textTbl[0].assign(mmap.get(), (size_t)mmap.size());
28
+ }
29
+ } init;
30
+
31
+ // f.getPrevString(out, 0, f.wm.size() - 1);
32
+
33
+ template<class FMINDEX, class STRING>
34
+ Set searchPos1(const FMINDEX& f, const STRING& key)
35
+ {
36
+ Set ret;
37
+ size_t begin, end = 0;
38
+ if (f.getRange(&begin, &end, key)) {
39
+ while (begin != end) {
40
+ ret.insert((int)f.convertPosition(begin));
41
+ ++begin;
42
+ }
43
+ }
44
+ return ret;
45
+ }
46
+
47
+ // standard search
48
+ template<class STRING>
49
+ Set searchPos2(const STRING& text, const STRING& key)
50
+ {
51
+ Set ret;
52
+ size_t pos = 0;
53
+ for (;;) {
54
+ size_t q = text.find(key, pos);
55
+ if (q == std::string::npos) break;
56
+ ret.insert((int)q);
57
+ pos = q + 1;
58
+ }
59
+ return ret;
60
+ }
61
+
62
+ template<class FMINDEX, class STRING>
63
+ void compareText(const FMINDEX& f, const STRING& text, const STRING *keyTbl, size_t keySize)
64
+ {
65
+ for (size_t i = 0; i < keySize; i++) {
66
+ const STRING& key = keyTbl[i];
67
+ Set a = searchPos1(f, key);
68
+ Set b = searchPos2(text, key);
69
+ CYBOZU_TEST_EQUAL(a.size(), b.size());
70
+ if (a.size() == b.size()) {
71
+ size_t pos = 0;
72
+ for (Set::const_iterator ia = a.begin(), ib = b.begin(); pos < a.size(); ++ia, ++ib, ++pos) {
73
+ CYBOZU_TEST_EQUAL(*ia, *ib);
74
+ }
75
+ }
76
+ }
77
+ // recover string
78
+ STRING org;
79
+ f.getPrevString(org, 0, f.wm.size() - 1);
80
+ CYBOZU_TEST_EQUAL(org.size(), text.size());
81
+ CYBOZU_TEST_ASSERT(org == text);
82
+ }
83
+
84
+ template<class FMINDEX, class STRING>
85
+ void searchTest(const STRING& text, const STRING *keyTbl, size_t keySize)
86
+ {
87
+ FMINDEX f;
88
+ f.init(text.begin(), text.end());
89
+ compareText(f, text, keyTbl, keySize);
90
+ std::stringstream ss;
91
+ f.save(ss);
92
+ {
93
+ FMINDEX ff;
94
+ ff.load(ss);
95
+ compareText(ff, text, keyTbl, keySize);
96
+ }
97
+ }
98
+
99
+ CYBOZU_TEST_AUTO(string)
100
+ {
101
+ static const std::string tbl[] = {
102
+ "double", "int", "cybozu", "std", "}", "\t", "xxx",
103
+ };
104
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(g_textTbl); i++) {
105
+ searchTest<cybozu::FMindex, std::string>(g_textTbl[i], tbl, CYBOZU_NUM_OF_ARRAY(tbl));
106
+ }
107
+ }
108
+
109
+ CYBOZU_TEST_AUTO(wstring)
110
+ {
111
+ static const cybozu::String text(CYBOZU_STR_W("あいうえおabcあいうえおaaabあああうえabうえあいう"));
112
+ static const cybozu::String tbl[] = {
113
+ CYBOZU_STR_W("あいう"),
114
+ CYBOZU_STR_W("ab"),
115
+ CYBOZU_STR_W("うえ"),
116
+ };
117
+ searchTest<cybozu::FMindexT<cybozu::Char>, cybozu::String>(text, tbl, CYBOZU_NUM_OF_ARRAY(tbl));
118
+ }
@@ -0,0 +1,12 @@
1
+ #include <cybozu/format.hpp>
2
+ #include <cybozu/test.hpp>
3
+
4
+ CYBOZU_TEST_AUTO(format)
5
+ {
6
+ std::string a;
7
+ cybozu::format(a, "%d", 1234567);
8
+ CYBOZU_TEST_EQUAL(a, "1234567");
9
+ CYBOZU_TEST_EQUAL(cybozu::format("%d", 123), "123");
10
+ a = cybozu::format("%s%c%d%s", "abcdefg", 0, 123, "xxx");
11
+ CYBOZU_TEST_EQUAL(a, std::string("abcdefg" "\x00" "123xxx", 14));
12
+ }
@@ -0,0 +1,104 @@
1
+ #include <cybozu/test.hpp>
2
+ #include <cybozu/frequency.hpp>
3
+ #include <sstream>
4
+
5
+ template<class Element>
6
+ struct Tbl {
7
+ Element c;
8
+ size_t n;
9
+ };
10
+
11
+ template<class Freq, class T, size_t N>
12
+ void verify(const Freq& freq, const T (&tbl)[N])
13
+ {
14
+ CYBOZU_TEST_EQUAL(freq.size(), N);
15
+ for (size_t i = 0; i < N; i++) {
16
+ CYBOZU_TEST_EQUAL(freq.getFrequency(tbl[i].c), tbl[i].n);
17
+ CYBOZU_TEST_EQUAL(freq.getIndex(tbl[i].c), i);
18
+ CYBOZU_TEST_EQUAL(freq.getElement(i), tbl[i].c);
19
+ }
20
+ }
21
+
22
+ CYBOZU_TEST_AUTO(char)
23
+ {
24
+ std::string a = "abcaaab\x80\x80\xff\xff\xff";
25
+ typedef cybozu::freq_local::FrequencyVec<char> Freq;
26
+ std::stringstream ss;
27
+ Freq freq;
28
+ {
29
+ Freq freqTmp(a.begin(), a.end());
30
+ freqTmp.save(ss);
31
+ }
32
+ freq.load(ss);
33
+ const Tbl<char> tbl[] = {
34
+ { 'a', 4 },
35
+ { '\xff', 3 },
36
+ { '\x80', 2 },
37
+ { 'b', 2 },
38
+ { 'c', 1 },
39
+ };
40
+ verify(freq, tbl);
41
+ Freq freq2;
42
+ for (size_t i = 0; i < a.size(); i++) {
43
+ freq2.append(a[i]);
44
+ }
45
+ freq2.ready();
46
+ verify(freq2, tbl);
47
+ }
48
+
49
+ CYBOZU_TEST_AUTO(int)
50
+ {
51
+ const int inTbl[] = {
52
+ 3, 5, 2, 3, 5, 2, 9, 5, 2, 2, 0,
53
+ };
54
+ typedef cybozu::Frequency<int> Freq;
55
+ std::stringstream ss;
56
+ Freq freq;
57
+ {
58
+ Freq freqTmp(inTbl, inTbl + CYBOZU_NUM_OF_ARRAY(inTbl));
59
+ freqTmp.save(ss);
60
+ }
61
+ freq.load(ss);
62
+ const Tbl<int> tbl[] = {
63
+ { 2, 4 },
64
+ { 5, 3 },
65
+ { 3, 2 },
66
+ { 9, 1 },
67
+ { 0, 1 },
68
+ };
69
+ verify(freq, tbl);
70
+ Freq freq2;
71
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(inTbl); i++) {
72
+ freq2.append(inTbl[i]);
73
+ }
74
+ freq2.ready();
75
+ verify(freq2, tbl);
76
+ }
77
+
78
+ CYBOZU_TEST_AUTO(string)
79
+ {
80
+ const std::string inTbl[] = {
81
+ "abc", "123", "a", "abc", "abc", "x", "123", "x",
82
+ };
83
+ typedef cybozu::Frequency<std::string> Freq;
84
+ std::stringstream ss;
85
+ Freq freq;
86
+ {
87
+ Freq freqTmp(inTbl, inTbl + CYBOZU_NUM_OF_ARRAY(inTbl));
88
+ freqTmp.save(ss);
89
+ }
90
+ freq.load(ss);
91
+ const Tbl<std::string> tbl[] = {
92
+ { "abc", 3 },
93
+ { "x", 2 },
94
+ { "123", 2 },
95
+ { "a", 1 },
96
+ };
97
+ verify(freq, tbl);
98
+ Freq freq2;
99
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(inTbl); i++) {
100
+ freq2.append(inTbl[i]);
101
+ }
102
+ freq2.ready();
103
+ verify(freq2, tbl);
104
+ }