Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ src/tscore/ParseRulesCType
src/tscore/ParseRulesCTypeToLower
src/tscore/ParseRulesCTypeToUpper
src/tscore/mkdfa
src/tscore/test_List
src/tscore/test_arena
src/tscore/test_atomic
src/tscore/test_freelist
src/tscore/test_Map
src/tscore/test_Vec
src/tscore/test_geometry
src/tscore/test_Regex
src/tscore/test_X509HostnameValidator
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1065,14 +1065,9 @@ add_library(libtscore SHARED
include/tscore/SimpleTokenizer.h
src/tscore/SourceLocation.cc
include/tscore/SourceLocation.h
src/tscore/test_arena.cc
src/tscore/test_atomic.cc
src/tscore/test_freelist.cc
src/tscore/test_geometry.cc
src/tscore/test_List.cc
src/tscore/test_Map.cc
src/tscore/test_Vec.cc
src/tscore/test_X509HostnameValidator.cc
include/tscore/TestBox.h
src/tscore/TestHttpHeader.cc
src/tscore/tests.cc
Expand All @@ -1090,6 +1085,7 @@ add_library(libtscore SHARED

add_executable(test_tscore
src/tscore/unit_tests/unit_test_main.cc
src/tscore/unit_tests/test_arena.cc
src/tscore/unit_tests/test_BufferWriter.cc
src/tscore/unit_tests/test_BufferWriterFormat.cc
src/tscore/unit_tests/test_History.cc
Expand All @@ -1099,6 +1095,8 @@ add_executable(test_tscore
src/tscore/unit_tests/test_IntrusivePtr.cc
src/tscore/unit_tests/test_IpMap.cc
src/tscore/unit_tests/test_layout.cc
src/tscore/unit_tests/test_List.cc
src/tscore/unit_tests/test_Map.cc
src/tscore/unit_tests/test_MemArena.cc
src/tscore/unit_tests/test_MemSpan.cc
src/tscore/unit_tests/test_MT_hashtable.cc
Expand All @@ -1107,6 +1105,8 @@ add_executable(test_tscore
src/tscore/unit_tests/test_Regex.cc
src/tscore/unit_tests/test_Scalar.cc
src/tscore/unit_tests/test_scoped_resource.cc
src/tscore/unit_tests/test_Vec.cc
src/tscore/unit_tests/test_X509HostnameValidator.cc
)

# iocore/cache
Expand Down
21 changes: 8 additions & 13 deletions src/tscore/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
include $(top_srcdir)/build/tidy.mk

noinst_PROGRAMS = mkdfa CompileParseRules
check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_List test_Map test_Vec test_X509HostnameValidator test_tscore
check_PROGRAMS = test_atomic test_freelist test_geometry test_X509HostnameValidator test_tscore

TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt

Expand Down Expand Up @@ -234,21 +234,12 @@ test_atomic_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
test_freelist_SOURCES = test_freelist.cc
test_freelist_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_arena_SOURCES = test_arena.cc
test_arena_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_List_SOURCES = test_List.cc
test_Map_SOURCES = test_Map.cc
test_Map_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_Vec_SOURCES = test_Vec.cc
test_Vec_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_geometry_SOURCES = test_geometry.cc
test_geometry_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@

test_X509HostnameValidator_SOURCES = test_X509HostnameValidator.cc
test_X509HostnameValidator_CPPFLAGS = $(AM_CPPFLAGS) -I$(abs_top_srcdir)/tests/include
test_X509HostnameValidator_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@ @OPENSSL_LIBS@
test_X509HostnameValidator_SOURCES = unit_tests/test_X509HostnameValidator.cc

test_tscore_CPPFLAGS = $(AM_CPPFLAGS)\
-I$(abs_top_srcdir)/tests/include
Expand All @@ -258,6 +249,7 @@ test_tscore_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la
test_tscore_SOURCES = \
unit_tests/unit_test_main.cc \
unit_tests/test_AcidPtr.cc \
unit_tests/test_arena.cc \
unit_tests/test_BufferWriter.cc \
unit_tests/test_BufferWriterFormat.cc \
unit_tests/test_Extendible.cc \
Expand All @@ -268,14 +260,17 @@ test_tscore_SOURCES = \
unit_tests/test_IntrusivePtr.cc \
unit_tests/test_IpMap.cc \
unit_tests/test_layout.cc \
unit_tests/test_List.cc \
unit_tests/test_Map.cc \
unit_tests/test_MemSpan.cc \
unit_tests/test_MemArena.cc \
unit_tests/test_MT_hashtable.cc \
unit_tests/test_PriorityQueue.cc \
unit_tests/test_Ptr.cc \
unit_tests/test_Regex.cc \
unit_tests/test_Scalar.cc \
unit_tests/test_scoped_resource.cc
unit_tests/test_scoped_resource.cc \
unit_tests/test_Vec.cc

CompileParseRules_SOURCES = CompileParseRules.cc

Expand Down
13 changes: 4 additions & 9 deletions src/tscore/test_List.cc → src/tscore/unit_tests/test_List.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
limitations under the License.
*/

#include "catch.hpp"

#include "tscore/List.h"

class Foo
Expand All @@ -39,8 +41,7 @@ class Foo
Foo(int i = 0) : x(i) {}
};

int
main()
TEST_CASE("test list", "[List]")
{
SList(Foo, slink) s;
DList(Foo, dlink) d;
Expand All @@ -59,11 +60,5 @@ main()
tot += foo->x;
delete foo;
}
if (tot != 4957) {
printf("test_List FAILED\n");
exit(1);
} else {
printf("test_List PASSED\n");
exit(0);
}
REQUIRE(tot == 4957);
}
148 changes: 72 additions & 76 deletions src/tscore/test_Map.cc → src/tscore/unit_tests/test_Map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "catch.hpp"

#include <cstdint>
#include "tscore/Map.h"
#include <list>
Expand Down Expand Up @@ -63,67 +66,6 @@ Item::Hash::equal(Key lhs, Key rhs)

using Table = TSHashTable<Item::Hash>;

void
test_TSHashTable()
{
static uint32_t const N = 270;
Table t;
Item *item = nullptr;
Table::Location loc;
std::list<Item *> to_delete;

for (uint32_t i = 1; i <= N; ++i) {
item = new Item(i);
t.insert(item);
to_delete.push_back(item);
}

for (uint32_t i = 1; i <= N; ++i) {
Table::Location l = t.find(i);
ink_assert(l.isValid());
ink_assert(i == l->_value);
}

ink_assert(!(t.find(N * 2).isValid()));

loc = t.find(N / 2 | 1);
if (loc) {
t.remove(loc);
} else {
ink_assert(!"Did not find expected value");
}

if (!loc) {
; // compiler check.
}

ink_assert(!(t.find(N / 2 | 1).isValid()));

for (uint32_t i = 1; i <= N; i += 2) {
t.remove(i);
}

for (uint32_t i = 1; i <= N; ++i) {
Table::Location l = t.find(i);
if (1 & i) {
ink_assert(!l.isValid());
} else {
ink_assert(l.isValid());
}
}

int n = 0;
for (Table::iterator spot = t.begin(), limit = t.end(); spot != limit; ++spot) {
++n;
ink_assert((spot->_value & 1) == 0);
}
ink_assert(n == N / 2);

for (auto it : to_delete) {
delete it;
}
}

class testHashMap
{
private:
Expand All @@ -143,8 +85,7 @@ class testHashMap
}
};

int
main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
TEST_CASE("test Map", "[Map]")
{
typedef Map<cchar *, cchar *> SSMap;
typedef MapElem<cchar *, cchar *> SSMapElem;
Expand Down Expand Up @@ -177,30 +118,85 @@ main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
sh.put(ho, 2);
sh.put(hum, 3);
sh.put(hhi, 4);
ink_assert(sh.get(hi) == 4);
ink_assert(sh.get(ho) == 2);
ink_assert(sh.get(hum) == 3);
REQUIRE(sh.get(hi) == 4);
REQUIRE(sh.get(ho) == 2);
REQUIRE(sh.get(hum) == 3);
sh.put("aa", 5);
sh.put("ab", 6);
sh.put("ac", 7);
sh.put("ad", 8);
sh.put("ae", 9);
sh.put("af", 10);
ink_assert(sh.get(hi) == 4);
ink_assert(sh.get(ho) == 2);
ink_assert(sh.get(hum) == 3);
ink_assert(sh.get("af") == 10);
ink_assert(sh.get("ac") == 7);
REQUIRE(sh.get(hi) == 4);
REQUIRE(sh.get(ho) == 2);
REQUIRE(sh.get(hum) == 3);
REQUIRE(sh.get("af") == 10);
REQUIRE(sh.get("ac") == 7);

HashMap<cchar *, StringHashFns, int> sh2(-99); // return -99 if key not found
sh2.put("aa", 15);
sh2.put("ab", 16);
testsh.put("aa", 15);
testsh.put("ab", 16);
ink_assert(sh2.get("aa") == 15);
ink_assert(sh2.get("ac") == -99);
ink_assert(testsh.get("aa") == 15);
test_TSHashTable();
REQUIRE(sh2.get("aa") == 15);
REQUIRE(sh2.get("ac") == -99);
REQUIRE(testsh.get("aa") == 15);

// test_TSHashTable
static uint32_t const N = 270;
Table t;
Item *item = nullptr;
Table::Location loc;
std::list<Item *> to_delete;

for (uint32_t i = 1; i <= N; ++i) {
item = new Item(i);
t.insert(item);
to_delete.push_back(item);
}

for (uint32_t i = 1; i <= N; ++i) {
Table::Location l = t.find(i);
REQUIRE(l.isValid());
REQUIRE(i == l->_value);
}

REQUIRE(!(t.find(N * 2).isValid()));

loc = t.find(N / 2 | 1);
if (loc) {
t.remove(loc);
} else {
REQUIRE(!"Did not find expected value");
}

printf("test_Map PASSED\n");
if (!loc) {
; // compiler check.
}

REQUIRE(!(t.find(N / 2 | 1).isValid()));

for (uint32_t i = 1; i <= N; i += 2) {
t.remove(i);
}

for (uint32_t i = 1; i <= N; ++i) {
Table::Location l = t.find(i);
if (1 & i) {
REQUIRE(!l.isValid());
} else {
REQUIRE(l.isValid());
}
}

int n = 0;
for (Table::iterator spot = t.begin(), limit = t.end(); spot != limit; ++spot) {
++n;
REQUIRE((spot->_value & 1) == 0);
}
REQUIRE(n == N / 2);

for (auto it : to_delete) {
delete it;
}
}
Loading