diff --git a/tests/File-Page Abstraction/2/.gitignore b/tests/File-Page Abstraction/2/.gitignore new file mode 100644 index 0000000..f5bdd21 --- /dev/null +++ b/tests/File-Page Abstraction/2/.gitignore @@ -0,0 +1 @@ +run diff --git a/tests/File-Page Abstraction/2/compile.sh b/tests/File-Page Abstraction/2/compile.sh new file mode 100755 index 0000000..3255eb8 --- /dev/null +++ b/tests/File-Page Abstraction/2/compile.sh @@ -0,0 +1,5 @@ +#!/bin/sh +if [ ! -d run ]; then + mkdir run +fi +gcc -g filePageTest2.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest2 \ No newline at end of file diff --git a/tests/File-Page Abstraction/2/filePageTest2.c b/tests/File-Page Abstraction/2/filePageTest2.c new file mode 100644 index 0000000..77009e4 --- /dev/null +++ b/tests/File-Page Abstraction/2/filePageTest2.c @@ -0,0 +1,36 @@ +#include "../../../File-Page Abstraction/cdb_file-page.h" +#include + +int main() { + fp_File file = fp_fileTemp("created", 512); + + if(file == NULL) { + printf("file is null\n"); + return 1; + } + + char * memory = fp_fileToMemroy(file); + memory[0] = 'a'; + memory[511] = 'b'; + + printf("Append pages\n"); + memory = fp_fileAppendPages(file, 1); + if(memory == NULL) { + printf("memory is null\n"); + return 1; + } + memory[1023] = 'z'; + + printf("Close\n"); + fp_fileClose(file); + + printf("Open\n"); + file = fp_fileOpen("created"); + if(file == NULL) { + printf("second file is null\n"); + return 0; + }else { + printf("second file was NOT null\n"); + return 1; + } +} \ No newline at end of file diff --git a/tests/File-Page Abstraction/2/run.sh b/tests/File-Page Abstraction/2/run.sh new file mode 100755 index 0000000..94f05d7 --- /dev/null +++ b/tests/File-Page Abstraction/2/run.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +./compile.sh +cd run + +# Test 1 +echo "-- Test 1" +echo "Expected output: second file is null" +./filePageTest2 + +# Test 2 +echo "-- Test 2" +echo "Expected output: file is null" +touch created +./filePageTest2 +rm created + +cd .. \ No newline at end of file