summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/include/test_memory_chunk.cpp45
1 files changed, 21 insertions, 24 deletions
diff --git a/tests/include/test_memory_chunk.cpp b/tests/include/test_memory_chunk.cpp
index 6282d93..1edaecc 100755
--- a/tests/include/test_memory_chunk.cpp
+++ b/tests/include/test_memory_chunk.cpp
@@ -1,8 +1,7 @@
#include <stdio.h>
-#include <iostream>
#include "memory_chunk.h"
-// Test Memory Chunk Functionality
+//Test Memory Chunk Functionality
int main(int argc, char * argv[]){
MemoryChunk* chunk;
chunk = new MemoryChunk();
@@ -11,26 +10,27 @@ int main(int argc, char * argv[]){
int * p = (int *)chunk->begin();
assert(chunk->size() == sizeof(int));
- std::cout<<*p<<std::endl;
- std::cout<<chunk->capacity()<<std::endl;
+ printf("%d\n", *p);
+ printf("%d\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());
- std::cout<<chunk->capacity()<<std::endl;
+ printf("%d\n", chunk->capacity());
p = (int *)chunk->begin();
short * p2 =(short *)(((char *) (chunk->begin())) + sizeof(int));
- std::cout<<*p<<'\t'<<*p2<<std::endl;
+ 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());
- std::cout<<chunk->capacity()<<std::endl;
+ printf("%d\n", chunk->capacity());
p = (int *)chunk->begin();
p2 =(short *)(((char *) (chunk->begin())) + sizeof(int));
- std::cout<<*p<<'\t'<<*p2<<'\t'<<*(p2 + 1)<<std::endl;
+ printf("%d\t%d\t%d\n", *p, *p2, *(p2 + 1));
chunk->set_size(sizeof(int) + sizeof(short) *3);
p = (int *)chunk->begin();
@@ -39,7 +39,7 @@ int main(int argc, char * argv[]){
chunk->set_content(0, &i, sizeof(int));
*(p2+2) = 3;
- std::cout<<*p<<'\t'<<*p2<<'\t'<<*(p2 + 1)<<'\t'<<*(p2+2)<<std::endl;
+ 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);
@@ -49,30 +49,28 @@ int main(int argc, char * argv[]){
chunk->insert_content(sizeof(int), &n, sizeof(int));
int * p3 = (int *)chunk->begin();
- std::cout<<*p3<<'\t'<<*(p3+1)<<'\t'<<*(p3+2)<<std::endl;
+ printf("%d\t%d\t%d\n", *p3, *(p3+1), *(p3+2));
chunk->remove_content(sizeof(int), sizeof(int));
- std::cout<<*p3<<'\t'<<*(p3+1)<<std::endl;
+ printf("%d\t%d\n", *p3, *(p3+1));
int tmp;
assert(chunk->get_content(sizeof(int), &tmp, sizeof(int)));
- std::cout<<tmp<<std::endl;
-
-
+ printf("%d\n", tmp);
+
+ //clean up chunk
delete chunk;
const char * filename = "/tmp/version";
const char * version = "0.2.0";
+ //testing version check.
chunk = new MemoryChunk;
bool retval = chunk->load(filename);
if ( !retval ){
- std::cerr<<"can't find chunk"<<std::endl;
- }else{
- if ( memcmp(version, chunk->begin(), strlen(version) + 1) == 0){
- std::cout<<"match"<<std::endl;
- }
-
+ fprintf(stderr, "can't find chunk\n");
+ }else if ( memcmp(version, chunk->begin(), strlen(version) + 1) == 0){
+ printf("match\n");
}
chunk->set_content(0, version, strlen(version) + 1);
@@ -80,10 +78,9 @@ int main(int argc, char * argv[]){
retval = chunk->load(filename);
if ( !retval ){
- std::cerr<<"can't find chunk"<<std::endl;
- }
- if ( memcmp(version, chunk->begin(), strlen(version) + 1) == 0){
- std::cout<<"match"<<std::endl;
+ fprintf(stderr, "can't find chunk\n");
+ } else if ( memcmp(version, chunk->begin(), strlen(version) + 1) == 0){
+ printf("match\n");
}
return 0;