From f41d1fdf83408e042ab07925710a8913bad0c27c Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 3 Aug 2010 10:42:47 +0800 Subject: import from pinyin. --- tests/include/Makefile.am | 25 +++++++++++ tests/include/test_memory_chunk.cpp | 90 +++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tests/include/Makefile.am create mode 100755 tests/include/test_memory_chunk.cpp (limited to 'tests/include') diff --git a/tests/include/Makefile.am b/tests/include/Makefile.am new file mode 100644 index 0000000..53bc089 --- /dev/null +++ b/tests/include/Makefile.am @@ -0,0 +1,25 @@ +## Makefile.am -- Process this file with automake to produce Makefile.in +## Copyright (C) 2007 Peng Wu +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program 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 General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +INCLUDES = -I$(top_srcdir)/src/include + +noinst_PROGRAMS = test_memory_chunk + +test_memory_chunk_SOURCES = test_memory_chunk.cpp + +test_memory_chunk_LDADD = ../../src/storage/libstorage.la @GLIB2_LIBS@ + diff --git a/tests/include/test_memory_chunk.cpp b/tests/include/test_memory_chunk.cpp new file mode 100755 index 0000000..6282d93 --- /dev/null +++ b/tests/include/test_memory_chunk.cpp @@ -0,0 +1,90 @@ +#include +#include +#include "memory_chunk.h" +// Test Memory Chunk Functionality + +int main(int argc, char * argv[]){ + MemoryChunk* chunk; + chunk = new MemoryChunk(); + int i = 12; + chunk->set_content(0, &i, sizeof(int)); + + int * p = (int *)chunk->begin(); + assert(chunk->size() == sizeof(int)); + std::cout<<*p<capacity()<set_chunk(p, sizeof(int), NULL); + short t = 5; + chunk->set_content(sizeof(int), &t, sizeof(short)); + assert( sizeof(int) + sizeof(short) == chunk->size()); + std::cout<capacity()<begin(); + short * p2 =(short *)(((char *) (chunk->begin())) + sizeof(int)); + std::cout<<*p<<'\t'<<*p2<set_content(sizeof(int) + sizeof(short), &t, sizeof(short)); + + assert( sizeof(int) + (sizeof(short) << 1) == chunk->size()); + std::cout<capacity()<begin(); + p2 =(short *)(((char *) (chunk->begin())) + sizeof(int)); + std::cout<<*p<<'\t'<<*p2<<'\t'<<*(p2 + 1)<set_size(sizeof(int) + sizeof(short) *3); + p = (int *)chunk->begin(); + p2 =(short *)(((char *) (chunk->begin())) + sizeof(int)); + + chunk->set_content(0, &i, sizeof(int)); + + *(p2+2) = 3; + std::cout<<*p<<'\t'<<*p2<<'\t'<<*(p2 + 1)<<'\t'<<*(p2+2)<set_chunk(&m, sizeof(int), NULL); + int n = 12; + chunk->insert_content(sizeof(int), &n, sizeof(int)); + n = 11; + chunk->insert_content(sizeof(int), &n, sizeof(int)); + + int * p3 = (int *)chunk->begin(); + std::cout<<*p3<<'\t'<<*(p3+1)<<'\t'<<*(p3+2)<remove_content(sizeof(int), sizeof(int)); + std::cout<<*p3<<'\t'<<*(p3+1)<get_content(sizeof(int), &tmp, sizeof(int))); + std::cout<load(filename); + if ( !retval ){ + std::cerr<<"can't find chunk"<begin(), strlen(version) + 1) == 0){ + std::cout<<"match"<set_content(0, version, strlen(version) + 1); + chunk->save(filename); + + retval = chunk->load(filename); + if ( !retval ){ + std::cerr<<"can't find chunk"<begin(), strlen(version) + 1) == 0){ + std::cout<<"match"<