From fff3fb8c3e9e01aa438102e4522f374b7c03adf3 Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Mon, 2 Jan 2023 18:25:51 +0100 Subject: [PATCH] feat: adjust tdd --- .gitignore | 2 ++ write-location-file/main.c | 2 +- .../write-location-file-test.c | 34 +++++++++++++++---- write-location-file/write-location-file.c | 6 ++-- write-location-file/write-location-file.h | 2 +- 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbfb6d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.csv +a.out diff --git a/write-location-file/main.c b/write-location-file/main.c index 69866b1..78da8b3 100644 --- a/write-location-file/main.c +++ b/write-location-file/main.c @@ -38,7 +38,7 @@ int main() fprintf(fp, "%8s,%8s\n", lat, lon); fclose(fp); - write_location_file(); + write_location_file("52.26594", "10.52673"); printf("\nDone!\n"); return 0; diff --git a/write-location-file/write-location-file-test.c b/write-location-file/write-location-file-test.c index 3ebd6d2..0a3cee2 100644 --- a/write-location-file/write-location-file-test.c +++ b/write-location-file/write-location-file-test.c @@ -1,16 +1,38 @@ /*write-location-file-test.c*/ - #include "write-location-file.h" -/*use printf*/ -//#include - #include #include +#include +#include +#include + +/*use macro extern int errno*/ +#include + static void test(){ - //printf("write_location_file() return %d:\n",write_location_file()); - assert(write_location_file()==0 && "test()"); + FILE* read; + char buf[17]; + read = fopen("location-file.csv", "a+"); + + if (NULL == read) { + /*failed to open file and associate stream*/ + fprintf(stderr, "Value of errno: %d\n", errno); + fprintf(stderr, "Error opening file: %s\n", strerror(errno)); + } + + //printf("content of this file are \n"); + fscanf(read, "%17s", buf); + printf("test() buf: %17s\n", buf); + + fclose(read); + + char result[18] = "52.26594,10.52673"; + printf("test() result: %17s\n", result); + + assert(strcmp(buf, result)==0 && "test()"); + //assert(write_location_file("52.26594", "10.52673")==0 && "test()"); } int main(){ diff --git a/write-location-file/write-location-file.c b/write-location-file/write-location-file.c index 8b5497b..70f6f92 100644 --- a/write-location-file/write-location-file.c +++ b/write-location-file/write-location-file.c @@ -8,12 +8,14 @@ #include #include -int write_location_file(){ +int write_location_file(char *lat, char *lon){ FILE *fp; printf("\nwrite-location-file() Start...\n"); + printf("\nwrite-location-file() lat: %s, lon: %s\n", lat, lon); + fp = fopen("location-file.csv", "w"); if (fp==NULL) { @@ -24,7 +26,7 @@ int write_location_file(){ /*latitude e.g. 52.26594*/ /*longitude e.g. 10.52673*/ - fprintf(fp, "52.26594,10.52673\n"); + fprintf(fp, "%s,%s\n", lat, lon); fclose(fp); printf("\nwrite-location-file() Done!\n"); diff --git a/write-location-file/write-location-file.h b/write-location-file/write-location-file.h index 4595843..617d3db 100644 --- a/write-location-file/write-location-file.h +++ b/write-location-file/write-location-file.h @@ -1,3 +1,3 @@ /*write-location-file.h*/ -int write_location_file(); +int write_location_file(char *lat, char *lon);