MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_reading

Function test_reading

test/test_files.c:28–61  ·  view source on GitHub ↗

Reading

Source from the content-addressed store, hash-verified

26
27// Reading
28void test_reading() {
29 FILE *file = fopen("somefile.binary", "rb");
30 assert(file);
31
32 fseek(file, 0, SEEK_END);
33 int size = ftell(file);
34 rewind (file);
35 printf("size: %d\n", size);
36
37 char *buffer = (char*)malloc(sizeof(char)*size);
38 assert(buffer);
39
40 size_t read = fread(buffer, 1, size, file);
41 assert(read == size);
42
43 printf("data: %d", buffer[0]);
44 for (int i = 1; i < size; i++)
45 printf(",%d", buffer[i]);
46 printf("\n");
47
48 fclose(file);
49 free(buffer);
50
51 // Do it again, with a loop on feof
52 printf("loop: ");
53 file = fopen("somefile.binary", "rb");
54 assert(file);
55 while (!feof(file)) {
56 char c = fgetc(file);
57 if (c != EOF) printf("%d ", c);
58 }
59 fclose(file);
60 printf("\n");
61}
62
63// Standard streams
64void test_stdstreams() {

Callers 1

mainFunction · 0.85

Calls 12

fopenFunction · 0.85
fseekFunction · 0.85
ftellFunction · 0.85
rewindFunction · 0.85
printfFunction · 0.85
freadFunction · 0.85
fcloseFunction · 0.85
feofFunction · 0.85
fgetcFunction · 0.85
assertFunction · 0.50
mallocFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected