Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pal_fileSystem_test.c Source File

pal_fileSystem_test.c

00001 /*******************************************************************************
00002  * Copyright 2016, 2017 ARM Ltd.
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 
00017 #include "pal.h"
00018 #include "unity.h"
00019 #include "unity_fixture.h"
00020 
00021 
00022 #define TEST_DIR "dir1"
00023 #define TEST_DIR2 "dir2"
00024 #define TEST_WORKING_DIR "work1"
00025 #define TEST_DIR_FILE "dir1/test.txt"
00026 #define TEST_NUMBER_OF_FILE_TO_CREATE 20
00027 #define TEST_BUFFER_SIZE 100
00028 #define TEST_BUFFER_SMALL_SIZE 17
00029 //#define TEST_BYTES_TO_WRITE 300*4
00030 #define TEST_BYTES_TO_WRITE 100
00031 #define TEST_FILE_NAME "%s/test_f%d"
00032 #define BUFFER_TEST_SIZE 1123
00033 
00034 #if (false == PAL_PRIMARY_PARTITION_PRIVATE)
00035     #define PAL_TEST_PRIMARY_PATH "/pri"
00036 #else
00037     #define PAL_TEST_PRIMARY_PATH ""
00038 #endif
00039 
00040 #if (false == PAL_SECONDARY_PARTITION_PRIVATE)
00041     #define PAL_TEST_SECONDARY_PATH "/sec"
00042 #else
00043     #define PAL_TEST_SECONDARY_PATH ""
00044 #endif
00045 
00046 //out should in length be PAL_MAX_FILE_AND_FOLDER_LENGTH
00047 static char* addRootToPath(const char* in, char* out,pal_fsStorageID_t id)
00048 {
00049     char root[PAL_MAX_FILE_AND_FOLDER_LENGTH] = { 0 };
00050     size_t len = 0;
00051     palStatus_t status;
00052 
00053     memset(out,0,PAL_MAX_FILE_AND_FOLDER_LENGTH);
00054     status = pal_fsGetMountPoint(id, PAL_MAX_FILE_AND_FOLDER_LENGTH, root);
00055     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00056 
00057     strncat(out, root, PAL_MAX_FILE_AND_FOLDER_LENGTH-1); //-1 for null terminator space
00058     len = strlen(out);
00059     if (PAL_FS_PARTITION_PRIMARY == id)
00060     {
00061         strncat(out, PAL_TEST_PRIMARY_PATH, PAL_MAX_FILE_AND_FOLDER_LENGTH - len);
00062     }
00063     else
00064     {
00065         strncat(out, PAL_TEST_SECONDARY_PATH, PAL_MAX_FILE_AND_FOLDER_LENGTH - len);
00066     }
00067     len = strlen(out);
00068     if (*in != '\0')
00069     {
00070         strncat(out,"/",PAL_MAX_FILE_AND_FOLDER_LENGTH - len);
00071         strncat(out,in,PAL_MAX_FILE_AND_FOLDER_LENGTH -len -1);
00072     }
00073     return(out);
00074 }
00075 
00076 
00077 
00078 PAL_PRIVATE uint8_t *bufferTest = NULL;
00079 PAL_PRIVATE uint8_t *bufferTest2  = NULL;
00080 
00081 PAL_PRIVATE palFileDescriptor_t g_fd1 = 0;
00082 PAL_PRIVATE palFileDescriptor_t g_fd2 = 0;
00083 
00084 PAL_PRIVATE palStatus_t pal_fsClearAndInitialyze(pal_fsStorageID_t id)
00085 {
00086     palStatus_t status = PAL_SUCCESS;
00087 
00088     if (pal_fsIsPrivatePartition(id))
00089     {
00090         status = pal_fsFormat(id);
00091     }
00092     else
00093     {
00094         char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00095         status = pal_fsRmFiles(addRootToPath("",buffer,id));
00096     }
00097     return(status);
00098 }
00099 
00100 /*! \brief This function compare two files
00101 *
00102 * @param[in]    *pathCmp1 - pointer to the null-terminated string that specifies the first filename to be compare
00103 * @param[in]    *pathCmp2 - pointer to the null-terminated string that specifies the second filename to be compare
00104 *
00105 * \return PAL_SUCCESS upon successful operation.\n
00106 *
00107 */
00108 PAL_PRIVATE palStatus_t fileSystemCompareUtil(const char * pathCmp1, const char * pathCmp2)
00109 {
00110     palStatus_t status = PAL_SUCCESS;
00111 
00112     char bufferCmp1[TEST_BUFFER_SIZE];
00113     char bufferCmp2[TEST_BUFFER_SIZE];
00114     size_t numOfBytesCmp1 = 0;
00115     size_t numOfBytesCmp2 = 0;
00116     palFileDescriptor_t  fdCmp1 = 0;
00117     palFileDescriptor_t  fdCmp2 = 0;
00118 
00119     status =  pal_fsFopen(pathCmp1, PAL_FS_FLAG_READONLY, &fdCmp1);
00120     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00121 
00122     status =  pal_fsFopen(pathCmp2, PAL_FS_FLAG_READONLY, &fdCmp2);
00123     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00124 
00125     while(true)
00126     {
00127 
00128         status  = pal_fsFread(&fdCmp1, bufferCmp1, TEST_BUFFER_SIZE, &numOfBytesCmp1);
00129         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00130 
00131         status  = pal_fsFread(&fdCmp2, bufferCmp2, TEST_BUFFER_SIZE, &numOfBytesCmp2);
00132         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00133 
00134         if ((numOfBytesCmp2 == 0) && (numOfBytesCmp1 == 0))
00135         {//End of file reached
00136             break;
00137         }
00138 
00139         TEST_ASSERT_EQUAL(numOfBytesCmp1, numOfBytesCmp2);
00140         TEST_ASSERT_EQUAL_MEMORY(bufferCmp1, bufferCmp2, numOfBytesCmp1);
00141     }
00142 
00143     status =  pal_fsFclose(&fdCmp1);
00144     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00145 
00146     status =  pal_fsFclose(&fdCmp2);
00147     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00148 
00149     return status;
00150 }
00151 
00152 TEST_GROUP(pal_fileSystem);
00153 
00154 TEST_SETUP(pal_fileSystem)
00155 {
00156 
00157     pal_init();
00158     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00159 
00160     pal_fsRmFiles(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY));//Remove all files in the testing DIRECTORY
00161     pal_fsRmDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Delete Directory if exist
00162     pal_fsRmFiles(addRootToPath(TEST_WORKING_DIR,buffer,PAL_FS_PARTITION_PRIMARY));//Remove all files in the testing DIRECTORY
00163     pal_fsRmDir(addRootToPath(TEST_WORKING_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Delete Directory if exist
00164     pal_fsRmFiles(addRootToPath(TEST_DIR2,buffer,PAL_FS_PARTITION_PRIMARY));//Remove all files in the testing DIRECTORY
00165     pal_fsRmDir(addRootToPath(TEST_DIR2,buffer,PAL_FS_PARTITION_PRIMARY)); //Delete Directory if exist
00166 
00167 
00168     pal_fsRmFiles(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_SECONDARY));//Remove all files in the testing DIRECTORY
00169     pal_fsRmDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_SECONDARY)); //Delete Directory if exist
00170     pal_fsRmFiles(addRootToPath(TEST_WORKING_DIR,buffer,PAL_FS_PARTITION_SECONDARY));//Remove all files in the testing DIRECTORY
00171     pal_fsRmDir(addRootToPath(TEST_WORKING_DIR,buffer,PAL_FS_PARTITION_SECONDARY)); //Delete Directory if exist
00172     pal_fsRmFiles(addRootToPath(TEST_DIR2,buffer,PAL_FS_PARTITION_SECONDARY));//Remove all files in the testing DIRECTORY
00173     pal_fsRmDir(addRootToPath(TEST_DIR2,buffer,PAL_FS_PARTITION_SECONDARY)); //Delete Directory if exist
00174 
00175     g_fd1 = 0;
00176     g_fd2 = 0;
00177     bufferTest = NULL;
00178     bufferTest2 = NULL;
00179     if(!pal_fsIsPrivatePartition(PAL_FS_PARTITION_PRIMARY))
00180     {
00181 
00182         addRootToPath("",buffer,PAL_FS_PARTITION_PRIMARY);
00183         pal_fsMkDir(buffer);
00184     }
00185     if(!pal_fsIsPrivatePartition(PAL_FS_PARTITION_SECONDARY))
00186     {
00187         addRootToPath("",buffer,PAL_FS_PARTITION_SECONDARY);
00188         pal_fsMkDir(buffer);
00189     }
00190 }
00191 
00192 TEST_TEAR_DOWN(pal_fileSystem)
00193 {
00194     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00195     if (g_fd1) 
00196     {
00197         pal_fsFclose(&g_fd1);
00198     }
00199     if (g_fd2) 
00200     {
00201         pal_fsFclose(&g_fd2);
00202     }
00203     g_fd1 = 0;
00204     g_fd2 = 0;
00205 
00206     if (bufferTest != NULL)
00207     {
00208         free(bufferTest);
00209         bufferTest = NULL;
00210     }
00211     if (bufferTest2 != NULL)
00212     {
00213         free(bufferTest2);
00214         bufferTest2 = NULL;
00215     }
00216     pal_fsClearAndInitialyze(PAL_FS_PARTITION_PRIMARY);
00217     pal_fsClearAndInitialyze(PAL_FS_PARTITION_SECONDARY);
00218 
00219     if(!pal_fsIsPrivatePartition(PAL_FS_PARTITION_PRIMARY))
00220     {
00221 
00222         addRootToPath("",buffer,PAL_FS_PARTITION_PRIMARY);
00223         pal_fsRmDir(buffer);
00224     }
00225     if(!pal_fsIsPrivatePartition(PAL_FS_PARTITION_SECONDARY))
00226     {
00227         addRootToPath("",buffer,PAL_FS_PARTITION_SECONDARY);
00228         pal_fsRmDir(buffer);
00229     }
00230     pal_destroy();
00231 
00232 }
00233 
00234 /*! \brief /b SDFormat function tests formatting an SD card.
00235 *
00236 ** \test
00237 * | # |    Step                        |   Expected  |
00238 * |---|--------------------------------|-------------|
00239 * | 1 | create TEST_DIR with pal_fsMkDir                                                | PAL_SUCCESS |
00240 * | 2 | create TEST_DIR_FILE file with pal_fsOpen                                       | PAL_SUCCESS |
00241 * | 3 | close file TEST_DIR_FILE with pal_fsClose                                       | PAL_SUCCESS |
00242 * | 4 | Format SD card with pal_FormatSDPartition                                       | PAL_SUCCESS |
00243 * | 5 | TEST_DIR_FILE should not exist after format                                     | PAL_ERR_FS_NO_FILE |
00244 * | 6 | create TEST_DIR with pal_fsMkDir                                                | PAL_SUCCESS |
00245 */
00246 void SDFormat_1Partition()
00247 {
00248     palStatus_t status = PAL_SUCCESS;
00249     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00250 
00251     /*#1*/
00252     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Create Directory
00253     if (PAL_SUCCESS == status)
00254     {
00255         /*#2*/
00256         status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_PRIMARY), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00257         TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00258         /*#3*/
00259         status = pal_fsFclose(&g_fd1);
00260         TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00261     }
00262 
00263 
00264     /*#4*/
00265     status = pal_fsClearAndInitialyze(PAL_FS_PARTITION_PRIMARY); //Format SD
00266     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00267 
00268     /*#5*/
00269     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_PRIMARY), PAL_FS_FLAG_READONLY, &g_fd1);
00270     TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00271     
00272     status = pal_fsClearAndInitialyze(PAL_FS_PARTITION_SECONDARY); //Format SD
00273     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00274 
00275 
00276     /*#6*/
00277     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Create Directory
00278     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00279 
00280 }
00281 
00282 /*! \brief /b SDFormat function tests formatting an SD card.
00283 *
00284 ** \test
00285 * | # |    Step                        |   Expected  |
00286 * |---|--------------------------------|-------------|
00287 * | 1 | create TEST_DIR with pal_fsMkDir primary partition                              | PAL_SUCCESS |
00288 * | 2 | create TEST_DIR_FILE file with pal_fsOpen primary partition                     | PAL_SUCCESS |
00289 * | 3 | close file TEST_DIR_FILE with pal_fsClose                                       | PAL_SUCCESS |
00290 * | 4 | create TEST_DIR with pal_fsMkDir secondary partition                            | PAL_SUCCESS |
00291 * | 5 | create TEST_DIR_FILE file with pal_fsOpen secondary partition                   | PAL_SUCCESS |
00292 * | 6 | close file TEST_DIR_FILE with pal_fsClose                                       | PAL_SUCCESS |
00293 * | 7 | Format SD card primary partition with pal_FormatSDPartition                     | PAL_SUCCESS |
00294 * | 8 | TEST_DIR_FILE in primary should not exist after format                          | PAL_ERR_FS_NO_FILE |
00295 * | 9 | TEST_DIR_FILE in secondary should  exist after format                           | PAL_SUCCESS |
00296 * | 10| Format SD card secondary partition with pal_FormatSDPartition                   | PAL_SUCCESS |
00297 * | 11| TEST_DIR_FILE in secondary should not exist after format                        | PAL_ERR_FS_NO_FILE |
00298 * | 12| create TEST_DIR with pal_fsMkDir in primary partition                           | PAL_SUCCESS |
00299 * | 13| create TEST_DIR with pal_fsMkDir in secondary partition                         | PAL_SUCCESS |
00300 */
00301 void SDFormat_2Partition()
00302 {
00303     palStatus_t status = PAL_SUCCESS;
00304     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00305 
00306     /*#1*/
00307     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Create Directory
00308     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00309     /*#2*/
00310     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_PRIMARY), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00311     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00312     /*#3*/
00313     status = pal_fsFclose(&g_fd1);
00314     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00315 
00316     /*#4*/
00317     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_SECONDARY)); //Create Directory
00318     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00319 
00320     /*#5*/
00321     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_SECONDARY), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00322     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00323     /*#6*/
00324     status = pal_fsFclose(&g_fd1);
00325     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00326 
00327 
00328     /*#7*/
00329     status = pal_fsClearAndInitialyze(PAL_FS_PARTITION_PRIMARY); //Format SD
00330     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00331 
00332     /*#8*/
00333     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_PRIMARY), PAL_FS_FLAG_READONLY, &g_fd1);
00334     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00335 
00336     /*#9*/
00337     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_SECONDARY), PAL_FS_FLAG_READONLY, &g_fd1);
00338     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);    //the file still exists in secondary
00339 
00340     status = pal_fsFclose(&g_fd1);
00341     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00342 
00343     /*#10*/
00344     status = pal_fsClearAndInitialyze(PAL_FS_PARTITION_SECONDARY); //Format SD
00345     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00346     /*#11*/
00347     status = pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,PAL_FS_PARTITION_SECONDARY), PAL_FS_FLAG_READONLY, &g_fd1);
00348     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00349 
00350     /*#12*/
00351     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_PRIMARY)); //Create Directory
00352     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00353     /*#13*/
00354     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,PAL_FS_PARTITION_SECONDARY)); //Create Directory
00355     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00356 }
00357 
00358 
00359 
00360 TEST(pal_fileSystem, SDFormat)
00361 {
00362     SDFormat_2Partition();
00363     SDFormat_1Partition();
00364 }
00365 
00366 
00367 /*! \brief /b directoryTests function Tests  root Directory commands
00368 *
00369 ** \test
00370 * | # |    Step                        |   Expected  |
00371 * |---|--------------------------------|-------------|
00372 * | 1 | get root directory with pal_fsGetMountPoint                                    | PAL_SUCCESS |
00373 * | 2 | create TEST_WORKING_DIR with pal_fsMkDir                                       | PAL_SUCCESS |
00374 * | 3 | Change Root Directory to TEST_WORKING_DIR with     pal_fsSetMountPoint         | PAL_SUCCESS |
00375 * | 4 | create TEST_WORKING_DIR with pal_fsMkDir                                       | PAL_ERR_FS_NAME_ALREADY_EXIST |
00376 * | 5 | get root directory with pal_fsGetMountPoint                                    | PAL_SUCCESS |
00377 */
00378 void rootDirectoryTests(pal_fsStorageID_t storageId)
00379 {
00380     palStatus_t status = PAL_SUCCESS;
00381     char getRootPath[TEST_BUFFER_SIZE] = { 0 };
00382     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00383 /*#1*/
00384     status = pal_fsGetMountPoint(storageId, TEST_BUFFER_SIZE, getRootPath); //Setting New working Directory
00385     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00386     
00387 /*#2*/
00388     status = pal_fsMkDir(addRootToPath(TEST_WORKING_DIR,buffer,storageId)); //Create Directory
00389     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00390 
00391 /*#3*/
00392     status = pal_fsSetMountPoint(storageId, addRootToPath(TEST_WORKING_DIR,buffer,storageId)); //Setting New working Directory
00393     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00394 
00395 /*#4*/
00396     status = pal_fsMkDir(getRootPath); //should fail because already exits and path is absolute
00397     TEST_ASSERT_EQUAL(PAL_ERR_FS_NAME_ALREADY_EXIST, status);
00398 
00399 /*#5*/
00400     status = pal_fsGetMountPoint(storageId, TEST_BUFFER_SIZE, getRootPath); //Setting New working Directory
00401     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00402 
00403 }
00404 
00405 
00406 TEST(pal_fileSystem, rootDirectoryTests)
00407 {
00408 
00409     rootDirectoryTests(PAL_FS_PARTITION_PRIMARY);
00410 
00411 }
00412 
00413 
00414 /*! \brief /b directoryTests function Tests Directory commands
00415 *
00416 ** \test
00417 * | # |    Step                        |   Expected  |
00418 * |---|--------------------------------|-------------|
00419 * | 1 | create TEST_DIR with pal_fsMkDir                                                | PAL_SUCCESS |
00420 * | 2 | create TEST_DIR with pal_fsMkDir                                                | PAL_ERR_FS_NAME_ALREADY_EXIST |
00421 * | 3 | Create File TEST_DIR_FILE With PAL_ERR_FS_READWRITEEXCLUSIVE with pal_fsFopen   | PAL_SUCCESS |
00422 * | 4 | Create File TEST_DIR_FILE With PAL_ERR_FS_READWRITEEXCLUSIVE with pal_fsFopen   | PAL_ERR_FS_NAME_ALREADY_EXIST |
00423 * | 5 | Close file with uninitialized file descriptor                                   | PAL_ERR_FS_BAD_FD |
00424 * | 6 | Close file with initialized file descriptor                                     | PAL_SUCCESS |
00425 * | 7 | Delete directory with  pal_fsRmDir (directory not empty)                        | PAL_ERR_FS_ERROR |
00426 * | 8 | Delete file TEST_DIR_FILE with pal_fsUnlink                                     | PAL_SUCCESS |
00427 * | 9 | Delete file TEST_DIR_FILE with pal_fsUnlink                                     | PAL_SUCCESS |
00428 * | 10 | Delete a folder which not exists with pal_fsUnlink                             | PAL_ERR_FS_NO_PATH |
00429 *
00430 */
00431 void directoryTests(pal_fsStorageID_t storageId)
00432 {
00433     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00434     char *pathToFile = NULL;
00435     palStatus_t status = PAL_SUCCESS;
00436 
00437 /*#1*/
00438     pathToFile = addRootToPath(TEST_DIR,buffer,storageId);
00439     status = pal_fsMkDir(pathToFile); //Create Directory
00440     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00441 
00442 /*#2*/
00443     pathToFile = addRootToPath(TEST_DIR,buffer,storageId);
00444     status = pal_fsMkDir(pathToFile); //Create same Directory Shall failed
00445     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_NAME_ALREADY_EXIST, status);
00446 
00447 /*#3*/
00448     pathToFile = addRootToPath(TEST_DIR_FILE,buffer,storageId);
00449     status =  pal_fsFopen(pathToFile, PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00450     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00451 
00452 /*#4*/
00453     pathToFile = addRootToPath(TEST_DIR_FILE,buffer,storageId);
00454     status =  pal_fsFopen(pathToFile, PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd2); // Failed open Exclusively and file already created
00455     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_NAME_ALREADY_EXIST, status);
00456 /*#5*/
00457     #ifdef DEBUG
00458         pal_fsFclose(&g_fd2);//Failed fd1 was not a valid File descriptor
00459     #endif
00460     //TEST_ASSERT_EQUAL(PAL_ERR_FS_BAD_FD, status); //TODO Pass on mbedOS
00461 
00462 /*#6*/    
00463     status =  pal_fsFclose(&g_fd1);
00464     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00465 
00466 /*#7*/
00467     pathToFile = addRootToPath(TEST_DIR,buffer,storageId);
00468     status = pal_fsRmDir(pathToFile); //Delete Directory Failed Directory not empty
00469     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_DIR_NOT_EMPTY, status);
00470 
00471 /*#8*/
00472     pathToFile = addRootToPath(TEST_DIR_FILE,buffer,storageId);
00473     status = pal_fsUnlink(pathToFile); //Delete the file in a directory
00474     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00475 
00476 /*#9*/
00477     pathToFile = addRootToPath(TEST_DIR,buffer,storageId);
00478     status = pal_fsRmDir(pathToFile); //Delete Directory success
00479     TEST_ASSERT_EQUAL_HEX(PAL_SUCCESS, status);
00480 
00481 /*#10*/
00482     
00483     pathToFile = addRootToPath(TEST_DIR,buffer,storageId);
00484     status = pal_fsRmDir(pathToFile); //Delete not existing Directory
00485     TEST_ASSERT_EQUAL_HEX(PAL_ERR_FS_NO_PATH, status);
00486 }
00487 
00488 TEST(pal_fileSystem, directoryTests)
00489 {
00490     directoryTests(PAL_FS_PARTITION_PRIMARY);
00491     directoryTests(PAL_FS_PARTITION_SECONDARY);
00492 }
00493 
00494 /*! \brief /b FilesTests function Tests files commands
00495 *
00496 ** \test
00497 * | # |    Step                        |   Expected  |
00498 * |---|--------------------------------|-------------|
00499 * | 1 | Init Test                                                                                                       | |
00500 * | 2 | create TEST_DIR with pal_fsMkDir                                                                                | PAL_SUCCESS |
00501 * | 3 | create TEST_DIR2 with pal_fsMkDir                                                                               | PAL_SUCCESS |
00502 * | 4 | Start Loop i from [0 - TEST_NUMBER_OF_FILE_TO_CREATE]                                                           | |
00503 * | 5 | Create File in DIR_FILE named f_i (i - index of loop)with PAL_ERR_FS_READWRITEEXCLUSIVE mode using pal_fsFopen  | PAL_SUCCESS |
00504 * | 6 | Write random buffer[TEST_BYTES_TO_WRITE] to file with pal_fsFwrite                                              | PAL_SUCCESS |
00505 * | 7 | close file handler with pal_fsFclose                                                                            | PAL_SUCCESS |
00506 * | 8 | End Loop                                                                                                        | |
00507 * | 9 | Copy TEST_DIR folder to TEST_DIR2 with pal_fsCpFolder                                                           | PAL_SUCCESS |
00508 * | 10 | Compare Folders                                                                                                | |
00509 * | 11 | remove all files from TEST_DIR2                                                                                | PAL_SUCCESS |
00510 * | 12 | remove all files from TEST_DIR                                                                                 | PAL_SUCCESS |
00511 * | 13 | Start Loop i from [0 - TEST_NUMBER_OF_FILE_TO_CREATE]                                                          | |
00512 * | 14 | open Files in DIR_FILE named f_i (i - index of loop) with PAL_ERR_FS_READONLY mode using pal_fsFopen           | PAL_ERR_FS_NO_FILE |
00513 * | 15 | open Files in DIR_FILE named f_i (i - index of loop) with PAL_ERR_FS_READWRITE mode using pal_fsFopen          | PAL_ERR_FS_NO_FILE |
00514 * | 16 | open Files in DIR_FILE2 named f_i (i - index of loop) with PAL_ERR_FS_READONLY mode using pal_fsFopen          | PAL_ERR_FS_NO_FILE |
00515 * | 17 | open Files in DIR_FILE2 named f_i (i - index of loop) with PAL_ERR_FS_READWRITE mode using pal_fsFopen         | PAL_ERR_FS_NO_FILE |
00516 * | 18 | remove TEST_DIR with pal_fsRmDir                                                                               | PAL_SUCCESS |
00517 * | 19 | remove TEST_DIR2 with pal_fsRmDir                                                                              | PAL_SUCCESS |
00518 * | 20 | try to remove a file that does not exist                                                                       | PAL_ERR_FS_NO_FILE |
00519 * | 21 | try to remove a a variety of files that does not exist                                                         | PAL_ERR_FS_NO_PATH |
00520 * | 22 | try to copy a non existing folder                                                                              | PAL_ERR_FS_NO_PATH |
00521 *
00522 */
00523 void FilesTests(pal_fsStorageID_t storageId)
00524 {
00525     palStatus_t status = PAL_SUCCESS;
00526     char rootPathBuffer1[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00527     char rootPathBuffer2[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00528     char buffer1[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00529     char buffer2[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00530     int i = 0;
00531     size_t numOfBytes;
00532 /*#1*/
00533     //---------------- INIT TESTS----------------------------//
00534     memset(rootPathBuffer1, '1', PAL_MAX_FILE_AND_FOLDER_LENGTH);
00535     memset(rootPathBuffer2, '1', PAL_MAX_FILE_AND_FOLDER_LENGTH);
00536     //----------------END INIT TESTS-------------------------//
00537 
00538 /*#2*/
00539     status = pal_fsMkDir(addRootToPath(TEST_DIR,rootPathBuffer1,storageId)); //Create Directory
00540     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00541 
00542 /*#3*/
00543     status = pal_fsMkDir(addRootToPath(TEST_DIR2,rootPathBuffer2,storageId)); //Create Directory
00544     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00545 
00546 /*#4*/
00547     for(i = 0; i < TEST_NUMBER_OF_FILE_TO_CREATE; i++)
00548     {
00549 /*#5*/
00550         snprintf(rootPathBuffer1, PAL_MAX_FILE_AND_FOLDER_LENGTH, TEST_FILE_NAME, TEST_DIR, i);
00551         status =  pal_fsFopen(addRootToPath(rootPathBuffer1,buffer1,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00552         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00553 
00554 /*#6*/
00555         status =  pal_fsFwrite(&g_fd1, (void *)rootPathBuffer1, TEST_BYTES_TO_WRITE, &numOfBytes);
00556         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00557 
00558 /*#7*/
00559         status =  pal_fsFclose(&g_fd1);
00560         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00561 /*#8*/
00562     }
00563 
00564 /*#9*/
00565     status = pal_fsCpFolder(addRootToPath(TEST_DIR,rootPathBuffer1,storageId), addRootToPath(TEST_DIR2,rootPathBuffer2,storageId));//Copy all files from TEST_DIR to TEST_DIR2
00566     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00567 /*#10*/
00568     for(i = 0; i < TEST_NUMBER_OF_FILE_TO_CREATE; i++)
00569     {
00570         snprintf(rootPathBuffer1, PAL_MAX_FILE_AND_FOLDER_LENGTH, TEST_FILE_NAME, TEST_DIR, i);
00571         snprintf(rootPathBuffer2, PAL_MAX_FILE_AND_FOLDER_LENGTH, TEST_FILE_NAME, TEST_DIR2, i);
00572 
00573         fileSystemCompareUtil(addRootToPath(rootPathBuffer1,buffer1,storageId), addRootToPath(rootPathBuffer2,buffer2,storageId));
00574     }
00575 
00576 /*#11*/
00577     status = pal_fsRmFiles(addRootToPath(TEST_DIR2,rootPathBuffer2,storageId));//Remove all files in the testing DIRECTORY
00578     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00579 
00580 /*#12*/
00581     status = pal_fsRmFiles(addRootToPath(TEST_DIR,rootPathBuffer1,storageId));//Remove all files in the testing DIRECTORY
00582     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00583 
00584 /*#13*/
00585     for(i = 0; i < TEST_NUMBER_OF_FILE_TO_CREATE; i++)
00586     {
00587 /*#14*/
00588         snprintf(buffer1, PAL_MAX_FILE_AND_FOLDER_LENGTH, TEST_FILE_NAME, TEST_DIR, i);
00589         status =  pal_fsFopen(addRootToPath(buffer1,rootPathBuffer1,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
00590         TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00591 
00592 /*#15*/
00593         status =  pal_fsFopen(addRootToPath(buffer1,rootPathBuffer1,storageId), PAL_FS_FLAG_READWRITE, &g_fd1);
00594         TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00595 
00596 /*#16*/
00597         snprintf(buffer2, PAL_MAX_FILE_AND_FOLDER_LENGTH, TEST_FILE_NAME, TEST_DIR2, i);
00598         status =  pal_fsFopen(addRootToPath(buffer2,rootPathBuffer2,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
00599         TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00600 
00601 /*#17*/
00602         status =  pal_fsFopen(addRootToPath(buffer1,rootPathBuffer1,storageId), PAL_FS_FLAG_READWRITE, &g_fd1);
00603         TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);    //Failed all files where deleted in previous step
00604 
00605     }
00606 
00607 /*#18*/
00608     status = pal_fsRmDir(addRootToPath(TEST_DIR,buffer1,storageId));
00609     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00610 
00611 /*#19*/
00612     status = pal_fsRmDir(addRootToPath(TEST_DIR2,buffer2,storageId));
00613     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00614 
00615 /*#20*/
00616     status = pal_fsUnlink(addRootToPath("aaaa.t",rootPathBuffer1, storageId));//not existing file
00617     TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_FILE, status);
00618 
00619 /*#21*/
00620     status = pal_fsRmFiles(addRootToPath("aaaaa",rootPathBuffer1, storageId));//Remove all file in not existing directory
00621     TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_PATH, status);
00622 
00623 /*#22*/
00624 
00625     status = pal_fsCpFolder(addRootToPath("aaaaa", rootPathBuffer1, storageId), addRootToPath("bbbb" ,rootPathBuffer2,storageId)); //copy from not existing dir
00626     TEST_ASSERT_EQUAL(PAL_ERR_FS_NO_PATH, status);
00627 }
00628 
00629 TEST(pal_fileSystem, FilesTests)
00630 {
00631     FilesTests(PAL_FS_PARTITION_PRIMARY);
00632     FilesTests(PAL_FS_PARTITION_SECONDARY);
00633 }
00634 
00635 /*! \brief /b FilesTestsSeek function Tests \b fseek() , \b fteel() & \b fread() function
00636 *
00637 ** \test
00638 * | # |    Step                        |   Expected  |
00639 * |---|--------------------------------|-------------|
00640 * | 1 | create TEST_DIR with pal_fsMkDir                                                        | PAL_SUCCESS |
00641 * | 2 | Create File TEST_DIR_FILE With PAL_ERR_FS_READWRITETRUNC with pal_fsFopen               | PAL_SUCCESS |
00642 * | 3 | Create buffer[TEST_BUFFER_SIZE] with incremental data, Buffer size TEST_BUFFER_SIZE     | PAL_SUCCESS |
00643 * | 4 | Write buffer to file with pal_fsFwrite                                                  | PAL_SUCCESS |
00644 * | 5 | Start Loop     i from [0 - TEST_BUFFER_SIZE]                                            | |
00645 * | 6 | run pal_fsFseek with PAL_FS_OFFSET_SEEKSET option and incremental offset i              | PAL_SUCCESS |
00646 * | 7 | run    pal_fsFtell and compare offset to i                                              | PAL_SUCCESS |
00647 * | 8 | run    pal_fsFread, read one byte and compare it to the buffer[i]                       | PAL_SUCCESS |
00648 * | 9 | End Loop                                                                                | |
00649 * | 10 | Start Loop i from [0 - TEST_BUFFER_SIZE]                                               | |
00650 * | 11 | run pal_fsFseek with PAL_FS_OFFSET_SEEKEND option and incremental offset (-1)*i        | PAL_SUCCESS |
00651 * | 12 | run pal_fsFtell and compare offset to TEST_BUFFER_SIZE - i                             | PAL_SUCCESS |
00652 * | 13 | End Loop                                                                               | |
00653 * | 14 | run pal_fsFseek with PAL_FS_OFFSET_SEEKSET option offset TEST_BUFFER_SIZE/2            | PAL_SUCCESS |
00654 * | 15 | Start Loop i from [0 - TEST_BUFFER_SIZE/10]                                            | |
00655 * | 16 | run pal_fsFseek with PAL_FS_OFFSET_SEEKEND option and incremental offset i             | PAL_SUCCESS |
00656 * | 17 | run    pal_fsFtell and compare offset to i                                             | PAL_SUCCESS |
00657 * | 18 | End Loop                                                                               | |
00658 * | 19 | Cleanup                                                                                | PAL_SUCCESS |
00659 *
00660 */
00661 void FilesTestsSeek(pal_fsStorageID_t storageId)
00662 {
00663     palStatus_t status = PAL_SUCCESS;
00664     char buffer[TEST_BUFFER_SIZE];
00665     int i = 0;
00666     size_t numOfBytes;
00667     int32_t pos = 0;
00668     char read_buf = 1;
00669     size_t prePos = 0;
00670 /*#1*/
00671     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,storageId)); //Create Directory
00672     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00673 
00674 /*#2*/
00675     status =  pal_fsFopen(addRootToPath(TEST_DIR_FILE,buffer,storageId), PAL_FS_FLAG_READWRITETRUNC, &g_fd1);
00676     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00677 
00678 /*#3*/
00679     for(i = 0; i < TEST_BUFFER_SIZE; i++)
00680     {
00681         buffer[i] = i;
00682     }
00683 
00684 /*#4*/
00685     status =  pal_fsFwrite(&g_fd1, (void *)buffer, TEST_BUFFER_SIZE, &numOfBytes);  //Write incremental buffer for seek testing
00686     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00687     TEST_ASSERT_EQUAL(TEST_BUFFER_SIZE, numOfBytes);
00688 
00689 /*#5*/
00690     //Test Seek "PAL_FS_OFFSET_SEEKSET"
00691     for(i = 0; i < TEST_BUFFER_SIZE; i++)
00692     {
00693 
00694 /*#6*/    
00695         status = pal_fsFseek(&g_fd1, i, PAL_FS_OFFSET_SEEKSET); //Set position to start of the stream
00696         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00697 
00698 /*#7*/    
00699         status = pal_fsFtell(&g_fd1, &pos); //Check if position is in the start of the stream
00700         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00701         TEST_ASSERT_EQUAL(i, pos);
00702 
00703 /*#8*/    
00704         status  = pal_fsFread(&g_fd1, &read_buf, 1, &numOfBytes);
00705         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00706         TEST_ASSERT_EQUAL(1, numOfBytes);
00707         TEST_ASSERT_EQUAL(buffer[i], read_buf);
00708 
00709 /*#9*/
00710     }
00711     
00712 /*#10*/
00713     //Test Seek "PAL_FS_OFFSET_SEEKEND"
00714     for(i = 0; i < TEST_BUFFER_SIZE; i++)
00715     {
00716 /*#11*/    
00717         status = pal_fsFseek(&g_fd1, (-1)*i, PAL_FS_OFFSET_SEEKEND); //Set position to end  of the stream
00718         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00719 
00720 /*#12*/    
00721         status = pal_fsFtell(&g_fd1, &pos); //Get position
00722         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00723         TEST_ASSERT_EQUAL(TEST_BUFFER_SIZE - i, pos);
00724 
00725 /*#13*/
00726     }
00727 
00728 /*#14*/
00729     //Test Seek "PAL_ERR_FS_SEEKCUR"
00730     status = pal_fsFseek(&g_fd1, TEST_BUFFER_SIZE/2, PAL_FS_OFFSET_SEEKSET); //Set position to middle of the stream
00731     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00732     prePos = TEST_BUFFER_SIZE/2;
00733 
00734 /*#15*/
00735     for(i = 0; i < TEST_BUFFER_SIZE/10 ; i++)
00736     {
00737 
00738 /*#16*/    
00739         status = pal_fsFseek(&g_fd1, i, PAL_FS_OFFSET_SEEKCUR); //Set position to start of the stream
00740         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00741 
00742 /*17*/    
00743         status = pal_fsFtell(&g_fd1, &pos); //Get position
00744         TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00745         TEST_ASSERT_EQUAL(prePos + i, pos);
00746         prePos = pos;
00747 
00748 /*#18*/
00749     }
00750 
00751 /*#19*/
00752     status =  pal_fsFclose(&g_fd1);
00753     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00754 }
00755 
00756 
00757 TEST(pal_fileSystem, FilesTestsSeek)
00758 {
00759     FilesTestsSeek(PAL_FS_PARTITION_PRIMARY);
00760 #if (PAL_NUMBER_OF_PARTITIONS == 2)
00761     FilesTestsSeek(PAL_FS_PARTITION_SECONDARY);
00762 #endif
00763 }
00764 
00765 /*! \brief /b FilesPermission function Tests \b fopen() with r
00766 *
00767 ** \test
00768 * | # |    Step                        |   Expected  |
00769 * |---|--------------------------------|-------------|
00770 * | 1 | Init Test                                                                               | Success |
00771 * | 2 | create TEST_DIR with pal_fsMkDir                                                        | PAL_SUCCESS |
00772 * | 3 | create new file using fopen with PAL_FS_FLAG_READWRITEEXCLUSIVE                         | PAL_SUCCESS |
00773 * | 4 | write buffer to file                                                                    | PAL_SUCCESS |
00774 * | 5 | close file                                                                              | PAL_SUCCESS |
00775 * | 6 | open file using fopen() with PAL_FS_FLAG_READONLY                                       | PAL_SUCCESS |
00776 * | 7 | write buffer to file with fwrite()                                                      | failed |
00777 * | 8 | read buffer from file with fread()                                                      | PAL_SUCCESS |
00778 * | 9 | close file                                                                              | PAL_SUCCESS |
00779 * | 10 | remove all files in folder                                                             | PAL_SUCCESS |
00780 * | 11 | remove folder                                                                          | PAL_SUCCESS |
00781 */
00782 void FilesPermission_read_only(pal_fsStorageID_t storageId)
00783 {
00784     palStatus_t status = PAL_SUCCESS;
00785     char readBuffer[TEST_BUFFER_SIZE];
00786     char readBuffer2[TEST_BUFFER_SIZE];
00787     char filename[TEST_BUFFER_SIZE];
00788     size_t numOfBytes = 0;
00789     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00790 
00791 /*#1*/
00792     //---------------- INIT TESTS----------------------------//
00793     memset(readBuffer, '1', TEST_BUFFER_SIZE);
00794     //----------------END INIT TESTS-------------------------//
00795 
00796 /*#2*/
00797     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,storageId)); //Create Directory
00798     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00799 
00800     snprintf(filename, TEST_BUFFER_SIZE, TEST_FILE_NAME, TEST_DIR, 1);
00801 /*#3*/
00802     status =  pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00803     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00804 
00805 /*#4*/
00806     status =  pal_fsFwrite(&g_fd1, (void *)readBuffer, TEST_BYTES_TO_WRITE, &numOfBytes);
00807     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00808     TEST_ASSERT_EQUAL(TEST_BYTES_TO_WRITE, numOfBytes);
00809 
00810 /*#5*/
00811     status =  pal_fsFclose(&g_fd1);
00812     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00813 
00814 /*#6*/
00815     status =  pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
00816     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00817 
00818 /*#7*/
00819     pal_fsFwrite(&g_fd1, (void *)readBuffer, TEST_BYTES_TO_WRITE, &numOfBytes);
00820     TEST_ASSERT_EQUAL(0, numOfBytes);
00821 
00822 /*#8*/
00823     status = pal_fsFread(&g_fd1, readBuffer2, TEST_BUFFER_SIZE, &numOfBytes);
00824     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00825     TEST_ASSERT_EQUAL(TEST_BUFFER_SIZE, numOfBytes);
00826     TEST_ASSERT_EQUAL_MEMORY(readBuffer, readBuffer2, TEST_BUFFER_SIZE);
00827 
00828 /*#9*/
00829     status =  pal_fsFclose(&g_fd1);
00830     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00831 
00832 /*#10*/
00833     status = pal_fsRmFiles(addRootToPath(TEST_DIR,buffer,storageId));//Remove all files in the testing DIRECTORY
00834     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00835 
00836 /*#11*/
00837     status = pal_fsRmDir(addRootToPath(TEST_DIR,buffer,storageId)); //Delete Directory if exist
00838     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00839 }
00840 
00841 TEST(pal_fileSystem, FilesPermission_read_only)
00842 {
00843     FilesPermission_read_only(PAL_FS_PARTITION_PRIMARY);
00844     FilesPermission_read_only(PAL_FS_PARTITION_SECONDARY);
00845 }
00846 
00847 
00848 /*! \brief /b FilesPermission function Tests \b fopen() with r+
00849 *
00850 ** \test
00851 * | # |    Step                        |   Expected  |
00852 * |---|--------------------------------|-------------|
00853 * | 1 | Init Test                                                                               | Success |
00854 * | 2 | create TEST_DIR with pal_fsMkDir                                                        | PAL_SUCCESS |
00855 * | 3 | create new file using fopen with PAL_FS_FLAG_READWRITEEXCLUSIVE                         | PAL_SUCCESS |
00856 * | 4 | write buffer to file                                                                    | PAL_SUCCESS |
00857 * | 5 | close file                                                                              | PAL_SUCCESS |
00858 * | 6 | open file using fopen() with PAL_FS_FLAG_READONLY                                       | PAL_SUCCESS |
00859 * | 7 | write buffer to file with fwrite()                                                      | PAL_SUCCESS |
00860 * | 8 | seek to the begining of the file                                                        | PAL_SUCCESS |
00861 * | 9 | read buffer from file with fread()                                                      | PAL_SUCCESS |
00862 * | 10 | close file                                                                             | PAL_SUCCESS |
00863 * | 11 | remove all files in folder                                                             | PAL_SUCCESS |
00864 * | 12 | remove folder                                                                          | PAL_SUCCESS |
00865 */
00866 void FilesPermission_read_write(pal_fsStorageID_t storageId)
00867 {
00868     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00869     palStatus_t status = PAL_SUCCESS;
00870     char readBuffer[TEST_BUFFER_SIZE];
00871     char readBuffer2[TEST_BUFFER_SIZE];
00872     char filename[TEST_BUFFER_SIZE];
00873     size_t numOfBytes = 0;
00874 
00875 /*#1*/
00876     //---------------- INIT TESTS----------------------------//
00877     memset(readBuffer, '1', TEST_BUFFER_SIZE);
00878     //----------------END INIT TESTS-------------------------//
00879 
00880 /*#2*/
00881     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,storageId)); //Create Directory
00882     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00883 
00884     snprintf(filename, TEST_BUFFER_SIZE, TEST_FILE_NAME, TEST_DIR, 1);
00885 /*#3*/
00886     status =  pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00887     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00888 
00889 /*#4*/
00890     status =  pal_fsFwrite(&g_fd1, (void *)readBuffer, TEST_BYTES_TO_WRITE, &numOfBytes);
00891     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00892     TEST_ASSERT_EQUAL(TEST_BYTES_TO_WRITE, numOfBytes);
00893 
00894 /*#5*/
00895     status =  pal_fsFclose(&g_fd1);
00896     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00897 
00898 /*#6*/
00899     status =  pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READWRITE, &g_fd1);
00900     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00901 
00902 /*#7*/
00903     status =  pal_fsFwrite(&g_fd1, (void *)readBuffer, TEST_BYTES_TO_WRITE, &numOfBytes);
00904     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00905     TEST_ASSERT_EQUAL(TEST_BYTES_TO_WRITE, numOfBytes);
00906 
00907 /*#8*/
00908     status = pal_fsFseek(&g_fd1, 0, PAL_FS_OFFSET_SEEKSET); //Set position to start of the stream
00909     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00910 
00911 /*#9*/
00912     status = pal_fsFread(&g_fd1, readBuffer2, TEST_BUFFER_SIZE, &numOfBytes);
00913     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00914     TEST_ASSERT_EQUAL(TEST_BYTES_TO_WRITE, numOfBytes);
00915     TEST_ASSERT_EQUAL_MEMORY(readBuffer, readBuffer2, TEST_BUFFER_SIZE);
00916 
00917 /*#10*/
00918     status =  pal_fsFclose(&g_fd1);
00919     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00920 
00921 /*#11*/
00922     status = pal_fsRmFiles(addRootToPath(TEST_DIR,buffer,storageId));//Remove all files in the testing DIRECTORY
00923     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00924 
00925 /*#12*/
00926     status = pal_fsRmDir(addRootToPath(TEST_DIR,buffer,storageId)); //Delete Directory if exist
00927     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00928 }
00929 
00930 
00931 TEST(pal_fileSystem, FilesPermission_read_write)
00932 {
00933     FilesPermission_read_write(PAL_FS_PARTITION_PRIMARY);
00934     FilesPermission_read_write(PAL_FS_PARTITION_SECONDARY);
00935 }
00936 
00937 
00938 /*! \brief /b FilesPermission function Tests \b fopen() with w+x
00939 *
00940 ** \test
00941 * | # |    Step                        |   Expected  |
00942 * |---|--------------------------------|-------------|
00943 * | 1 | Init Test                                                                               | Success |
00944 * | 2 | create TEST_DIR with pal_fsMkDir                                                        | PAL_SUCCESS |
00945 * | 3 | create new file using fopen with PAL_FS_FLAG_READWRITEEXCLUSIVE                         | PAL_SUCCESS |
00946 * | 4 | write buffer to file                                                                    | PAL_SUCCESS |
00947 * | 5 | close file                                                                              | PAL_SUCCESS |
00948 * | 6 | open file using fopen() withPAL_FS_FLAG_READWRITETRUNC                                  | PAL_SUCCESS |
00949 * | 7 | read buffer from file with fread()                                                      | PAL_SUCCESS with read length 0 |
00950 * | 8 | close file                                                                              | PAL_SUCCESS |
00951 * | 9 | remove all files in folder                                                              | PAL_SUCCESS |
00952 * | 10 | remove folder                                                                          | PAL_SUCCESS |
00953 */
00954 void FilesPermission_read_write_trunc(pal_fsStorageID_t storageId)
00955 {
00956     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
00957     palStatus_t status = PAL_SUCCESS;
00958     char readBuffer[TEST_BUFFER_SIZE];
00959     char filename[TEST_BUFFER_SIZE];
00960     size_t numOfBytes = 0;
00961 
00962 /*#1*/
00963     //---------------- INIT TESTS----------------------------//
00964     memset(readBuffer, '1', TEST_BUFFER_SIZE);
00965     //----------------END INIT TESTS-------------------------//
00966 
00967 /*#2*/
00968     status = pal_fsMkDir(addRootToPath(TEST_DIR,buffer,storageId)); //Create Directory
00969     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00970 
00971     snprintf(filename, TEST_BUFFER_SIZE, TEST_FILE_NAME, TEST_DIR, 1);
00972 /*#3*/
00973     status = pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
00974     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00975 
00976 /*#4*/
00977     status = pal_fsFwrite(&g_fd1, (void *)readBuffer, TEST_BYTES_TO_WRITE, &numOfBytes);
00978     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00979     TEST_ASSERT_EQUAL(TEST_BYTES_TO_WRITE, numOfBytes);
00980 
00981 /*#5*/
00982     status = pal_fsFclose(&g_fd1);
00983     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00984 
00985 /*#6*/
00986     status = pal_fsFopen(addRootToPath(filename,buffer,storageId), PAL_FS_FLAG_READWRITETRUNC, &g_fd1);
00987     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00988 
00989 /*#7*/
00990     status = pal_fsFread(&g_fd1, readBuffer, TEST_BUFFER_SIZE, &numOfBytes);
00991     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00992     TEST_ASSERT_EQUAL(0, numOfBytes); //nothing to read empty file
00993 
00994 /*#8*/
00995     status = pal_fsFclose(&g_fd1);
00996     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
00997 
00998 /*#9*/
00999     status = pal_fsRmFiles(addRootToPath(TEST_DIR,buffer,storageId));//Remove all files in the testing DIRECTORY
01000     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
01001 
01002 /*#10*/
01003     status = pal_fsRmDir(addRootToPath(TEST_DIR,buffer,storageId)); //Delete Directory if exist
01004     TEST_ASSERT_EQUAL(PAL_SUCCESS, status);
01005 }
01006 
01007 
01008 TEST(pal_fileSystem, FilesPermission_read_write_trunc)
01009 {
01010     FilesPermission_read_write_trunc(PAL_FS_PARTITION_PRIMARY);
01011     FilesPermission_read_write_trunc(PAL_FS_PARTITION_SECONDARY);
01012 }
01013 
01014 
01015 void create_write_and_read_pal_file(pal_fsStorageID_t storageId)
01016 {
01017     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
01018     char fileName[] = "fileName";
01019     palStatus_t res = PAL_SUCCESS;
01020     size_t num_bytes_write = 0;
01021     size_t num_bytes_read = 0;
01022 
01023     uint32_t i = 0;
01024 
01025     bufferTest = malloc(BUFFER_TEST_SIZE);
01026     TEST_ASSERT_NOT_EQUAL(bufferTest, NULL);
01027     bufferTest2 = malloc(BUFFER_TEST_SIZE);
01028     TEST_ASSERT_NOT_EQUAL(bufferTest2, NULL);
01029     memset(bufferTest, 0, BUFFER_TEST_SIZE);
01030     memset(bufferTest2, 0, BUFFER_TEST_SIZE);
01031 
01032     for (i = 0; i < BUFFER_TEST_SIZE; i++){
01033             bufferTest[i] = (uint8_t)(i % 256);
01034     }
01035 
01036     pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01037 
01038     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &(g_fd1));
01039     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01040 
01041     res = pal_fsFwrite(&(g_fd1), bufferTest, BUFFER_TEST_SIZE, &num_bytes_write);
01042     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01043     TEST_ASSERT_EQUAL(BUFFER_TEST_SIZE, num_bytes_write);
01044 
01045     res = pal_fsFclose(&(g_fd1));
01046     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01047 
01048     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READONLY, &(g_fd1));
01049     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01050 
01051     res = pal_fsFread(&(g_fd1), bufferTest2, 223, &num_bytes_read);
01052     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01053     TEST_ASSERT_EQUAL(223, num_bytes_read);
01054 
01055     // split the reads
01056     res = pal_fsFread(&(g_fd1), bufferTest2, 900, &num_bytes_read);
01057     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01058     TEST_ASSERT_EQUAL(900, num_bytes_read);
01059 
01060 
01061     // Compare the buffers � here we have a mismatch in location buffer2[288]
01062     TEST_ASSERT_EQUAL_INT8_ARRAY(&(bufferTest[223]), bufferTest2, 900);
01063 
01064     res = pal_fsFclose(&(g_fd1));
01065     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01066 
01067     res = pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01068     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01069 
01070     free(bufferTest);
01071     bufferTest = NULL;
01072     free(bufferTest2);
01073     bufferTest2 = NULL;
01074     
01075 }
01076 
01077 
01078 TEST(pal_fileSystem, create_write_and_read_pal_file)
01079 {
01080     create_write_and_read_pal_file(PAL_FS_PARTITION_PRIMARY);
01081     create_write_and_read_pal_file(PAL_FS_PARTITION_SECONDARY);
01082 }
01083 
01084 void WriteInTheMiddle(pal_fsStorageID_t storageId)
01085 {
01086     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
01087     char fileName[] = "fileName";
01088     const uint32_t inputSizeSmall = (TEST_BUFFER_SIZE * 6) + 1;
01089     const uint32_t inputSizeBig = BUFFER_TEST_SIZE;
01090     palStatus_t res = PAL_SUCCESS;
01091     size_t num_bytes_write = 0;
01092     size_t num_bytes_read = 0;
01093     unsigned char *smallBuffer = NULL;
01094     const size_t offset = 200;
01095     uint32_t residue = inputSizeBig - (offset + inputSizeSmall);
01096 
01097     bufferTest = malloc(inputSizeBig);
01098     TEST_ASSERT_NOT_EQUAL(bufferTest, NULL);
01099     bufferTest2 = malloc(inputSizeBig);
01100     TEST_ASSERT_NOT_EQUAL(bufferTest2, NULL);
01101     smallBuffer = malloc(inputSizeSmall);
01102     TEST_ASSERT_NOT_EQUAL(smallBuffer, NULL);
01103     memset(bufferTest, 0, inputSizeBig);
01104     memset(bufferTest2, 0, inputSizeBig);
01105     memset(smallBuffer, 0, inputSizeSmall);
01106 
01107     // create 1123 bytes buffer filled with the numbers 0..255
01108     for (uint32_t i = 0; i < inputSizeBig; i++)
01109     {
01110         bufferTest[i] = (uint8_t)(i % 256);
01111     }
01112 
01113     // create 601 bytes buffer filled with only 0xCC
01114     for (uint32_t i = 0; i < inputSizeSmall; i++)
01115     {
01116         smallBuffer[i] = 0xCC;
01117     }
01118 
01119     pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01120     TEST_ASSERT((PAL_SUCCESS == res) || (PAL_ERR_FS_NO_FILE == res));
01121 
01122     /* 1. Write bufferTest data to file, read it and compare read content to bufferTest */
01123     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
01124     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01125 
01126     res = pal_fsFwrite(&g_fd1, bufferTest, inputSizeBig, &num_bytes_write);
01127     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01128     TEST_ASSERT_EQUAL(inputSizeBig, num_bytes_write);
01129 
01130     res = pal_fsFclose(&g_fd1);
01131     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01132 
01133     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
01134     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01135 
01136     res = pal_fsFread(&g_fd1, bufferTest2, inputSizeBig, &num_bytes_read);
01137     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01138     TEST_ASSERT_EQUAL(inputSizeBig, num_bytes_read);
01139     TEST_ASSERT_EQUAL_HEX8_ARRAY(bufferTest, bufferTest2, inputSizeBig);
01140 
01141     res = pal_fsFclose(&g_fd1);
01142     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01143 
01144     /* 
01145     2. Write smallBuffer data to offset 201 of the file and then compare each fragment:
01146         - offset 0..200 equal to bufferTest[0..200]
01147         - offset 201..801 equal to smallBuffer
01148         - offset 802..1122 equal to bufferTest[802..1122]
01149     */
01150     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READWRITE, &g_fd1);
01151     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01152 
01153     res = pal_fsFseek(&g_fd1, offset, PAL_FS_OFFSET_SEEKSET);
01154     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01155 
01156     res = pal_fsFwrite(&g_fd1, smallBuffer, inputSizeSmall, &num_bytes_write);
01157     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01158     TEST_ASSERT_EQUAL(inputSizeSmall, num_bytes_write);
01159 
01160     res = pal_fsFclose(&g_fd1);
01161     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01162 
01163     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
01164     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01165 
01166     // offset 0..200 equal to bufferTest[0..200]
01167     res = pal_fsFread(&g_fd1, bufferTest2, offset, &num_bytes_read);
01168     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01169     TEST_ASSERT_EQUAL(offset, num_bytes_read);
01170     TEST_ASSERT_EQUAL_HEX8_ARRAY(bufferTest, bufferTest2, offset);
01171 
01172     // offset 201..801 equal to smallBuffer
01173     res = pal_fsFread(&g_fd1, bufferTest2, inputSizeSmall, &num_bytes_read);
01174     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01175     TEST_ASSERT_EQUAL(inputSizeSmall, num_bytes_read);
01176     TEST_ASSERT_EQUAL_HEX8_ARRAY(smallBuffer, bufferTest2, inputSizeSmall);
01177 
01178     // offset 802..1122 equal to bufferTest[802..1122]
01179     res = pal_fsFread(&g_fd1, bufferTest2, residue, &num_bytes_read);
01180     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01181     TEST_ASSERT_EQUAL(residue, num_bytes_read);
01182     TEST_ASSERT_EQUAL_HEX8_ARRAY(bufferTest + offset + inputSizeSmall, bufferTest2, residue);
01183 
01184     res = pal_fsFclose(&g_fd1);
01185     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01186 
01187     res = pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01188     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01189 
01190     free(bufferTest);
01191     bufferTest = NULL;
01192     free(bufferTest2);
01193     bufferTest2 = NULL;
01194     free(smallBuffer);
01195     smallBuffer = NULL;
01196 }
01197 
01198 TEST(pal_fileSystem, WriteInTheMiddle)
01199 {
01200     WriteInTheMiddle(PAL_FS_PARTITION_PRIMARY);
01201     WriteInTheMiddle(PAL_FS_PARTITION_SECONDARY);
01202 }
01203 
01204 
01205 
01206 
01207 void SequentialWriteAndRead(pal_fsStorageID_t storageId)
01208 {
01209     char buffer[PAL_MAX_FILE_AND_FOLDER_LENGTH] = {0};
01210     char fileName[] = "fileName";
01211     palStatus_t res = PAL_SUCCESS;
01212     size_t num_bytes_write = 0;
01213     size_t num_bytes_read = 0;
01214     unsigned char small_write_buffer[TEST_BUFFER_SMALL_SIZE] = {
01215         0x2D, 0x6B, 0xAC, 0xCC, 0x08, 0x6B, 0x14, 0x82,
01216         0xF3, 0x0C, 0xF5, 0x67, 0x17, 0x23, 0x50, 0xB4,
01217         0xFF
01218     };
01219     unsigned char small_read_buffer[TEST_BUFFER_SMALL_SIZE] = { 0 };
01220     bufferTest = malloc(BUFFER_TEST_SIZE);
01221     TEST_ASSERT_NOT_EQUAL(bufferTest, NULL);
01222     bufferTest2 = malloc(BUFFER_TEST_SIZE);
01223     TEST_ASSERT_NOT_EQUAL(bufferTest2, NULL);
01224     memset(bufferTest, 0, BUFFER_TEST_SIZE);
01225     memset(bufferTest2, 0, BUFFER_TEST_SIZE);
01226 
01227     // create 1123 bytes buffer filled with the numbers 0..255
01228     for (uint32_t i = 0; i < BUFFER_TEST_SIZE; i++)
01229     {
01230         bufferTest[i] = (uint8_t)(i % 256);
01231     }
01232     res = pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01233     TEST_ASSERT((PAL_SUCCESS == res) || (PAL_ERR_FS_NO_FILE == res));
01234 
01235     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READWRITEEXCLUSIVE, &g_fd1);
01236     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01237 
01238     // split the writes
01239     res = pal_fsFwrite(&g_fd1, small_write_buffer, TEST_BUFFER_SMALL_SIZE, &num_bytes_write);
01240     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01241     TEST_ASSERT_EQUAL(TEST_BUFFER_SMALL_SIZE, num_bytes_write);
01242 
01243     res = pal_fsFwrite(&g_fd1, bufferTest, BUFFER_TEST_SIZE, &num_bytes_write);
01244     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01245     TEST_ASSERT_EQUAL(BUFFER_TEST_SIZE, num_bytes_write);
01246 
01247     res = pal_fsFclose(&g_fd1);
01248     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01249 
01250     res = pal_fsFopen(addRootToPath(fileName,buffer,storageId), PAL_FS_FLAG_READONLY, &g_fd1);
01251     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01252 
01253     // split the reads
01254     res = pal_fsFread(&g_fd1, small_read_buffer, TEST_BUFFER_SMALL_SIZE, &num_bytes_read);
01255     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01256     TEST_ASSERT_EQUAL(TEST_BUFFER_SMALL_SIZE, num_bytes_read);
01257 
01258     res = pal_fsFread(&g_fd1, bufferTest2, BUFFER_TEST_SIZE, &num_bytes_read);
01259     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01260     TEST_ASSERT_EQUAL(BUFFER_TEST_SIZE, num_bytes_read);
01261 
01262     TEST_ASSERT_EQUAL_INT8_ARRAY(bufferTest, bufferTest2, BUFFER_TEST_SIZE);
01263 
01264     res = pal_fsFclose(&g_fd1);
01265     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01266 
01267     res = pal_fsUnlink(addRootToPath(fileName,buffer,storageId));
01268     TEST_ASSERT_EQUAL(PAL_SUCCESS, res);
01269 
01270     free(bufferTest);
01271     bufferTest = NULL;
01272     free(bufferTest2);
01273     bufferTest2 = NULL;    
01274 }
01275 
01276 TEST(pal_fileSystem, SequentialWriteAndRead)
01277 {
01278     SequentialWriteAndRead(PAL_FS_PARTITION_PRIMARY);
01279     SequentialWriteAndRead(PAL_FS_PARTITION_SECONDARY);
01280 }