@digitalshieldfe/react-native-backup-card-sdk 0.1.1 → 0.1.3
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.
- package/README.md +17 -25
- package/android/build.gradle +49 -4
- package/android/consumer-rules.pro +0 -0
- package/android/proguard-rules.pro +21 -0
- package/android/src/main/AndroidManifest.xml +4 -1
- package/android/src/main/java/com/ziancube/backupcardsdk/BackupCardSdk.kt +478 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/GPChannelNatives.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/listener/ApiAsyncListener.java +13 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ApiNfc.java +173 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ImplNfc.java +39 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/NfcComm.java +115 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/ApduParam.java +67 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/CommList.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/Utils.java +109 -0
- package/android/src/main/jni/CMakeLists.txt +60 -0
- package/android/src/main/jni/GPChannel/include/GPChannelSDK.h +306 -0
- package/android/src/main/jni/GPChannel/include/context/BaseContext.h +56 -0
- package/android/src/main/jni/GPChannel/include/device/ApduBuilder.hpp +72 -0
- package/android/src/main/jni/GPChannel/include/utility/Apdu.hpp +166 -0
- package/android/src/main/jni/GPChannel/include/utility/Debug.hpp +59 -0
- package/android/src/main/jni/GPChannel/include/utility/Singleton.h +34 -0
- package/android/src/main/jni/GPChannel/include/utility/mutex.h +24 -0
- package/android/src/main/jni/GPChannel/include/utility/trim.hpp +155 -0
- package/android/src/main/jni/GPChannel/include/utility/util.h +104 -0
- package/android/src/main/jni/GPChannel/include/utility/xFactory.hpp +26 -0
- package/android/src/main/jni/GPChannel/include/utility/xManager.hpp +84 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/src/implJni.cpp +313 -0
- package/android/src/main/jni/src/implJni.h +9 -0
- package/android/src/main/jni/utils/jsoncpp/AUTHORS +111 -0
- package/android/src/main/jni/utils/jsoncpp/CMakeLists.txt +159 -0
- package/android/src/main/jni/utils/jsoncpp/LICENSE +55 -0
- package/android/src/main/jni/utils/jsoncpp/README.md +135 -0
- package/android/src/main/jni/utils/jsoncpp/amalgamate.py +155 -0
- package/android/src/main/jni/utils/jsoncpp/appveyor.yml +22 -0
- package/android/src/main/jni/utils/jsoncpp/dev.makefile +35 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/__init__.py +6 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmw7.json +33 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmxp.json +26 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/antglob.py +205 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/batchbuild.py +278 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/fixeol.py +70 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/licenseupdater.py +94 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/tarball.py +52 -0
- package/android/src/main/jni/utils/jsoncpp/doxybuild.py +189 -0
- package/android/src/main/jni/utils/jsoncpp/include/CMakeLists.txt +2 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/allocator.h +98 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/assertions.h +54 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/autolink.h +25 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/config.h +187 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/features.h +61 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/forwards.h +37 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/json.h +15 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/reader.h +411 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/value.h +888 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/version.h +20 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/writer.h +357 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/jsontest.vcproj +119 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/lib_json.vcproj +205 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/test_lib_json.vcproj +130 -0
- package/android/src/main/jni/utils/jsoncpp/makerelease.py +390 -0
- package/android/src/main/jni/utils/jsoncpp/meson.build +103 -0
- package/android/src/main/jni/utils/jsoncpp/pkg-config/jsoncpp.pc.in +9 -0
- package/android/src/main/jni/utils/jsoncpp/src/CMakeLists.txt +5 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/CMakeLists.txt +25 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/main.cpp +333 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/version.h.in +20 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/CMakeLists.txt +38 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.cpp +457 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.h +286 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/main.cpp +2606 -0
- package/android/src/main/jni/utils/jsoncpp/travis.sh +23 -0
- package/android/src/main/jni/utils/jsoncpp/version +1 -0
- package/android/src/main/jni/utils/jsoncpp/version.in +1 -0
- package/android/src/main/jni/utils/logUtils.cpp +108 -0
- package/android/src/main/jni/utils/logUtils.h +87 -0
- package/android/src/main/jni/utils/mSIGNA/stdutils/uchar_vector.h +614 -0
- package/package.json +2 -3
- package/android/libs/backupcardsdk-1.0.0.aar +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// DO NOT EDIT. This file (and "version") is generated by CMake.
|
|
2
|
+
// Run CMake configure step to update it.
|
|
3
|
+
#ifndef JSON_VERSION_H_INCLUDED
|
|
4
|
+
# define JSON_VERSION_H_INCLUDED
|
|
5
|
+
|
|
6
|
+
# define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@"
|
|
7
|
+
# define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@
|
|
8
|
+
# define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@
|
|
9
|
+
# define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@
|
|
10
|
+
# define JSONCPP_VERSION_QUALIFIER
|
|
11
|
+
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
|
|
12
|
+
|
|
13
|
+
#ifdef JSONCPP_USING_SECURE_MEMORY
|
|
14
|
+
#undef JSONCPP_USING_SECURE_MEMORY
|
|
15
|
+
#endif
|
|
16
|
+
#define JSONCPP_USING_SECURE_MEMORY @JSONCPP_USE_SECURE_MEMORY@
|
|
17
|
+
// If non-zero, the library zeroes any memory that it has allocated before
|
|
18
|
+
// it frees its memory.
|
|
19
|
+
|
|
20
|
+
#endif // JSON_VERSION_H_INCLUDED
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# vim: et ts=4 sts=4 sw=4 tw=0
|
|
2
|
+
|
|
3
|
+
ADD_EXECUTABLE( jsoncpp_test
|
|
4
|
+
jsontest.cpp
|
|
5
|
+
jsontest.h
|
|
6
|
+
main.cpp
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
IF(BUILD_SHARED_LIBS)
|
|
11
|
+
ADD_DEFINITIONS( -DJSON_DLL )
|
|
12
|
+
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib)
|
|
13
|
+
ELSE(BUILD_SHARED_LIBS)
|
|
14
|
+
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static)
|
|
15
|
+
ENDIF()
|
|
16
|
+
|
|
17
|
+
# another way to solve issue #90
|
|
18
|
+
#set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store)
|
|
19
|
+
|
|
20
|
+
# Run unit tests in post-build
|
|
21
|
+
# (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
|
|
22
|
+
IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
|
|
23
|
+
IF(BUILD_SHARED_LIBS)
|
|
24
|
+
# First, copy the shared lib, for Microsoft.
|
|
25
|
+
# Then, run the test executable.
|
|
26
|
+
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
|
|
27
|
+
POST_BUILD
|
|
28
|
+
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test>
|
|
29
|
+
COMMAND $<TARGET_FILE:jsoncpp_test>)
|
|
30
|
+
ELSE(BUILD_SHARED_LIBS)
|
|
31
|
+
# Just run the test executable.
|
|
32
|
+
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
|
|
33
|
+
POST_BUILD
|
|
34
|
+
COMMAND $<TARGET_FILE:jsoncpp_test>)
|
|
35
|
+
ENDIF()
|
|
36
|
+
ENDIF()
|
|
37
|
+
|
|
38
|
+
SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
|
2
|
+
// Distributed under MIT license, or public domain if desired and
|
|
3
|
+
// recognized in your jurisdiction.
|
|
4
|
+
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
|
5
|
+
|
|
6
|
+
#define _CRT_SECURE_NO_WARNINGS 1 // Prevents deprecation warning with MSVC
|
|
7
|
+
#include "jsontest.h"
|
|
8
|
+
#include <stdio.h>
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
#if defined(_MSC_VER)
|
|
12
|
+
// Used to install a report hook that prevent dialog on assertion and error.
|
|
13
|
+
#include <crtdbg.h>
|
|
14
|
+
#endif // if defined(_MSC_VER)
|
|
15
|
+
|
|
16
|
+
#if defined(_WIN32)
|
|
17
|
+
// Used to prevent dialog on memory fault.
|
|
18
|
+
// Limits headers included by Windows.h
|
|
19
|
+
#define WIN32_LEAN_AND_MEAN
|
|
20
|
+
#define NOSERVICE
|
|
21
|
+
#define NOMCX
|
|
22
|
+
#define NOIME
|
|
23
|
+
#define NOSOUND
|
|
24
|
+
#define NOCOMM
|
|
25
|
+
#define NORPC
|
|
26
|
+
#define NOGDI
|
|
27
|
+
#define NOUSER
|
|
28
|
+
#define NODRIVERS
|
|
29
|
+
#define NOLOGERROR
|
|
30
|
+
#define NOPROFILER
|
|
31
|
+
#define NOMEMMGR
|
|
32
|
+
#define NOLFILEIO
|
|
33
|
+
#define NOOPENFILE
|
|
34
|
+
#define NORESOURCE
|
|
35
|
+
#define NOATOM
|
|
36
|
+
#define NOLANGUAGE
|
|
37
|
+
#define NOLSTRING
|
|
38
|
+
#define NODBCS
|
|
39
|
+
#define NOKEYBOARDINFO
|
|
40
|
+
#define NOGDICAPMASKS
|
|
41
|
+
#define NOCOLOR
|
|
42
|
+
#define NOGDIOBJ
|
|
43
|
+
#define NODRAWTEXT
|
|
44
|
+
#define NOTEXTMETRIC
|
|
45
|
+
#define NOSCALABLEFONT
|
|
46
|
+
#define NOBITMAP
|
|
47
|
+
#define NORASTEROPS
|
|
48
|
+
#define NOMETAFILE
|
|
49
|
+
#define NOSYSMETRICS
|
|
50
|
+
#define NOSYSTEMPARAMSINFO
|
|
51
|
+
#define NOMSG
|
|
52
|
+
#define NOWINSTYLES
|
|
53
|
+
#define NOWINOFFSETS
|
|
54
|
+
#define NOSHOWWINDOW
|
|
55
|
+
#define NODEFERWINDOWPOS
|
|
56
|
+
#define NOVIRTUALKEYCODES
|
|
57
|
+
#define NOKEYSTATES
|
|
58
|
+
#define NOWH
|
|
59
|
+
#define NOMENUS
|
|
60
|
+
#define NOSCROLL
|
|
61
|
+
#define NOCLIPBOARD
|
|
62
|
+
#define NOICONS
|
|
63
|
+
#define NOMB
|
|
64
|
+
#define NOSYSCOMMANDS
|
|
65
|
+
#define NOMDI
|
|
66
|
+
#define NOCTLMGR
|
|
67
|
+
#define NOWINMESSAGES
|
|
68
|
+
#include <windows.h>
|
|
69
|
+
#endif // if defined(_WIN32)
|
|
70
|
+
|
|
71
|
+
namespace JsonTest {
|
|
72
|
+
|
|
73
|
+
// class TestResult
|
|
74
|
+
// //////////////////////////////////////////////////////////////////
|
|
75
|
+
|
|
76
|
+
TestResult::TestResult()
|
|
77
|
+
: predicateId_(1), lastUsedPredicateId_(0), messageTarget_(0) {
|
|
78
|
+
// The root predicate has id 0
|
|
79
|
+
rootPredicateNode_.id_ = 0;
|
|
80
|
+
rootPredicateNode_.next_ = 0;
|
|
81
|
+
predicateStackTail_ = &rootPredicateNode_;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void TestResult::setTestName(const JSONCPP_STRING& name) { name_ = name; }
|
|
85
|
+
|
|
86
|
+
TestResult&
|
|
87
|
+
TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
|
|
88
|
+
/// Walks the PredicateContext stack adding them to failures_ if not already
|
|
89
|
+
/// added.
|
|
90
|
+
unsigned int nestingLevel = 0;
|
|
91
|
+
PredicateContext* lastNode = rootPredicateNode_.next_;
|
|
92
|
+
for (; lastNode != 0; lastNode = lastNode->next_) {
|
|
93
|
+
if (lastNode->id_ > lastUsedPredicateId_) // new PredicateContext
|
|
94
|
+
{
|
|
95
|
+
lastUsedPredicateId_ = lastNode->id_;
|
|
96
|
+
addFailureInfo(
|
|
97
|
+
lastNode->file_, lastNode->line_, lastNode->expr_, nestingLevel);
|
|
98
|
+
// Link the PredicateContext to the failure for message target when
|
|
99
|
+
// popping the PredicateContext.
|
|
100
|
+
lastNode->failure_ = &(failures_.back());
|
|
101
|
+
}
|
|
102
|
+
++nestingLevel;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Adds the failed assertion
|
|
106
|
+
addFailureInfo(file, line, expr, nestingLevel);
|
|
107
|
+
messageTarget_ = &(failures_.back());
|
|
108
|
+
return *this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void TestResult::addFailureInfo(const char* file,
|
|
112
|
+
unsigned int line,
|
|
113
|
+
const char* expr,
|
|
114
|
+
unsigned int nestingLevel) {
|
|
115
|
+
Failure failure;
|
|
116
|
+
failure.file_ = file;
|
|
117
|
+
failure.line_ = line;
|
|
118
|
+
if (expr) {
|
|
119
|
+
failure.expr_ = expr;
|
|
120
|
+
}
|
|
121
|
+
failure.nestingLevel_ = nestingLevel;
|
|
122
|
+
failures_.push_back(failure);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
TestResult& TestResult::popPredicateContext() {
|
|
126
|
+
PredicateContext* lastNode = &rootPredicateNode_;
|
|
127
|
+
while (lastNode->next_ != 0 && lastNode->next_->next_ != 0) {
|
|
128
|
+
lastNode = lastNode->next_;
|
|
129
|
+
}
|
|
130
|
+
// Set message target to popped failure
|
|
131
|
+
PredicateContext* tail = lastNode->next_;
|
|
132
|
+
if (tail != 0 && tail->failure_ != 0) {
|
|
133
|
+
messageTarget_ = tail->failure_;
|
|
134
|
+
}
|
|
135
|
+
// Remove tail from list
|
|
136
|
+
predicateStackTail_ = lastNode;
|
|
137
|
+
lastNode->next_ = 0;
|
|
138
|
+
return *this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
bool TestResult::failed() const { return !failures_.empty(); }
|
|
142
|
+
|
|
143
|
+
unsigned int TestResult::getAssertionNestingLevel() const {
|
|
144
|
+
unsigned int level = 0;
|
|
145
|
+
const PredicateContext* lastNode = &rootPredicateNode_;
|
|
146
|
+
while (lastNode->next_ != 0) {
|
|
147
|
+
lastNode = lastNode->next_;
|
|
148
|
+
++level;
|
|
149
|
+
}
|
|
150
|
+
return level;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void TestResult::printFailure(bool printTestName) const {
|
|
154
|
+
if (failures_.empty()) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (printTestName) {
|
|
159
|
+
printf("* Detail of %s test failure:\n", name_.c_str());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Print in reverse to display the callstack in the right order
|
|
163
|
+
Failures::const_iterator itEnd = failures_.end();
|
|
164
|
+
for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
|
|
165
|
+
const Failure& failure = *it;
|
|
166
|
+
JSONCPP_STRING indent(failure.nestingLevel_ * 2, ' ');
|
|
167
|
+
if (failure.file_) {
|
|
168
|
+
printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
|
|
169
|
+
}
|
|
170
|
+
if (!failure.expr_.empty()) {
|
|
171
|
+
printf("%s\n", failure.expr_.c_str());
|
|
172
|
+
} else if (failure.file_) {
|
|
173
|
+
printf("\n");
|
|
174
|
+
}
|
|
175
|
+
if (!failure.message_.empty()) {
|
|
176
|
+
JSONCPP_STRING reindented = indentText(failure.message_, indent + " ");
|
|
177
|
+
printf("%s\n", reindented.c_str());
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
JSONCPP_STRING TestResult::indentText(const JSONCPP_STRING& text,
|
|
183
|
+
const JSONCPP_STRING& indent) {
|
|
184
|
+
JSONCPP_STRING reindented;
|
|
185
|
+
JSONCPP_STRING::size_type lastIndex = 0;
|
|
186
|
+
while (lastIndex < text.size()) {
|
|
187
|
+
JSONCPP_STRING::size_type nextIndex = text.find('\n', lastIndex);
|
|
188
|
+
if (nextIndex == JSONCPP_STRING::npos) {
|
|
189
|
+
nextIndex = text.size() - 1;
|
|
190
|
+
}
|
|
191
|
+
reindented += indent;
|
|
192
|
+
reindented += text.substr(lastIndex, nextIndex - lastIndex + 1);
|
|
193
|
+
lastIndex = nextIndex + 1;
|
|
194
|
+
}
|
|
195
|
+
return reindented;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
TestResult& TestResult::addToLastFailure(const JSONCPP_STRING& message) {
|
|
199
|
+
if (messageTarget_ != 0) {
|
|
200
|
+
messageTarget_->message_ += message;
|
|
201
|
+
}
|
|
202
|
+
return *this;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
TestResult& TestResult::operator<<(Json::Int64 value) {
|
|
206
|
+
return addToLastFailure(Json::valueToString(value));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
TestResult& TestResult::operator<<(Json::UInt64 value) {
|
|
210
|
+
return addToLastFailure(Json::valueToString(value));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
TestResult& TestResult::operator<<(bool value) {
|
|
214
|
+
return addToLastFailure(value ? "true" : "false");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// class TestCase
|
|
218
|
+
// //////////////////////////////////////////////////////////////////
|
|
219
|
+
|
|
220
|
+
TestCase::TestCase() : result_(0) {}
|
|
221
|
+
|
|
222
|
+
TestCase::~TestCase() {}
|
|
223
|
+
|
|
224
|
+
void TestCase::run(TestResult& result) {
|
|
225
|
+
result_ = &result;
|
|
226
|
+
runTestCase();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// class Runner
|
|
230
|
+
// //////////////////////////////////////////////////////////////////
|
|
231
|
+
|
|
232
|
+
Runner::Runner() {}
|
|
233
|
+
|
|
234
|
+
Runner& Runner::add(TestCaseFactory factory) {
|
|
235
|
+
tests_.push_back(factory);
|
|
236
|
+
return *this;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
unsigned int Runner::testCount() const {
|
|
240
|
+
return static_cast<unsigned int>(tests_.size());
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
JSONCPP_STRING Runner::testNameAt(unsigned int index) const {
|
|
244
|
+
TestCase* test = tests_[index]();
|
|
245
|
+
JSONCPP_STRING name = test->testName();
|
|
246
|
+
delete test;
|
|
247
|
+
return name;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void Runner::runTestAt(unsigned int index, TestResult& result) const {
|
|
251
|
+
TestCase* test = tests_[index]();
|
|
252
|
+
result.setTestName(test->testName());
|
|
253
|
+
printf("Testing %s: ", test->testName());
|
|
254
|
+
fflush(stdout);
|
|
255
|
+
#if JSON_USE_EXCEPTION
|
|
256
|
+
try {
|
|
257
|
+
#endif // if JSON_USE_EXCEPTION
|
|
258
|
+
test->run(result);
|
|
259
|
+
#if JSON_USE_EXCEPTION
|
|
260
|
+
}
|
|
261
|
+
catch (const std::exception& e) {
|
|
262
|
+
result.addFailure(__FILE__, __LINE__, "Unexpected exception caught:")
|
|
263
|
+
<< e.what();
|
|
264
|
+
}
|
|
265
|
+
#endif // if JSON_USE_EXCEPTION
|
|
266
|
+
delete test;
|
|
267
|
+
const char* status = result.failed() ? "FAILED" : "OK";
|
|
268
|
+
printf("%s\n", status);
|
|
269
|
+
fflush(stdout);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
bool Runner::runAllTest(bool printSummary) const {
|
|
273
|
+
unsigned int count = testCount();
|
|
274
|
+
std::deque<TestResult> failures;
|
|
275
|
+
for (unsigned int index = 0; index < count; ++index) {
|
|
276
|
+
TestResult result;
|
|
277
|
+
runTestAt(index, result);
|
|
278
|
+
if (result.failed()) {
|
|
279
|
+
failures.push_back(result);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (failures.empty()) {
|
|
284
|
+
if (printSummary) {
|
|
285
|
+
printf("All %d tests passed\n", count);
|
|
286
|
+
}
|
|
287
|
+
return true;
|
|
288
|
+
} else {
|
|
289
|
+
for (unsigned int index = 0; index < failures.size(); ++index) {
|
|
290
|
+
TestResult& result = failures[index];
|
|
291
|
+
result.printFailure(count > 1);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (printSummary) {
|
|
295
|
+
unsigned int failedCount = static_cast<unsigned int>(failures.size());
|
|
296
|
+
unsigned int passedCount = count - failedCount;
|
|
297
|
+
printf("%d/%d tests passed (%d failure(s))\n",
|
|
298
|
+
passedCount,
|
|
299
|
+
count,
|
|
300
|
+
failedCount);
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
bool Runner::testIndex(const JSONCPP_STRING& testName,
|
|
307
|
+
unsigned int& indexOut) const {
|
|
308
|
+
unsigned int count = testCount();
|
|
309
|
+
for (unsigned int index = 0; index < count; ++index) {
|
|
310
|
+
if (testNameAt(index) == testName) {
|
|
311
|
+
indexOut = index;
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
void Runner::listTests() const {
|
|
319
|
+
unsigned int count = testCount();
|
|
320
|
+
for (unsigned int index = 0; index < count; ++index) {
|
|
321
|
+
printf("%s\n", testNameAt(index).c_str());
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
int Runner::runCommandLine(int argc, const char* argv[]) const {
|
|
326
|
+
// typedef std::deque<JSONCPP_STRING> TestNames;
|
|
327
|
+
Runner subrunner;
|
|
328
|
+
for (int index = 1; index < argc; ++index) {
|
|
329
|
+
JSONCPP_STRING opt = argv[index];
|
|
330
|
+
if (opt == "--list-tests") {
|
|
331
|
+
listTests();
|
|
332
|
+
return 0;
|
|
333
|
+
} else if (opt == "--test-auto") {
|
|
334
|
+
preventDialogOnCrash();
|
|
335
|
+
} else if (opt == "--test") {
|
|
336
|
+
++index;
|
|
337
|
+
if (index < argc) {
|
|
338
|
+
unsigned int testNameIndex;
|
|
339
|
+
if (testIndex(argv[index], testNameIndex)) {
|
|
340
|
+
subrunner.add(tests_[testNameIndex]);
|
|
341
|
+
} else {
|
|
342
|
+
fprintf(stderr, "Test '%s' does not exist!\n", argv[index]);
|
|
343
|
+
return 2;
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
printUsage(argv[0]);
|
|
347
|
+
return 2;
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
printUsage(argv[0]);
|
|
351
|
+
return 2;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
bool succeeded;
|
|
355
|
+
if (subrunner.testCount() > 0) {
|
|
356
|
+
succeeded = subrunner.runAllTest(subrunner.testCount() > 1);
|
|
357
|
+
} else {
|
|
358
|
+
succeeded = runAllTest(true);
|
|
359
|
+
}
|
|
360
|
+
return succeeded ? 0 : 1;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
#if defined(_MSC_VER) && defined(_DEBUG)
|
|
364
|
+
// Hook MSVCRT assertions to prevent dialog from appearing
|
|
365
|
+
static int
|
|
366
|
+
msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
|
|
367
|
+
// The default CRT handling of error and assertion is to display
|
|
368
|
+
// an error dialog to the user.
|
|
369
|
+
// Instead, when an error or an assertion occurs, we force the
|
|
370
|
+
// application to terminate using abort() after display
|
|
371
|
+
// the message on stderr.
|
|
372
|
+
if (reportType == _CRT_ERROR || reportType == _CRT_ASSERT) {
|
|
373
|
+
// calling abort() cause the ReportHook to be called
|
|
374
|
+
// The following is used to detect this case and let's the
|
|
375
|
+
// error handler fallback on its default behaviour (
|
|
376
|
+
// display a warning message)
|
|
377
|
+
static volatile bool isAborting = false;
|
|
378
|
+
if (isAborting) {
|
|
379
|
+
return TRUE;
|
|
380
|
+
}
|
|
381
|
+
isAborting = true;
|
|
382
|
+
|
|
383
|
+
fprintf(stderr, "CRT Error/Assert:\n%s\n", message);
|
|
384
|
+
fflush(stderr);
|
|
385
|
+
abort();
|
|
386
|
+
}
|
|
387
|
+
// Let's other reportType (_CRT_WARNING) be handled as they would by default
|
|
388
|
+
return FALSE;
|
|
389
|
+
}
|
|
390
|
+
#endif // if defined(_MSC_VER)
|
|
391
|
+
|
|
392
|
+
void Runner::preventDialogOnCrash() {
|
|
393
|
+
#if defined(_MSC_VER) && defined(_DEBUG)
|
|
394
|
+
// Install a hook to prevent MSVCRT error and assertion from
|
|
395
|
+
// popping a dialog
|
|
396
|
+
// This function a NO-OP in release configuration
|
|
397
|
+
// (which cause warning since msvcrtSilentReportHook is not referenced)
|
|
398
|
+
_CrtSetReportHook(&msvcrtSilentReportHook);
|
|
399
|
+
#endif // if defined(_MSC_VER)
|
|
400
|
+
|
|
401
|
+
// @todo investigate this handler (for buffer overflow)
|
|
402
|
+
// _set_security_error_handler
|
|
403
|
+
|
|
404
|
+
#if defined(_WIN32)
|
|
405
|
+
// Prevents the system from popping a dialog for debugging if the
|
|
406
|
+
// application fails due to invalid memory access.
|
|
407
|
+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
|
|
408
|
+
SEM_NOOPENFILEERRORBOX);
|
|
409
|
+
#endif // if defined(_WIN32)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
void Runner::printUsage(const char* appName) {
|
|
413
|
+
printf("Usage: %s [options]\n"
|
|
414
|
+
"\n"
|
|
415
|
+
"If --test is not specified, then all the test cases be run.\n"
|
|
416
|
+
"\n"
|
|
417
|
+
"Valid options:\n"
|
|
418
|
+
"--list-tests: print the name of all test cases on the standard\n"
|
|
419
|
+
" output and exit.\n"
|
|
420
|
+
"--test TESTNAME: executes the test case with the specified name.\n"
|
|
421
|
+
" May be repeated.\n"
|
|
422
|
+
"--test-auto: prevent dialog prompting for debugging on crash.\n",
|
|
423
|
+
appName);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Assertion functions
|
|
427
|
+
// //////////////////////////////////////////////////////////////////
|
|
428
|
+
|
|
429
|
+
JSONCPP_STRING ToJsonString(const char* toConvert) {
|
|
430
|
+
return JSONCPP_STRING(toConvert);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
JSONCPP_STRING ToJsonString(JSONCPP_STRING in) {
|
|
434
|
+
return in;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
#if JSONCPP_USING_SECURE_MEMORY
|
|
438
|
+
JSONCPP_STRING ToJsonString(std::string in) {
|
|
439
|
+
return JSONCPP_STRING(in.data(), in.data() + in.length());
|
|
440
|
+
}
|
|
441
|
+
#endif
|
|
442
|
+
|
|
443
|
+
TestResult& checkStringEqual(TestResult& result,
|
|
444
|
+
const JSONCPP_STRING& expected,
|
|
445
|
+
const JSONCPP_STRING& actual,
|
|
446
|
+
const char* file,
|
|
447
|
+
unsigned int line,
|
|
448
|
+
const char* expr) {
|
|
449
|
+
if (expected != actual) {
|
|
450
|
+
result.addFailure(file, line, expr);
|
|
451
|
+
result << "Expected: '" << expected << "'\n";
|
|
452
|
+
result << "Actual : '" << actual << "'";
|
|
453
|
+
}
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
} // namespace JsonTest
|