diff --git a/libc-test/src/functional/fscanf.c b/libc-test/src/functional/fscanf.c index 45e0c5e66fe9849e062459fdf9fd87ff3616f937..4a518b53685d32da555ee2399d8e699ca3448afb 100644 --- a/libc-test/src/functional/fscanf.c +++ b/libc-test/src/functional/fscanf.c @@ -5,6 +5,11 @@ #include #include "test.h" +#define CONTENT "0.1234567\n" +#define EXPECT 0.1234567 +#define TMP_FILE "/data/local/tmp/fscanf_test.txt" +#define TOTAL 515 + #define TEST(r, f, x, m) ( \ errno=0, ((r) = (f)) == (x) || \ (t_error("%s failed (" m ")\n", #f, r, x, strerror(errno)), 0) ) @@ -25,6 +30,45 @@ static FILE *writetemp(const char *data) return f; } +void write_content() +{ + FILE *fp; + fp = fopen(TMP_FILE, "w"); + if (fp == NULL) { + t_error("FAIL %s create failed!\n", TMP_FILE); + } + for (size_t i = 0; i < TOTAL; i++) { + fwrite(CONTENT, sizeof(char), strlen(CONTENT), fp); + } + fclose(fp); +} + +void check_content() +{ + FILE *fp; + int res; + double value = 0; + fp = fopen(TMP_FILE, "r"); + if (fp == NULL) { + t_error("FAIL %s open failed!\n", TMP_FILE); + } + for (size_t i = 0; i < TOTAL; i++) { + res = fscanf(fp, "%lf", &value); + if (res != 1 || value != EXPECT) { + t_error("FAIL: fscanf expect %lf but get %lf, index=%d\n", EXPECT, value, i); + } + } + fclose(fp); +} + +void test_read_large_data() +{ + write_content(); + check_content(); + remove(TMP_FILE); +} + + int main(void) { int i, x, y; @@ -131,5 +175,7 @@ int main(void) fclose(f); } + test_read_large_data(); + return t_status; }