feat: add tdd
This commit is contained in:
parent
9ede7ca889
commit
26694a270d
|
@ -4,6 +4,8 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "write-location-file.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -36,6 +38,8 @@ int main()
|
||||||
fprintf(fp, "%8s,%8s\n", lat, lon);
|
fprintf(fp, "%8s,%8s\n", lat, lon);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
write_location_file();
|
||||||
|
|
||||||
printf("\nDone!\n");
|
printf("\nDone!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#put the most commonly desired target first (default)
|
#put the most commonly desired target first (default)
|
||||||
all: main.o
|
all: main.o write-location-file.o
|
||||||
gcc main.o -o write
|
gcc main.o write-location-file.o -o write
|
||||||
main.o: main.c
|
main.o: main.c write-location-file.h
|
||||||
gcc -I . -c main.c
|
gcc -I . -c main.c
|
||||||
|
write-location-file.o: write-location-file.c write-location-file.h
|
||||||
|
gcc -I . -c write-location-file.c
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.o
|
rm -rf *.o
|
||||||
rm -rf write
|
rm -rf write
|
||||||
rm -rf *.csv
|
rm -rf *.csv
|
||||||
|
rm -rf a.out
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# tdd
|
||||||
|
|
||||||
|
* test write-location-file
|
||||||
|
|
||||||
|
```
|
||||||
|
gcc -Wall write-location-file-test.c write-location-file.c && ./a.out
|
||||||
|
```
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*write-location-file-test.c*/
|
||||||
|
|
||||||
|
#include "write-location-file.h"
|
||||||
|
|
||||||
|
/*use printf*/
|
||||||
|
//#include <stdio.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
static void test(){
|
||||||
|
//printf("write_location_file() return %d:\n",write_location_file());
|
||||||
|
assert(write_location_file()==0 && "test()");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
test();
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*write-location-file.c*/
|
||||||
|
|
||||||
|
#include "write-location-file.h"
|
||||||
|
|
||||||
|
#include<stdio.h>
|
||||||
|
|
||||||
|
/*use macro extern int errno*/
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int write_location_file(){
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nwrite-location-file() Start...\n");
|
||||||
|
|
||||||
|
fp = fopen("location-file.csv", "w");
|
||||||
|
if (fp==NULL)
|
||||||
|
{
|
||||||
|
/*failed to open file and associate stream*/
|
||||||
|
fprintf(stderr, "Value of errno: %d\n", errno);
|
||||||
|
fprintf(stderr, "Error opening file: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*latitude e.g. 52.26594*/
|
||||||
|
/*longitude e.g. 10.52673*/
|
||||||
|
fprintf(fp, "52.26594,10.52673\n");
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
printf("\nwrite-location-file() Done!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
/*write-location-file.h*/
|
||||||
|
|
||||||
|
int write_location_file();
|
Loading…
Reference in New Issue