init

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "greentea-client/test_env.h"
00018 #include "unity.h"
00019 #include "utest.h"
00020 #include <stdlib.h>
00021 #include <errno.h>
00022 
00023 using namespace utest::v1;
00024 
00025 // test configuration
00026 #ifndef MBED_TEST_FILESYSTEM
00027 #define MBED_TEST_FILESYSTEM LittleFileSystem
00028 #endif
00029 
00030 #ifndef MBED_TEST_FILESYSTEM_DECL
00031 #define MBED_TEST_FILESYSTEM_DECL MBED_TEST_FILESYSTEM fs("fs")
00032 #endif
00033 
00034 #ifndef MBED_TEST_BLOCKDEVICE
00035 #error [NOT_SUPPORTED] Non-volatile block device required
00036 #endif
00037 
00038 #ifndef MBED_TEST_BLOCKDEVICE_DECL
00039 #define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
00040 #endif
00041 
00042 #ifndef MBED_TEST_FILES
00043 #define MBED_TEST_FILES 4
00044 #endif
00045 
00046 #ifndef MBED_TEST_DIRS
00047 #define MBED_TEST_DIRS 4
00048 #endif
00049 
00050 #ifndef MBED_TEST_BUFFER
00051 #define MBED_TEST_BUFFER 8192
00052 #endif
00053 
00054 #ifndef MBED_TEST_TIMEOUT
00055 #define MBED_TEST_TIMEOUT 480
00056 #endif
00057 
00058 
00059 // declarations
00060 #define STRINGIZE(x) STRINGIZE2(x)
00061 #define STRINGIZE2(x) #x
00062 #define INCLUDE(x) STRINGIZE(x.h)
00063 
00064 #include INCLUDE(MBED_TEST_FILESYSTEM)
00065 #include INCLUDE(MBED_TEST_BLOCKDEVICE)
00066 
00067 MBED_TEST_FILESYSTEM_DECL;
00068 MBED_TEST_BLOCKDEVICE_DECL;
00069 
00070 Dir dir[MBED_TEST_DIRS];
00071 File file[MBED_TEST_FILES];
00072 DIR *dd[MBED_TEST_DIRS];
00073 FILE *fd[MBED_TEST_FILES];
00074 struct dirent ent;
00075 struct dirent *ed;
00076 size_t size;
00077 uint8_t buffer[MBED_TEST_BUFFER];
00078 uint8_t rbuffer[MBED_TEST_BUFFER];
00079 uint8_t wbuffer[MBED_TEST_BUFFER];
00080 
00081 
00082 // tests
00083 
00084 void test_directory_tests()
00085 {
00086     int res = bd.init();
00087     TEST_ASSERT_EQUAL(0, res);
00088 
00089     {
00090         res = MBED_TEST_FILESYSTEM::format(&bd);
00091         TEST_ASSERT_EQUAL(0, res);
00092     }
00093 
00094     res = bd.deinit();
00095     TEST_ASSERT_EQUAL(0, res);
00096 }
00097 
00098 void test_root_directory()
00099 {
00100     int res = bd.init();
00101     TEST_ASSERT_EQUAL(0, res);
00102 
00103     {
00104         res = fs.mount(&bd);
00105         TEST_ASSERT_EQUAL(0, res);
00106         res = dir[0].open(&fs, "/");
00107         TEST_ASSERT_EQUAL(0, res);
00108         res = dir[0].close();
00109         TEST_ASSERT_EQUAL(0, res);
00110         res = fs.unmount();
00111         TEST_ASSERT_EQUAL(0, res);
00112     }
00113 
00114     res = bd.deinit();
00115     TEST_ASSERT_EQUAL(0, res);
00116 }
00117 
00118 void test_directory_creation()
00119 {
00120     int res = bd.init();
00121     TEST_ASSERT_EQUAL(0, res);
00122 
00123     {
00124         res = fs.mount(&bd);
00125         TEST_ASSERT_EQUAL(0, res);
00126         res = fs.mkdir("potato", 0777);
00127         TEST_ASSERT_EQUAL(0, res);
00128         res = fs.unmount();
00129         TEST_ASSERT_EQUAL(0, res);
00130     }
00131 
00132     res = bd.deinit();
00133     TEST_ASSERT_EQUAL(0, res);
00134 }
00135 
00136 void test_file_creation()
00137 {
00138     int res = bd.init();
00139     TEST_ASSERT_EQUAL(0, res);
00140 
00141     {
00142         res = fs.mount(&bd);
00143         TEST_ASSERT_EQUAL(0, res);
00144         res = file[0].open(&fs, "burito", O_CREAT | O_WRONLY);
00145         TEST_ASSERT_EQUAL(0, res);
00146         res = file[0].close();
00147         TEST_ASSERT_EQUAL(0, res);
00148         res = fs.unmount();
00149         TEST_ASSERT_EQUAL(0, res);
00150     }
00151 
00152     res = bd.deinit();
00153     TEST_ASSERT_EQUAL(0, res);
00154 }
00155 
00156 void test_directory_iteration()
00157 {
00158     int res = bd.init();
00159     TEST_ASSERT_EQUAL(0, res);
00160 
00161     {
00162         res = fs.mount(&bd);
00163         TEST_ASSERT_EQUAL(0, res);
00164         res = dir[0].open(&fs, "/");
00165         TEST_ASSERT_EQUAL(0, res);
00166         res = dir[0].read(&ent);
00167         TEST_ASSERT_EQUAL(1, res);
00168         res = strcmp(ent.d_name, ".");
00169         TEST_ASSERT_EQUAL(0, res);
00170         res = ent.d_type;
00171         TEST_ASSERT_EQUAL(DT_DIR, res);
00172         res = dir[0].read(&ent);
00173         TEST_ASSERT_EQUAL(1, res);
00174         res = strcmp(ent.d_name, "..");
00175         TEST_ASSERT_EQUAL(0, res);
00176         res = ent.d_type;
00177         TEST_ASSERT_EQUAL(DT_DIR, res);
00178         res = dir[0].read(&ent);
00179         TEST_ASSERT_EQUAL(1, res);
00180         res = strcmp(ent.d_name, "potato");
00181         TEST_ASSERT_EQUAL(0, res);
00182         res = ent.d_type;
00183         TEST_ASSERT_EQUAL(DT_DIR, res);
00184         res = dir[0].read(&ent);
00185         TEST_ASSERT_EQUAL(1, res);
00186         res = strcmp(ent.d_name, "burito");
00187         TEST_ASSERT_EQUAL(0, res);
00188         res = ent.d_type;
00189         TEST_ASSERT_EQUAL(DT_REG, res);
00190         res = dir[0].read(&ent);
00191         TEST_ASSERT_EQUAL(0, res);
00192         res = dir[0].close();
00193         TEST_ASSERT_EQUAL(0, res);
00194         res = fs.unmount();
00195         TEST_ASSERT_EQUAL(0, res);
00196     }
00197 
00198     res = bd.deinit();
00199     TEST_ASSERT_EQUAL(0, res);
00200 }
00201 
00202 void test_directory_failures()
00203 {
00204     int res = bd.init();
00205     TEST_ASSERT_EQUAL(0, res);
00206 
00207     {
00208         res = fs.mount(&bd);
00209         TEST_ASSERT_EQUAL(0, res);
00210         res = fs.mkdir("potato", 0777);
00211         TEST_ASSERT_EQUAL(-EEXIST, res);
00212         res = dir[0].open(&fs, "tomato");
00213         TEST_ASSERT_EQUAL(-ENOENT, res);
00214         res = dir[0].open(&fs, "burito");
00215         TEST_ASSERT_EQUAL(-ENOTDIR, res);
00216         res = file[0].open(&fs, "tomato", O_RDONLY);
00217         TEST_ASSERT_EQUAL(-ENOENT, res);
00218         res = file[0].open(&fs, "potato", O_RDONLY);
00219         TEST_ASSERT_EQUAL(-EISDIR, res);
00220         res = fs.unmount();
00221         TEST_ASSERT_EQUAL(0, res);
00222     }
00223 
00224     res = bd.deinit();
00225     TEST_ASSERT_EQUAL(0, res);
00226 }
00227 
00228 void test_nested_directories()
00229 {
00230     int res = bd.init();
00231     TEST_ASSERT_EQUAL(0, res);
00232 
00233     {
00234         res = fs.mount(&bd);
00235         TEST_ASSERT_EQUAL(0, res);
00236         res = fs.mkdir("potato/baked", 0777);
00237         TEST_ASSERT_EQUAL(0, res);
00238         res = fs.mkdir("potato/sweet", 0777);
00239         TEST_ASSERT_EQUAL(0, res);
00240         res = fs.mkdir("potato/fried", 0777);
00241         TEST_ASSERT_EQUAL(0, res);
00242         res = fs.unmount();
00243         TEST_ASSERT_EQUAL(0, res);
00244     }
00245 
00246     {
00247         res = fs.mount(&bd);
00248         TEST_ASSERT_EQUAL(0, res);
00249         res = dir[0].open(&fs, "potato");
00250         TEST_ASSERT_EQUAL(0, res);
00251         res = dir[0].read(&ent);
00252         TEST_ASSERT_EQUAL(1, res);
00253         res = strcmp(ent.d_name, ".");
00254         TEST_ASSERT_EQUAL(0, res);
00255         res = ent.d_type;
00256         TEST_ASSERT_EQUAL(DT_DIR, res);
00257         res = dir[0].read(&ent);
00258         TEST_ASSERT_EQUAL(1, res);
00259         res = strcmp(ent.d_name, "..");
00260         TEST_ASSERT_EQUAL(0, res);
00261         res = ent.d_type;
00262         TEST_ASSERT_EQUAL(DT_DIR, res);
00263         res = dir[0].read(&ent);
00264         TEST_ASSERT_EQUAL(1, res);
00265         res = strcmp(ent.d_name, "baked");
00266         TEST_ASSERT_EQUAL(0, res);
00267         res = ent.d_type;
00268         TEST_ASSERT_EQUAL(DT_DIR, res);
00269         res = dir[0].read(&ent);
00270         TEST_ASSERT_EQUAL(1, res);
00271         res = strcmp(ent.d_name, "sweet");
00272         TEST_ASSERT_EQUAL(0, res);
00273         res = ent.d_type;
00274         TEST_ASSERT_EQUAL(DT_DIR, res);
00275         res = dir[0].read(&ent);
00276         TEST_ASSERT_EQUAL(1, res);
00277         res = strcmp(ent.d_name, "fried");
00278         TEST_ASSERT_EQUAL(0, res);
00279         res = ent.d_type;
00280         TEST_ASSERT_EQUAL(DT_DIR, res);
00281         res = dir[0].read(&ent);
00282         TEST_ASSERT_EQUAL(0, res);
00283         res = dir[0].close();
00284         TEST_ASSERT_EQUAL(0, res);
00285         res = fs.unmount();
00286         TEST_ASSERT_EQUAL(0, res);
00287     }
00288 
00289     res = bd.deinit();
00290     TEST_ASSERT_EQUAL(0, res);
00291 }
00292 
00293 void test_multi_block_directory()
00294 {
00295     int res = bd.init();
00296     TEST_ASSERT_EQUAL(0, res);
00297 
00298     {
00299         res = fs.mount(&bd);
00300         TEST_ASSERT_EQUAL(0, res);
00301         res = fs.mkdir("cactus", 0777);
00302         TEST_ASSERT_EQUAL(0, res);
00303         for (int i = 0; i < 128; i++) {
00304             sprintf((char*)buffer, "cactus/test%d", i);
00305             res = fs.mkdir((char*)buffer, 0777);
00306             TEST_ASSERT_EQUAL(0, res);
00307         }
00308         res = fs.unmount();
00309         TEST_ASSERT_EQUAL(0, res);
00310     }
00311 
00312     {
00313         res = fs.mount(&bd);
00314         TEST_ASSERT_EQUAL(0, res);
00315         res = dir[0].open(&fs, "cactus");
00316         TEST_ASSERT_EQUAL(0, res);
00317         res = dir[0].read(&ent);
00318         TEST_ASSERT_EQUAL(1, res);
00319         res = strcmp(ent.d_name, ".");
00320         TEST_ASSERT_EQUAL(0, res);
00321         res = ent.d_type;
00322         TEST_ASSERT_EQUAL(DT_DIR, res);
00323         res = dir[0].read(&ent);
00324         TEST_ASSERT_EQUAL(1, res);
00325         res = strcmp(ent.d_name, "..");
00326         TEST_ASSERT_EQUAL(0, res);
00327         res = ent.d_type;
00328         TEST_ASSERT_EQUAL(DT_DIR, res);
00329         for (int i = 0; i < 128; i++) {
00330             sprintf((char*)buffer, "test%d", i);
00331             res = dir[0].read(&ent);
00332             TEST_ASSERT_EQUAL(1, res);
00333             res = strcmp(ent.d_name, (char*)buffer);
00334             TEST_ASSERT_EQUAL(0, res);
00335         }
00336         res = dir[0].read(&ent);
00337         TEST_ASSERT_EQUAL(0, res);
00338         res = dir[0].close();
00339         TEST_ASSERT_EQUAL(0, res);
00340         res = fs.unmount();
00341         TEST_ASSERT_EQUAL(0, res);
00342     }
00343 
00344     res = bd.deinit();
00345     TEST_ASSERT_EQUAL(0, res);
00346 }
00347 
00348 void test_directory_remove()
00349 {
00350     int res = bd.init();
00351     TEST_ASSERT_EQUAL(0, res);
00352 
00353     {
00354         res = fs.mount(&bd);
00355         TEST_ASSERT_EQUAL(0, res);
00356         res = fs.remove("potato");
00357         TEST_ASSERT_EQUAL(-EINVAL, res);
00358         res = fs.remove("potato/sweet");
00359         TEST_ASSERT_EQUAL(0, res);
00360         res = fs.remove("potato/baked");
00361         TEST_ASSERT_EQUAL(0, res);
00362         res = fs.remove("potato/fried");
00363         TEST_ASSERT_EQUAL(0, res);
00364         res = dir[0].open(&fs, "potato");
00365         TEST_ASSERT_EQUAL(0, res);
00366         res = dir[0].read(&ent);
00367         TEST_ASSERT_EQUAL(1, res);
00368         res = strcmp(ent.d_name, ".");
00369         TEST_ASSERT_EQUAL(0, res);
00370         res = ent.d_type;
00371         TEST_ASSERT_EQUAL(DT_DIR, res);
00372         res = dir[0].read(&ent);
00373         TEST_ASSERT_EQUAL(1, res);
00374         res = strcmp(ent.d_name, "..");
00375         TEST_ASSERT_EQUAL(0, res);
00376         res = ent.d_type;
00377         TEST_ASSERT_EQUAL(DT_DIR, res);
00378         res = dir[0].read(&ent);
00379         TEST_ASSERT_EQUAL(0, res);
00380         res = dir[0].close();
00381         TEST_ASSERT_EQUAL(0, res);
00382         res = fs.remove("potato");
00383         TEST_ASSERT_EQUAL(0, res);
00384         res = dir[0].open(&fs, "/");
00385         TEST_ASSERT_EQUAL(0, res);
00386         res = dir[0].read(&ent);
00387         TEST_ASSERT_EQUAL(1, res);
00388         res = strcmp(ent.d_name, ".");
00389         TEST_ASSERT_EQUAL(0, res);
00390         res = ent.d_type;
00391         TEST_ASSERT_EQUAL(DT_DIR, res);
00392         res = dir[0].read(&ent);
00393         TEST_ASSERT_EQUAL(1, res);
00394         res = strcmp(ent.d_name, "..");
00395         TEST_ASSERT_EQUAL(0, res);
00396         res = ent.d_type;
00397         TEST_ASSERT_EQUAL(DT_DIR, res);
00398         res = dir[0].read(&ent);
00399         TEST_ASSERT_EQUAL(1, res);
00400         res = strcmp(ent.d_name, "burito");
00401         TEST_ASSERT_EQUAL(0, res);
00402         res = ent.d_type;
00403         TEST_ASSERT_EQUAL(DT_REG, res);
00404         res = dir[0].read(&ent);
00405         TEST_ASSERT_EQUAL(1, res);
00406         res = strcmp(ent.d_name, "cactus");
00407         TEST_ASSERT_EQUAL(0, res);
00408         res = ent.d_type;
00409         TEST_ASSERT_EQUAL(DT_DIR, res);
00410         res = dir[0].read(&ent);
00411         TEST_ASSERT_EQUAL(0, res);
00412         res = dir[0].close();
00413         TEST_ASSERT_EQUAL(0, res);
00414         res = fs.unmount();
00415         TEST_ASSERT_EQUAL(0, res);
00416     }
00417 
00418     {
00419         res = fs.mount(&bd);
00420         TEST_ASSERT_EQUAL(0, res);
00421         res = dir[0].open(&fs, "/");
00422         TEST_ASSERT_EQUAL(0, res);
00423         res = dir[0].read(&ent);
00424         TEST_ASSERT_EQUAL(1, res);
00425         res = strcmp(ent.d_name, ".");
00426         TEST_ASSERT_EQUAL(0, res);
00427         res = ent.d_type;
00428         TEST_ASSERT_EQUAL(DT_DIR, res);
00429         res = dir[0].read(&ent);
00430         TEST_ASSERT_EQUAL(1, res);
00431         res = strcmp(ent.d_name, "..");
00432         TEST_ASSERT_EQUAL(0, res);
00433         res = ent.d_type;
00434         TEST_ASSERT_EQUAL(DT_DIR, res);
00435         res = dir[0].read(&ent);
00436         TEST_ASSERT_EQUAL(1, res);
00437         res = strcmp(ent.d_name, "burito");
00438         TEST_ASSERT_EQUAL(0, res);
00439         res = ent.d_type;
00440         TEST_ASSERT_EQUAL(DT_REG, res);
00441         res = dir[0].read(&ent);
00442         TEST_ASSERT_EQUAL(1, res);
00443         res = strcmp(ent.d_name, "cactus");
00444         TEST_ASSERT_EQUAL(0, res);
00445         res = ent.d_type;
00446         TEST_ASSERT_EQUAL(DT_DIR, res);
00447         res = dir[0].read(&ent);
00448         TEST_ASSERT_EQUAL(0, res);
00449         res = dir[0].close();
00450         TEST_ASSERT_EQUAL(0, res);
00451         res = fs.unmount();
00452         TEST_ASSERT_EQUAL(0, res);
00453     }
00454 
00455     res = bd.deinit();
00456     TEST_ASSERT_EQUAL(0, res);
00457 }
00458 
00459 void test_directory_rename()
00460 {
00461     int res = bd.init();
00462     TEST_ASSERT_EQUAL(0, res);
00463 
00464     {
00465         res = fs.mount(&bd);
00466         TEST_ASSERT_EQUAL(0, res);
00467         res = fs.mkdir("coldpotato", 0777);
00468         TEST_ASSERT_EQUAL(0, res);
00469         res = fs.mkdir("coldpotato/baked", 0777);
00470         TEST_ASSERT_EQUAL(0, res);
00471         res = fs.mkdir("coldpotato/sweet", 0777);
00472         TEST_ASSERT_EQUAL(0, res);
00473         res = fs.mkdir("coldpotato/fried", 0777);
00474         TEST_ASSERT_EQUAL(0, res);
00475         res = fs.unmount();
00476         TEST_ASSERT_EQUAL(0, res);
00477     }
00478 
00479     {
00480         res = fs.mount(&bd);
00481         TEST_ASSERT_EQUAL(0, res);
00482         res = fs.rename("coldpotato", "hotpotato");
00483         TEST_ASSERT_EQUAL(0, res);
00484         res = fs.unmount();
00485         TEST_ASSERT_EQUAL(0, res);
00486     }
00487 
00488     {
00489         res = fs.mount(&bd);
00490         TEST_ASSERT_EQUAL(0, res);
00491         res = dir[0].open(&fs, "hotpotato");
00492         TEST_ASSERT_EQUAL(0, res);
00493         res = dir[0].read(&ent);
00494         TEST_ASSERT_EQUAL(1, res);
00495         res = strcmp(ent.d_name, ".");
00496         TEST_ASSERT_EQUAL(0, res);
00497         res = ent.d_type;
00498         TEST_ASSERT_EQUAL(DT_DIR, res);
00499         res = dir[0].read(&ent);
00500         TEST_ASSERT_EQUAL(1, res);
00501         res = strcmp(ent.d_name, "..");
00502         TEST_ASSERT_EQUAL(0, res);
00503         res = ent.d_type;
00504         TEST_ASSERT_EQUAL(DT_DIR, res);
00505         res = dir[0].read(&ent);
00506         TEST_ASSERT_EQUAL(1, res);
00507         res = strcmp(ent.d_name, "baked");
00508         TEST_ASSERT_EQUAL(0, res);
00509         res = ent.d_type;
00510         TEST_ASSERT_EQUAL(DT_DIR, res);
00511         res = dir[0].read(&ent);
00512         TEST_ASSERT_EQUAL(1, res);
00513         res = strcmp(ent.d_name, "sweet");
00514         TEST_ASSERT_EQUAL(0, res);
00515         res = ent.d_type;
00516         TEST_ASSERT_EQUAL(DT_DIR, res);
00517         res = dir[0].read(&ent);
00518         TEST_ASSERT_EQUAL(1, res);
00519         res = strcmp(ent.d_name, "fried");
00520         TEST_ASSERT_EQUAL(0, res);
00521         res = ent.d_type;
00522         TEST_ASSERT_EQUAL(DT_DIR, res);
00523         res = dir[0].read(&ent);
00524         TEST_ASSERT_EQUAL(0, res);
00525         res = dir[0].close();
00526         TEST_ASSERT_EQUAL(0, res);
00527         res = fs.unmount();
00528         TEST_ASSERT_EQUAL(0, res);
00529     }
00530 
00531     {
00532         res = fs.mount(&bd);
00533         TEST_ASSERT_EQUAL(0, res);
00534         res = fs.mkdir("warmpotato", 0777);
00535         TEST_ASSERT_EQUAL(0, res);
00536         res = fs.mkdir("warmpotato/mushy", 0777);
00537         TEST_ASSERT_EQUAL(0, res);
00538         res = fs.rename("hotpotato", "warmpotato");
00539         TEST_ASSERT_EQUAL(-EINVAL, res);
00540         res = fs.remove("warmpotato/mushy");
00541         TEST_ASSERT_EQUAL(0, res);
00542         res = fs.rename("hotpotato", "warmpotato");
00543         TEST_ASSERT_EQUAL(0, res);
00544         res = fs.unmount();
00545         TEST_ASSERT_EQUAL(0, res);
00546     }
00547 
00548     {
00549         res = fs.mount(&bd);
00550         TEST_ASSERT_EQUAL(0, res);
00551         res = dir[0].open(&fs, "warmpotato");
00552         TEST_ASSERT_EQUAL(0, res);
00553         res = dir[0].read(&ent);
00554         TEST_ASSERT_EQUAL(1, res);
00555         res = strcmp(ent.d_name, ".");
00556         TEST_ASSERT_EQUAL(0, res);
00557         res = ent.d_type;
00558         TEST_ASSERT_EQUAL(DT_DIR, res);
00559         res = dir[0].read(&ent);
00560         TEST_ASSERT_EQUAL(1, res);
00561         res = strcmp(ent.d_name, "..");
00562         TEST_ASSERT_EQUAL(0, res);
00563         res = ent.d_type;
00564         TEST_ASSERT_EQUAL(DT_DIR, res);
00565         res = dir[0].read(&ent);
00566         TEST_ASSERT_EQUAL(1, res);
00567         res = strcmp(ent.d_name, "baked");
00568         TEST_ASSERT_EQUAL(0, res);
00569         res = ent.d_type;
00570         TEST_ASSERT_EQUAL(DT_DIR, res);
00571         res = dir[0].read(&ent);
00572         TEST_ASSERT_EQUAL(1, res);
00573         res = strcmp(ent.d_name, "sweet");
00574         TEST_ASSERT_EQUAL(0, res);
00575         res = ent.d_type;
00576         TEST_ASSERT_EQUAL(DT_DIR, res);
00577         res = dir[0].read(&ent);
00578         TEST_ASSERT_EQUAL(1, res);
00579         res = strcmp(ent.d_name, "fried");
00580         TEST_ASSERT_EQUAL(0, res);
00581         res = ent.d_type;
00582         TEST_ASSERT_EQUAL(DT_DIR, res);
00583         res = dir[0].read(&ent);
00584         TEST_ASSERT_EQUAL(0, res);
00585         res = dir[0].close();
00586         TEST_ASSERT_EQUAL(0, res);
00587         res = fs.unmount();
00588         TEST_ASSERT_EQUAL(0, res);
00589     }
00590 
00591     {
00592         res = fs.mount(&bd);
00593         TEST_ASSERT_EQUAL(0, res);
00594         res = fs.mkdir("coldpotato", 0777);
00595         TEST_ASSERT_EQUAL(0, res);
00596         res = fs.rename("warmpotato/baked", "coldpotato/baked");
00597         TEST_ASSERT_EQUAL(0, res);
00598         res = fs.rename("warmpotato/sweet", "coldpotato/sweet");
00599         TEST_ASSERT_EQUAL(0, res);
00600         res = fs.rename("warmpotato/fried", "coldpotato/fried");
00601         TEST_ASSERT_EQUAL(0, res);
00602         res = fs.remove("coldpotato");
00603         TEST_ASSERT_EQUAL(-EINVAL, res);
00604         res = fs.remove("warmpotato");
00605         TEST_ASSERT_EQUAL(0, res);
00606         res = fs.unmount();
00607         TEST_ASSERT_EQUAL(0, res);
00608     }
00609 
00610     {
00611         res = fs.mount(&bd);
00612         TEST_ASSERT_EQUAL(0, res);
00613         res = dir[0].open(&fs, "coldpotato");
00614         TEST_ASSERT_EQUAL(0, res);
00615         res = dir[0].read(&ent);
00616         TEST_ASSERT_EQUAL(1, res);
00617         res = strcmp(ent.d_name, ".");
00618         TEST_ASSERT_EQUAL(0, res);
00619         res = ent.d_type;
00620         TEST_ASSERT_EQUAL(DT_DIR, res);
00621         res = dir[0].read(&ent);
00622         TEST_ASSERT_EQUAL(1, res);
00623         res = strcmp(ent.d_name, "..");
00624         TEST_ASSERT_EQUAL(0, res);
00625         res = ent.d_type;
00626         TEST_ASSERT_EQUAL(DT_DIR, res);
00627         res = dir[0].read(&ent);
00628         TEST_ASSERT_EQUAL(1, res);
00629         res = strcmp(ent.d_name, "baked");
00630         TEST_ASSERT_EQUAL(0, res);
00631         res = ent.d_type;
00632         TEST_ASSERT_EQUAL(DT_DIR, res);
00633         res = dir[0].read(&ent);
00634         TEST_ASSERT_EQUAL(1, res);
00635         res = strcmp(ent.d_name, "sweet");
00636         TEST_ASSERT_EQUAL(0, res);
00637         res = ent.d_type;
00638         TEST_ASSERT_EQUAL(DT_DIR, res);
00639         res = dir[0].read(&ent);
00640         TEST_ASSERT_EQUAL(1, res);
00641         res = strcmp(ent.d_name, "fried");
00642         TEST_ASSERT_EQUAL(0, res);
00643         res = ent.d_type;
00644         TEST_ASSERT_EQUAL(DT_DIR, res);
00645         res = dir[0].read(&ent);
00646         TEST_ASSERT_EQUAL(0, res);
00647         res = dir[0].close();
00648         TEST_ASSERT_EQUAL(0, res);
00649         res = fs.unmount();
00650         TEST_ASSERT_EQUAL(0, res);
00651     }
00652 
00653     res = bd.deinit();
00654     TEST_ASSERT_EQUAL(0, res);
00655 }
00656 
00657 
00658 
00659 // test setup
00660 utest::v1::status_t test_setup(const size_t number_of_cases)
00661 {
00662     GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
00663     return verbose_test_setup_handler(number_of_cases);
00664 }
00665 
00666 Case cases[] = {
00667     Case("Directory tests", test_directory_tests),
00668     Case("Root directory", test_root_directory),
00669     Case("Directory creation", test_directory_creation),
00670     Case("File creation", test_file_creation),
00671     Case("Directory iteration", test_directory_iteration),
00672     Case("Directory failures", test_directory_failures),
00673     Case("Nested directories", test_nested_directories),
00674     Case("Multi-block directory", test_multi_block_directory),
00675     Case("Directory remove", test_directory_remove),
00676     Case("Directory rename", test_directory_rename),
00677 };
00678 
00679 Specification specification(test_setup, cases);
00680 
00681 int main()
00682 {
00683     return !Harness::run(specification);
00684 }