动态内存分配模块完成,并添加了测试程序
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include <include/dynamic_memory_allocation/main.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
struct data* _test = new_data();
|
||||
if(_test==NULL){
|
||||
return -1;
|
||||
}
|
||||
const char* _test_char = "Hello World!";
|
||||
if(write_data(_test,_test_char,strlen(_test_char))<0){
|
||||
return -2;
|
||||
}
|
||||
void* _test_buf = malloc(1024);
|
||||
memset(_test_buf,0,1024);
|
||||
memcpy(_test_buf,_test->pointer,strlen(_test->pointer));
|
||||
if(strcmp(_test_char,_test_buf)!=0){
|
||||
return -3;
|
||||
}
|
||||
memset(_test_buf,0,1024);
|
||||
if(read_data(*_test,_test_buf,0,(*_test).size)<0){
|
||||
return -4;
|
||||
}
|
||||
const char* _test_add_char = "TEST TEXT";
|
||||
if(add_data(_test,_test_add_char,strlen(_test_add_char))<0){
|
||||
return -5;
|
||||
}
|
||||
memcpy(_test_buf,_test->pointer,strlen(_test->pointer));
|
||||
void* _test_buf2 = malloc(1024);
|
||||
memset(_test_buf2,0,1024);
|
||||
memcpy(_test_buf2,_test_char,strlen(_test_char));
|
||||
strcat(_test_buf2,_test_add_char);
|
||||
if(strcmp(_test_buf2,_test_buf)!=0){
|
||||
return -6;
|
||||
}
|
||||
if(rm_data(_test)<0){
|
||||
return -7;
|
||||
}
|
||||
printf("Success! dynamic_memory_allocation\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user