diff options
Diffstat (limited to 'tests/include')
-rw-r--r-- | tests/include/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/include/Makefile.am | 31 | ||||
-rw-r--r-- | tests/include/test_memory_chunk.cpp | 64 |
3 files changed, 104 insertions, 0 deletions
diff --git a/tests/include/CMakeLists.txt b/tests/include/CMakeLists.txt new file mode 100644 index 0000000..f51c87e --- /dev/null +++ b/tests/include/CMakeLists.txt @@ -0,0 +1,9 @@ +add_executable( + test_memory_chunk + test_memory_chunk.cpp +) + +target_link_libraries( + test_memory_chunk + libpinyin +)
\ No newline at end of file diff --git a/tests/include/Makefile.am b/tests/include/Makefile.am new file mode 100644 index 0000000..7174bec --- /dev/null +++ b/tests/include/Makefile.am @@ -0,0 +1,31 @@ +## 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +INCLUDES = -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/include \ + -I$(top_srcdir)/src/storage \ + -I$(top_srcdir)/src/lookup \ + @GLIB2_CFLAGS@ + +TESTS = test_memory_chunk + +noinst_PROGRAMS = test_memory_chunk + +test_memory_chunk_SOURCES = test_memory_chunk.cpp + +test_memory_chunk_LDADD = @GLIB2_LIBS@ + diff --git a/tests/include/test_memory_chunk.cpp b/tests/include/test_memory_chunk.cpp new file mode 100644 index 0000000..9779c8f --- /dev/null +++ b/tests/include/test_memory_chunk.cpp @@ -0,0 +1,64 @@ +#include <stdio.h> +#include "pinyin_internal.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)); + printf("%d\n", *p); + printf("%ld\n", chunk->capacity()); + + p = & i; + chunk->set_chunk(p, sizeof(int), NULL); + short t = 5; + chunk->set_content(sizeof(int), &t, sizeof(short)); + assert( sizeof(int) + sizeof(short) == chunk->size()); + printf("%ld\n", chunk->capacity()); + + p = (int *)chunk->begin(); + short * p2 =(short *)(((char *) (chunk->begin())) + sizeof(int)); + printf("%d\t%d\n", *p, *p2); + + chunk->set_content(sizeof(int) + sizeof(short), &t, sizeof(short)); + + assert( sizeof(int) + (sizeof(short) << 1) == chunk->size()); + printf("%ld\n", chunk->capacity()); + p = (int *)chunk->begin(); + p2 =(short *)(((char *) (chunk->begin())) + sizeof(int)); + printf("%d\t%d\t%d\n", *p, *p2, *(p2 + 1)); + + chunk->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; + printf("%d\t%d\t%d\t%d\n", *p, *p2, *(p2 + 1), *(p2+2)); + + int m = 10; + chunk->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(); + printf("%d\t%d\t%d\n", *p3, *(p3+1), *(p3+2)); + + chunk->remove_content(sizeof(int), sizeof(int)); + printf("%d\t%d\n", *p3, *(p3+1)); + + int tmp; + assert(chunk->get_content(sizeof(int), &tmp, sizeof(int))); + printf("%d\n", tmp); + + delete chunk; + + return 0; +} |