1 /* Copyright 2011 Adam Green (http://mbed.org/users/AdamGreen/)
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 /* LocalFileSystem test modified to use SD cards instead. */
17 #include "SDFileSystem.h"
20 SDFileSystem
sd(p5
, p6
, p7
, p8
, "sd"); // the pinout on the mbed Cool Components workshop board
28 printf("\r\n\r\nGCC4MBED Test Suite\r\n");
29 printf("sdFileSystem Unit Tests\r\n");
31 printf("Test 1: fopen() for write\r\n");
32 FILE *fp
= fopen("/sd/out.txt", "w"); // Open "out.txt" on the sd file system for writing
35 error("%s(%d) fopen() failed\r\n", __FILE__
, __LINE__
);
38 printf("Test 2: fprintf()\r\n");
39 Result
= fprintf(fp
, "Hello World!");
42 error("%s(%d) fprintf() failed\r\n", __FILE__
, __LINE__
);
45 printf("Test 3: fclose() on written file\r\n");
49 error("%s(%d) fclose() failed\r\n", __FILE__
, __LINE__
);
54 printf("Test 4: fopen() for read\r\n");
55 fp
= fopen("/sd/out.txt", "r");
58 error("%s(%d) fopen() failed\r\n", __FILE__
, __LINE__
);
61 printf("Test 5: fscanf()\r\n");
62 Result
= fscanf(fp
, "%31s", Buffer
);
65 error("%s(%d) fscanf() failed\r\n", __FILE__
, __LINE__
);
67 printf("Contents of /sd/out.txt: %s\r\n", Buffer
);
69 printf("Test 6: fclose() on read file\r\n");
73 error("%s(%d) fclose() failed\r\n", __FILE__
, __LINE__
);
78 printf("Test 7: remove()\r\n");
79 Result
= remove("/sd/out.txt"); // Removes the file "out.txt" from the sd file system
82 error("%s(%d) remove() failed\r\n", __FILE__
, __LINE__
);
86 printf("Test 8: opendir()\r\n");
87 DIR *d
= opendir("/sd"); // Opens the root directory of the sd file system
91 error("%s(%d) opendir() failed\r\n", __FILE__
, __LINE__
);
95 printf("Test 9: readir() for all entries\r\n");
96 while((p
= readdir(d
)) != NULL
)
97 { // Print the names of the files in the sd file system
98 printf("%s\r\n", p
->d_name
); // to stdout.
101 printf("Test 10: closedir\r\n");
104 printf("\r\nTest completed\r\n");