mirror of https://gitlab.com/nakst/essence
create basic file operations test
This commit is contained in:
parent
033983efc6
commit
f3350f0604
|
@ -12,23 +12,82 @@ typedef struct Test { const char *cName; } Test;
|
||||||
#define TEST(_callback) { .callback = _callback }
|
#define TEST(_callback) { .callback = _callback }
|
||||||
struct Test { bool (*callback)(); };
|
struct Test { bool (*callback)(); };
|
||||||
|
|
||||||
bool SuccessTest() {
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool BasicFileOperationsDoByteCount(size_t byteCount) {
|
||||||
|
uint8_t *buffer = (uint8_t *) EsHeapAllocate(byteCount, false);
|
||||||
|
|
||||||
|
for (uintptr_t i = 0; i < byteCount; i++) {
|
||||||
|
buffer[i] = EsRandomU8();
|
||||||
|
}
|
||||||
|
|
||||||
|
EsError error = EsFileWriteAll(EsLiteral("|Settings:/temp.dat"), buffer, byteCount);
|
||||||
|
|
||||||
|
if (error != ES_SUCCESS) {
|
||||||
|
EsPrint("Error %d writing file of size %d.\n", error, byteCount);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t readSize;
|
||||||
|
uint8_t *read = (uint8_t *) EsFileReadAll(EsLiteral("|Settings:/temp.dat"), &readSize, &error);
|
||||||
|
|
||||||
|
if (error != ES_SUCCESS) {
|
||||||
|
EsPrint("Error %d reading file of size %d.\n", error, byteCount);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (readSize != byteCount) {
|
||||||
|
EsPrint("Read size mismatch: got %d, expected %d.\n", readSize, byteCount);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EsMemoryCompare(buffer, read, byteCount)) {
|
||||||
|
EsPrint("Read data mismatch.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EsHeapFree(buffer);
|
||||||
|
EsHeapFree(read);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FailureTest() {
|
bool BasicFileOperations() {
|
||||||
return false;
|
for (uintptr_t i = 0; i < 24; i += 2) {
|
||||||
}
|
if (!BasicFileOperationsDoByteCount(1 << i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uintptr_t i = 18; i > 0; i -= 3) {
|
||||||
|
if (!BasicFileOperationsDoByteCount(1 << i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EsError error = EsPathDelete(EsLiteral("|Settings:/temp.dat"));
|
||||||
|
|
||||||
|
if (error != ES_SUCCESS) {
|
||||||
|
EsPrint("Error %d deleting file.\n", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EsFileReadAll(EsLiteral("|Settings:/temp.dat"), nullptr, &error);
|
||||||
|
|
||||||
|
if (error != ES_ERROR_FILE_DOES_NOT_EXIST) {
|
||||||
|
EsPrint("Checking file does not exist after deleting, instead got error %d.\n", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool TimeoutTest() {
|
|
||||||
EsProcessTerminateCurrent();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const Test tests[] = {
|
const Test tests[] = {
|
||||||
TEST(TimeoutTest), TEST(SuccessTest), TEST(FailureTest)
|
TEST(BasicFileOperations),
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef API_TESTS_FOR_RUNNER
|
#ifndef API_TESTS_FOR_RUNNER
|
||||||
|
|
|
@ -1633,7 +1633,7 @@ void DoCommand(const char *l) {
|
||||||
FILE *f = fopen("root/Essence/Settings/API Tests/test.dat", "wb");
|
FILE *f = fopen("root/Essence/Settings/API Tests/test.dat", "wb");
|
||||||
fwrite(&index, 1, sizeof(uint32_t), f);
|
fwrite(&index, 1, sizeof(uint32_t), f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
emulatorTimeout = 10;
|
emulatorTimeout = 20;
|
||||||
if (optimisations) BuildAndRun(OPTIMISE_FULL, true, DEBUG_LATER, EMULATOR_QEMU_NO_GUI, LOG_NORMAL);
|
if (optimisations) BuildAndRun(OPTIMISE_FULL, true, DEBUG_LATER, EMULATOR_QEMU_NO_GUI, LOG_NORMAL);
|
||||||
else BuildAndRun(OPTIMISE_OFF, true, DEBUG_LATER, EMULATOR_QEMU_NO_GUI, LOG_NORMAL);
|
else BuildAndRun(OPTIMISE_OFF, true, DEBUG_LATER, EMULATOR_QEMU_NO_GUI, LOG_NORMAL);
|
||||||
emulatorTimeout = 0;
|
emulatorTimeout = 0;
|
||||||
|
|
Loading…
Reference in New Issue