]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/mbed/file/main.cpp
2 #include "semihost_api.h"
4 Serial
pc(USBTX
, USBRX
);
6 #define FILENAME "/local/out.txt"
7 #define TEST_STRING "Hello World!"
9 FILE *test_open(const char *mode
) {
10 FILE *f
= fopen(FILENAME
, mode
);
12 printf("Error opening file"NL
);
13 notify_completion(false);
18 void test_write(FILE *f
, char *str
, int str_len
) {
19 int n
= fprintf(f
, str
);
22 printf("Error writing file"NL
);
23 notify_completion(false);
27 void test_read(FILE *f
, char *str
, int str_len
) {
28 int n
= fread(str
, sizeof(unsigned char), str_len
, f
);
31 printf("Error reading file"NL
);
32 notify_completion(false);
36 void test_close(FILE *f
) {
40 printf("Error closing file"NL
);
41 notify_completion(false);
46 MBED_HOSTTEST_TIMEOUT(20);
47 MBED_HOSTTEST_SELECT(default_auto
);
48 MBED_HOSTTEST_DESCRIPTION(Semihost file system
);
49 MBED_HOSTTEST_START("MBED_A2");
51 pc
.printf("Test the Stream class\n");
53 printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
56 mbed_mac_address(mac
);
57 printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac
[0], mac
[1], mac
[2], mac
[3], mac
[4], mac
[5]);
59 LocalFileSystem
local("local");
62 char *str
= TEST_STRING
;
63 char *buffer
= (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING
));
64 int str_len
= strlen(TEST_STRING
);
68 test_write(f
, str
, str_len
);
73 test_read(f
, buffer
, str_len
);
76 // Check the two strings are equal
77 MBED_HOSTTEST_RESULT((strncmp(buffer
, str
, str_len
) == 0));