From 563ba7a3f0c6592edaeaf34e76e2e9b96de5c7ca Mon Sep 17 00:00:00 2001 From: Binbin Date: Sun, 8 Aug 2021 14:03:52 +0800 Subject: Fix the wrong method used in quicklistTest. (#8951) The test try to test `insert before 1 element`, but it use quicklist InsertAfter, a copy-paste typo. The commit also add an assert to verify results in some tests to make sure it is as expected. --- src/quicklist.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/quicklist.c') diff --git a/src/quicklist.c b/src/quicklist.c index 4874ecc05..5666aab22 100644 --- a/src/quicklist.c +++ b/src/quicklist.c @@ -1976,6 +1976,13 @@ int quicklistTest(int argc, char *argv[], int accurate) { quicklistIndex(ql, 0, &entry); quicklistInsertBefore(ql, &entry, "abc", 4); ql_verify(ql, 1, 1, 1, 1); + + /* verify results */ + quicklistIndex(ql, 0, &entry); + if (strncmp((char *)entry.value, "abc", 3)) { + ERR("Value 0 didn't match, instead got: %.*s", entry.sz, + entry.value); + } quicklistRelease(ql); } @@ -1985,6 +1992,13 @@ int quicklistTest(int argc, char *argv[], int accurate) { quicklistIndex(ql, 0, &entry); quicklistInsertAfter(ql, &entry, "abc", 4); ql_verify(ql, 1, 1, 1, 1); + + /* verify results */ + quicklistIndex(ql, 0, &entry); + if (strncmp((char *)entry.value, "abc", 3)) { + ERR("Value 0 didn't match, instead got: %.*s", entry.sz, + entry.value); + } quicklistRelease(ql); } @@ -1995,6 +2009,19 @@ int quicklistTest(int argc, char *argv[], int accurate) { quicklistIndex(ql, 0, &entry); quicklistInsertAfter(ql, &entry, "abc", 4); ql_verify(ql, 1, 2, 2, 2); + + /* verify results */ + quicklistIndex(ql, 0, &entry); + if (strncmp((char *)entry.value, "hello", 5)) { + ERR("Value 0 didn't match, instead got: %.*s", entry.sz, + entry.value); + } + quicklistIndex(ql, 1, &entry); + if (strncmp((char *)entry.value, "abc", 3)) { + ERR("Value 1 didn't match, instead got: %.*s", entry.sz, + entry.value); + } + quicklistRelease(ql); } @@ -2003,8 +2030,21 @@ int quicklistTest(int argc, char *argv[], int accurate) { quicklistPushHead(ql, "hello", 6); quicklistEntry entry; quicklistIndex(ql, 0, &entry); - quicklistInsertAfter(ql, &entry, "abc", 4); + quicklistInsertBefore(ql, &entry, "abc", 4); ql_verify(ql, 1, 2, 2, 2); + + /* verify results */ + quicklistIndex(ql, 0, &entry); + if (strncmp((char *)entry.value, "abc", 3)) { + ERR("Value 0 didn't match, instead got: %.*s", entry.sz, + entry.value); + } + quicklistIndex(ql, 1, &entry); + if (strncmp((char *)entry.value, "hello", 5)) { + ERR("Value 1 didn't match, instead got: %.*s", entry.sz, + entry.value); + } + quicklistRelease(ql); } -- cgit v1.2.1