sandbox-c/write-location-file/write-location-file-test.c

71 lines
1.9 KiB
C

#include "write-location-file.h"
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*use macro extern int errno*/
#include <errno.h>
char lat[11]="52.26594";
char lon[10]="10.52673";
static void test_write_stuct_location_file(){
FILE* read;
char buf[17];
/*create file*/
struct location lctnGet=getLocation(lat, lon);
write_struct_location_file(&lctnGet);
/*read file*/
read = fopen("struct-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_write_struct_location_file() buf: %17s\n", buf);
fclose(read);
char result[18] = "52.26594,10.52673";
printf("test_write_struct_location_file() result: %17s\n", result);
assert(strcmp(buf, result)==0 && "test_write_struct_location_file()");
}
static void test_write_location_file(){
FILE* read;
char buf[17];
/*create file*/
write_location_file(lat, lon);
/*read file*/
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_write_location_file() buf: %17s\n", buf);
fclose(read);
char result[18] = "52.26594,10.52673";
printf("test_write_location_file() result: %17s\n", result);
assert(strcmp(buf, result)==0 && "test_write_location_file()");
//assert(write_location_file("52.26594", "10.52673")==0 && "test_write_location_file()");
}
int main(){
test_write_location_file();
test_write_stuct_location_file();
}