mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-30 09:13:40 -05:00
* Introduced new tests directory.
* added old serialiser tests (FAIL at the moment). * moved Makefile scripts to tests diectory. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3173 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
69bba330ac
commit
9c6a3a7781
@ -268,7 +268,7 @@ HEADERS += dbase/cachestrapper.h \
|
|||||||
serialiser/rstlvkeys.h \
|
serialiser/rstlvkeys.h \
|
||||||
serialiser/rstlvkvwide.h \
|
serialiser/rstlvkvwide.h \
|
||||||
serialiser/rstlvtypes.h \
|
serialiser/rstlvtypes.h \
|
||||||
# serialiser/rstlvutil.h \
|
serialiser/rstlvutil.h \
|
||||||
services/p3channels.h \
|
services/p3channels.h \
|
||||||
services/p3chatservice.h \
|
services/p3chatservice.h \
|
||||||
services/p3disc.h \
|
services/p3disc.h \
|
||||||
@ -399,7 +399,7 @@ SOURCES += \
|
|||||||
serialiser/rsbaseitems.cc \
|
serialiser/rsbaseitems.cc \
|
||||||
serialiser/rstlvkvwide.cc \
|
serialiser/rstlvkvwide.cc \
|
||||||
serialiser/rstlvimage.cc \
|
serialiser/rstlvimage.cc \
|
||||||
# serialiser/rstlvutil.cc \
|
serialiser/rstlvutil.cc \
|
||||||
serialiser/rstlvfileitem.cc \
|
serialiser/rstlvfileitem.cc \
|
||||||
serialiser/rstlvkeys.cc \
|
serialiser/rstlvkeys.cc \
|
||||||
serialiser/rsbaseserial.cc \
|
serialiser/rsbaseserial.cc \
|
||||||
|
25
libretroshare/src/tests/scripts/checks.mk
Normal file
25
libretroshare/src/tests/scripts/checks.mk
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#Basic checks
|
||||||
|
|
||||||
|
ifndef RS_TOP_DIR
|
||||||
|
dummy:
|
||||||
|
echo "RS_TOP_DIR is not defined in your makefile"
|
||||||
|
endif
|
||||||
|
|
||||||
|
#ifndef SSL_DIR
|
||||||
|
#dummy:
|
||||||
|
# echo "you must define SSL_DIR before you can compile"
|
||||||
|
#
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ifneq ($(OS),Linux)
|
||||||
|
ifneq ($(OS),MacOSX)
|
||||||
|
ifndef PTHREADS_DIR
|
||||||
|
dummy:
|
||||||
|
echo "you must define PTHREADS_DIR before you can compile"
|
||||||
|
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
118
libretroshare/src/tests/scripts/config-cygwin.mk
Normal file
118
libretroshare/src/tests/scripts/config-cygwin.mk
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
ifneq ($(OS),Cygwin)
|
||||||
|
dummy:
|
||||||
|
echo "ERROR Cygwin configuration file included, but (OS != Cygwin)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
############ LINUX CONFIGURATION ########################
|
||||||
|
|
||||||
|
# flags for components....
|
||||||
|
PQI_USE_XPGP = 1
|
||||||
|
#PQI_USE_PROXY = 1
|
||||||
|
#PQI_USE_CHANNELS = 1
|
||||||
|
#USE_FILELOOK = 1
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#### DrBobs Versions.... Please Don't Delete.
|
||||||
|
### Comment out if needed.
|
||||||
|
ALT_SRC_ROOT=/cygdrive/c/home/rmfern/prog/MinGW
|
||||||
|
SRC_ROOT=../../../..
|
||||||
|
|
||||||
|
PTHREADS_DIR=$(ALT_SRC_ROOT)/pthreads/pthreads.2
|
||||||
|
|
||||||
|
###################
|
||||||
|
|
||||||
|
#ALT_SRC_ROOT=/cygdrive/c/RetroShareBuild/src
|
||||||
|
#SRC_ROOT=/cygdrive/c/RetroShareBuild/src
|
||||||
|
|
||||||
|
#PTHREADS_DIR=$(ALT_SRC_ROOT)/pthreads-w32-2-8-0-release
|
||||||
|
|
||||||
|
###################
|
||||||
|
|
||||||
|
ZLIB_DIR=$(ALT_SRC_ROOT)/zlib-1.2.3
|
||||||
|
|
||||||
|
SSL_DIR=$(SRC_ROOT)/openssl-0.9.7g-xpgp-0.1c
|
||||||
|
UPNPC_DIR=$(SRC_ROOT)/miniupnpc-1.0
|
||||||
|
|
||||||
|
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||||
|
|
||||||
|
############ ENFORCE DIRECTORY NAMING ########################
|
||||||
|
|
||||||
|
CC = g++
|
||||||
|
RM = /bin/rm
|
||||||
|
RANLIB = ranlib
|
||||||
|
LIBDIR = $(RS_TOP_DIR)/lib
|
||||||
|
LIBRS = $(LIBDIR)/libretroshare.a
|
||||||
|
|
||||||
|
# Unix: Linux/Cygwin
|
||||||
|
INCLUDE = -I $(RS_TOP_DIR)
|
||||||
|
|
||||||
|
ifdef PQI_DEBUG
|
||||||
|
CFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
else
|
||||||
|
CFLAGS = -Wall -O2 $(INCLUDE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
INCLUDE += -I $(SSL_DIR)/include
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
CFLAGS += -DPQI_USE_XPGP
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_PROXY
|
||||||
|
CFLAGS += -DPQI_USE_PROXY
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_CHANNELS
|
||||||
|
CFLAGS += -DPQI_USE_CHANNELS
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef USE_FILELOOK
|
||||||
|
CFLAGS += -DUSE_FILELOOK
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
RSCFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS Compile Options
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||||
|
BIOCC = gcc
|
||||||
|
|
||||||
|
# Cygwin - ?same? as Linux flags
|
||||||
|
BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS specific Linking.
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# for static pthread libs....
|
||||||
|
WININC += -DPTW32_STATIC_LIB
|
||||||
|
WININC += -mno-cygwin -mwindows -fno-exceptions
|
||||||
|
WININC += -DWINDOWS_SYS
|
||||||
|
|
||||||
|
WINLIB = -lws2_32 -luuid -lole32 -liphlpapi
|
||||||
|
WINLIB += -lcrypt32 -lwinmm
|
||||||
|
|
||||||
|
CFLAGS += -I$(PTHREADS_DIR) $(WININC)
|
||||||
|
CFLAGS += -I$(ZLIB_DIR)
|
||||||
|
|
||||||
|
LIBS = -L$(LIBDIR) -lretroshare
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
LIBS += -L$(SSL_DIR)
|
||||||
|
endif
|
||||||
|
|
||||||
|
LIBS += -lssl -lcrypto
|
||||||
|
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||||
|
LIBS += -L$(ZLIB_DIR) -lz
|
||||||
|
LIBS += -L$(PTHREADS_DIR) -lpthreadGC2d
|
||||||
|
LIBS += $(WINLIB)
|
||||||
|
|
||||||
|
RSCFLAGS += $(WININC)
|
||||||
|
|
||||||
|
|
70
libretroshare/src/tests/scripts/config-linux.mk
Normal file
70
libretroshare/src/tests/scripts/config-linux.mk
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
|
||||||
|
ifneq ($(OS),Linux)
|
||||||
|
dummy:
|
||||||
|
echo "ERROR Linux configuration file included, but (OS != Linux)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
############ LINUX CONFIGURATION ########################
|
||||||
|
|
||||||
|
#UPNPC_DIR=../../../../miniupnpc-1.0
|
||||||
|
|
||||||
|
# Need to define miniupnpc version because API changed a little between v1.0 and 1.2
|
||||||
|
# put 10 for 1.0 and 12 for 1.2
|
||||||
|
#DEFINES += -DMINIUPNPC_VERSION=10
|
||||||
|
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/checks.mk
|
||||||
|
|
||||||
|
############ ENFORCE DIRECTORY NAMING ########################
|
||||||
|
|
||||||
|
CC = g++
|
||||||
|
RM = /bin/rm
|
||||||
|
RANLIB = ranlib
|
||||||
|
LIBDIR = $(RS_TOP_DIR)/lib
|
||||||
|
LIBRS = $(LIBDIR)/libretroshare.a
|
||||||
|
|
||||||
|
# Unix: Linux/Cygwin
|
||||||
|
INCLUDE = -I $(RS_TOP_DIR)
|
||||||
|
CFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
CFLAGS += ${DEFINES}
|
||||||
|
|
||||||
|
#ifdef PQI_USE_XPGP
|
||||||
|
# INCLUDE += -I $(SSL_DIR)/include
|
||||||
|
#endif
|
||||||
|
#
|
||||||
|
#ifdef PQI_USE_XPGP
|
||||||
|
# CFLAGS += -DPQI_USE_XPGP
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RSCFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
#########################################################################
|
||||||
|
# OS Compile Options
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||||
|
BIOCC = gcc
|
||||||
|
|
||||||
|
# march=i686 causes problems while 64Bit compiling, GCC tries to generate Output for a m64 machine, but the marchi686
|
||||||
|
# doesnt allow the instructionfs for that.
|
||||||
|
#
|
||||||
|
# gcc docu: http://gcc.gnu.org/onlinedocs/gcc-4.0.3/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options
|
||||||
|
|
||||||
|
# Linux flags
|
||||||
|
BIOCFLAGS = -I $(SSL_DIR)/include ${DEFINES} -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS specific Linking.
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
LIBS = -L$(LIBDIR) -lretroshare
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
LIBS += -L$(SSL_DIR)
|
||||||
|
endif
|
||||||
|
LIBS += -lssl -lcrypto -lpthread
|
||||||
|
#LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||||
|
LIBS += $(XLIB) -ldl -lz
|
||||||
|
LIBS += -lgpgme
|
||||||
|
|
||||||
|
RSLIBS = $(LIBS)
|
||||||
|
|
||||||
|
|
152
libretroshare/src/tests/scripts/config-macosx.mk
Normal file
152
libretroshare/src/tests/scripts/config-macosx.mk
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
|
||||||
|
ifneq ($(OS),MacOSX)
|
||||||
|
dummy:
|
||||||
|
echo "ERROR MacOSX configuration file included, but (OS != MacOSX)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
############ LINUX CONFIGURATION ########################
|
||||||
|
|
||||||
|
|
||||||
|
# FLAGS to decide if we want i386 Build or ppc Build
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
# PPC is default
|
||||||
|
# Could define both for combined compilation...
|
||||||
|
# except might not work for bio_tou.c file!
|
||||||
|
#
|
||||||
|
# MAC_I386_BUILD = 1
|
||||||
|
# MAC_PPC_BUILD = 1
|
||||||
|
|
||||||
|
#MAC_I386_BUILD = 1
|
||||||
|
#MAC_PPC_BUILD = 1
|
||||||
|
|
||||||
|
ifndef MAC_I386_BUILD
|
||||||
|
MAC_PPC_BUILD = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
# flags for components....
|
||||||
|
#PQI_USE_SSLONLY = 1
|
||||||
|
#PQI_USE_XPGP = 1
|
||||||
|
|
||||||
|
#PQI_USE_PROXY = 1
|
||||||
|
#PQI_USE_CHANNELS = 1
|
||||||
|
#USE_FILELOOK = 1
|
||||||
|
|
||||||
|
SSL_DIR=../../../../../src/openssl-0.9.7g-xpgp-0.1c
|
||||||
|
UPNPC_DIR=../../../../../src/miniupnpc-1.0
|
||||||
|
|
||||||
|
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||||
|
|
||||||
|
############ ENFORCE DIRECTORY NAMING ########################
|
||||||
|
|
||||||
|
CC = g++
|
||||||
|
RM = /bin/rm
|
||||||
|
|
||||||
|
RANLIB = ranlib
|
||||||
|
|
||||||
|
# Dummy ranlib -> can't do it until afterwards with universal binaries.
|
||||||
|
# RANLIB = ls -l
|
||||||
|
|
||||||
|
LIBDIR = $(RS_TOP_DIR)/lib
|
||||||
|
LIBRS = $(LIBDIR)/libretroshare.a
|
||||||
|
|
||||||
|
OPT_DIR = /opt/local
|
||||||
|
OPT_INCLUDE = $(OPT_DIR)/include
|
||||||
|
OPT_LIBS = $(OPT_DIR)/lib
|
||||||
|
|
||||||
|
INCLUDE = -I $(RS_TOP_DIR) -I $(OPT_INCLUDE)
|
||||||
|
#CFLAGS = -Wall -O3
|
||||||
|
CFLAGS = -Wall -g
|
||||||
|
|
||||||
|
# Flags for architecture builds.
|
||||||
|
ifdef MAC_I386_BUILD
|
||||||
|
CFLAGS += -arch i386
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef MAC_PPC_BUILD
|
||||||
|
CFLAGS += -arch ppc
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS += $(INCLUDE)
|
||||||
|
|
||||||
|
# This Line is for Universal BUILD for 10.4 + 10.5
|
||||||
|
# (but unlikely to work unless Qt Libraries are build properly)
|
||||||
|
# CFLAGS += -isysroot /Developer/SDKs/MacOSX10.4u.sdk
|
||||||
|
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
INCLUDE += -I $(SSL_DIR)/include
|
||||||
|
CFLAGS += -DPQI_USE_XPGP
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_SSLONLY
|
||||||
|
CFLAGS += -DPQI_USE_SSLONLY
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_PROXY
|
||||||
|
CFLAGS += -DPQI_USE_PROXY
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_CHANNELS
|
||||||
|
CFLAGS += -DPQI_USE_CHANNELS
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef USE_FILELOOK
|
||||||
|
CFLAGS += -DUSE_FILELOOK
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# RSCFLAGS = -Wall -O3 $(INCLUDE)
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS Compile Options
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||||
|
BIOCC = gcc
|
||||||
|
|
||||||
|
|
||||||
|
# Flags for architecture builds.
|
||||||
|
ifdef MAC_I386_BUILD
|
||||||
|
BIOCFLAGS = -arch i386 -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef MAC_PPC_BUILD
|
||||||
|
BIOCFLAGS = -arch ppc -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# MacOSX flags
|
||||||
|
# BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||||
|
|
||||||
|
# This is for the Universal Build...
|
||||||
|
# but is unlikely to work... as options are PPC specific....
|
||||||
|
#
|
||||||
|
# BIOCFLAGS = -arch ppc -arch i386 -I $(SSL_DIR)/include -DOPENSSL_SYSNAME_MACOSX -DOPENSSL_THREADS -D_REENTRANT -DOPENSSL_NO_KRB5 -O3 -fomit-frame-pointer -fno-common -DB_ENDIAN
|
||||||
|
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS specific Linking.
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
LIBS = -Wl,-search_paths_first
|
||||||
|
|
||||||
|
# for Univeral BUILD
|
||||||
|
# LIBS += -arch ppc -arch i386
|
||||||
|
# LIBS += -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386
|
||||||
|
|
||||||
|
LIBS += -L$(LIBDIR) -lretroshare
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
LIBS += -L$(SSL_DIR)
|
||||||
|
endif
|
||||||
|
LIBS += -lssl -lcrypto -lpthread
|
||||||
|
LIBS += -L$(OPT_LIBS)
|
||||||
|
LIBS += -lgpgme -lgpg-error
|
||||||
|
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||||
|
LIBS += $(XLIB) -ldl -lz
|
||||||
|
|
||||||
|
RSLIBS = $(LIBS)
|
||||||
|
|
||||||
|
|
138
libretroshare/src/tests/scripts/config-mingw.mk
Normal file
138
libretroshare/src/tests/scripts/config-mingw.mk
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
#ifneq ($(OS),"Win ")
|
||||||
|
#dummy:
|
||||||
|
# echo "ERROR OS = $(OS)"
|
||||||
|
# echo "ERROR MinGW configuration file included, but (OS != Win)
|
||||||
|
#
|
||||||
|
#endif
|
||||||
|
|
||||||
|
############ LINUX CONFIGURATION ########################
|
||||||
|
|
||||||
|
# flags for components....
|
||||||
|
#PQI_USE_XPGP = 1
|
||||||
|
#PQI_USE_PROXY = 1
|
||||||
|
#PQI_USE_CHANNELS = 1
|
||||||
|
#USE_FILELOOK = 1
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#### DrBobs Versions.... Please Don't Delete.
|
||||||
|
### Comment out if needed.
|
||||||
|
SRC_ROOT_PKG=/home/Mark/prog/retroshare/package/rs-win-v0.5.0/src
|
||||||
|
SRC_ROOT_GPG=/local
|
||||||
|
|
||||||
|
#ALT_SRC_ROOT=/cygdrive/c/home/rmfern/prog/MinGW
|
||||||
|
#SRC_ROOT=../../../..
|
||||||
|
|
||||||
|
PTHREADS_DIR=$(SRC_ROOT_PKG)/pthreads-w32-2-8-0/Pre-built.2
|
||||||
|
ZLIB_DIR=$(SRC_ROOT_PKG)/zlib-1.2.3
|
||||||
|
SSL_DIR=$(SRC_ROOT_PKG)/openssl-tmp
|
||||||
|
UPNPC_DIR=$(SRC_ROOT_PKG)/miniupnpc-1.3
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#### Enable this section for compiling with MSYS/MINGW compile
|
||||||
|
#SRC_ROOT=/home/linux
|
||||||
|
|
||||||
|
#SSL_DIR=$(SRC_ROOT)/OpenSSL
|
||||||
|
#GPGME_DIR=$(SRC_ROOT)/gpgme-1.1.8
|
||||||
|
#GPG_ERROR_DIR=$(SRC_ROOT)/libgpg-error-1.7
|
||||||
|
|
||||||
|
#ZLIB_DIR=$(SRC_ROOT)/zlib-1.2.3
|
||||||
|
#UPNPC_DIR=$(SRC_ROOT)/miniupnpc-1.0
|
||||||
|
#PTHREADS_DIR=$(SRC_ROOT)/pthreads-w32-2-8-0-release
|
||||||
|
|
||||||
|
include $(RS_TOP_DIR)/scripts/checks.mk
|
||||||
|
|
||||||
|
############ ENFORCE DIRECTORY NAMING #######################################
|
||||||
|
|
||||||
|
CC = g++
|
||||||
|
RM = /bin/rm
|
||||||
|
RANLIB = ranlib
|
||||||
|
LIBDIR = $(RS_TOP_DIR)/lib
|
||||||
|
LIBRS = $(LIBDIR)/libretroshare.a
|
||||||
|
|
||||||
|
# Unix: Linux/Cygwin
|
||||||
|
INCLUDE = -I $(RS_TOP_DIR)
|
||||||
|
|
||||||
|
ifdef PQI_DEBUG
|
||||||
|
CFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
else
|
||||||
|
CFLAGS = -Wall -O2 $(INCLUDE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# These aren't used anymore.... really.
|
||||||
|
ifdef PQI_USE_XPGP
|
||||||
|
CFLAGS += -DPQI_USE_XPGP
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_PROXY
|
||||||
|
CFLAGS += -DPQI_USE_PROXY
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef PQI_USE_CHANNELS
|
||||||
|
CFLAGS += -DPQI_USE_CHANNELS
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef USE_FILELOOK
|
||||||
|
CFLAGS += -DUSE_FILELOOK
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# SSL / pthreads / Zlib
|
||||||
|
# included by default for Windows compilation.
|
||||||
|
INCLUDE += -I $(SSL_DIR)/include
|
||||||
|
INCLUDE += -I$(PTHREADS_DIR)
|
||||||
|
INCLUDE += -I$(ZLIB_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS Compile Options
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# For the SSL BIO compilation. (Copied from OpenSSL compilation flags)
|
||||||
|
BIOCC = gcc
|
||||||
|
|
||||||
|
# Cygwin - ?same? as Linux flags
|
||||||
|
BIOCFLAGS = -I $(SSL_DIR)/include -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DOPENSSL_NO_KRB5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -DSHA1_ASM -DMD5_ASM -DRMD160_ASM
|
||||||
|
BIOCFLAGS += -DWINDOWS_SYS
|
||||||
|
|
||||||
|
#########################################################################
|
||||||
|
# OS specific Linking.
|
||||||
|
#########################################################################
|
||||||
|
|
||||||
|
# for static pthread libs....
|
||||||
|
#WININC += -DPTW32_STATIC_LIB
|
||||||
|
#WININC += -mno-cygwin -mwindows -fno-exceptions
|
||||||
|
|
||||||
|
WININC += -DWINDOWS_SYS
|
||||||
|
|
||||||
|
WINLIB = -lws2_32 -luuid -lole32 -liphlpapi
|
||||||
|
WINLIB += -lcrypt32 -lwinmm
|
||||||
|
|
||||||
|
CFLAGS += -I$(SSL_DIR)/include
|
||||||
|
CFLAGS += -I$(PTHREADS_DIR)/include
|
||||||
|
CFLAGS += -I$(ZLIB_DIR)
|
||||||
|
CFLAGS += -I$(SRC_ROOT_GPG)/include
|
||||||
|
|
||||||
|
### Enable this for GPGME and GPG ERROR dirs
|
||||||
|
#CFLAGS += -I$(GPGME_DIR)/src
|
||||||
|
#CFLAGS += -I$(GPG_ERROR_DIR)/src
|
||||||
|
|
||||||
|
CFLAGS += $(WININC)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
LIBS = -L$(LIBDIR) -lretroshare
|
||||||
|
|
||||||
|
LIBS += -L$(SSL_DIR)
|
||||||
|
|
||||||
|
LIBS += -lssl -lcrypto
|
||||||
|
LIBS += -L$(UPNPC_DIR) -lminiupnpc
|
||||||
|
LIBS += -L$(ZLIB_DIR) -lz
|
||||||
|
LIBS += -L$(PTHREADS_DIR) -lpthreadGC2d
|
||||||
|
LIBS += $(WINLIB)
|
||||||
|
|
||||||
|
#RSCFLAGS = -Wall -g $(INCLUDE)
|
||||||
|
#RSCFLAGS += $(WININC)
|
||||||
|
|
||||||
|
|
27
libretroshare/src/tests/scripts/config.mk
Normal file
27
libretroshare/src/tests/scripts/config.mk
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
# determine which operating system
|
||||||
|
#
|
||||||
|
###########################################################################
|
||||||
|
#Define OS.
|
||||||
|
#
|
||||||
|
OS = Linux
|
||||||
|
#OS = MacOSX
|
||||||
|
#OS = Cygwin
|
||||||
|
#OS = Win # MinGw.
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
ifeq ($(OS),Linux)
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/config-linux.mk
|
||||||
|
else
|
||||||
|
ifeq ($(OS),MacOSX)
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/config-macosx.mk
|
||||||
|
else
|
||||||
|
ifeq ($(OS),Cygwin)
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/config-cygwin.mk
|
||||||
|
else
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/config-mingw.mk
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
###########################################################################
|
25
libretroshare/src/tests/scripts/regress.mk
Normal file
25
libretroshare/src/tests/scripts/regress.mk
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
testoutputfiles = $(foreach tt,$(1),$(tt).tstout)
|
||||||
|
|
||||||
|
%.tstout : %.sh
|
||||||
|
-sh ./$< > $@ 2>&1
|
||||||
|
|
||||||
|
%.tstout : %
|
||||||
|
-./$< > $@ 2>&1
|
||||||
|
|
||||||
|
TESTOUT = $(call testoutputfiles,$(TESTS))
|
||||||
|
|
||||||
|
.phony : tests regress retest clobber
|
||||||
|
|
||||||
|
tests: $(TESTS)
|
||||||
|
|
||||||
|
regress: $(TESTOUT)
|
||||||
|
@-echo "--------------- SUCCESS (count):"
|
||||||
|
@-grep -c SUCCESS $(TESTOUT)
|
||||||
|
@-echo "--------------- FAILURE REPORTS:"
|
||||||
|
@-grep FAILURE $(TESTOUT) || echo no failures
|
||||||
|
@-echo "--------------- end"
|
||||||
|
|
||||||
|
retest:
|
||||||
|
-/bin/rm $(TESTOUT)
|
||||||
|
|
23
libretroshare/src/tests/scripts/rules.mk
Normal file
23
libretroshare/src/tests/scripts/rules.mk
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
# defines required / used.
|
||||||
|
#
|
||||||
|
# CFLAGS
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
librs: $(RSOBJ)
|
||||||
|
$(AR) r $(LIBRS) $(RSOBJ)
|
||||||
|
$(RANLIB) $(LIBRS)
|
||||||
|
|
||||||
|
.cc.o:
|
||||||
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-/bin/rm $(RSOBJ) $(EXECOBJ) $(TESTOBJ)
|
||||||
|
|
||||||
|
clobber: clean retest
|
||||||
|
-/bin/rm $(EXEC) $(TESTS)
|
||||||
|
|
||||||
|
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/regress.mk
|
||||||
|
|
57
libretroshare/src/tests/serialiser/Makefile
Normal file
57
libretroshare/src/tests/serialiser/Makefile
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
RS_TOP_DIR = ../..
|
||||||
|
##### Define any flags that are needed for this section #######
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
TESTOBJ = tlvbase_test.o tlvbase_test2.o tlvfileitem_test.o
|
||||||
|
TESTOBJ += tlvitems_test.o tlvstack_test.o tlvconfig_test.o
|
||||||
|
TESTOBJ += rsserial_test.o rstlvwidetest.o tlvrandom_test.o
|
||||||
|
|
||||||
|
TESTS = tlvbase_test tlvbase_test2 tlvfileitem_test
|
||||||
|
TESTS += tlvitems_test tlvstack_test tlvconfig_test
|
||||||
|
TESTS += rstlvwidetest tlvrandom_test
|
||||||
|
#rsserial_test
|
||||||
|
|
||||||
|
#rsbaseitem_test
|
||||||
|
|
||||||
|
all: tests
|
||||||
|
|
||||||
|
tlvbase_test : tlvbase_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvbase_test tlvbase_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvbase_test2 : tlvbase_test2.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvbase_test2 tlvbase_test2.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvfileitem_test : tlvfileitem_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvfileitem_test tlvfileitem_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvitems_test : tlvitems_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvitems_test tlvitems_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvstack_test : tlvstack_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvstack_test tlvstack_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvconfig_test : tlvconfig_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvconfig_test tlvconfig_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
rsserial_test : rsserial_test.o
|
||||||
|
$(CC) $(CFLAGS) -o rsserial_test rsserial_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
rsbaseitem_test : rsbaseitem_test.o
|
||||||
|
$(CC) $(CFLAGS) -o rsbaseitem_test rsbaseitem_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
rstlvwidetest : rstlvwidetest.o
|
||||||
|
$(CC) $(CFLAGS) -o rstlvwidetest rstlvwidetest.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
tlvrandom_test : tlvrandom_test.o
|
||||||
|
$(CC) $(CFLAGS) -o tlvrandom_test tlvrandom_test.o $(OBJ) $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
include $(RS_TOP_DIR)/scripts/rules.mk
|
||||||
|
###############################################################
|
||||||
|
|
191
libretroshare/src/tests/serialiser/rsbaseitem_test.cc
Normal file
191
libretroshare/src/tests/serialiser/rsbaseitem_test.cc
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: rsbaseitem_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsFileItem();
|
||||||
|
static int test_RsFileData();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsFile[Item/Data/...] Tests" << std::endl;
|
||||||
|
|
||||||
|
test_RsFileItem();
|
||||||
|
test_RsFileData();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvFile[Item/Data/...] Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvFileItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RsTlvFileItem i1;
|
||||||
|
RsTlvFileItem i2;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
i1.filesize = 101010;
|
||||||
|
i1.hash = "ABCDEFEGHE";
|
||||||
|
i1.name = "TestFile.txt";
|
||||||
|
i1.pop = 12;
|
||||||
|
i1.age = 456;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
/* do it again without optional data */
|
||||||
|
i1.filesize = 123;
|
||||||
|
i1.name = "";
|
||||||
|
i1.pop = 0;
|
||||||
|
i1.age = 0;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
/* one more time - long file name, some optional data */
|
||||||
|
i1.filesize = 123;
|
||||||
|
i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend";
|
||||||
|
i1.pop = 666;
|
||||||
|
i1.age = 0;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileItem");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvFileSet()
|
||||||
|
{
|
||||||
|
RsTlvFileSet s1;
|
||||||
|
RsTlvFileSet s2;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
RsTlvFileItem fi;
|
||||||
|
fi.filesize = 16 + i * i;
|
||||||
|
fi.hash = "ABCDEF";
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "File" << i << "_inSet.txt";
|
||||||
|
fi.name = out.str();
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
fi.age = 10 * i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fi.age = 0;
|
||||||
|
}
|
||||||
|
fi.pop = 0;
|
||||||
|
|
||||||
|
s1.items.push_back(fi);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||||
|
|
||||||
|
/* check the data is the same - TODO */
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileSet");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_RsTlvFileData()
|
||||||
|
{
|
||||||
|
RsTlvFileData d1;
|
||||||
|
RsTlvFileData d2;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
d1.file.filesize = 101010;
|
||||||
|
d1.file.hash = "ABCDEFEGHE";
|
||||||
|
d1.file.name = "";
|
||||||
|
d1.file.age = 0;
|
||||||
|
d1.file.pop = 0;
|
||||||
|
|
||||||
|
char data[15];
|
||||||
|
d1.binData.setBinData(data, 15);
|
||||||
|
|
||||||
|
d1.file_offset = 222;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(d1.file.filesize == d2.file.filesize);
|
||||||
|
CHECK(d1.file.hash == d2.file.hash);
|
||||||
|
CHECK(d1.file.name == d2.file.name);
|
||||||
|
CHECK(d1.file.path == d2.file.path);
|
||||||
|
CHECK(d1.file.pop == d2.file.pop);
|
||||||
|
CHECK(d1.file.age == d2.file.age);
|
||||||
|
|
||||||
|
CHECK(d1.file_offset == d2.file_offset);
|
||||||
|
CHECK(d1.binData.bin_len == d2.binData.bin_len);
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileData");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
88
libretroshare/src/tests/serialiser/rstlvwidetest.cc
Normal file
88
libretroshare/src/tests/serialiser/rstlvwidetest.cc
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: rstlvkvwidetest.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Chris Parker
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "serialiser/rstlvkvwide.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
/* define utility functions to test out with */
|
||||||
|
|
||||||
|
//static int testRstlvWide();
|
||||||
|
static int testRsTlvWideSet();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvWideTest[Item/Data/...] Tests" << std::endl;
|
||||||
|
|
||||||
|
testRsTlvWideSet();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvWideTest[Item/Data/...] Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
int testRsTlvWideSet()
|
||||||
|
{
|
||||||
|
RsTlvKeyValueWideSet i1, i2; // one to set and other to get
|
||||||
|
RsTlvKeyValueWide i_pair; // input pair
|
||||||
|
RsTlvFileItem hello;
|
||||||
|
|
||||||
|
std::string randString("it should work now.");
|
||||||
|
int j, k;
|
||||||
|
|
||||||
|
std::cerr << "entering loop now" << std::endl;
|
||||||
|
/* store a 15 random pairs */
|
||||||
|
|
||||||
|
for(int i = 0; i < 15 ; i++)
|
||||||
|
{
|
||||||
|
j = rand() % 4;
|
||||||
|
k = rand() % 4;
|
||||||
|
std::cerr << "j: " << j << " k: " << k << std::endl;
|
||||||
|
i_pair.wKey.assign(randString.begin(), randString.end());
|
||||||
|
std::cerr << "loop count:" << i << std::endl;
|
||||||
|
i_pair.wValue.assign(randString.begin(), randString.end());
|
||||||
|
std::cerr << "loop count:" << i << std::endl;
|
||||||
|
i1.wPairs.push_back(i_pair);
|
||||||
|
|
||||||
|
i_pair.TlvClear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "out of loop now" << std::endl;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
|
||||||
|
REPORT("Serialize/Deserialize RsTlvKeyValueWideSet");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
185
libretroshare/src/tests/serialiser/tlvbase_test.cc
Normal file
185
libretroshare/src/tests/serialiser/tlvbase_test.cc
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvbase_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Horatio.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "serialiser/rstlvbase.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
#include "util/rsnet.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsTlvBase();
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << " RsTlvBase Tests" <<std::endl;
|
||||||
|
|
||||||
|
test_RsTlvBase();
|
||||||
|
FINALREPORT("RsTlvBase Tests");
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int test_RsTlvBase()
|
||||||
|
{
|
||||||
|
//uint32_t array[] = {0x122, 0x234};
|
||||||
|
char data[20];
|
||||||
|
memset((void*)data, 65, sizeof(data)); // In ASCII 'A' =65
|
||||||
|
|
||||||
|
|
||||||
|
std::string out;
|
||||||
|
|
||||||
|
data[0]=0;
|
||||||
|
data[1]=0;
|
||||||
|
data[2]=0;
|
||||||
|
data[3]=8;
|
||||||
|
uint32_t off =0;
|
||||||
|
GetTlvString((void*)data, 20, &off, 0, out);
|
||||||
|
|
||||||
|
CHECK(out == "AAAA");
|
||||||
|
|
||||||
|
std::cout << "Output is : " << out << std::endl;
|
||||||
|
|
||||||
|
uint16_t data2[] = {0, 0x0300};
|
||||||
|
|
||||||
|
uint16_t t = GetTlvSize((void*) data2);
|
||||||
|
|
||||||
|
|
||||||
|
CHECK( t == ntohs(0x0300));
|
||||||
|
|
||||||
|
//std::cout << "GetTlvSize = " <<t <<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
|
||||||
|
//*************Test SetTlvBase***********
|
||||||
|
{
|
||||||
|
uint16_t data3 [2];
|
||||||
|
off =0;
|
||||||
|
uint32_t *offset = &off;
|
||||||
|
uint32_t const SIZE_SetTlvBase=4;
|
||||||
|
uint32_t val_before = *offset;
|
||||||
|
SetTlvBase((void *)data3, SIZE_SetTlvBase, offset, 0x0011, 0x0001);
|
||||||
|
|
||||||
|
CHECK(*offset - val_before == SIZE_SetTlvBase);
|
||||||
|
CHECK(0x0011 == ntohs(data3[0]));
|
||||||
|
CHECK(0x0001 == ntohs(data3[1]));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
REPORT("Test SetTlvBase");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test GetTlvUInt32 & SetTlvGetUInt32
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
uint16_t data4[4];
|
||||||
|
bool ok = true;
|
||||||
|
uint32_t off =0;
|
||||||
|
uint32_t pre_set_off = off;
|
||||||
|
uint32_t* offset = &off;
|
||||||
|
uint32_t out = 3324;
|
||||||
|
*offset =0;
|
||||||
|
ok = SetTlvUInt32((void*)data4, 8, offset, 0x0011, out);
|
||||||
|
CHECK(*offset - pre_set_off == 8);
|
||||||
|
|
||||||
|
uint32_t readPos = 0;
|
||||||
|
offset = &readPos;
|
||||||
|
uint32_t in =0;
|
||||||
|
ok &= GetTlvUInt32((void*)data4, 8, offset, 0x0011, &in);
|
||||||
|
CHECK(*offset - pre_set_off == 8);
|
||||||
|
CHECK(in == out);
|
||||||
|
|
||||||
|
std::cerr<<"in = " <<in <<std::endl;
|
||||||
|
std::cout << "*offset = " <<*offset <<std::endl;
|
||||||
|
std::cout <<std::hex << data4[2]<< " " <<data4[3] <<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
uint16_t data4[4];
|
||||||
|
data4[0] = 0x0500; /* type (little-endian?) */
|
||||||
|
data4[1] = 0x0800; /* size (little-endian?) */
|
||||||
|
data4[3]=0x0000;
|
||||||
|
data4[2] = 0xFFFF;
|
||||||
|
uint32_t got;
|
||||||
|
uint32_t off =0;
|
||||||
|
uint32_t*offset = &off;
|
||||||
|
GetTlvUInt32((void*)data4, 8, offset, 5, &got);
|
||||||
|
CHECK(got ==0xFFFF0000);
|
||||||
|
std::cout << " got = " << std::hex << got <<std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
REPORT("Test TlvUInt32");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test GetTlvString()
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
std::string teststring = "Hello RS!";
|
||||||
|
uint16_t data5[4 + 20];
|
||||||
|
uint32_t pos =0;
|
||||||
|
uint32_t* offset = &pos;
|
||||||
|
uint32_t pre_pos = pos;
|
||||||
|
SetTlvString((void*)data5, sizeof(data5), offset, TLV_TYPE_STR_NAME, teststring);
|
||||||
|
uint16_t tlvsize = GetTlvStringSize(teststring);
|
||||||
|
CHECK(tlvsize == *offset);
|
||||||
|
CHECK(data5[0] == htons(TLV_TYPE_STR_NAME));
|
||||||
|
CHECK(data5[1] == htons(tlvsize));
|
||||||
|
|
||||||
|
std::string str((char*) ((char*)data5 +4) ,strlen("Hello RS!"));
|
||||||
|
CHECK(str == "Hello RS!");
|
||||||
|
|
||||||
|
// std::cout <<str <<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
std::string out_str;
|
||||||
|
|
||||||
|
pos =0;
|
||||||
|
GetTlvString((void*)data5, sizeof(data5), offset, TLV_TYPE_STR_NAME, out_str);
|
||||||
|
CHECK(out_str == "Hello RS!");
|
||||||
|
CHECK(*offset == sizeof(uint16_t)*2 + out_str.size());
|
||||||
|
uint16_t data6[2];
|
||||||
|
*offset =0;
|
||||||
|
SetTlvSize((void*)data6, sizeof(data6), 0x00000022);
|
||||||
|
std::cout << std::hex << data6[1] <<std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
REPORT("Test TlvString");
|
||||||
|
return 0;
|
||||||
|
}
|
191
libretroshare/src/tests/serialiser/tlvbase_test2.cc
Normal file
191
libretroshare/src/tests/serialiser/tlvbase_test2.cc
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvbase_test2.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvbase.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
#include "util/rsnet.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsTlvString();
|
||||||
|
static int test_RsTlvUInt32();
|
||||||
|
static int test_RsTlvIPAddr();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvBase Tests" << std::endl;
|
||||||
|
|
||||||
|
test_RsTlvString();
|
||||||
|
test_RsTlvUInt32();
|
||||||
|
test_RsTlvIPAddr();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvBase Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvUInt32()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_OneString(std::string input, uint16_t type);
|
||||||
|
|
||||||
|
int test_RsTlvString()
|
||||||
|
{
|
||||||
|
std::string nullString;
|
||||||
|
std::string oneString = "1";
|
||||||
|
std::string shortString = "ab cd";
|
||||||
|
std::string longString = "abcd efgh ijkl mnop qrst uvw";
|
||||||
|
|
||||||
|
std::cerr << "test_RsTlvString() Testing" << std::endl;
|
||||||
|
test_OneString(nullString, 1234);
|
||||||
|
test_OneString(oneString, 12);
|
||||||
|
test_OneString(shortString, 79);
|
||||||
|
test_OneString(longString, 7654);
|
||||||
|
|
||||||
|
REPORT("Serialise RsTlvFileItem");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_OneString(std::string input, uint16_t type)
|
||||||
|
{
|
||||||
|
/* an array to work from */
|
||||||
|
char tlvdata[2048];
|
||||||
|
std::string OutString;
|
||||||
|
|
||||||
|
std::cerr << "test_OneString() Testing ... Print/Serialise/Deserialise";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
/* start with SetTlvString() */
|
||||||
|
|
||||||
|
uint16_t initsize = GetTlvStringSize(input);
|
||||||
|
uint32_t outOffset = 0;
|
||||||
|
uint32_t inOffset = 0;
|
||||||
|
|
||||||
|
std::cerr << "Serialising: " << input << std::endl;
|
||||||
|
CHECK(SetTlvString((void*)tlvdata, 2048, &outOffset, type, input));
|
||||||
|
std::cerr << "Init Size: " << initsize << std::endl;
|
||||||
|
std::cerr << "Serialised Size: " << outOffset << std::endl;
|
||||||
|
displayRawPacket(std::cerr, tlvdata, outOffset);
|
||||||
|
|
||||||
|
CHECK(outOffset == initsize); /* check that the offset matches the size */
|
||||||
|
|
||||||
|
std::cerr << "DeSerialising" << std::endl;
|
||||||
|
|
||||||
|
/* fails if type is wrong! */
|
||||||
|
CHECK(0 == GetTlvString((void*)tlvdata, outOffset, &inOffset, type-1, OutString));
|
||||||
|
CHECK(GetTlvString((void*)tlvdata, outOffset, &inOffset, type, OutString));
|
||||||
|
|
||||||
|
CHECK(initsize == inOffset); /* check that the offset matches the size */
|
||||||
|
CHECK(input == OutString); /* check that strings match */
|
||||||
|
std::cerr << "Deserialised: Size: " << inOffset << std::endl;
|
||||||
|
std::cerr << "Deserialised: String: " << OutString << std::endl;
|
||||||
|
|
||||||
|
REPORT("Serialise OneString");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_IpAddr(struct sockaddr_in *addr, uint16_t type);
|
||||||
|
|
||||||
|
static int test_RsTlvIPAddr()
|
||||||
|
{
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
|
inet_aton("10.0.0.111", &(addr.sin_addr));
|
||||||
|
addr.sin_port = htons(1111);
|
||||||
|
|
||||||
|
test_IpAddr(&addr, 1234);
|
||||||
|
|
||||||
|
inet_aton("255.255.255.1", &(addr.sin_addr));
|
||||||
|
addr.sin_port = htons(9999);
|
||||||
|
|
||||||
|
test_IpAddr(&addr, 1234);
|
||||||
|
|
||||||
|
inet_aton("128.255.255.1", &(addr.sin_addr));
|
||||||
|
addr.sin_port = htons(0);
|
||||||
|
|
||||||
|
test_IpAddr(&addr, 1234);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_IpAddr(struct sockaddr_in *addr, uint16_t type)
|
||||||
|
{
|
||||||
|
/* an array to work from */
|
||||||
|
char tlvdata[2048];
|
||||||
|
struct sockaddr_in outaddr;
|
||||||
|
|
||||||
|
std::cerr << "test_IpAddr() Testing ... Print/Serialise/Deserialise";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
/* start with SetTlvString() */
|
||||||
|
|
||||||
|
uint16_t initsize = GetTlvIpAddrPortV4Size();
|
||||||
|
uint32_t outOffset = 0;
|
||||||
|
uint32_t inOffset = 0;
|
||||||
|
|
||||||
|
std::cerr << "Serialising IPAddr: " << inet_ntoa(addr->sin_addr) << std::endl;
|
||||||
|
std::cerr << " Port : " << ntohs(addr->sin_port) << std::endl;
|
||||||
|
|
||||||
|
CHECK(SetTlvIpAddrPortV4((void*)tlvdata, 2048, &outOffset, type, addr));
|
||||||
|
std::cerr << "Init Size: " << initsize << std::endl;
|
||||||
|
std::cerr << "Serialised Size: " << outOffset << std::endl;
|
||||||
|
displayRawPacket(std::cerr, tlvdata, outOffset);
|
||||||
|
|
||||||
|
CHECK(outOffset == initsize); /* check that the offset matches the size */
|
||||||
|
|
||||||
|
std::cerr << "DeSerialising" << std::endl;
|
||||||
|
|
||||||
|
/* fails if type is wrong! */
|
||||||
|
CHECK(0 == GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type-1, &outaddr));
|
||||||
|
CHECK(GetTlvIpAddrPortV4((void*)tlvdata, outOffset, &inOffset, type, &outaddr));
|
||||||
|
|
||||||
|
CHECK(initsize == inOffset); /* check that the offset matches the size */
|
||||||
|
CHECK(addr->sin_addr.s_addr == outaddr.sin_addr.s_addr); /* check that IP match */
|
||||||
|
CHECK(addr->sin_port == outaddr.sin_port); /* check that Port match */
|
||||||
|
std::cerr << "Deserialised: Size: " << inOffset << std::endl;
|
||||||
|
std::cerr << "Deserialised IPAddr: " << inet_ntoa(outaddr.sin_addr) << std::endl;
|
||||||
|
std::cerr << " Port : " << ntohs(outaddr.sin_port) << std::endl;
|
||||||
|
|
||||||
|
REPORT("Serialise OneIP/Port");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
192
libretroshare/src/tests/serialiser/tlvconfig_test.cc
Normal file
192
libretroshare/src/tests/serialiser/tlvconfig_test.cc
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvconfig_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Chris Parker.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvkvwide.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int testRsTlvPeerIdSet();
|
||||||
|
static int testRsTlvServiceIdSet();
|
||||||
|
static int testRsTlvKeyValue();
|
||||||
|
static int testRsTlvKeyValueSet();
|
||||||
|
static int testRsTlvWideSet();
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvConfig[Item/Data/...] Tests" << std::endl;
|
||||||
|
|
||||||
|
testRsTlvPeerIdSet();
|
||||||
|
testRsTlvServiceIdSet();//tbd
|
||||||
|
testRsTlvKeyValue();//tbd
|
||||||
|
testRsTlvKeyValueSet();//tbd
|
||||||
|
testRsTlvWideSet();
|
||||||
|
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvConfig[Item/Data/...] Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
int testRsTlvPeerIdSet()
|
||||||
|
{
|
||||||
|
|
||||||
|
RsTlvPeerIdSet i1, i2; // one to set and other to get
|
||||||
|
|
||||||
|
std::string testString;
|
||||||
|
|
||||||
|
std::string randString[5];
|
||||||
|
randString[0] = "e$424!<21>!<21>";
|
||||||
|
randString[1] = "e~:@L{L{KHKG";
|
||||||
|
randString[2] = "e{@O**/*/*";
|
||||||
|
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||||
|
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||||
|
|
||||||
|
/* store a number of random ids */
|
||||||
|
|
||||||
|
for(int i = 0; i < 15 ; i++)
|
||||||
|
{
|
||||||
|
testString = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||||
|
|
||||||
|
i1.ids.push_back(testString);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
|
||||||
|
REPORT("Serialize/Deserialize RsTlvPeerIdSet");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int testRsTlvServiceIdSet()
|
||||||
|
{
|
||||||
|
RsTlvServiceIdSet i1, i2; // one to set and other to get
|
||||||
|
|
||||||
|
|
||||||
|
/* store random numbers */
|
||||||
|
for(int i = 0; i < 15 ; i++)
|
||||||
|
{
|
||||||
|
i1.ids.push_back(1 + rand() % 12564);
|
||||||
|
}
|
||||||
|
std::cout << "error here!!!?";
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
REPORT("Serialize/Deserialize RsTlvServiceIdSet");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int testRsTlvKeyValue()
|
||||||
|
{
|
||||||
|
RsTlvKeyValue i1, i2; // one to set and other to get
|
||||||
|
|
||||||
|
i1.key = "whatever";
|
||||||
|
i1.value = "better work";
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
REPORT("Serialize/Deserialize RsTlvKeyValue");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int testRsTlvKeyValueSet()
|
||||||
|
{
|
||||||
|
RsTlvKeyValueSet i1, i2; // one to set and other to get
|
||||||
|
|
||||||
|
/* instantiate the objects values */
|
||||||
|
|
||||||
|
std::string randString[5];
|
||||||
|
randString[0] = "e$424!<21>!<21>";
|
||||||
|
randString[1] = "e~:@L{L{KHKG";
|
||||||
|
randString[2] = "e{@O**/*/*";
|
||||||
|
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||||
|
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||||
|
|
||||||
|
for(int i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
RsTlvKeyValue kv;
|
||||||
|
|
||||||
|
kv.key = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||||
|
kv.value = randString[(rand() % 4)] + randString[(rand() % 4)];
|
||||||
|
|
||||||
|
i1.pairs.push_back(kv);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
REPORT("Serialize/Deserialize RsTlvKeyValueSet");
|
||||||
|
}
|
||||||
|
|
||||||
|
int testRsTlvWideSet()
|
||||||
|
{
|
||||||
|
RsTlvKeyValueWideSet i1, i2; // one to set and other to get
|
||||||
|
RsTlvKeyValueWide i_pair; // input pair
|
||||||
|
RsTlvFileItem hello;
|
||||||
|
|
||||||
|
std::string randString[5];
|
||||||
|
randString[0] = "e$424!<21>!<21>";
|
||||||
|
randString[1] = "e~:@L{L{KHKG";
|
||||||
|
randString[2] = "e{@O**/*/*";
|
||||||
|
randString[3] = "e?<<BNMB>HG<48>!<21>%$";
|
||||||
|
randString[4] = "e><?<NVBCEE<45>$$%*^";
|
||||||
|
|
||||||
|
/* store a 15 random pairs */
|
||||||
|
|
||||||
|
for(int i = 0; i < 15 ; i++)
|
||||||
|
{
|
||||||
|
i_pair.wKey.assign(randString[(rand() % 4)].begin(), randString[(rand() % 4)].end());
|
||||||
|
i_pair.wValue.assign(randString[(rand() % 4)].begin(), randString[(rand() % 4)].end());
|
||||||
|
i1.wPairs.push_back(i_pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/*check that the data is the same*/
|
||||||
|
|
||||||
|
REPORT("Serialize/Deserialize RsTlvKeyValueWideSet");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
190
libretroshare/src/tests/serialiser/tlvfileitem_test.cc
Normal file
190
libretroshare/src/tests/serialiser/tlvfileitem_test.cc
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvfileitem_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsTlvFileItem();
|
||||||
|
static int test_RsTlvFileSet();
|
||||||
|
static int test_RsTlvFileData();
|
||||||
|
static int test_RsTlvFileStack();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvFile[Item/Data/...] Tests" << std::endl;
|
||||||
|
|
||||||
|
test_RsTlvFileItem();
|
||||||
|
test_RsTlvFileData();
|
||||||
|
test_RsTlvFileSet();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvFile[Item/Data/...] Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvFileItem()
|
||||||
|
{
|
||||||
|
RsTlvFileItem i1;
|
||||||
|
RsTlvFileItem i2;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
i1.filesize = 101010;
|
||||||
|
i1.hash = "ABCDEFEGHE";
|
||||||
|
i1.name = "TestFile.txt";
|
||||||
|
i1.pop = 12;
|
||||||
|
i1.age = 456;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
/* do it again without optional data */
|
||||||
|
i1.filesize = 123;
|
||||||
|
i1.name = "";
|
||||||
|
i1.pop = 0;
|
||||||
|
i1.age = 0;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
/* one more time - long file name, some optional data */
|
||||||
|
i1.filesize = 123;
|
||||||
|
i1.name = "A Very Long File name that should fit in easily ??? with som $&%&^%* strange char (**$^%#&^$#*^%(&^ in there too!!!! ~~~!!$#(^$)$)(&%^)&\" oiyu thend";
|
||||||
|
i1.pop = 666;
|
||||||
|
i1.age = 0;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &i1, &i2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(i1.filesize == i2.filesize);
|
||||||
|
CHECK(i1.hash == i2.hash);
|
||||||
|
CHECK(i1.name == i2.name);
|
||||||
|
CHECK(i1.path == i2.path);
|
||||||
|
CHECK(i1.pop == i2.pop);
|
||||||
|
CHECK(i1.age == i2.age);
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileItem");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvFileSet()
|
||||||
|
{
|
||||||
|
RsTlvFileSet s1;
|
||||||
|
RsTlvFileSet s2;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
RsTlvFileItem fi;
|
||||||
|
fi.filesize = 16 + i * i;
|
||||||
|
fi.hash = "ABCDEF";
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "File" << i << "_inSet.txt";
|
||||||
|
fi.name = out.str();
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
fi.age = 10 * i;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fi.age = 0;
|
||||||
|
}
|
||||||
|
fi.pop = 0;
|
||||||
|
|
||||||
|
s1.items.push_back(fi);
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &s1, &s2));
|
||||||
|
|
||||||
|
/* check the data is the same - TODO */
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileSet");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int test_RsTlvFileData()
|
||||||
|
{
|
||||||
|
RsTlvFileData d1;
|
||||||
|
RsTlvFileData d2;
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
d1.file.filesize = 101010;
|
||||||
|
d1.file.hash = "ABCDEFEGHE";
|
||||||
|
d1.file.name = "";
|
||||||
|
d1.file.age = 0;
|
||||||
|
d1.file.pop = 0;
|
||||||
|
|
||||||
|
char data[15];
|
||||||
|
d1.binData.setBinData(data, 15);
|
||||||
|
|
||||||
|
d1.file_offset = 222;
|
||||||
|
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||||
|
|
||||||
|
/* check the data is the same */
|
||||||
|
CHECK(d1.file.filesize == d2.file.filesize);
|
||||||
|
CHECK(d1.file.hash == d2.file.hash);
|
||||||
|
CHECK(d1.file.name == d2.file.name);
|
||||||
|
CHECK(d1.file.path == d2.file.path);
|
||||||
|
CHECK(d1.file.pop == d2.file.pop);
|
||||||
|
CHECK(d1.file.age == d2.file.age);
|
||||||
|
|
||||||
|
CHECK(d1.file_offset == d2.file_offset);
|
||||||
|
CHECK(d1.binData.bin_len == d2.binData.bin_len);
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvFileData");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
89
libretroshare/src/tests/serialiser/tlvitems_test.cc
Normal file
89
libretroshare/src/tests/serialiser/tlvitems_test.cc
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvitems_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsTlvBinData();
|
||||||
|
static int test_RsTlvStepping();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvItems Tests" << std::endl;
|
||||||
|
|
||||||
|
test_RsTlvBinData();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvItems Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BIN_LEN 523456 /* bigger than 64k */
|
||||||
|
|
||||||
|
int test_RsTlvBinData()
|
||||||
|
{
|
||||||
|
RsTlvBinaryData d1(1023);
|
||||||
|
RsTlvBinaryData d2(1023);
|
||||||
|
|
||||||
|
char data[BIN_LEN] = {0};
|
||||||
|
int i, j;
|
||||||
|
for(i = 0; i < BIN_LEN; i++)
|
||||||
|
{
|
||||||
|
data[i] = i%13;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(j = 1; j < BIN_LEN; j *= 2)
|
||||||
|
{
|
||||||
|
d1.setBinData(data, j);
|
||||||
|
CHECK(test_SerialiseTlvItem(std::cerr, &d1, &d2));
|
||||||
|
|
||||||
|
CHECK(d1.bin_len == d2.bin_len);
|
||||||
|
CHECK(0 == memcmp(d1.bin_data, d2.bin_data, d1.bin_len));
|
||||||
|
}
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvBinData");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_RsTlvStepping()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
194
libretroshare/src/tests/serialiser/tlvrandom_test.cc
Normal file
194
libretroshare/src/tests/serialiser/tlvrandom_test.cc
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvrandom_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2009 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvrandom_test.
|
||||||
|
*
|
||||||
|
* This test is designed to attempt to break the TLV serialiser.
|
||||||
|
*
|
||||||
|
* To do this we throw random data at the serialisers and try to decode it.
|
||||||
|
* As the serialiser will only attempt to deserialise if the tlvtype matches
|
||||||
|
* we cheat a little, and make this match - to increase to actual deserialise
|
||||||
|
* attempts.
|
||||||
|
*
|
||||||
|
* This test runs for 30 seconds and attempts to do as
|
||||||
|
* many deserialisation as possible.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "serialiser/rstlvbase.h"
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvkeys.h"
|
||||||
|
#include "serialiser/rstlvkvwide.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
#define TEST_LENGTH 30
|
||||||
|
|
||||||
|
static int test_TlvRandom(void *data, uint32_t len, uint32_t offset);
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "TlvRandom Tests" << std::endl;
|
||||||
|
|
||||||
|
/* random data array to work through */
|
||||||
|
uint32_t dsize = 10000000;
|
||||||
|
uint32_t i;
|
||||||
|
uint8_t *data = (uint8_t *) malloc(dsize);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to allocate array";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t startTs = time(NULL);
|
||||||
|
time_t endTs = startTs + TEST_LENGTH;
|
||||||
|
|
||||||
|
srandom(startTs);
|
||||||
|
for(i = 0; i < dsize; i++)
|
||||||
|
{
|
||||||
|
data[i] = random() % 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "TlvRandom Tests: setup data." << std::endl;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for(i = 0; endTs > time(NULL); i += 2)
|
||||||
|
{
|
||||||
|
uint32_t len = dsize - i;
|
||||||
|
count += test_TlvRandom(&(data[i]), len, i);
|
||||||
|
|
||||||
|
std::cerr << "Run: " << count << " tests";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvItems Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BIN_LEN 523456 /* bigger than 64k */
|
||||||
|
|
||||||
|
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset);
|
||||||
|
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset);
|
||||||
|
|
||||||
|
|
||||||
|
int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
|
||||||
|
{
|
||||||
|
uint32_t tmpoffset = 0;
|
||||||
|
|
||||||
|
/* List of all the TLV types it could be! */
|
||||||
|
RsTlvSecurityKey skey;
|
||||||
|
RsTlvSecurityKeySet skeyset;
|
||||||
|
RsTlvKeySignature keysign;
|
||||||
|
|
||||||
|
RsTlvBinaryData bindata(TLV_TYPE_IMAGE);
|
||||||
|
|
||||||
|
RsTlvFileItem fileitem;
|
||||||
|
RsTlvFileSet fileset;
|
||||||
|
RsTlvFileData filedata;
|
||||||
|
|
||||||
|
RsTlvPeerIdSet peerset;
|
||||||
|
RsTlvServiceIdSet servset;
|
||||||
|
|
||||||
|
RsTlvKeyValue kv;
|
||||||
|
RsTlvKeyValueSet kvset;
|
||||||
|
RsTlvKeyValueWide kvwide;
|
||||||
|
RsTlvKeyValueWideSet kvwideset;
|
||||||
|
|
||||||
|
RsTlvImage image;
|
||||||
|
|
||||||
|
/* try to decode - with all types first */
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Files " << std::endl;
|
||||||
|
test_TlvItem(&bindata, data, len, offset);
|
||||||
|
test_TlvItem(&fileitem, data, len, offset);
|
||||||
|
test_TlvItem(&fileset, data, len, offset);
|
||||||
|
test_TlvItem(&filedata, data, len, offset);
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Sets " << std::endl;
|
||||||
|
test_TlvItem(&peerset, data, len, offset);
|
||||||
|
test_TlvItem(&servset, data, len, offset);
|
||||||
|
test_TlvItem(&kv, data, len, offset);
|
||||||
|
test_TlvItem(&kvset, data, len, offset);
|
||||||
|
test_TlvItem(&kvwide, data, len, offset);
|
||||||
|
test_TlvItem(&kvwideset, data, len, offset);
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Keys " << std::endl;
|
||||||
|
test_TlvItem(&skey, data, len, offset);
|
||||||
|
test_TlvItem(&skeyset, data, len, offset);
|
||||||
|
test_TlvItem(&keysign, data, len, offset);
|
||||||
|
|
||||||
|
/* now set the type correctly before decoding */
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Files (TYPESET)" << std::endl;
|
||||||
|
test_SetTlvItem(&bindata, TLV_TYPE_IMAGE, data, len, offset);
|
||||||
|
test_SetTlvItem(&fileitem,TLV_TYPE_FILEITEM, data, len, offset);
|
||||||
|
test_SetTlvItem(&fileset, TLV_TYPE_FILESET, data, len, offset);
|
||||||
|
test_SetTlvItem(&filedata, TLV_TYPE_FILEDATA, data, len, offset);
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Sets (TYPESET)" << std::endl;
|
||||||
|
test_SetTlvItem(&peerset, TLV_TYPE_PEERSET, data, len, offset);
|
||||||
|
test_SetTlvItem(&servset, TLV_TYPE_SERVICESET, data, len, offset);
|
||||||
|
test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset);
|
||||||
|
test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset);
|
||||||
|
test_SetTlvItem(&kvwide, TLV_TYPE_WKEYVALUE, data, len, offset);
|
||||||
|
test_SetTlvItem(&kvwideset, TLV_TYPE_WKEYVALUESET, data, len, offset);
|
||||||
|
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
|
||||||
|
test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset);
|
||||||
|
test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset);
|
||||||
|
test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset);
|
||||||
|
|
||||||
|
return 26; /* number of tests */
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_TlvItem(RsTlvItem *item, void *data, uint32_t size, uint32_t offset)
|
||||||
|
{
|
||||||
|
uint32_t tmp_offset = offset;
|
||||||
|
if (item->GetTlv(data, size, &tmp_offset))
|
||||||
|
{
|
||||||
|
std::cerr << "TLV decoded Random!";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
item->print(std::cerr, 20);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "TLV failed to decode";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_SetTlvItem(RsTlvItem *item, uint16_t type, void *data, uint32_t size, uint32_t offset)
|
||||||
|
{
|
||||||
|
/* set TLV type first! */
|
||||||
|
void *typedata = (((uint8_t *) data) + offset);
|
||||||
|
SetTlvType(typedata, size - offset, type);
|
||||||
|
|
||||||
|
return test_TlvItem(item, data, size, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
104
libretroshare/src/tests/serialiser/tlvstack_test.cc
Normal file
104
libretroshare/src/tests/serialiser/tlvstack_test.cc
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
* libretroshare/src/serialiser: tlvstack_test.cc
|
||||||
|
*
|
||||||
|
* RetroShare Serialiser.
|
||||||
|
*
|
||||||
|
* Copyright 2007-2008 by Robert Fernie.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License Version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*
|
||||||
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/******************************************************************
|
||||||
|
* tlvfileitem test.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "serialiser/rstlvtypes.h"
|
||||||
|
#include "serialiser/rstlvutil.h"
|
||||||
|
#include "util/utest.h"
|
||||||
|
|
||||||
|
INITTEST();
|
||||||
|
|
||||||
|
static int test_RsTlvStack();
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cerr << "RsTlvItem Stack Tests" << std::endl;
|
||||||
|
|
||||||
|
test_RsTlvStack();
|
||||||
|
|
||||||
|
FINALREPORT("RsTlvItem Stack Tests");
|
||||||
|
|
||||||
|
return TESTRESULT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define BIN_LEN 53
|
||||||
|
|
||||||
|
int test_RsTlvStack()
|
||||||
|
{
|
||||||
|
|
||||||
|
/* now create a set of TLV items for the random generator */
|
||||||
|
|
||||||
|
RsTlvBinaryData *bd1 = new RsTlvBinaryData(123);
|
||||||
|
RsTlvBinaryData *bd2 = new RsTlvBinaryData(125);
|
||||||
|
|
||||||
|
char data[BIN_LEN] = {0};
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < BIN_LEN; i++)
|
||||||
|
{
|
||||||
|
data[i] = i%13;
|
||||||
|
}
|
||||||
|
|
||||||
|
bd1->setBinData(data, 5);
|
||||||
|
bd2->setBinData(data, 21);
|
||||||
|
|
||||||
|
RsTlvFileItem *fi1 = new RsTlvFileItem();
|
||||||
|
RsTlvFileItem *fi2 = new RsTlvFileItem();
|
||||||
|
|
||||||
|
/* initialise */
|
||||||
|
fi1->filesize = 101010;
|
||||||
|
fi1->hash = "ABCDEFEGHE";
|
||||||
|
fi1->name = "TestFile.txt";
|
||||||
|
fi1->pop = 12;
|
||||||
|
fi1->age = 456;
|
||||||
|
|
||||||
|
fi2->filesize = 101010;
|
||||||
|
fi2->hash = "ABCDEFEGHE";
|
||||||
|
fi2->name = "TestFile.txt";
|
||||||
|
fi2->pop = 0;
|
||||||
|
fi2->age = 0;;
|
||||||
|
|
||||||
|
std::vector<RsTlvItem *> items;
|
||||||
|
items.resize(4);
|
||||||
|
items[0] = bd1;
|
||||||
|
items[1] = bd2;
|
||||||
|
items[2] = fi1;
|
||||||
|
items[3] = fi2;
|
||||||
|
|
||||||
|
test_TlvSet(items, 1024);
|
||||||
|
|
||||||
|
REPORT("Serialise/Deserialise RsTlvBinData");
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user