summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2019-04-16 15:44:59 +0200
committerGitHub <noreply@github.com>2019-04-16 15:44:59 +0200
commit57c27980452cf36e0d320b490dace35f679e389e (patch)
tree3461e1eaa07c8e765e3ef0cb9b5fdcb9c5412712
parent6035f5c9a30dc9b53c7ae6d253c18ecbf45beb99 (diff)
parentdd999c18a6eeb6c2cc70a4257d27e68f592a876b (diff)
Merge pull request #9141 from vespa-engine/toregge/migrate-document-unit-tests-from-cppunit-to-gtest-3
Migrate document unit tests from cppunit to gtest.
-rw-r--r--document/CMakeLists.txt4
-rw-r--r--document/src/tests/CMakeLists.txt18
-rw-r--r--document/src/tests/heapdebugger.h60
-rw-r--r--document/src/tests/heapdebuggerlinux.cpp701
-rw-r--r--document/src/tests/heapdebuggerother.cpp37
-rw-r--r--document/src/tests/testbytebuffer.cpp329
-rw-r--r--document/src/tests/testbytebuffer.h73
-rw-r--r--document/src/tests/testrunner.cpp14
8 files changed, 150 insertions, 1086 deletions
diff --git a/document/CMakeLists.txt b/document/CMakeLists.txt
index 7de1b0c0b89..574ac98f845 100644
--- a/document/CMakeLists.txt
+++ b/document/CMakeLists.txt
@@ -25,10 +25,6 @@ vespa_define_module(
src/vespa/document/util
src/vespa/document/test
- TEST_DEPENDS
- vdstestlib
- cppunit
-
TESTS
src/tests
src/tests/annotation
diff --git a/document/src/tests/CMakeLists.txt b/document/src/tests/CMakeLists.txt
index cd0208da5f3..1421297b284 100644
--- a/document/src/tests/CMakeLists.txt
+++ b/document/src/tests/CMakeLists.txt
@@ -25,6 +25,7 @@ vespa_add_executable(document_gtest_runner_app TEST
primitivefieldvaluetest.cpp
stringtokenizertest.cpp
structfieldvaluetest.cpp
+ testbytebuffer.cpp
testdocmantest.cpp
teststringutil.cpp
testxml.cpp
@@ -41,20 +42,3 @@ vespa_add_test(
NAME document_gtest_runner_app
COMMAND document_gtest_runner_app
)
-
-# Runner for unit tests written in CppUnit (DEPRECATED).
-vespa_add_executable(document_testrunner_app TEST
- SOURCES
- testbytebuffer.cpp
- testrunner.cpp
- heapdebuggerother.cpp
- DEPENDS
- document
- AFTER
- document_documentconfig
-)
-
-vespa_add_test(
- NAME document_testrunner_app
- COMMAND document_testrunner_app
-)
diff --git a/document/src/tests/heapdebugger.h b/document/src/tests/heapdebugger.h
deleted file mode 100644
index 1706b99a0a9..00000000000
--- a/document/src/tests/heapdebugger.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * Author: Ove Martin Malm
- */
-
-#pragma once
-#include <cstddef>
-
-
-/**
- * This function is used for counting memory usage. Must be called before any block is allocated
- * (pt. linux only)
- * Parameter controls operation
- */
-extern void enableHeapUsageMonitor(int param = 0);
-
-
-/**
- * This function return the current memory used.
- * @return Net number of bytes allocated on the heap
- */
-extern size_t getHeapUsage(void);
-
-/**
- * This enables heap debugging. Must be called before any block is allocated
- * Parameter controls operation
- * (pt. linux only)
- */
-extern void enableHeapCorruptCheck(int param = 0);
-
-#define HEAPCHECKMODE_REMOVE -1 // Deinstall
-#define HEAPCHECKMODE_NORMAL 0 // Normal
-#define HEAPCHECKMODE_EXTENSIVE 1 // All allocated blocks checked on all ops..
-#define HEAPCHECKMODE_DISABLED 2 // No checking (but extra bytes allocated)
-
-
-
-/**
- * Run a heap check now. Will lock the heap and run through a full check. Will crash if it fails...
- */
-extern void checkHeapNow(void);
-
-
-/**
- * And this enables linux mcheck function with an approprate callback function. (absolutely linux only)
- * see man mcheck
- */
-extern void enableMCheck(void);
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/document/src/tests/heapdebuggerlinux.cpp b/document/src/tests/heapdebuggerlinux.cpp
deleted file mode 100644
index fa3a8e3d64b..00000000000
--- a/document/src/tests/heapdebuggerlinux.cpp
+++ /dev/null
@@ -1,701 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * Author: Ove Martin Malm
- */
-
-
-// These are necessary to make it compile....
-#define _MALLOC_INTERNAL
-#define MALLOC_HOOKS
-#include <stdio.h>
-#define _LIBC
-#include <malloc.h>
-#include <mcheck.h>
-#include <stdint.h>
-#include <libintl.h>
-
-#include <iostream>
-#include <pthread.h>
-#include <csignal>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "heapdebugger.h"
-
-// Predeclaration
-static void HeapCorrupt(const char * caller, const struct elemheader *hdr, enum mcheck_status err);
-
-// -------------------------------
-// Part #1 Memory usage
-
-
-#ifndef INTERNAL_SIZE_T
-#define INTERNAL_SIZE_T size_t
-#endif
-
-#define SIZE_SZ (sizeof(INTERNAL_SIZE_T))
-
-/* size field is or'ed with PREV_INUSE when previous adjacent chunk in use */
-
-#define PREV_INUSE 0x1
-
-/* size field is or'ed with IS_MMAPPED if the chunk was obtained with mmap() */
-
-#define IS_MMAPPED 0x2
-
-/* Bits to mask off when extracting size */
-
-#define SIZE_BITS (PREV_INUSE|IS_MMAPPED)
-
-struct malloc_chunk
-{
- INTERNAL_SIZE_T prev_size; /* Size of previous chunk (if free). */
- INTERNAL_SIZE_T size; /* Size in bytes, including overhead. */
- struct malloc_chunk* fd; /* double links -- used only if free. */
- struct malloc_chunk* bk;
-};
-
-typedef struct malloc_chunk* mchunkptr;
-
-/* conversion from malloc headers to user pointers, and back */
-
-#define chunk2mem(p) ((Void_t*)((char*)(p) + 2*SIZE_SZ))
-#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - 2*SIZE_SZ))
-
-/* Get size, ignoring use bits */
-
-#define chunkSize(p) ((p)->size & ~(SIZE_BITS))
-
-
-static void (*old_free_hook_memusage)(void* buf, const void * caller );
-static void* (*old_malloc_hook_memusage)(size_t bytes, const void * caller);
-static void* (*old_realloc_hook_memusage)(void *buf, size_t bytes, const void *caller);
-static void* (*old_memalign_hook_memusage)(size_t alignment, size_t bytes,const void *caller);
-static size_t MemoryUsage = 0;
-static pthread_mutex_t memUsageMutex = PTHREAD_MUTEX_INITIALIZER;
-static bool MemUsageHookInstalled = false;
-
-
-static void me_use_free_hook(void *ptr, const void *caller)
-{
- mchunkptr p;
-
- pthread_mutex_lock(&memUsageMutex);
-
- if (ptr) {
- p = mem2chunk(ptr);
- MemoryUsage -= chunkSize(p);
- }
-
- __free_hook = old_free_hook_memusage;
-
- if (old_free_hook_memusage != NULL) {
- (*old_free_hook_memusage) (ptr, caller);
- } else {
- free (ptr);
- }
-
- __free_hook = me_use_free_hook;
-
- pthread_mutex_unlock(&memUsageMutex);
-}
-
-static void* me_use_malloc_hook(size_t size, const void *caller)
-{
- void *anew;
- mchunkptr p;
-
- pthread_mutex_lock(&memUsageMutex);
-
- __malloc_hook = old_malloc_hook_memusage;
-
- if (old_malloc_hook_memusage != NULL) {
- anew = (*old_malloc_hook_memusage) (size, caller);
- } else {
- anew = malloc (size);
- }
-
- if (anew) {
- p = mem2chunk(anew);
- MemoryUsage += chunkSize(p);
- }
-
- __malloc_hook = me_use_malloc_hook;
- pthread_mutex_unlock(&memUsageMutex);
-
- return(anew);
-}
-
-static void* me_use_realloc_hook(void *ptr, size_t size, const void* caller)
-{
- void *anew;
- mchunkptr p;
- size_t oldsz = 0;
- size_t newsz = 0;
-
- pthread_mutex_lock(&memUsageMutex);
-
- if (ptr) {
- p = mem2chunk(ptr);
- oldsz = chunkSize(p);
- }
-
- __free_hook = old_free_hook_memusage;
- __malloc_hook = old_malloc_hook_memusage;
- __realloc_hook = old_realloc_hook_memusage;
-
- if (old_realloc_hook_memusage != NULL) {
- anew = (*old_realloc_hook_memusage) (ptr, size, caller);
- } else {
- anew = realloc (ptr, size);
- }
-
- if (anew) {
- p = mem2chunk(anew);
- newsz = chunkSize(p);
-
- MemoryUsage += (newsz - oldsz);
- }
-
- __free_hook = me_use_free_hook;
- __malloc_hook = me_use_malloc_hook;
- __realloc_hook = me_use_realloc_hook;
-
- pthread_mutex_unlock(&memUsageMutex);
-
- return anew;
-}
-
-static void* me_use_memalign_hook(size_t alignment, size_t bytes,const void *caller)
-{
-
- void *aligned;
-
- std::cout << "memalign" << std::endl;
- __memalign_hook = old_memalign_hook_memusage;
-
- if (old_memalign_hook_memusage != NULL) {
- aligned = (*old_memalign_hook_memusage) (alignment, bytes,caller);
- } else {
- aligned = memalign (alignment, bytes);
- }
-
- __memalign_hook = me_use_memalign_hook;
-
- return aligned;
-}
-
-
-void enableHeapUsageMonitor(int param)
-{
- (void)param;
- if (!MemUsageHookInstalled) {
- old_free_hook_memusage = __free_hook;
- __free_hook = me_use_free_hook;
- old_malloc_hook_memusage = __malloc_hook;
- __malloc_hook = me_use_malloc_hook;
- old_realloc_hook_memusage = __realloc_hook;
- __realloc_hook = me_use_realloc_hook;
- MemUsageHookInstalled = true;
- std::cout << "Memory usage will be counted" << std::endl;
- }
-}
-
-size_t getHeapUsage(void)
-{
- return(MemoryUsage);
-}
-
-
-// + Get status message....
-
-
-
-
-// -------------------
-// Part 2: Heap corrupt
-
-static void (*old_free_hook_memcorrupt)(void*, const void *);
-static void* (*old_malloc_hook_memcorrupt)(size_t, const void *);
-static void* (*old_realloc_hook_memcorrupt)(void*, size_t, const void *);
-static void* (*old_memalign_hook_memcorrupt)(size_t alignment, size_t bytes,const void *caller);
-
-static pthread_mutex_t HeapCorruptCheckMutex = PTHREAD_MUTEX_INITIALIZER;
-
-static int HeapCorruptCheckMode = HEAPCHECKMODE_REMOVE;
-static bool PrintUsage = false;
-
-
-/* Arbitrary magical numbers. */
-#define MAGICWORD 0xfedabeeb
-#define MAGICFREE 0xf1eef1ee
-#define MAGICBYTE ((char) 0x01) // "End byte"
-#define MALLOCFLOOD ((char) 0x02) // "Fresh (unused) memory"
-#define FREEFLOOD ((char) 0x03) // "Dead" memory
-
-struct elemheader {
- __malloc_size_t size; /* Exact size requested by user. */
- unsigned long int magic; /* Magic number to check header integrity. */
- struct elemheader *prev;
- struct elemheader *next;
-};
-
-/* This is the beginning of the list of all memory blocks allocated.
- It is only constructed if the pedantic testing is requested. */
-
-static struct elemheader *root;
-
-static enum mcheck_status me_corrupt_mprobe (const struct elemheader * block)
-{
- enum mcheck_status status;
- switch (block->magic ^ ((uintptr_t) block->prev + (uintptr_t) block->next)) {
- case MAGICFREE:
- status = MCHECK_FREE;
- break;
- case MAGICWORD:
- {
- const char *elem = (const char *)block;
- status = (elem[sizeof(struct elemheader)+block->size] != MAGICBYTE) ? MCHECK_TAIL : MCHECK_OK;
- }
- break;
-
- default:
- status = MCHECK_HEAD;
- break;
- }
- return status;
-}
-
-
-
-static void unlink_blk (struct elemheader *ptr)
-{
- if (ptr->next != NULL) {
- ptr->next->prev = ptr->prev;
- ptr->next->magic = MAGICWORD ^ ((uintptr_t) ptr->next->prev + (uintptr_t) ptr->next->next);
- }
-
- if (ptr->prev != NULL) {
- ptr->prev->next = ptr->next;
- ptr->prev->magic = MAGICWORD ^ ((uintptr_t) ptr->prev->prev + (uintptr_t) ptr->prev->next);
- } else {
- root = ptr->next;
- }
-}
-
-static void link_blk (struct elemheader *ptr)
-{
- ptr->prev = NULL;
- ptr->next = root;
- root = ptr;
- ptr->magic = MAGICWORD ^ (uintptr_t) ptr->next;
-
- /* And the next block. */
- if (ptr->next != NULL) {
- ptr->next->prev = ptr;
- ptr->next->magic = MAGICWORD ^ ((uintptr_t) ptr + (uintptr_t) ptr->next->next);
- }
-}
-
-static void heapwalker(void)
-{
- const struct elemheader *runp = root;
-
- while (runp) {
- enum mcheck_status mstatus = me_corrupt_mprobe(runp);
- if (mstatus != MCHECK_OK) {
- HeapCorrupt("heapwalker",runp,mstatus);
- }
- runp = runp->next;
- }
-}
-
-
-static void me_corrupt_free_hook (__ptr_t ptr, const __ptr_t caller)
-{
- enum mcheck_status mstatus;
-
- pthread_mutex_lock(&HeapCorruptCheckMutex);
-
- if (HeapCorruptCheckMode == HEAPCHECKMODE_EXTENSIVE) {
- heapwalker();
- }
-
- if (PrintUsage) {
- if (ptr) {
- struct elemheader *hdr = (struct elemheader *)ptr - 1;
- std::cout << "pid :" << getpid() << " free: Attempting to delete area with size " << hdr->size << " bytes" << std::endl;
- } else {
- std::cout << "pid :" << getpid() << " free: Attempting to delete NULL pointer " << std::endl;
- }
- }
-
-
- if (ptr) {
- struct elemheader *hdr = (struct elemheader *)ptr - 1;
-
- mstatus = (HeapCorruptCheckMode == HEAPCHECKMODE_DISABLED) ? MCHECK_OK : me_corrupt_mprobe(hdr);
- if (mstatus != MCHECK_OK) {
- HeapCorrupt("free", hdr ,mstatus);
- }
-
- if (mstatus == MCHECK_OK) { // ForGet element if not detected or reallocated..
- hdr->magic = MAGICFREE;
- unlink_blk (hdr);
- hdr->prev = hdr->next = NULL;
-
- char * userdata = (char *)hdr+sizeof(struct elemheader);
- if (hdr->size > 0) {
- memset (userdata, FREEFLOOD, hdr->size);
- }
-
- ptr = (__ptr_t) hdr;
- } else {
- ptr = NULL; // ForGet element if not detected or reallocated..
- }
- }
-
-
- __free_hook = old_free_hook_memcorrupt;
-
- if (old_free_hook_memcorrupt != NULL) {
- (*old_free_hook_memcorrupt) (ptr, caller);
- } else {
- free (ptr);
- }
-
- __free_hook = me_corrupt_free_hook;
-
- pthread_mutex_unlock(&HeapCorruptCheckMutex);
-}
-
-static __ptr_t me_corrupt_malloc_hook (__malloc_size_t size, const __ptr_t caller)
-{
- struct elemheader *hdr;
- enum mcheck_status mstatus;
-
- pthread_mutex_lock(&HeapCorruptCheckMutex);
-
-
- if (HeapCorruptCheckMode == HEAPCHECKMODE_EXTENSIVE) {
- heapwalker();
- }
-
- if (PrintUsage) {
- std::cout << "pid :" << getpid() << " malloc: Attempting to allocate " << size << " bytes" << std::endl;
- }
-
-
- __malloc_hook = old_malloc_hook_memcorrupt;
- if (old_malloc_hook_memcorrupt != NULL) {
- hdr = (struct elemheader *) (*old_malloc_hook_memcorrupt) (sizeof (struct elemheader) + size + 1,caller);
- } else {
- hdr = (struct elemheader *) malloc (sizeof (struct elemheader) + size + 1);
- }
-
- __malloc_hook = me_corrupt_malloc_hook;
-
- if (hdr) {
- hdr->size = size;
- link_blk (hdr);
-
- char * userdata = (char *)hdr+sizeof(struct elemheader);
- userdata[size] = MAGICBYTE;
- if (size > 0) {
- memset (userdata, MALLOCFLOOD, size);
- }
-
- // Self check!
- mstatus = (HeapCorruptCheckMode == HEAPCHECKMODE_DISABLED) ? MCHECK_OK : me_corrupt_mprobe(hdr);
- if (mstatus != MCHECK_OK) {
- HeapCorrupt("malloc", hdr ,mstatus);
- }
- }
-
- pthread_mutex_unlock(&HeapCorruptCheckMutex);
-
- return hdr ? (__ptr_t) (hdr + 1) : NULL;
-}
-
-static __ptr_t me_corrupt_realloc_hook (__ptr_t ptr, __malloc_size_t size, const __ptr_t caller)
-{
- struct elemheader *hdr;
- __malloc_size_t osize;
- enum mcheck_status mstatus;
-
- pthread_mutex_lock(&HeapCorruptCheckMutex);
-
- if (HeapCorruptCheckMode == HEAPCHECKMODE_EXTENSIVE) {
- heapwalker();
- }
-
- if (PrintUsage) {
- std::cout << "pid :" << getpid() << " realloc: Attempting to allocate area with size " << size << " bytes.";
- if (ptr) {
- hdr = (struct elemheader *)ptr - 1;
- std::cout << " Old buffer was " << hdr->size << " bytes" << std::endl;
- } else {
- std::cout << " No old buffer." << std::endl;
- }
- }
-
- if (ptr) {
- hdr = ((struct elemheader *) ptr) - 1;
- osize = hdr->size;
-
- mstatus = (HeapCorruptCheckMode == HEAPCHECKMODE_DISABLED) ? MCHECK_OK : me_corrupt_mprobe(hdr);
- if (mstatus != MCHECK_OK) {
- HeapCorrupt("realloc/1", hdr ,mstatus);
- }
-
- unlink_blk (hdr);
- if (size < osize) {
- memset ((char *) ptr + size, FREEFLOOD, osize - size);
- }
- } else {
- osize = 0;
- hdr = NULL;
- }
-
- __free_hook = old_free_hook_memcorrupt;
- __malloc_hook = old_malloc_hook_memcorrupt;
- __realloc_hook = old_realloc_hook_memcorrupt;
-
- if (old_realloc_hook_memcorrupt != NULL) {
- hdr = (struct elemheader *) (*old_realloc_hook_memcorrupt) ((__ptr_t) hdr, sizeof (struct elemheader) + size + 1, caller);
- } else {
- hdr = (struct elemheader *) realloc ((__ptr_t) hdr,sizeof (struct elemheader) + size + 1);
- }
-
- __free_hook = me_corrupt_free_hook;
- __malloc_hook = me_corrupt_malloc_hook;
- __realloc_hook = me_corrupt_realloc_hook;
-
- if (hdr) {
- hdr->size = size;
- link_blk (hdr);
-
- char * userdata = (char *)hdr+sizeof(struct elemheader);
- userdata[size] = MAGICBYTE;
-
- if (size > osize) {
- memset (&userdata[osize], MALLOCFLOOD, size-osize);
- }
-
- mstatus = (HeapCorruptCheckMode == HEAPCHECKMODE_DISABLED) ? MCHECK_OK : me_corrupt_mprobe(hdr);
- if (mstatus != MCHECK_OK) {
- HeapCorrupt("realloc/2", hdr ,mstatus);
- }
- }
-
- pthread_mutex_unlock(&HeapCorruptCheckMutex);
-
- return hdr ? (__ptr_t) (hdr + 1) : NULL;
-}
-
-
-static void* me_corrupt_memalign_hook(size_t alignment, size_t bytes,const void *caller)
-{
- void *aligned;
-
- std::cout << "memalign #2 " << std::endl;
- __memalign_hook = old_memalign_hook_memcorrupt;
-
- if (old_memalign_hook_memcorrupt != NULL) {
- aligned = (*old_memalign_hook_memcorrupt) (alignment, bytes,caller);
- } else {
- aligned = memalign (alignment, bytes);
- }
-
- __memalign_hook = me_corrupt_memalign_hook;
-
- return aligned;
-}
-
-
-
-void enableHeapCorruptCheck(int param)
-{
-
- pthread_mutex_lock(&HeapCorruptCheckMutex);
-
-
- // This is install..
- if (HeapCorruptCheckMode == HEAPCHECKMODE_REMOVE && param != HEAPCHECKMODE_REMOVE) {
- old_free_hook_memcorrupt = __free_hook;
- __free_hook = me_corrupt_free_hook;
- old_malloc_hook_memcorrupt = __malloc_hook;
- __malloc_hook=me_corrupt_malloc_hook;
- old_realloc_hook_memcorrupt = __realloc_hook;
- __realloc_hook = me_corrupt_realloc_hook;
- old_memalign_hook_memcorrupt = __memalign_hook;
- __memalign_hook = me_corrupt_memalign_hook;
- std::cout << "Heap corruption detector installed" << std::endl;
- }
-
- // This is deinstall..
- if (HeapCorruptCheckMode != HEAPCHECKMODE_REMOVE && param == HEAPCHECKMODE_REMOVE) {
- __free_hook = old_free_hook_memcorrupt;
- __malloc_hook = old_malloc_hook_memcorrupt;
- __realloc_hook = old_realloc_hook_memcorrupt;
- __memalign_hook = old_memalign_hook_memcorrupt;
- std::cout << "Heap corruption detector removed" << std::endl;
- }
-
- HeapCorruptCheckMode = param;
- pthread_mutex_unlock(&HeapCorruptCheckMutex);
-}
-
-
-
-
-void checkHeapNow(void)
-{
- pthread_mutex_lock(&HeapCorruptCheckMutex);
- heapwalker();
- pthread_mutex_unlock(&HeapCorruptCheckMutex);
-}
-
-
-//---------------------------------
-// Part 3: glibc's mcheck librrary
-
-static void mcheckabortfunc(enum mcheck_status err)
-{
- HeapCorrupt("mcheckabortfunc",NULL,err);
-}
-
-
-void enableMCheck(void)
-{
- mcheck(&mcheckabortfunc);
-}
-
-
-//---------------------------------
-// Part 4: error report & exit
-
-static void HeapDump(const char *info,const char *p,int cnt)
-{
- char Legend[150];
- snprintf(Legend,sizeof(Legend),"Legend: Magic (tail) [%02x]. allocated, but unused: [%02x]. Reclaimed to free pool: [%02x]",
- (unsigned char)MAGICBYTE,
- (unsigned char)MALLOCFLOOD,
- (unsigned char)FREEFLOOD);
-
- std::cout << Legend << std::endl;
- std::cout << "Buffer dump: " << info << std::endl;
-
- for (int i = 0;i < cnt;i++) {
- char c = p[i];
- if (isgraph(c) || c == ' ') {
- std::cout << c;
- } else {
- char Tmp[10];
- snprintf(Tmp,sizeof(Tmp),"[%02x]",(unsigned char)c);
- std::cout << Tmp;
- }
- }
- std::cout << std::endl;
-}
-
-
-static void HeapCorrupt(const char * caller, const struct elemheader *hdr, enum mcheck_status err)
-{
-
- bool AbortNow = true;
-
-#define DUMPSIZE 100
-
- if (!caller) {
- caller = "?";
- }
- switch (err) {
- case MCHECK_DISABLED:
- std::cout << caller
- << ": Heap check was not called before the first allocation. No consistency checking can be done."
- << std::endl;
- break;
-
- case MCHECK_OK:
- std::cout << caller
- << ": No inconsistency detected."
- << std::endl;
- AbortNow = false;
- break;
-
- case MCHECK_HEAD:
- std::cout << caller
- << ": The data immediately before the block was modified. This commonly happens when an array index or pointer is decremented too far."
- << std::endl
- << " This block is ignored (and may appear as memory leakage)."
- << std::endl;
-
- if (hdr) {
- HeapDump("Immediately before ",((const char *)hdr) - (DUMPSIZE/2) ,DUMPSIZE/2);
- HeapDump("The element in question ",(const char *)hdr,DUMPSIZE/2);
- }
- AbortNow = false;
- break;
-
- case MCHECK_TAIL:
- std::cout << caller
- << ": The data immediately after the block was modified. This commonly happens when an array index or pointer is incremented too far."
- << std::endl;
-
- if (hdr) {
- HeapDump("Tail of element in question: ", ((const char *)hdr) + sizeof(struct elemheader) + hdr->size + 1 - (DUMPSIZE/2),(DUMPSIZE/2));
- HeapDump("Immediately after element: ",((const char *)hdr) + sizeof(struct elemheader) + hdr->size + 1 + 1, (DUMPSIZE/2));
- }
-
- break;
-
- case MCHECK_FREE:
- std::cout << caller
- << ": The block was already freed."
- << std::endl;
- break;
-
-
- default:
- std::cout << caller
- << ": Unexpected event " << err
- << std::endl;
- break;
- }
-
-
- if (hdr) {
- std::cout << caller << ": The element size was " << hdr->size << " bytes." << std::endl;
- if (err == MCHECK_HEAD) {
- std::cout << caller << ": But size may be incorrect since other parts of the header is destroyed/undecodable." << std::endl;
- }
- }
-
- if (AbortNow) {
- std::cout << caller << ": Application will crash now." << std::flush;
-
- // No core dump? Check ulimit -c
-
- kill(getpid(), SIGSEGV);
- }
-
-}
-
-// Enable this one if you want the heapdebugger to be installed "before anything else"
-// Uses same method as -lmcheck
-#if 0
-
-/* This one is called from malloc init.. */
-
-static void MallocInitHook(void)
-{
- enableHeapUsageMonitor(0);
- enableHeapCorruptCheck(0);
-}
-
-void (*__malloc_initialize_hook) (void) = MallocInitHook;
-
-
-#endif
diff --git a/document/src/tests/heapdebuggerother.cpp b/document/src/tests/heapdebuggerother.cpp
deleted file mode 100644
index 0aeaad57de2..00000000000
--- a/document/src/tests/heapdebuggerother.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/*
- * Author: Ove Martin Malm
- */
-
-#include <stdlib.h>
-#include "heapdebugger.h"
-
-// Not implemented
-void enableHeapUsageMonitor(int param)
-{
- (void)param;
-
-}
-
-// Not implemented
-extern size_t getHeapUsage(void)
-{
- return 0;
-}
-
-// Not implemented
-void enableHeapCorruptCheck(int param)
-{
- (void)param;
-
-}
-
-// Not implemented
-void enableMCheck(void)
-{
-}
-
-// Not implemented
-void checkHeapNow(void)
-{
-}
diff --git a/document/src/tests/testbytebuffer.cpp b/document/src/tests/testbytebuffer.cpp
index 777803d621b..17807fb4ff5 100644
--- a/document/src/tests/testbytebuffer.cpp
+++ b/document/src/tests/testbytebuffer.cpp
@@ -3,16 +3,13 @@
#include <vespa/document/util/stringutil.h>
#include <vespa/document/util/bytebuffer.h>
#include <vespa/document/fieldvalue/serializablearray.h>
-#include "heapdebugger.h"
#include <iostream>
-#include "testbytebuffer.h"
#include <vespa/vespalib/util/macro.h>
#include <vespa/document/util/bufferexceptions.h>
+#include <gtest/gtest.h>
using namespace document;
-CPPUNIT_TEST_SUITE_REGISTRATION( ByteBuffer_Test );
-
namespace {
template <typename S>
@@ -23,42 +20,29 @@ void assign(S &lhs, const S &rhs)
}
-void ByteBuffer_Test::setUp()
+TEST(ByteBuffer_Test, test_constructors)
{
- enableHeapUsageMonitor();
-}
-
-
-void ByteBuffer_Test::test_constructors()
-{
- size_t MemUsedAtEntry=getHeapUsage();
-
-
ByteBuffer* simple=new ByteBuffer();
delete simple;
ByteBuffer* less_simple=new ByteBuffer("hei",3);
- CPPUNIT_ASSERT(strcmp(less_simple->getBufferAtPos(),"hei")==0);
+ EXPECT_TRUE(strcmp(less_simple->getBufferAtPos(),"hei")==0);
delete less_simple;
-
- CPPUNIT_ASSERT(getHeapUsage()-MemUsedAtEntry == 0);
}
-void ByteBuffer_Test::test_assignment_operator()
+TEST(ByteBuffer_Test, test_assignment_operator)
{
- size_t MemUsedAtEntry=getHeapUsage();
try {
ByteBuffer b1;
ByteBuffer b2 = b1;
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL(b1.getLimit(),b2.getLimit());
- CPPUNIT_ASSERT_EQUAL(b1.getRemaining(),b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ(b1.getLimit(),b2.getLimit());
+ EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
} catch (std::exception &e) {
- fprintf(stderr,"Unexpected exception at %s: \"%s\"\n", VESPA_STRLOC.c_str(),e.what());
- CPPUNIT_ASSERT(false);
+ FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
try {
@@ -68,68 +52,62 @@ void ByteBuffer_Test::test_assignment_operator()
ByteBuffer b2 = b1;
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL(b1.getLimit(),b2.getLimit());
- CPPUNIT_ASSERT_EQUAL(b1.getRemaining(),b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ(b1.getLimit(),b2.getLimit());
+ EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
int test = 0;
b2.flip();
b2.getInt(test);
- CPPUNIT_ASSERT_EQUAL(1,test);
+ EXPECT_EQ(1,test);
b2.getInt(test);
- CPPUNIT_ASSERT_EQUAL(2,test);
+ EXPECT_EQ(2,test);
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL((size_t) 8,b2.getLimit());
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ((size_t) 8,b2.getLimit());
+ EXPECT_EQ((size_t) 0,b2.getRemaining());
// Test Selfassignment == no change
//
assign(b2, b2);
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL((size_t) 8,b2.getLimit());
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ((size_t) 8,b2.getLimit());
+ EXPECT_EQ((size_t) 0,b2.getRemaining());
ByteBuffer b3;
// Empty
b2 = b3;
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getPos());
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getLength());
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getLimit());
- CPPUNIT_ASSERT_EQUAL((size_t) 0,b2.getRemaining());
+ EXPECT_EQ((size_t) 0,b2.getPos());
+ EXPECT_EQ((size_t) 0,b2.getLength());
+ EXPECT_EQ((size_t) 0,b2.getLimit());
+ EXPECT_EQ((size_t) 0,b2.getRemaining());
} catch (std::exception &e) {
- fprintf(stderr,"Unexpected exception at %s: \"%s\"\n", VESPA_STRLOC.c_str(),e.what());
- CPPUNIT_ASSERT(false);
+ FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
-
- CPPUNIT_ASSERT(getHeapUsage()-MemUsedAtEntry == 0);
-
}
-void ByteBuffer_Test::test_copy_constructor()
+TEST(ByteBuffer_Test, test_copy_constructor)
{
- size_t MemUsedAtEntry=getHeapUsage();
try {
// Empty buffer first
ByteBuffer b1;
ByteBuffer b2(b1);
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL(b1.getLimit(),b2.getLimit());
- CPPUNIT_ASSERT_EQUAL(b1.getRemaining(),b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ(b1.getLimit(),b2.getLimit());
+ EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
} catch (std::exception &e) {
- fprintf(stderr,"Unexpected exception at %s: %s\n", VESPA_STRLOC.c_str(),e.what());
- CPPUNIT_ASSERT(false);
+ FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
try {
@@ -139,28 +117,24 @@ void ByteBuffer_Test::test_copy_constructor()
ByteBuffer b2(b1);
- CPPUNIT_ASSERT_EQUAL(b1.getPos(),b2.getPos());
- CPPUNIT_ASSERT_EQUAL(b1.getLength(),b2.getLength());
- CPPUNIT_ASSERT_EQUAL(b1.getLimit(),b2.getLimit());
- CPPUNIT_ASSERT_EQUAL(b1.getRemaining(),b2.getRemaining());
+ EXPECT_EQ(b1.getPos(),b2.getPos());
+ EXPECT_EQ(b1.getLength(),b2.getLength());
+ EXPECT_EQ(b1.getLimit(),b2.getLimit());
+ EXPECT_EQ(b1.getRemaining(),b2.getRemaining());
int test = 0;
b2.flip();
b2.getInt(test);
- CPPUNIT_ASSERT_EQUAL(1,test);
+ EXPECT_EQ(1,test);
b2.getInt(test);
- CPPUNIT_ASSERT_EQUAL(2,test);
+ EXPECT_EQ(2,test);
} catch (std::exception &e) {
- fprintf(stderr,"Unexpected exception at %s: %s\n", VESPA_STRLOC.c_str(),e.what());
- CPPUNIT_ASSERT(false);
+ FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
-
- CPPUNIT_ASSERT(getHeapUsage()-MemUsedAtEntry == 0);
-
}
-void ByteBuffer_Test::test_slice()
+TEST(ByteBuffer_Test, test_slice)
{
ByteBuffer* newBuf=ByteBuffer::copyBuffer("hei der",8);
@@ -169,15 +143,15 @@ void ByteBuffer_Test::test_slice()
delete newBuf;
newBuf = NULL;
- CPPUNIT_ASSERT(strcmp(slice->getBufferAtPos(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice->getBufferAtPos(),"hei der")==0);
ByteBuffer* slice2 = new ByteBuffer;
slice2->sliceFrom(*slice, 4, slice->getLength());
delete slice;
slice = NULL;
- CPPUNIT_ASSERT(strcmp(slice2->getBufferAtPos(),"der")==0);
- CPPUNIT_ASSERT(strcmp(slice2->getBuffer(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice2->getBufferAtPos(),"der")==0);
+ EXPECT_TRUE(strcmp(slice2->getBuffer(),"hei der")==0);
delete slice2;
slice2 = NULL;
@@ -190,22 +164,20 @@ void ByteBuffer_Test::test_slice()
delete newBuf2;
newBuf2 = NULL;
- CPPUNIT_ASSERT(strcmp(slice3->getBufferAtPos(),"der")==0);
- CPPUNIT_ASSERT(strcmp(slice4->getBuffer(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice3->getBufferAtPos(),"der")==0);
+ EXPECT_TRUE(strcmp(slice4->getBuffer(),"hei der")==0);
delete slice3;
slice3 = NULL;
- CPPUNIT_ASSERT(strcmp(slice4->getBuffer(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice4->getBuffer(),"hei der")==0);
delete slice4;
slice4 = NULL;
}
-void ByteBuffer_Test::test_slice2()
+TEST(ByteBuffer_Test, test_slice2)
{
- size_t MemUsedAtEntry=getHeapUsage();
-
ByteBuffer* newBuf=ByteBuffer::copyBuffer("hei der",8);
ByteBuffer slice;
@@ -214,13 +186,13 @@ void ByteBuffer_Test::test_slice2()
delete newBuf;
newBuf = NULL;
- CPPUNIT_ASSERT(strcmp(slice.getBufferAtPos(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice.getBufferAtPos(),"hei der")==0);
ByteBuffer slice2;
slice2.sliceFrom(slice, 4, slice.getLength());
- CPPUNIT_ASSERT(strcmp(slice2.getBufferAtPos(),"der")==0);
- CPPUNIT_ASSERT(strcmp(slice2.getBuffer(),"hei der")==0);
+ EXPECT_TRUE(strcmp(slice2.getBufferAtPos(),"der")==0);
+ EXPECT_TRUE(strcmp(slice2.getBuffer(),"hei der")==0);
ByteBuffer* newBuf2=new ByteBuffer("hei der", 8);
@@ -229,14 +201,12 @@ void ByteBuffer_Test::test_slice2()
delete newBuf2;
newBuf2 = NULL;
- CPPUNIT_ASSERT(strcmp(slice.getBufferAtPos(),"der")==0);
- CPPUNIT_ASSERT(strcmp(slice2.getBuffer(),"hei der")==0);
-
- CPPUNIT_ASSERT(getHeapUsage()-MemUsedAtEntry == 0);
+ EXPECT_TRUE(strcmp(slice.getBufferAtPos(),"der")==0);
+ EXPECT_TRUE(strcmp(slice2.getBuffer(),"hei der")==0);
}
-void ByteBuffer_Test::test_putGetFlip()
+TEST(ByteBuffer_Test, test_putGetFlip)
{
ByteBuffer* newBuf=new ByteBuffer(100);
@@ -246,38 +216,37 @@ void ByteBuffer_Test::test_putGetFlip()
newBuf->flip();
newBuf->getInt(test);
- CPPUNIT_ASSERT(test==10);
+ EXPECT_TRUE(test==10);
newBuf->clear();
newBuf->putDouble(3.35);
newBuf->flip();
- CPPUNIT_ASSERT(newBuf->getRemaining()==sizeof(double));
+ EXPECT_TRUE(newBuf->getRemaining()==sizeof(double));
double test2;
newBuf->getDouble(test2);
- CPPUNIT_ASSERT(test2==3.35);
+ EXPECT_TRUE(test2==3.35);
newBuf->clear();
newBuf->putBytes("heisann",8);
newBuf->putInt(4);
- CPPUNIT_ASSERT(newBuf->getPos()==12);
- CPPUNIT_ASSERT(newBuf->getLength()==100);
+ EXPECT_TRUE(newBuf->getPos()==12);
+ EXPECT_TRUE(newBuf->getLength()==100);
newBuf->flip();
- CPPUNIT_ASSERT(newBuf->getRemaining()==12);
+ EXPECT_TRUE(newBuf->getRemaining()==12);
char testStr[12];
newBuf->getBytes(testStr, 8);
- CPPUNIT_ASSERT(strcmp(testStr,"heisann")==0);
+ EXPECT_TRUE(strcmp(testStr,"heisann")==0);
newBuf->getInt(test);
- CPPUNIT_ASSERT(test==4);
+ EXPECT_TRUE(test==4);
} catch (std::exception &e) {
- fprintf(stderr,"Unexpected exception at %s: %s\n", VESPA_STRLOC.c_str(),e.what());
- CPPUNIT_ASSERT(false);
+ FAIL() << "Unexpected exception at " << VESPA_STRLOC << ": \"" << e.what() << "\"";
}
delete newBuf;
}
-void ByteBuffer_Test::test_NumberEncodings()
+TEST(ByteBuffer_Test, test_NumberEncodings)
{
ByteBuffer* buf=new ByteBuffer(1024);
@@ -313,14 +282,14 @@ void ByteBuffer_Test::test_NumberEncodings()
// Check 7
try {
buf->putInt1_2_4Bytes(0x7FFFFFFF);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
buf->putInt2_4_8Bytes(0x7FFFFFFFll);
buf->putInt1_4Bytes(0x7FFFFFFF);
try {
buf->putInt2_4_8Bytes(0x7FFFFFFFFFFFFFFFll);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
buf->putInt1_2_4Bytes(0x7FFF);
@@ -334,33 +303,33 @@ void ByteBuffer_Test::test_NumberEncodings()
try {
buf->putInt1_2_4Bytes(-1);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt2_4_8Bytes(-1);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt1_4Bytes(-1);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt1_2_4Bytes(-0x7FFFFFFF);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt2_4_8Bytes(-0x7FFFFFFF);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt1_4Bytes(-0x7FFFFFFF);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
try {
buf->putInt2_4_8Bytes(-0x7FFFFFFFFFFFFFFFll);
- CPPUNIT_ASSERT(false);
+ FAIL() << "Expected input out of range exception";
} catch (InputOutOfRangeException& e) { }
uint32_t endWritePos = buf->getPos();
@@ -371,130 +340,130 @@ void ByteBuffer_Test::test_NumberEncodings()
// Check 0
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(124, tmp32);
+ EXPECT_EQ(124, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)124, tmp64);
+ EXPECT_EQ((int64_t)124, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(124, tmp32);
+ EXPECT_EQ(124, tmp32);
// Check 1
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(127, tmp32);
+ EXPECT_EQ(127, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)127, tmp64);
+ EXPECT_EQ((int64_t)127, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(127, tmp32);
+ EXPECT_EQ(127, tmp32);
// Check 2
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(128, tmp32);
+ EXPECT_EQ(128, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)128, tmp64);
+ EXPECT_EQ((int64_t)128, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(128, tmp32);
+ EXPECT_EQ(128, tmp32);
// Check 3
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(255, tmp32);
+ EXPECT_EQ(255, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)255, tmp64);
+ EXPECT_EQ((int64_t)255, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(255, tmp32);
+ EXPECT_EQ(255, tmp32);
// Check 4
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(256, tmp32);
+ EXPECT_EQ(256, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)256, tmp64);
+ EXPECT_EQ((int64_t)256, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(256, tmp32);
+ EXPECT_EQ(256, tmp32);
// Check 5
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0, tmp32);
+ EXPECT_EQ(0, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)0, tmp64);
+ EXPECT_EQ((int64_t)0, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0, tmp32);
+ EXPECT_EQ(0, tmp32);
// Check 6
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(1, tmp32);
+ EXPECT_EQ(1, tmp32);
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)1, tmp64);
+ EXPECT_EQ((int64_t)1, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(1, tmp32);
+ EXPECT_EQ(1, tmp32);
// Check 7
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)0x7FFFFFFF, tmp64);
+ EXPECT_EQ((int64_t)0x7FFFFFFF, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0x7FFFFFFF, tmp32);
+ EXPECT_EQ(0x7FFFFFFF, tmp32);
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0x7FFF, tmp32);
+ EXPECT_EQ(0x7FFF, tmp32);
// Check 8
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)0x7FFF, tmp64);
+ EXPECT_EQ((int64_t)0x7FFF, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0x7FFF, tmp32);
+ EXPECT_EQ(0x7FFF, tmp32);
buf->getInt1_2_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0x7F, tmp32);
+ EXPECT_EQ(0x7F, tmp32);
// Check 9
buf->getInt2_4_8Bytes(tmp64);
- CPPUNIT_ASSERT_EQUAL((int64_t)0x7F, tmp64);
+ EXPECT_EQ((int64_t)0x7F, tmp64);
buf->getInt1_4Bytes(tmp32);
- CPPUNIT_ASSERT_EQUAL(0x7F, tmp32);
+ EXPECT_EQ(0x7F, tmp32);
uint32_t endReadPos = buf->getPos();
- CPPUNIT_ASSERT_EQUAL(endWritePos, endReadPos);
+ EXPECT_EQ(endWritePos, endReadPos);
delete buf;
}
-void ByteBuffer_Test::test_NumberLengths()
+TEST(ByteBuffer_Test, test_NumberLengths)
{
ByteBuffer b;
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(0));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(1));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(4));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(31));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(126));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_4Bytes(127));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_4Bytes(128));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_4Bytes(129));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_4Bytes(255));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_4Bytes(256));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_4Bytes(0x7FFFFFFF));
-
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(0));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(1));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(4));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(31));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(126));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(127));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(128));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize2_4_8Bytes(32767));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize2_4_8Bytes(32768));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize2_4_8Bytes(32769));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize2_4_8Bytes(1030493));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize2_4_8Bytes(0x3FFFFFFF));
- CPPUNIT_ASSERT_EQUAL((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000000));
- CPPUNIT_ASSERT_EQUAL((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000001));
-
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(0));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(1));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(4));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(31));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(126));
- CPPUNIT_ASSERT_EQUAL((size_t) 1, b.getSerializedSize1_2_4Bytes(127));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize1_2_4Bytes(128));
- CPPUNIT_ASSERT_EQUAL((size_t) 2, b.getSerializedSize1_2_4Bytes(16383));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_2_4Bytes(16384));
- CPPUNIT_ASSERT_EQUAL((size_t) 4, b.getSerializedSize1_2_4Bytes(16385));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(0));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(1));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(4));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(31));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(126));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_4Bytes(127));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(128));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(129));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(255));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(256));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_4Bytes(0x7FFFFFFF));
+
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(0));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(1));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(4));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(31));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(126));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(127));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(128));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize2_4_8Bytes(32767));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(32768));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(32769));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(1030493));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize2_4_8Bytes(0x3FFFFFFF));
+ EXPECT_EQ((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000000));
+ EXPECT_EQ((size_t) 8, b.getSerializedSize2_4_8Bytes(0x40000001));
+
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(0));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(1));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(4));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(31));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(126));
+ EXPECT_EQ((size_t) 1, b.getSerializedSize1_2_4Bytes(127));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize1_2_4Bytes(128));
+ EXPECT_EQ((size_t) 2, b.getSerializedSize1_2_4Bytes(16383));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_2_4Bytes(16384));
+ EXPECT_EQ((size_t) 4, b.getSerializedSize1_2_4Bytes(16385));
}
-void ByteBuffer_Test::test_SerializableArray()
+TEST(ByteBuffer_Test, test_SerializableArray)
{
SerializableArray array;
array.set(0,"http",4);
- CPPUNIT_ASSERT_EQUAL(4ul, array.get(0).size());
+ EXPECT_EQ(4ul, array.get(0).size());
SerializableArray copy(array);
- CPPUNIT_ASSERT_EQUAL(4ul, array.get(0).size());
- CPPUNIT_ASSERT_EQUAL(copy.get(0).size(), array.get(0).size());
- CPPUNIT_ASSERT(copy.get(0).c_str() != array.get(0).c_str());
- CPPUNIT_ASSERT_EQUAL(0, strcmp(copy.get(0).c_str(), array.get(0).c_str()));
- CPPUNIT_ASSERT_EQUAL(16ul, sizeof(SerializableArray::Entry));
+ EXPECT_EQ(4ul, array.get(0).size());
+ EXPECT_EQ(copy.get(0).size(), array.get(0).size());
+ EXPECT_TRUE(copy.get(0).c_str() != array.get(0).c_str());
+ EXPECT_EQ(0, strcmp(copy.get(0).c_str(), array.get(0).c_str()));
+ EXPECT_EQ(16ul, sizeof(SerializableArray::Entry));
}
diff --git a/document/src/tests/testbytebuffer.h b/document/src/tests/testbytebuffer.h
deleted file mode 100644
index d7dfc835d3c..00000000000
--- a/document/src/tests/testbytebuffer.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-/* $Id$*/
-
-#pragma once
-
-#include <cppunit/extensions/HelperMacros.h>
-
-/**
- CPPUnit test case for ByteBuffer class.
-*/
-class ByteBuffer_Test : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE( ByteBuffer_Test);
- CPPUNIT_TEST(test_constructors);
- CPPUNIT_TEST(test_copy_constructor);
- CPPUNIT_TEST(test_assignment_operator);
- CPPUNIT_TEST(test_slice);
- CPPUNIT_TEST(test_slice2);
- CPPUNIT_TEST(test_putGetFlip);
- CPPUNIT_TEST(test_NumberEncodings);
- CPPUNIT_TEST(test_NumberLengths);
- CPPUNIT_TEST(test_SerializableArray);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- /**
- Initialization.
- */
- void setUp() override;
-
-protected:
- /**
- Test construction and deletion.
- */
- void test_constructors();
- void test_SerializableArray();
-
- /**
- Test copy constructor
- */
- void test_copy_constructor();
- /**
- Test construction and deletion.
- */
- void test_assignment_operator();
-
- /**
- Test the slice() method
- */
- void test_slice();
-
- /**
- Test the slice2() method
- */
- void test_slice2();
-
- /**
- Test put(), get() and flip() methods.
- */
- void test_putGetFlip();
-
- /**
- Test writing integers with funny encodings.
- */
- void test_NumberEncodings();
-
- /**
- Tests lengths of those encodings.
- */
- void test_NumberLengths();
-
-};
-
-
diff --git a/document/src/tests/testrunner.cpp b/document/src/tests/testrunner.cpp
deleted file mode 100644
index abe9c53debb..00000000000
--- a/document/src/tests/testrunner.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/vdstestlib/cppunit/cppunittestrunner.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP("documentcppunittests");
-
-int
-main(int argc, const char *argv[])
-{
- vdstestlib::CppUnitTestRunner testRunner;
- return testRunner.run(argc, argv);
-}
-