ooxml_crypt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/ooxml_crypt/extconf.rb +18 -0
- data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
- data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
- data/lib/ooxml_crypt/version.rb +5 -0
- data/lib/ooxml_crypt.rb +75 -0
- data/vendor/cybozulib/.github/workflows/main.yml +12 -0
- data/vendor/cybozulib/.gitignore +5 -0
- data/vendor/cybozulib/CMakeLists.txt +6 -0
- data/vendor/cybozulib/COPYRIGHT +27 -0
- data/vendor/cybozulib/Makefile +26 -0
- data/vendor/cybozulib/bin/libeay32.dll +0 -0
- data/vendor/cybozulib/bin/libmecab.dll +0 -0
- data/vendor/cybozulib/bin/ssleay32.dll +0 -0
- data/vendor/cybozulib/common.mk +116 -0
- data/vendor/cybozulib/common.props +25 -0
- data/vendor/cybozulib/cybozulib.sln +286 -0
- data/vendor/cybozulib/debug.props +14 -0
- data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
- data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
- data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
- data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
- data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
- data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
- data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
- data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
- data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
- data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
- data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
- data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
- data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
- data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
- data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
- data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
- data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
- data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
- data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
- data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
- data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
- data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
- data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
- data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
- data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
- data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
- data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
- data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
- data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
- data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
- data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
- data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
- data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
- data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
- data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
- data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
- data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
- data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
- data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
- data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
- data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
- data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
- data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
- data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
- data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
- data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
- data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
- data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
- data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
- data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
- data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
- data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
- data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
- data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
- data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
- data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
- data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
- data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
- data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
- data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
- data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
- data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
- data/vendor/cybozulib/include/sais.hxx +364 -0
- data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
- data/vendor/cybozulib/mk.bat +37 -0
- data/vendor/cybozulib/readme.md +29 -0
- data/vendor/cybozulib/release.props +12 -0
- data/vendor/cybozulib/sample/Makefile +30 -0
- data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
- data/vendor/cybozulib/sample/data/svd/test1 +4 -0
- data/vendor/cybozulib/sample/data/svd/test2 +4 -0
- data/vendor/cybozulib/sample/desymbol.cpp +127 -0
- data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
- data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
- data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
- data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
- data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
- data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
- data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
- data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
- data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
- data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
- data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
- data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
- data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
- data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
- data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
- data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
- data/vendor/cybozulib/src/Makefile +8 -0
- data/vendor/cybozulib/src/base/Makefile +19 -0
- data/vendor/cybozulib/test/Makefile +12 -0
- data/vendor/cybozulib/test/base/Makefile +37 -0
- data/vendor/cybozulib/test/base/array_test.cpp +173 -0
- data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
- data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
- data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
- data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
- data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
- data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
- data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
- data/vendor/cybozulib/test/base/config_test.cpp +236 -0
- data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
- data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
- data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
- data/vendor/cybozulib/test/base/data/a.xml +26 -0
- data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
- data/vendor/cybozulib/test/base/env_test.cpp +22 -0
- data/vendor/cybozulib/test/base/event_test.cpp +41 -0
- data/vendor/cybozulib/test/base/file_test.cpp +233 -0
- data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
- data/vendor/cybozulib/test/base/format_test.cpp +12 -0
- data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
- data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
- data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
- data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
- data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
- data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
- data/vendor/cybozulib/test/base/option_test.cpp +487 -0
- data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
- data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
- data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
- data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
- data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
- data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
- data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
- data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
- data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
- data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
- data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
- data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
- data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
- data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
- data/vendor/cybozulib/test/base/time_test.cpp +164 -0
- data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
- data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
- data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
- data/vendor/cybozulib/test/nlp/Makefile +27 -0
- data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
- data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
- data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
- data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
- data/vendor/cybozulib/tool/create_vcproj.py +186 -0
- data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
- data/vendor/msoffice/COPYRIGHT +27 -0
- data/vendor/msoffice/Makefile +29 -0
- data/vendor/msoffice/bin/64/msoc.dll +0 -0
- data/vendor/msoffice/bin/64/msocsample.exe +0 -0
- data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/bin/msoc.dll +0 -0
- data/vendor/msoffice/bin/msocsample.exe +0 -0
- data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/common.mk +71 -0
- data/vendor/msoffice/common.props +26 -0
- data/vendor/msoffice/debug.props +14 -0
- data/vendor/msoffice/include/attack.hpp +211 -0
- data/vendor/msoffice/include/cfb.hpp +777 -0
- data/vendor/msoffice/include/crypto_util.hpp +450 -0
- data/vendor/msoffice/include/custom_sha1.hpp +342 -0
- data/vendor/msoffice/include/decode.hpp +240 -0
- data/vendor/msoffice/include/encode.hpp +221 -0
- data/vendor/msoffice/include/make_dataspace.hpp +316 -0
- data/vendor/msoffice/include/msoc.h +129 -0
- data/vendor/msoffice/include/resource.hpp +7 -0
- data/vendor/msoffice/include/standard_encryption.hpp +145 -0
- data/vendor/msoffice/include/uint32vec.hpp +179 -0
- data/vendor/msoffice/include/util.hpp +212 -0
- data/vendor/msoffice/lib/.emptydir +0 -0
- data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
- data/vendor/msoffice/mk.bat +1 -0
- data/vendor/msoffice/mkdll.bat +3 -0
- data/vendor/msoffice/msoc.def +13 -0
- data/vendor/msoffice/msocsample.py +178 -0
- data/vendor/msoffice/msoffice12.sln +31 -0
- data/vendor/msoffice/readme.md +110 -0
- data/vendor/msoffice/release.props +28 -0
- data/vendor/msoffice/src/Makefile +19 -0
- data/vendor/msoffice/src/attack.cpp +124 -0
- data/vendor/msoffice/src/cfb_test.cpp +77 -0
- data/vendor/msoffice/src/minisample.c +54 -0
- data/vendor/msoffice/src/msocdll.cpp +276 -0
- data/vendor/msoffice/src/msocsample.c +136 -0
- data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
- data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
- data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
- data/vendor/msoffice/src/sha1.cpp +234 -0
- data/vendor/msoffice/test/Makefile +20 -0
- data/vendor/msoffice/test/cfb_test.cpp +74 -0
- data/vendor/msoffice/test/hash_test.cpp +59 -0
- data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
- data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
- data/vendor/msoffice/test/sampl.bat +8 -0
- data/vendor/msoffice/test_all.py +46 -0
- data/vendor/update +4 -0
- metadata +351 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief unit test class
|
|
5
|
+
|
|
6
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include <string.h>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include <list>
|
|
13
|
+
#include <iostream>
|
|
14
|
+
#include <utility>
|
|
15
|
+
#if defined(_MSC_VER) && (MSC_VER <= 1500)
|
|
16
|
+
#include <cybozu/inttype.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#include <stdint.h>
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
namespace cybozu { namespace test {
|
|
22
|
+
|
|
23
|
+
class AutoRun {
|
|
24
|
+
typedef void (*Func)();
|
|
25
|
+
typedef std::list<std::pair<const char*, Func> > UnitTestList;
|
|
26
|
+
public:
|
|
27
|
+
AutoRun()
|
|
28
|
+
: init_(0)
|
|
29
|
+
, term_(0)
|
|
30
|
+
, okCount_(0)
|
|
31
|
+
, ngCount_(0)
|
|
32
|
+
, exceptionCount_(0)
|
|
33
|
+
{
|
|
34
|
+
}
|
|
35
|
+
void setup(Func init, Func term)
|
|
36
|
+
{
|
|
37
|
+
init_ = init;
|
|
38
|
+
term_ = term;
|
|
39
|
+
}
|
|
40
|
+
void append(const char *name, Func func)
|
|
41
|
+
{
|
|
42
|
+
list_.push_back(std::make_pair(name, func));
|
|
43
|
+
}
|
|
44
|
+
void set(bool isOK)
|
|
45
|
+
{
|
|
46
|
+
if (isOK) {
|
|
47
|
+
okCount_++;
|
|
48
|
+
} else {
|
|
49
|
+
ngCount_++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
std::string getBaseName(const std::string& name) const
|
|
53
|
+
{
|
|
54
|
+
#ifdef _WIN32
|
|
55
|
+
const char sep = '\\';
|
|
56
|
+
#else
|
|
57
|
+
const char sep = '/';
|
|
58
|
+
#endif
|
|
59
|
+
size_t pos = name.find_last_of(sep);
|
|
60
|
+
std::string ret = name.substr(pos + 1);
|
|
61
|
+
pos = ret.find('.');
|
|
62
|
+
return ret.substr(0, pos);
|
|
63
|
+
}
|
|
64
|
+
int run(int, char *argv[])
|
|
65
|
+
{
|
|
66
|
+
std::string msg;
|
|
67
|
+
try {
|
|
68
|
+
if (init_) init_();
|
|
69
|
+
for (UnitTestList::const_iterator i = list_.begin(), ie = list_.end(); i != ie; ++i) {
|
|
70
|
+
std::cout << "ctest:module=" << i->first << std::endl;
|
|
71
|
+
try {
|
|
72
|
+
(i->second)();
|
|
73
|
+
} catch (std::exception& e) {
|
|
74
|
+
exceptionCount_++;
|
|
75
|
+
std::cout << "ctest: " << i->first << " is stopped by exception " << e.what() << std::endl;
|
|
76
|
+
} catch (...) {
|
|
77
|
+
exceptionCount_++;
|
|
78
|
+
std::cout << "ctest: " << i->first << " is stopped by unknown exception" << std::endl;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (term_) term_();
|
|
82
|
+
} catch (std::exception& e) {
|
|
83
|
+
msg = std::string("ctest:err:") + e.what();
|
|
84
|
+
} catch (...) {
|
|
85
|
+
msg = "ctest:err: catch unknown exception";
|
|
86
|
+
}
|
|
87
|
+
fflush(stdout);
|
|
88
|
+
if (msg.empty()) {
|
|
89
|
+
int err = ngCount_ + exceptionCount_;
|
|
90
|
+
int total = okCount_ + err;
|
|
91
|
+
std::cout << "ctest:name=" << getBaseName(*argv)
|
|
92
|
+
<< ", module=" << list_.size()
|
|
93
|
+
<< ", total=" << total
|
|
94
|
+
<< ", ok=" << okCount_
|
|
95
|
+
<< ", ng=" << ngCount_
|
|
96
|
+
<< ", exception=" << exceptionCount_ << std::endl;
|
|
97
|
+
return err > 0 ? 1 : 0;
|
|
98
|
+
} else {
|
|
99
|
+
std::cout << msg << std::endl;
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
static inline AutoRun& getInstance()
|
|
104
|
+
{
|
|
105
|
+
static AutoRun instance;
|
|
106
|
+
return instance;
|
|
107
|
+
}
|
|
108
|
+
private:
|
|
109
|
+
Func init_;
|
|
110
|
+
Func term_;
|
|
111
|
+
int okCount_;
|
|
112
|
+
int ngCount_;
|
|
113
|
+
int exceptionCount_;
|
|
114
|
+
UnitTestList list_;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
static AutoRun& autoRun = AutoRun::getInstance();
|
|
118
|
+
|
|
119
|
+
inline void test(bool ret, const std::string& msg, const std::string& param, const char *file, int line)
|
|
120
|
+
{
|
|
121
|
+
autoRun.set(ret);
|
|
122
|
+
if (!ret) {
|
|
123
|
+
printf("%s(%d):ctest:%s(%s);\n", file, line, msg.c_str(), param.c_str());
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
template<typename T, typename U>
|
|
128
|
+
bool isEqual(const T& lhs, const U& rhs)
|
|
129
|
+
{
|
|
130
|
+
return lhs == rhs;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// avoid warning of comparision of integers of different signs
|
|
134
|
+
inline bool isEqual(size_t lhs, int rhs)
|
|
135
|
+
{
|
|
136
|
+
return lhs == size_t(rhs);
|
|
137
|
+
}
|
|
138
|
+
inline bool isEqual(int lhs, size_t rhs)
|
|
139
|
+
{
|
|
140
|
+
return size_t(lhs) == rhs;
|
|
141
|
+
}
|
|
142
|
+
inline bool isEqual(const char *lhs, const char *rhs)
|
|
143
|
+
{
|
|
144
|
+
return strcmp(lhs, rhs) == 0;
|
|
145
|
+
}
|
|
146
|
+
inline bool isEqual(char *lhs, const char *rhs)
|
|
147
|
+
{
|
|
148
|
+
return strcmp(lhs, rhs) == 0;
|
|
149
|
+
}
|
|
150
|
+
inline bool isEqual(const char *lhs, char *rhs)
|
|
151
|
+
{
|
|
152
|
+
return strcmp(lhs, rhs) == 0;
|
|
153
|
+
}
|
|
154
|
+
inline bool isEqual(char *lhs, char *rhs)
|
|
155
|
+
{
|
|
156
|
+
return strcmp(lhs, rhs) == 0;
|
|
157
|
+
}
|
|
158
|
+
// avoid to compare float directly
|
|
159
|
+
inline bool isEqual(float lhs, float rhs)
|
|
160
|
+
{
|
|
161
|
+
union fi {
|
|
162
|
+
float f;
|
|
163
|
+
uint32_t i;
|
|
164
|
+
} lfi, rfi;
|
|
165
|
+
lfi.f = lhs;
|
|
166
|
+
rfi.f = rhs;
|
|
167
|
+
return lfi.i == rfi.i;
|
|
168
|
+
}
|
|
169
|
+
// avoid to compare double directly
|
|
170
|
+
inline bool isEqual(double lhs, double rhs)
|
|
171
|
+
{
|
|
172
|
+
union di {
|
|
173
|
+
double d;
|
|
174
|
+
uint64_t i;
|
|
175
|
+
} ldi, rdi;
|
|
176
|
+
ldi.d = lhs;
|
|
177
|
+
rdi.d = rhs;
|
|
178
|
+
return ldi.i == rdi.i;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
} } // cybozu::test
|
|
182
|
+
|
|
183
|
+
#ifndef CYBOZU_TEST_DISABLE_AUTO_RUN
|
|
184
|
+
int main(int argc, char *argv[])
|
|
185
|
+
{
|
|
186
|
+
return cybozu::test::autoRun.run(argc, argv);
|
|
187
|
+
}
|
|
188
|
+
#endif
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
alert if !x
|
|
192
|
+
@param x [in]
|
|
193
|
+
*/
|
|
194
|
+
#define CYBOZU_TEST_ASSERT(x) cybozu::test::test(!!(x), "CYBOZU_TEST_ASSERT", #x, __FILE__, __LINE__)
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
alert if x != y
|
|
198
|
+
@param x [in]
|
|
199
|
+
@param y [in]
|
|
200
|
+
*/
|
|
201
|
+
#define CYBOZU_TEST_EQUAL(x, y) { \
|
|
202
|
+
bool _cybozu_eq = cybozu::test::isEqual(x, y); \
|
|
203
|
+
cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL", #x ", " #y, __FILE__, __LINE__); \
|
|
204
|
+
if (!_cybozu_eq) { \
|
|
205
|
+
std::cout << "ctest: lhs=" << (x) << std::endl; \
|
|
206
|
+
std::cout << "ctest: rhs=" << (y) << std::endl; \
|
|
207
|
+
} \
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
alert if fabs(x, y) >= eps
|
|
211
|
+
@param x [in]
|
|
212
|
+
@param y [in]
|
|
213
|
+
*/
|
|
214
|
+
#define CYBOZU_TEST_NEAR(x, y, eps) { \
|
|
215
|
+
bool _cybozu_isNear = fabs((x) - (y)) < eps; \
|
|
216
|
+
cybozu::test::test(_cybozu_isNear, "CYBOZU_TEST_NEAR", #x ", " #y, __FILE__, __LINE__); \
|
|
217
|
+
if (!_cybozu_isNear) { \
|
|
218
|
+
std::cout << "ctest: lhs=" << (x) << std::endl; \
|
|
219
|
+
std::cout << "ctest: rhs=" << (y) << std::endl; \
|
|
220
|
+
} \
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#define CYBOZU_TEST_EQUAL_POINTER(x, y) { \
|
|
224
|
+
bool _cybozu_eq = x == y; \
|
|
225
|
+
cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL_POINTER", #x ", " #y, __FILE__, __LINE__); \
|
|
226
|
+
if (!_cybozu_eq) { \
|
|
227
|
+
std::cout << "ctest: lhs=" << static_cast<const void*>(x) << std::endl; \
|
|
228
|
+
std::cout << "ctest: rhs=" << static_cast<const void*>(y) << std::endl; \
|
|
229
|
+
} \
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
alert if x[] != y[]
|
|
233
|
+
@param x [in]
|
|
234
|
+
@param y [in]
|
|
235
|
+
@param n [in]
|
|
236
|
+
*/
|
|
237
|
+
#define CYBOZU_TEST_EQUAL_ARRAY(x, y, n) { \
|
|
238
|
+
for (size_t _cybozu_test_i = 0, _cybozu_ie = (size_t)(n); _cybozu_test_i < _cybozu_ie; _cybozu_test_i++) { \
|
|
239
|
+
bool _cybozu_eq = cybozu::test::isEqual((x)[_cybozu_test_i], (y)[_cybozu_test_i]); \
|
|
240
|
+
cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL_ARRAY", #x ", " #y ", " #n, __FILE__, __LINE__); \
|
|
241
|
+
if (!_cybozu_eq) { \
|
|
242
|
+
std::cout << "ctest: i=" << _cybozu_test_i << std::endl; \
|
|
243
|
+
std::cout << "ctest: lhs=" << (x)[_cybozu_test_i] << std::endl; \
|
|
244
|
+
std::cout << "ctest: rhs=" << (y)[_cybozu_test_i] << std::endl; \
|
|
245
|
+
} \
|
|
246
|
+
} \
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
always alert
|
|
251
|
+
@param msg [in]
|
|
252
|
+
*/
|
|
253
|
+
#define CYBOZU_TEST_FAIL(msg) cybozu::test::test(false, "CYBOZU_TEST_FAIL", msg, __FILE__, __LINE__)
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
verify message in exception
|
|
257
|
+
*/
|
|
258
|
+
#define CYBOZU_TEST_EXCEPTION_MESSAGE(statement, Exception, msg) \
|
|
259
|
+
{ \
|
|
260
|
+
int _cybozu_ret = 0; \
|
|
261
|
+
std::string _cybozu_errMsg; \
|
|
262
|
+
try { \
|
|
263
|
+
statement; \
|
|
264
|
+
_cybozu_ret = 1; \
|
|
265
|
+
} catch (const Exception& _cybozu_e) { \
|
|
266
|
+
_cybozu_errMsg = _cybozu_e.what(); \
|
|
267
|
+
if (_cybozu_errMsg.find(msg) == std::string::npos) { \
|
|
268
|
+
_cybozu_ret = 2; \
|
|
269
|
+
} \
|
|
270
|
+
} catch (...) { \
|
|
271
|
+
_cybozu_ret = 3; \
|
|
272
|
+
} \
|
|
273
|
+
if (_cybozu_ret) { \
|
|
274
|
+
cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION_MESSAGE", #statement ", " #Exception ", " #msg, __FILE__, __LINE__); \
|
|
275
|
+
if (_cybozu_ret == 1) { \
|
|
276
|
+
std::cout << "ctest: no exception" << std::endl; \
|
|
277
|
+
} else if (_cybozu_ret == 2) { \
|
|
278
|
+
std::cout << "ctest: bad exception msg:" << _cybozu_errMsg << std::endl; \
|
|
279
|
+
} else { \
|
|
280
|
+
std::cout << "ctest: unexpected exception" << std::endl; \
|
|
281
|
+
} \
|
|
282
|
+
} else { \
|
|
283
|
+
cybozu::test::autoRun.set(true); \
|
|
284
|
+
} \
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
#define CYBOZU_TEST_EXCEPTION(statement, Exception) \
|
|
288
|
+
{ \
|
|
289
|
+
int _cybozu_ret = 0; \
|
|
290
|
+
try { \
|
|
291
|
+
statement; \
|
|
292
|
+
_cybozu_ret = 1; \
|
|
293
|
+
} catch (const Exception&) { \
|
|
294
|
+
} catch (...) { \
|
|
295
|
+
_cybozu_ret = 2; \
|
|
296
|
+
} \
|
|
297
|
+
if (_cybozu_ret) { \
|
|
298
|
+
cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION", #statement ", " #Exception, __FILE__, __LINE__); \
|
|
299
|
+
if (_cybozu_ret == 1) { \
|
|
300
|
+
std::cout << "ctest: no exception" << std::endl; \
|
|
301
|
+
} else { \
|
|
302
|
+
std::cout << "ctest: unexpected exception" << std::endl; \
|
|
303
|
+
} \
|
|
304
|
+
} else { \
|
|
305
|
+
cybozu::test::autoRun.set(true); \
|
|
306
|
+
} \
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
verify statement does not throw
|
|
311
|
+
*/
|
|
312
|
+
#define CYBOZU_TEST_NO_EXCEPTION(statement) \
|
|
313
|
+
try { \
|
|
314
|
+
statement; \
|
|
315
|
+
cybozu::test::autoRun.set(true); \
|
|
316
|
+
} catch (...) { \
|
|
317
|
+
cybozu::test::test(false, "CYBOZU_TEST_NO_EXCEPTION", #statement, __FILE__, __LINE__); \
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
append auto unit test
|
|
322
|
+
@param name [in] module name
|
|
323
|
+
*/
|
|
324
|
+
#define CYBOZU_TEST_AUTO(name) \
|
|
325
|
+
void cybozu_test_ ## name(); \
|
|
326
|
+
struct cybozu_test_local_ ## name { \
|
|
327
|
+
cybozu_test_local_ ## name() \
|
|
328
|
+
{ \
|
|
329
|
+
cybozu::test::autoRun.append(#name, cybozu_test_ ## name); \
|
|
330
|
+
} \
|
|
331
|
+
} cybozu_test_local_instance_ ## name; \
|
|
332
|
+
void cybozu_test_ ## name()
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
append auto unit test with fixture
|
|
336
|
+
@param name [in] module name
|
|
337
|
+
*/
|
|
338
|
+
#define CYBOZU_TEST_AUTO_WITH_FIXTURE(name, Fixture) \
|
|
339
|
+
void cybozu_test_ ## name(); \
|
|
340
|
+
void cybozu_test_real_ ## name() \
|
|
341
|
+
{ \
|
|
342
|
+
Fixture f; \
|
|
343
|
+
cybozu_test_ ## name(); \
|
|
344
|
+
} \
|
|
345
|
+
struct cybozu_test_local_ ## name { \
|
|
346
|
+
cybozu_test_local_ ## name() \
|
|
347
|
+
{ \
|
|
348
|
+
cybozu::test::autoRun.append(#name, cybozu_test_real_ ## name); \
|
|
349
|
+
} \
|
|
350
|
+
} cybozu_test_local_instance_ ## name; \
|
|
351
|
+
void cybozu_test_ ## name()
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
setup fixture
|
|
355
|
+
@param Fixture [in] class name of fixture
|
|
356
|
+
@note cstr of Fixture is called before test and dstr of Fixture is called after test
|
|
357
|
+
*/
|
|
358
|
+
#define CYBOZU_TEST_SETUP_FIXTURE(Fixture) \
|
|
359
|
+
Fixture *cybozu_test_local_fixture; \
|
|
360
|
+
void cybozu_test_local_init() \
|
|
361
|
+
{ \
|
|
362
|
+
cybozu_test_local_fixture = new Fixture(); \
|
|
363
|
+
} \
|
|
364
|
+
void cybozu_test_local_term() \
|
|
365
|
+
{ \
|
|
366
|
+
delete cybozu_test_local_fixture; \
|
|
367
|
+
} \
|
|
368
|
+
struct cybozu_test_local_fixture_setup_ { \
|
|
369
|
+
cybozu_test_local_fixture_setup_() \
|
|
370
|
+
{ \
|
|
371
|
+
cybozu::test::autoRun.setup(cybozu_test_local_init, cybozu_test_local_term); \
|
|
372
|
+
} \
|
|
373
|
+
} cybozu_test_local_fixture_setup_instance_;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief tiny thread class
|
|
5
|
+
|
|
6
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
7
|
+
@author MITSUNARI Shigeo
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include <cybozu/atomic.hpp>
|
|
11
|
+
#include <assert.h>
|
|
12
|
+
#ifdef _WIN32
|
|
13
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
14
|
+
#define WIN32_LEAN_AND_MEAN
|
|
15
|
+
#endif
|
|
16
|
+
#include <windows.h>
|
|
17
|
+
#include <process.h>
|
|
18
|
+
#ifdef _MSC_VER
|
|
19
|
+
#pragma warning(push)
|
|
20
|
+
#pragma warning(disable : 4127)
|
|
21
|
+
#endif
|
|
22
|
+
#else
|
|
23
|
+
#include <unistd.h>
|
|
24
|
+
#include <pthread.h>
|
|
25
|
+
#include <time.h>
|
|
26
|
+
#include <errno.h>
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
namespace cybozu {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
sleep
|
|
34
|
+
@param [in] msec time out(msec)
|
|
35
|
+
*/
|
|
36
|
+
inline void Sleep(int msec)
|
|
37
|
+
{
|
|
38
|
+
#ifdef _WIN32
|
|
39
|
+
::Sleep(msec);
|
|
40
|
+
#else
|
|
41
|
+
struct timespec req;
|
|
42
|
+
req.tv_sec = msec / 1000;
|
|
43
|
+
req.tv_nsec = (msec % 1000) * 1000000;
|
|
44
|
+
for (;;) {
|
|
45
|
+
struct timespec rem;
|
|
46
|
+
int ret = nanosleep(&req, &rem);
|
|
47
|
+
if (ret == 0) break;
|
|
48
|
+
if (errno != EINTR) {
|
|
49
|
+
printf("Sleep errno %d\n", errno);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
req = rem;
|
|
53
|
+
}
|
|
54
|
+
#endif
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
get pid
|
|
59
|
+
*/
|
|
60
|
+
inline unsigned int GetProcessId()
|
|
61
|
+
{
|
|
62
|
+
#ifdef _WIN32
|
|
63
|
+
return GetCurrentProcessId();
|
|
64
|
+
#else
|
|
65
|
+
assert(sizeof(pid_t) == 4);
|
|
66
|
+
return getpid();
|
|
67
|
+
#endif
|
|
68
|
+
}
|
|
69
|
+
/*
|
|
70
|
+
number of processor
|
|
71
|
+
@note include hyperthread
|
|
72
|
+
@return 0 if error
|
|
73
|
+
*/
|
|
74
|
+
inline int GetProcessorNum()
|
|
75
|
+
{
|
|
76
|
+
#ifdef _WIN32
|
|
77
|
+
SYSTEM_INFO systemInfo;
|
|
78
|
+
::GetSystemInfo(&systemInfo);
|
|
79
|
+
return (int)systemInfo.dwNumberOfProcessors;
|
|
80
|
+
#else
|
|
81
|
+
long ret = sysconf(_SC_NPROCESSORS_ONLN);
|
|
82
|
+
if (ret < 0) return 0;
|
|
83
|
+
return static_cast<int>(ret);
|
|
84
|
+
#endif
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
namespace thread {
|
|
88
|
+
|
|
89
|
+
#ifdef _WIN32
|
|
90
|
+
typedef HANDLE ThreadHandle;
|
|
91
|
+
const int Infinite = INFINITE;
|
|
92
|
+
typedef unsigned __stdcall ThreadEntryCallback(void*);
|
|
93
|
+
#else
|
|
94
|
+
typedef pthread_t ThreadHandle;
|
|
95
|
+
const int Infinite = 0x7fffffff;
|
|
96
|
+
typedef void* ThreadEntryCallback(void*);
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
generate thread handle
|
|
101
|
+
@param hdl [out] thread handle
|
|
102
|
+
@param entryFct [in] thread entry
|
|
103
|
+
@param arg [in] thread parameter
|
|
104
|
+
*/
|
|
105
|
+
inline bool Begin(ThreadHandle& hdl, ThreadEntryCallback entryFct, void *arg, int stackSize = 0)
|
|
106
|
+
{
|
|
107
|
+
#ifdef _WIN32
|
|
108
|
+
unsigned int threadId = 0;
|
|
109
|
+
hdl = reinterpret_cast<ThreadHandle>(_beginthreadex(0, stackSize, entryFct, arg, 0, &threadId));
|
|
110
|
+
return hdl != 0;
|
|
111
|
+
#else
|
|
112
|
+
pthread_attr_t attr;
|
|
113
|
+
if (pthread_attr_init(&attr)) {
|
|
114
|
+
perror("pthread_attr_init");
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
int ret = 0;
|
|
118
|
+
if (stackSize) {
|
|
119
|
+
ret = pthread_attr_setstacksize(&attr, stackSize);
|
|
120
|
+
if (ret) {
|
|
121
|
+
perror("pthread_attr_setstacksize");
|
|
122
|
+
goto EXIT;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
ret = pthread_create(&hdl, &attr, entryFct, arg);
|
|
126
|
+
EXIT:
|
|
127
|
+
if (pthread_attr_destroy(&attr)) {
|
|
128
|
+
perror("pthread_attr_destroy");
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return ret == 0;
|
|
132
|
+
#endif
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
inline bool Detach(ThreadHandle hdl)
|
|
136
|
+
{
|
|
137
|
+
#ifdef _WIN32
|
|
138
|
+
int ret = CloseHandle(hdl);
|
|
139
|
+
return ret != 0;
|
|
140
|
+
#else
|
|
141
|
+
int ret = pthread_detach(hdl);
|
|
142
|
+
return ret == 0;
|
|
143
|
+
#endif
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
join thread
|
|
148
|
+
@param hdl [in] thread handle
|
|
149
|
+
@param timeoutMsec [in] time out(msec)
|
|
150
|
+
*/
|
|
151
|
+
inline bool Join(ThreadHandle hdl, int timeoutMsec)
|
|
152
|
+
{
|
|
153
|
+
#ifdef _WIN32
|
|
154
|
+
bool waitRet = WaitForSingleObject(hdl, timeoutMsec) == WAIT_OBJECT_0;
|
|
155
|
+
bool closeRet = CloseHandle(hdl) != 0;
|
|
156
|
+
return waitRet && closeRet;
|
|
157
|
+
#else
|
|
158
|
+
if (timeoutMsec != Infinite) {
|
|
159
|
+
fprintf(stderr, "not support timeout\n");
|
|
160
|
+
}
|
|
161
|
+
return pthread_join(hdl, NULL) == 0;
|
|
162
|
+
#endif
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
} // cybozu::thread
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
thread generator class
|
|
169
|
+
*/
|
|
170
|
+
class ThreadBase {
|
|
171
|
+
private:
|
|
172
|
+
ThreadBase(const ThreadBase&);
|
|
173
|
+
void operator=(const ThreadBase&);
|
|
174
|
+
virtual void threadEntry() = 0;
|
|
175
|
+
protected:
|
|
176
|
+
thread::ThreadHandle threadHdl_;
|
|
177
|
+
|
|
178
|
+
/*
|
|
179
|
+
thread loop interface
|
|
180
|
+
*/
|
|
181
|
+
#ifdef _WIN32
|
|
182
|
+
static unsigned __stdcall threadLoopIF(void *arg)
|
|
183
|
+
#else
|
|
184
|
+
static void* threadLoopIF(void *arg)
|
|
185
|
+
#endif
|
|
186
|
+
{
|
|
187
|
+
ThreadBase* main = static_cast<ThreadBase*>(arg);
|
|
188
|
+
main->threadEntry();
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
public:
|
|
192
|
+
ThreadBase()
|
|
193
|
+
: threadHdl_(0)
|
|
194
|
+
{
|
|
195
|
+
}
|
|
196
|
+
virtual ~ThreadBase()
|
|
197
|
+
{
|
|
198
|
+
joinThread();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
bool beginThread(int stackSize = 0)
|
|
202
|
+
{
|
|
203
|
+
return thread::Begin(threadHdl_, threadLoopIF, this, stackSize);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
bool detachThread()
|
|
207
|
+
{
|
|
208
|
+
thread::ThreadHandle hdl = cybozu::AtomicExchange<thread::ThreadHandle>(&threadHdl_, 0);
|
|
209
|
+
if (hdl) {
|
|
210
|
+
return thread::Detach(hdl);
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
bool joinThread(int waitMsec = thread::Infinite)
|
|
216
|
+
{
|
|
217
|
+
thread::ThreadHandle hdl = cybozu::AtomicExchange<thread::ThreadHandle>(&threadHdl_, 0);
|
|
218
|
+
if (hdl) {
|
|
219
|
+
return thread::Join(hdl, waitMsec);
|
|
220
|
+
}
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
} // cybozu
|
|
226
|
+
|
|
227
|
+
#ifdef _MSC_VER
|
|
228
|
+
#pragma warning(pop)
|
|
229
|
+
#endif
|