Skip to content

Commit 4e2929e

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#25617: refactor: univalue test cleanups
1f0c83f refactor: remove BOOST_*_TEST_ macros (fanquake) 70d807c refactor: integrate no_nul into univalue unitester (fanquake) 98a0ae6 doc: remove references to downstream (fanquake) Pull request description: Remove references to "downstream" from makefiles, as they are now redundant. Remove `BOOST_TEST` macros in favour of just using functions. Add missing call to `univalue_push_throw` tests. ACKs for top commit: MarcoFalke: ACK 1f0c83f 🍎 Tree-SHA512: e0e1ec159a82ece9b364c656b3b49d98f72a04f2614eeb2a386825c3e37bb5a10416446a8ea22d9048227d96aca3e5c1a3dbf3264a290443add382ded073575c
2 parents 82ab22a + 1f0c83f commit 4e2929e

File tree

8 files changed

+20
-39
lines changed

8 files changed

+20
-39
lines changed

ci/test/wrap-qemu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
export LC_ALL=C.UTF-8
88

9-
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{no_nul,test_json,unitester,object}}; do
9+
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{test_json,unitester,object}}; do
1010
# shellcheck disable=SC2044
1111
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do
1212
echo "Wrap $b ..."

ci/test/wrap-wine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
export LC_ALL=C.UTF-8
88

9-
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{no_nul,test_json,unitester,object}}.exe; do
9+
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{test_json,unitester,object}}.exe; do
1010
# shellcheck disable=SC2044
1111
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do
1212
if (file "$b" | grep "Windows"); then

src/Makefile.test.include

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ endif
373373
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
374374

375375
if ENABLE_TESTS
376-
UNIVALUE_TESTS = univalue/test/object univalue/test/unitester univalue/test/no_nul
376+
UNIVALUE_TESTS = univalue/test/object univalue/test/unitester
377377
noinst_PROGRAMS += $(UNIVALUE_TESTS)
378378
TESTS += $(UNIVALUE_TESTS)
379379

@@ -382,11 +382,6 @@ univalue_test_unitester_LDADD = $(LIBUNIVALUE)
382382
univalue_test_unitester_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) -DJSON_TEST_SRC=\"$(srcdir)/$(UNIVALUE_TEST_DATA_DIR_INT)\"
383383
univalue_test_unitester_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
384384

385-
univalue_test_no_nul_SOURCES = $(UNIVALUE_TEST_NO_NUL_INT)
386-
univalue_test_no_nul_LDADD = $(LIBUNIVALUE)
387-
univalue_test_no_nul_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
388-
univalue_test_no_nul_LDFLAGS = -static $(LIBTOOL_APP_LDFLAGS)
389-
390385
univalue_test_object_SOURCES = $(UNIVALUE_TEST_OBJECT_INT)
391386
univalue_test_object_LDADD = $(LIBUNIVALUE)
392387
univalue_test_object_CPPFLAGS = -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)

src/univalue/sources.mk

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# - All variables are namespaced with UNIVALUE_ to avoid colliding with
2-
# downstream makefiles.
31
# - All Variables ending in _HEADERS or _SOURCES confuse automake, so the
42
# _INT postfix is applied.
53
# - Convenience variables, for example a UNIVALUE_TEST_DIR should not be used
64
# as they interfere with automatic dependency generation
7-
# - The %reldir% is the relative path from the Makefile.am. This allows
8-
# downstreams to use these variables without having to manually account for
9-
# the path change.
5+
# - The %reldir% is the relative path from the Makefile.am.
106

117
UNIVALUE_INCLUDE_DIR_INT = %reldir%/include
128

@@ -29,9 +25,6 @@ UNIVALUE_TEST_UNITESTER_INT += %reldir%/test/unitester.cpp
2925
UNIVALUE_TEST_JSON_INT =
3026
UNIVALUE_TEST_JSON_INT += %reldir%/test/test_json.cpp
3127

32-
UNIVALUE_TEST_NO_NUL_INT =
33-
UNIVALUE_TEST_NO_NUL_INT += %reldir%/test/no_nul.cpp
34-
3528
UNIVALUE_TEST_OBJECT_INT =
3629
UNIVALUE_TEST_OBJECT_INT += %reldir%/test/object.cpp
3730

src/univalue/test/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
object
33
unitester
44
test_json
5-
no_nul
65

76
*.trs
87
*.log

src/univalue/test/no_nul.cpp

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/univalue/test/object.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
#include <string>
1414
#include <vector>
1515

16-
#define BOOST_FIXTURE_TEST_SUITE(a, b)
17-
#define BOOST_AUTO_TEST_CASE(funcName) void funcName()
18-
#define BOOST_AUTO_TEST_SUITE_END()
1916
#define BOOST_CHECK(expr) assert(expr)
2017
#define BOOST_CHECK_EQUAL(v1, v2) assert((v1) == (v2))
2118
#define BOOST_CHECK_THROW(stmt, excMatch) { \
@@ -35,9 +32,7 @@
3532
} \
3633
}
3734

38-
BOOST_FIXTURE_TEST_SUITE(univalue_tests, BasicTestingSetup)
39-
40-
BOOST_AUTO_TEST_CASE(univalue_constructor)
35+
void univalue_constructor()
4136
{
4237
UniValue v1;
4338
BOOST_CHECK(v1.isNull());
@@ -85,7 +80,7 @@ BOOST_AUTO_TEST_CASE(univalue_constructor)
8580
BOOST_CHECK_EQUAL(v9.getValStr(), "zappa");
8681
}
8782

88-
BOOST_AUTO_TEST_CASE(univalue_push_throw)
83+
void univalue_push_throw()
8984
{
9085
UniValue j;
9186
BOOST_CHECK_THROW(j.push_back(1), std::runtime_error);
@@ -95,7 +90,7 @@ BOOST_AUTO_TEST_CASE(univalue_push_throw)
9590
BOOST_CHECK_THROW(j.pushKVs({}), std::runtime_error);
9691
}
9792

98-
BOOST_AUTO_TEST_CASE(univalue_typecheck)
93+
void univalue_typecheck()
9994
{
10095
UniValue v1;
10196
BOOST_CHECK(v1.setNumStr("1"));
@@ -144,7 +139,7 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
144139
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
145140
}
146141

147-
BOOST_AUTO_TEST_CASE(univalue_set)
142+
void univalue_set()
148143
{
149144
UniValue v(UniValue::VSTR, "foo");
150145
v.clear();
@@ -203,7 +198,7 @@ BOOST_AUTO_TEST_CASE(univalue_set)
203198
BOOST_CHECK(v.isNull());
204199
}
205200

206-
BOOST_AUTO_TEST_CASE(univalue_array)
201+
void univalue_array()
207202
{
208203
UniValue arr(UniValue::VARR);
209204

@@ -262,7 +257,7 @@ BOOST_AUTO_TEST_CASE(univalue_array)
262257
BOOST_CHECK_EQUAL(arr.size(), 0);
263258
}
264259

265-
BOOST_AUTO_TEST_CASE(univalue_object)
260+
void univalue_object()
266261
{
267262
UniValue obj(UniValue::VOBJ);
268263
std::string strKey, strVal;
@@ -381,7 +376,7 @@ BOOST_AUTO_TEST_CASE(univalue_object)
381376
static const char *json1 =
382377
"[1.10000000,{\"key1\":\"str\\u0000\",\"key2\":800,\"key3\":{\"name\":\"martian http://test.com\"}}]";
383378

384-
BOOST_AUTO_TEST_CASE(univalue_readwrite)
379+
void univalue_readwrite()
385380
{
386381
UniValue v;
387382
BOOST_CHECK(v.read(json1));
@@ -424,11 +419,10 @@ BOOST_AUTO_TEST_CASE(univalue_readwrite)
424419
BOOST_CHECK(!v.read("{} 42"));
425420
}
426421

427-
BOOST_AUTO_TEST_SUITE_END()
428-
429422
int main (int argc, char *argv[])
430423
{
431424
univalue_constructor();
425+
univalue_push_throw();
432426
univalue_typecheck();
433427
univalue_set();
434428
univalue_array();

src/univalue/test/unitester.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,21 @@ void unescape_unicode_test()
149149
assert(val[0].get_str() == "\xf0\x9d\x85\xa1");
150150
}
151151

152+
void no_nul_test()
153+
{
154+
char buf[] = "___[1,2,3]___";
155+
UniValue val;
156+
assert(val.read(buf + 3, 7));
157+
}
158+
152159
int main (int argc, char *argv[])
153160
{
154161
for (const auto& f: filenames) {
155162
runtest_file(f);
156163
}
157164

158165
unescape_unicode_test();
166+
no_nul_test();
159167

160168
return 0;
161169
}

0 commit comments

Comments
 (0)