Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
This commit is contained in:
parent
a20ef7052c
commit
1fe4406f37
4198 changed files with 2016457 additions and 0 deletions
|
@ -0,0 +1,63 @@
|
|||
#include "TestHarness.h"
|
||||
#include "mbed.h"
|
||||
#include "semihost_api.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define FILENAME "/local/out.txt"
|
||||
#define TEST_STRING "Hello World!"
|
||||
|
||||
TEST_GROUP(FirstTestGroup)
|
||||
{
|
||||
|
||||
FILE *test_open(const char *mode) {
|
||||
FILE *f = fopen(FILENAME, mode);
|
||||
return f;
|
||||
}
|
||||
|
||||
bool test_write(FILE *f, char *str, int str_len) {
|
||||
int n = fprintf(f, str);
|
||||
return (n == str_len) ? true : false;
|
||||
}
|
||||
|
||||
bool test_read(FILE *f, char *str, int str_len) {
|
||||
int n = fread(str, sizeof(unsigned char), str_len, f);
|
||||
return (n == str_len) ? true : false;
|
||||
}
|
||||
|
||||
bool test_close(FILE *f) {
|
||||
int rc = fclose(f);
|
||||
return rc ? true : false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST(FirstTestGroup, FirstTest)
|
||||
{
|
||||
CHECK_TEXT(semihost_connected(), "Semihost not connected")
|
||||
|
||||
LocalFileSystem local("local");
|
||||
|
||||
char *str = TEST_STRING;
|
||||
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
|
||||
int str_len = strlen(TEST_STRING);
|
||||
|
||||
CHECK_TEXT(buffer != NULL, "Buffer allocation failed");
|
||||
CHECK_TEXT(str_len > 0, "Test string is empty (len <= 0)");
|
||||
|
||||
{
|
||||
// Perform write / read tests
|
||||
FILE *f = NULL;
|
||||
// Write
|
||||
f = test_open("w");
|
||||
CHECK_TEXT(f != NULL, "Error opening file for writing")
|
||||
CHECK_TEXT(test_write(f, str, str_len), "Error writing file");
|
||||
CHECK_TEXT(test_close(f) != EOF, "Error closing file after write");
|
||||
|
||||
// Read
|
||||
f = test_open("r");
|
||||
CHECK_TEXT(f != NULL, "Error opening file for reading")
|
||||
CHECK_TEXT(test_read(f, buffer, str_len), "Error reading file");
|
||||
CHECK_TEXT(test_close(f) != EOF, "Error closing file after read");
|
||||
}
|
||||
CHECK(strncmp(buffer, str, str_len) == 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue