MemFilesystem_test

Dependencies:   SDFileSystem mbed

Revision:
0:f1015c4245f6
Child:
1:48383762a1ff
diff -r 000000000000 -r f1015c4245f6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 01 16:33:30 2015 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "MemFileSystem.h"
+#include "SDFileSystem.h"
+
+SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
+
+namespace {
+const char *mem_file_path = "/ram/out.txt";
+const char *sd_file_path = "/sd/fatdump";
+const int DATA_SIZE = 10 * 1024;
+}
+
+int main()
+{
+    uint8_t data_written[DATA_SIZE] = { 0 };
+    bool result = true;
+    
+    MemFileSystem *ramfs1 = new MemFileSystem("ram");
+    ramfs1->format();
+    {
+        FILE *f = fopen(mem_file_path, "w");
+ 
+        printf("Mem: Writing ... ");
+        for (int i = 0; i < DATA_SIZE; i++) {
+            data_written[i] = rand() % 0XFF;
+            fprintf(f, "%c", data_written[i]);
+        }
+        printf("[OK]\r\n");
+        fclose(f);
+    }
+ 
+    {
+        FILE *f = fopen(mem_file_path, "r");
+        printf("Mem: Reading data ... ");
+        for (int i = 0; i < DATA_SIZE; i++) {
+            uint8_t data = fgetc(f);
+            if (data != data_written[i]) {
+                result = false;
+                break;
+            }
+        }
+        printf("[%s]\r\n", result ? "OK" : "FAIL");
+        fclose(f);
+    }
+
+    {
+        FILE *f = fopen(sd_file_path, "w");
+        printf("Dump from MemFs to SDFs ... ");
+        ramfs1->dump(f);
+        printf("[OK]\r\n");
+        fclose(f);
+    }
+
+    delete ramfs1;
+    MemFileSystem *ramfs2 = new MemFileSystem("ram");
+
+    {
+        FILE *f = fopen(sd_file_path, "r");
+        printf("Load from SDFs to MemFs ... ");
+        ramfs2->load(f);
+        printf("[OK]\r\n");
+        fclose(f);
+    }
+
+    {
+        FILE *f = fopen(mem_file_path, "r");
+        printf("Mem: Reading data ... ");
+        for (int i = 0; i < DATA_SIZE; i++) {
+            uint8_t data = fgetc(f);
+            if (data != data_written[i]) {
+                result = false;
+                break;
+            }
+        }
+        printf("[%s]\r\n", result ? "OK" : "FAIL");
+        fclose(f);
+    }
+}
\ No newline at end of file