Beispiel #1
0
void TextFileTestCase::ReadMixedWithFuzzing()
{
    for ( int iteration = 0; iteration < 100; iteration++)
    {
        // Create a random buffer with lots of newlines. This is intended to catch
        // bad parsing in unexpected situations such as the one from ReadCRCRLF()
        // (which is so common it deserves a test of its own).
        static const char CHOICES[] = {'\r', '\n', 'X'};

        const size_t BUF_LEN = 100;
        char data[BUF_LEN + 1];
        data[0] = 'X';
        data[BUF_LEN] = '\0';
        unsigned linesCnt = 0;
        for ( size_t i = 1; i < BUF_LEN; i++ )
        {
            char ch = CHOICES[rand() % WXSIZEOF(CHOICES)];
            data[i] = ch;
            if ( ch == '\r' || (ch == '\n' && data[i-1] != '\r') )
                linesCnt++;
        }
        if (data[BUF_LEN-1] != '\r' && data[BUF_LEN-1] != '\n')
            linesCnt++; // last line was unterminated

        CreateTestFile(data);

        wxTextFile f;
        CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );
        CPPUNIT_ASSERT_EQUAL( (size_t)linesCnt, f.GetLineCount() );
    }
}
Beispiel #2
0
void TextFileTestCase::ReadEmpty()
{
    CreateTestFile("");

    wxTextFile f;
    CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );

    CPPUNIT_ASSERT_EQUAL( (size_t)0, f.GetLineCount() );
}
Beispiel #3
0
void TextFileTestCase::ReadMacLast()
{
    CreateTestFile("foo\r");

    wxTextFile f;
    CPPUNIT_ASSERT( f.Open(GetTestFileName()) );

    CPPUNIT_ASSERT_EQUAL( 1, f.GetLineCount() );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_Mac, f.GetLineType(0) );
    CPPUNIT_ASSERT_EQUAL( "foo", f.GetFirstLine() );
}
Beispiel #4
0
void TextFileTestCase::ReadUnix()
{
    CreateTestFile("foo\nbar\nbaz");

    wxTextFile f;
    CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );

    CPPUNIT_ASSERT_EQUAL( (size_t)3, f.GetLineCount() );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(2) );
    CPPUNIT_ASSERT_EQUAL( wxString(wxT("bar")), f.GetLine(1) );
    CPPUNIT_ASSERT_EQUAL( wxString(wxT("baz")), f.GetLastLine() );
}
/*
 * It is the responsibility of the invoking environment to delete the
 * file passed as command-line argument.  See the build.scons file.
 */
int main(int ac, char **av) {
  char const *test_dir_name = "/tmp/nacl_host_desc_test";
  struct NaClHostDesc hd;
  struct NaClHostDesc hd_ro;
  size_t error_count;
  size_t ix;
  int test_passed;
  int opt;
  int num_runs = 1;
  int test_run;

  while (EOF != (opt = getopt(ac, av, "c:t:"))) {
    switch (opt) {
      case 'c':
        num_runs = atoi(optarg);
        break;
      case 't':
        test_dir_name = optarg;
        break;
      default:
        fprintf(stderr,
                "Usage: nacl_host_desc_mmap_test [-c run_count]\n"
                "                                [-t test_temp_dir]\n");
        exit(1);
    }
  }

  NaClPlatformInit();

  error_count = 0;
  for (test_run = 0; test_run < num_runs; ++test_run) {
    printf("Test run %d\n\n", test_run);
    for (ix = 0; ix < NACL_ARRAY_SIZE(tests); ++ix) {
      char test_file_name[PATH_MAX];
      SNPRINTF(test_file_name, sizeof test_file_name,
               "%s/f%d.%"NACL_PRIuS, test_dir_name, test_run, ix);
      printf("%s\n", tests[ix].test_name);
      CreateTestFile(&hd, &hd_ro, test_file_name, &tests[ix]);
      test_passed = (*tests[ix].test_func)(&hd, &hd_ro, tests[ix].test_params);
      CloseTestFile(&hd);
      error_count += !test_passed;
      printf("%s\n", test_passed ? "PASSED" : "FAILED");
    }
  }

  NaClPlatformFini();

  /* we ignore the 2^32 or 2^64 total errors case */
  return (error_count > 255) ? 255 : error_count;
}
Beispiel #6
0
void CFileAskDlg::OnBnClickedOk()
{
	CString strFileName = this->m_strDistinationFolder + _T("\\test.txt1");
	if(!CreateTestFile(strFileName))
	{
		if(StrCmp(gl_strLanguageId, CHINESE) == 0)
			AfxMessageBox(szInvalidDir_CH);
		else
			AfxMessageBox(szInvalidDir_EN);
		
		return;
	}

	CString strFilePathName = m_strDistinationFolder + _T("\\") + this->m_strFileName;
	CFileStatus   status;   
	if(CFile::GetStatus(strFilePathName, status) == TRUE)  
	{
		int nRes = -1;
		if(StrCmp(gl_strLanguageId, CHINESE) == 0)
		{
			nRes = MessageBox(szOverWrite_CH, szMsgTitle_CH, MB_YESNOCANCEL);
		}
		else
			nRes = MessageBox(szOverWrite_CH, szMsgTitle_EN, MB_YESNOCANCEL);
		if(IDYES == nRes)
		{
			//gl_llSize = 0;
			gl_mapllSize[m_hRapperWnd] = 0;
		}
		else if (IDNO == nRes)
		{
			CFile file;
			if (!file.Open(strFilePathName, CFile::modeRead))
				//gl_llSize = 0;
				gl_mapllSize[m_hRapperWnd] = 0;
			else
			{
				//gl_llSize = file.GetLength();
				gl_mapllSize[m_hRapperWnd] = file.GetLength();
				file.Close();
			}
		}
		else if (IDCANCEL == nRes)
		{
			return;
		}
	}
	OnOK();
}
Beispiel #7
0
void TextFileTestCase::ReadUTF8()
{
    CreateTestFile("\xd0\x9f\n"
                   "\xd1\x80\xd0\xb8\xd0\xb2\xd0\xb5\xd1\x82");

    wxTextFile f;
    CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName()), wxConvUTF8) );

    CPPUNIT_ASSERT_EQUAL( (size_t)2, f.GetLineCount() );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_Unix, f.GetLineType(0) );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(1) );
#ifdef wxHAVE_U_ESCAPE
    CPPUNIT_ASSERT_EQUAL( wxString(L"\u041f"), f.GetFirstLine() );
    CPPUNIT_ASSERT_EQUAL( wxString(L"\u0440\u0438\u0432\u0435\u0442"),
                          f.GetLastLine() );
#endif // wxHAVE_U_ESCAPE
}
Beispiel #8
0
// Create an AAF file to be used by module test.
AAFRESULT CreateTestFile(
    const aafCharacter*         p_file_name,
    aafUID_constref             file_kind,
    const testRawStorageType_t  raw_storage_type,
    IAAFFile**                  pp_new_file )
{
  assert( p_file_name != 0 );
  assert( pp_new_file != 0 );


  aafProductIdentification_t    product_identification = MakeProductID();

  return CreateTestFile( p_file_name,
                         file_kind,
                         raw_storage_type,
                         product_identification,
                         pp_new_file );
}
Beispiel #9
0
void TextFileTestCase::ReadCRCRLF()
{
    // Notepad may create files with CRCRLF line endings (see
    // http://stackoverflow.com/questions/6998506/text-file-with-0d-0d-0a-line-breaks).
    // Older versions of wx would loose all data when reading such files.
    // Test that the data are read, but don't worry about empty lines in between or
    // line endings. Also include a longer streak of CRs, because they can
    // happen as well.
    CreateTestFile("foo\r\r\nbar\r\r\r\nbaz\r\r\n");

    wxTextFile f;
    CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName())) );

    wxString all;
    for ( wxString str = f.GetFirstLine(); !f.Eof(); str = f.GetNextLine() )
        all += str;

    CPPUNIT_ASSERT_EQUAL( "foobarbaz", all );
}
Beispiel #10
0
void TextFileTestCase::ReadUTF16()
{
    CreateTestFile(16,
                   "\x1f\x04\x0d\x00\x0a\x00"
                   "\x40\x04\x38\x04\x32\x04\x35\x04\x42\x04");

    wxTextFile f;
    wxMBConvUTF16LE conv;
    CPPUNIT_ASSERT( f.Open(wxString::FromAscii(GetTestFileName()), conv) );

    CPPUNIT_ASSERT_EQUAL( (size_t)2, f.GetLineCount() );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_Dos, f.GetLineType(0) );
    CPPUNIT_ASSERT_EQUAL( wxTextFileType_None, f.GetLineType(1) );

#ifdef wxHAVE_U_ESCAPE
    CPPUNIT_ASSERT_EQUAL( wxString(L"\u041f"), f.GetFirstLine() );
    CPPUNIT_ASSERT_EQUAL( wxString(L"\u0440\u0438\u0432\u0435\u0442"),
                          f.GetLastLine() );
#endif // wxHAVE_U_ESCAPE
}
Beispiel #11
0
// All files must have the main function.
int main(int UNUSED(argc), char **UNUSED(argv))
{
  Result result;
  hid_t file_id;

  InitResult(&result);
  file_id = CreateTestFile();

  if (file_id < 0)
  {
    printf("Fail to open temporary test file: %s\n", TEST_FILE);
    Clean(file_id);
    return EXIT_FAILURE;
  }

  CheckTestResult(TestRead(file_id), &result);

  Clean(file_id);
  DisplayResult(&result);

  return result.status;
}
Beispiel #12
0
static void Dialog2OkButton_CB(void)
{
    int    IMax   = 5;
    int    JMax   = 5;
    double XStart = 0.1;
    double YStart = 1.3;
    double XDelta = 1.0;
    double YDelta = 2.1;

    TecGUITextFieldGetLgIndex(IMax_TF_D2, &IMax);
    TecGUITextFieldGetLgIndex(JMax_TF_D2, &JMax);
    TecGUITextFieldGetDouble(XStart_TF_D2, &XStart);
    TecGUITextFieldGetDouble(YStart_TF_D2, &YStart);
    TecGUITextFieldGetDouble(XDelta_TF_D2, &XDelta);
    TecGUITextFieldGetDouble(YDelta_TF_D2, &YDelta);

    std::string testFileName = CreateTestFile(IMax, JMax,
                                              XStart, YStart,
                                              XDelta, YDelta);

    if (testFileName.empty())
    {
        TecUtilDialogErrMsg("Unable to open file for writing.");
    }
    else
    {
        TecGUITextFieldSetString(FileName_TF_D1,
                                 testFileName.c_str());
    }

    TecGUIDialogDrop(Dialog2Manager);
    /* Modal Dialogs must call TecUtilLockStart prior to coming */
    /* up and then call TecUtilLockFinish when the Ok or Cancel */
    /* button is pressed.  Only TecUtilLockFinish is supplied here. */
    TecUtilLockFinish(AddOnID);

}
/*
 * It is the responsibility of the invoking environment to delete the
 * file passed as command-line argument.  See the build.scons file.
 */
int main(int ac, char **av) {
  char const *test_dir_name = "/tmp/nacl_host_desc_mmap_win_test";
  struct NaClHostDesc hd;
  int test_passed;
  size_t error_count;
  size_t ix;
  int opt;
  int num_runs = 1;
  int test_run;
  HANDLE h;
  int d;

  while (EOF != (opt = getopt(ac, av, "c:t:"))) {
    switch (opt) {
      case 'c':
        num_runs = atoi(optarg);
        break;
      case 't':
        test_dir_name = optarg;
        break;
      default:
        fprintf(stderr,
                "Usage: nacl_host_desc_mmap_win_test [-c run_count]\n"
                "                                    [-t test_temp_dir]\n");
        exit(1);
    }
  }

  NaClPlatformInit();

  error_count = 0;
  for (test_run = 0; test_run < num_runs; ++test_run) {
    printf("Test run %d\n\n", test_run);
    for (ix = 0; ix < NACL_ARRAY_SIZE(tests); ++ix) {
      char test_file_name[PATH_MAX];
      _snprintf_s(test_file_name, sizeof test_file_name, _TRUNCATE,
                  "%s/f%d.%"NACL_PRIuS, test_dir_name, test_run, ix);
      printf("%s\n", tests[ix].test_info);
      printf("-- %s\n", tests[ix].file_type->file_type_description);

      h = CreateTestFile(test_file_name, tests[ix].file_type);
      if (ERROR_SUCCESS == tests[ix].expected_open_error) {
        if (INVALID_HANDLE_VALUE == h) {
          DWORD err = GetLastError();
          NaClLog(LOG_ERROR,
                  "CreateTestFile for %s failed, error %d\n",
                  test_file_name, err);
          printf("FAILED\n");
          ++error_count;
          continue;
        }

        d = _open_osfhandle((intptr_t) h, tests[ix].oflags);
        NaClHostDescPosixTake(&hd, d, tests[ix].posix_flags);
        test_passed = TryToMap(&hd, tests[ix].map_bytes, tests[ix].prot,
                               tests[ix].map_flags,
                               tests[ix].expected_mmap_errno);
        error_count += !test_passed;
        printf("%s\n", test_passed ? "PASSED" : "FAILED");

        CHECK(0 == NaClHostDescClose(&hd));
        AttemptToDeleteTestFile(test_file_name);
      } else {
        if (INVALID_HANDLE_VALUE == h) {
          DWORD err = GetLastError();
          if (err != tests[ix].expected_open_error) {
            NaClLog(LOG_ERROR,
                    "Expected CreateTestFile for %s to failed with"
                    " error %d, but got error %d\n",
                    test_file_name, err, tests[ix].expected_open_error);
            printf("FAILED\n");
            ++error_count;
          } else {
            printf("PASSED (open failed)\n");
          }
          continue;
        } else {
          NaClLog(LOG_ERROR,
                  "Expected CreateTestFile for %s to fail with error %d,"
                  " but succeeded instead!\n",
                  test_file_name,
                  tests[ix].expected_open_error);
          (void) CloseHandle(h);
          AttemptToDeleteTestFile(test_file_name);
          printf("FAILED\n");
          ++error_count;
          continue;
        }
      }
    }
  }

  printf("Total of %d error%s.\n", error_count, (error_count == 1) ? "" : "s");

  NaClPlatformFini();

  /* we ignore the 2^32 or 2^64 total errors case */
  return (error_count > 255) ? 255 : error_count;
}
static void TestWithCaps(TUint32 aCaps, TInt aExpectedError, const TDesC& aFileName)
/**
	Helper function for TestWithCaps(TUint32, TInt).  This function invokes
	a helper executable with the supplied capabilities and tells it to delete
	the supplied filename.
	
 	@param	aCapMask		Capabilities of process which calls RLoader::Delete.
	@param	aExpectedError	Expected error reason.  The launched executable is expected
							to panic with category KTldPanicCat and this reason, which
							is the expected return code from RLoader::Delete.
	@param	aFileName		The helper executable is told to delete this file.
*/
	{
	test.Printf(
		_L("TestWithCaps,aCaps=0x%x,aExpectedError=%d,aFileName=\"%S\"\n"),
		aCaps, aExpectedError, &aFileName);

	TInt r;

	// create the file to delete
	RFs fs;
	r = fs.Connect();
	test(r == KErrNone);

	// if this file is expected to exist then create it
	TPtrC dirName;
	TBool shouldExist = (aFileName == KTldTcbFile || aFileName == KTldAllFilesFile);
	if (shouldExist)
		{
		TParsePtrC pp(aFileName);
		dirName.Set(pp.DriveAndPath());
		r = fs.MkDirAll(dirName);
		test(r == KErrNone || r == KErrAlreadyExists);
		CreateTestFile(fs, aFileName);
		}

	SetHelperCaps(aCaps);
	RunHelper(aFileName, aExpectedError);

	if (shouldExist)
		{
		// if the file could not be deleted then delete it now
		TEntry e;
		// a C++ bool for the following equality operator
		bool exists = (fs.Entry(aFileName, e) == KErrNone);
		test(exists == (aExpectedError != KErrNone));
		
		if (exists)
			{
			r = fs.Delete(aFileName);
			test(r == KErrNone);
			}

		// delete the immediate containing directory.  The error code is not
		// used because the directory may be used for something else.
		fs.RmDir(dirName);
		}

	// delete the generated different-caps file
	r = fs.Delete(_L("c:\\sys\\bin\\tld_helper_caps.exe"));
	test(r == KErrNone);
	r = fs.Delete(_L("c:\\sys\\hash\\tld_helper_caps.exe"));
	test(r == KErrNone || r == KErrNotFound || r == KErrPathNotFound);

	fs.Close();
	}
/*
 * This test is a NaCl module that writes a file containing
 * instructions -- a simple function, f(x) = x+1 -- that is then
 * mmapped in and executed.  Since we write the file at runtime rather
 * than check in architecture-specific test data files, this code must
 * run sel_ldr with -a option.
 *
 * This test was adapted from the trusted code test in
 * src/shared/platform/nacl_host_desc_mmap_test.c
 *
 * It is the responsibility of the invoking environment to delete the
 * file passed as command-line argument.  See the nacl.scons file.
 */
int main(int ac, char **av) {
  char const *test_file_dir = "/tmp/nacl_host_desc_test";
  int fd;
  size_t err_count;
  size_t test_errors;
  size_t ix;
  int opt;
  int num_runs = 1;
  int test_run;

  while (EOF != (opt = getopt(ac, av, "c:dmt:"))) {
    switch (opt) {
      case 'c':
        num_runs = atoi(optarg);
        break;
      case 'd':
        g_prot_exec_disabled = 1;
        break;
      case 'm':
        g_mach_copy_on_write_behavior = 1;
        break;
      case 't':
        test_file_dir = optarg;
        break;
      default:
        fprintf(stderr,
                "Usage: nacl_host_desc_mmap_test [-c run_count]\n"
                "                                [-t test_temporary_dir]\n"
                "                                [-dm]\n");
        exit(1);
    }
  }

  /*
   * This print helps to ensure that the function address escapes, so
   * that a whole program optimizer is less likely to optimize it out
   * and remove the x_plus_1 code completely.
   */
  printf("x_plus_1 addr is %p\n", (void *) (uintptr_t) x_plus_1);

  err_count = 0;
  for (test_run = 0; test_run < num_runs; ++test_run) {
    printf("Test run %d\n\n", test_run);
    for (ix = 0; ix < NACL_ARRAY_SIZE(tests); ++ix) {
      char test_file_name[PATH_MAX];
      printf("%s\n", tests[ix].test_name);
      snprintf(test_file_name, sizeof test_file_name,
               "%s/f%d.%u", test_file_dir, test_run, ix);
      fd = CreateTestFile(test_file_name, &tests[ix]);
      test_errors = (*tests[ix].test_func)(fd,
                                           tests[ix].map_size,
                                           tests[ix].test_specifics);
      printf("%s\n", (0 == test_errors) ? "PASS" : "FAIL");
      err_count += test_errors;
      CloseTestFile(fd);
    }
  }

  /* we ignore the 2^32 or 2^64 total errors case */
  return (err_count > 255) ? 255 : err_count;
}
Beispiel #16
0
 // create the test file with the given contents
 static void CreateTestFile(const char *contents)
 {
     CreateTestFile(strlen(contents), contents);
 }
Beispiel #17
0
uint TestFile3(void)
{
  tIORes res;
  uint result = 1;
  tFATFile file;
  tFATFSStatus FSStatus1, FSStatus2;
  uchar buf[4UL*MAX_CLUSTER_SIZE+1];
  uint32 aFileSize[]=
  {0, 1,                                                  // ~= 0
   FAT_SECTOR_SIZE-1, FAT_SECTOR_SIZE, FAT_SECTOR_SIZE+1, // ~= sector
   -1, 0, 1,                                              // ~= cluster
   -1, 0, 1,                                              // ~= 2 clusters
   -1, 0, 1};                                             // ~= 4 clusters
  int FileSizeCount = 5;
  int FileSizeIndex = 0;
  int CloseIndex;
  int ReadSizeIndex = 0;

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  if (FSStatus1.ClusterSize != FAT_SECTOR_SIZE)
  {
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize - 1;
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize;
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize + 1;
  }
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize - 1;
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize;
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize + 1;

  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize - 1;
  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize;
  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize + 1;

  for (CloseIndex = 0; CloseIndex <= 1; CloseIndex++)
  {
    for (FileSizeIndex = 0; FileSizeIndex < FileSizeCount; FileSizeIndex++)
    {
      for (ReadSizeIndex = 0; ReadSizeIndex < FileSizeCount; ReadSizeIndex++)
      {
        uint32 size, pos=0, ReadPos;
        size_t ReadSize, s;
        int IsEof;

        size = (size_t)aFileSize[FileSizeIndex];
        ReadSize = aFileSize[ReadSizeIndex];

        CreateTestFile (&res, &file, "file1",
                        size, CloseIndex);
        CHK(res == ior_OK);

        if (!CloseIndex)
        {
          FAT_rewind (&stdio_FATFS, &res, &file);
          CHK(res == ior_OK);
        }
        else
        {
          FAT_fopen (&stdio_FATFS, &res, &file, "file1", "rb");
          CHK(res == ior_OK);
        }

        FAT_fsize (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(size == ReadPos);

        FAT_feof (&stdio_FATFS, &res, &file, &IsEof);
        CHK(res == ior_OK);
        CHK(size ? !IsEof : IsEof);

        FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(pos == ReadPos);

        while (pos < size)
        {
          uint32 i;

          s = FAT_fread (&stdio_FATFS, &res, buf, 1, ReadSize, &file);
          CHK(res == ior_OK);
          CHK(s == MIN(size - pos, ReadSize));

          if (!ReadSize)
            break;

          for (i = 0; i < s; i++)
          {
            CHK(buf[i] == (pos + i) % 251);
          }

          pos += s;
          FAT_ftell  (&stdio_FATFS, &res, &file, &ReadPos);
          CHK(res == ior_OK);
          CHK(pos == ReadPos);
        }

        if (ReadSize)
        {
          s = FAT_fread (&stdio_FATFS, &res, buf, 1, ReadSize, &file);
          CHK(res == ior_OK);
          CHK(s == 0);

          CHK(pos == size);

          FAT_feof (&stdio_FATFS, &res, &file, &IsEof);
          CHK(res == ior_OK);
          CHK(IsEof);
        }

        FAT_fclose (&stdio_FATFS, &res, &file);
        CHK(res == ior_OK);

        FAT_unlink (&stdio_FATFS, &res, "file1");
        CHK(res == ior_OK);
      }
    }
  }

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}
Beispiel #18
0
INT
_cdecl main (
    INT Argc,
    CHAR *Argv[]
    )
{
    UCHAR testCase;

    //
    // Parse cmd line
    //

    if (!ParseCmdLine(Argc,Argv)) {
        return 1;
    }

    //
    // Create the test file
    //

    if (!CreateTestFile()) {
        return 2;
    }

    //
    // Call appropriate test routine.
    //

    testCase = (Test << 1) | Access;
    switch (testCase) {
        case 0:

           if (!ReadSequential(Iterations)) {
               return 3;
           }
            break;

        case 1:

            //
            // Read random
            //

            if (!ReadRandom(Iterations)) {
                return 3;
            }

            break;

        case 2:

            if (!WriteSequential(Iterations)) {
                return 3;
            }

            break;

        case 3:

            //
            // Write random
            //

            if (!WriteRandom(Iterations)) {
                return 3;
            }

            break;

        default:
            printf("Invalid test case\n");
            return 3;
    }



    return 0;

}
Beispiel #19
0
uint TestFile4(void)
{
  tIORes res;
  uint result = 1;
  tFATFile file;
  tFATFSStatus FSStatus1, FSStatus2;
  uint32 aFileSize[]=
  {0, 1,                                                  // ~= 0
   FAT_SECTOR_SIZE-1, FAT_SECTOR_SIZE, FAT_SECTOR_SIZE+1, // ~= sector
   -1, 0, 1,                                              // ~= cluster
   -1, 0, 1,                                              // ~= 2 clusters
   -1, 0, 1};                                             // ~= 4 clusters
  int FileSizeCount = 5;
  int FileSizeIndex = 0;
  int CloseIndex;
  int ReadSizeIndex = 0;

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus1);
  CHK(res == ior_OK);

  if (FSStatus1.ClusterSize != FAT_SECTOR_SIZE)
  {
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize - 1;
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize;
    aFileSize[FileSizeCount++] = FSStatus1.ClusterSize + 1;
  }
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize - 1;
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize;
  aFileSize[FileSizeCount++] = 2 * FSStatus1.ClusterSize + 1;

  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize - 1;
  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize;
  aFileSize[FileSizeCount++] = 4 * FSStatus1.ClusterSize + 1;

  for (CloseIndex = 0; CloseIndex <= 1; CloseIndex++)
  {
    for (FileSizeIndex = 0; FileSizeIndex < FileSizeCount; FileSizeIndex++)
    {
      for (ReadSizeIndex = 0; ReadSizeIndex < FileSizeCount; ReadSizeIndex++)
      {
        uint32 size, pos=0, ReadPos;
        size_t ReadSize;

        size = (size_t)aFileSize[FileSizeIndex];
        ReadSize = aFileSize[ReadSizeIndex];

        CreateTestFile (&res, &file, "file1",
                        size, CloseIndex);
        CHK(res == ior_OK);

        if (!CloseIndex)
        {
          FAT_rewind (&stdio_FATFS, &res, &file);
          CHK(res == ior_OK);
        }
        else
        {
          FAT_fopen (&stdio_FATFS, &res, &file, "file1", "rb");
          CHK(res == ior_OK);
        }

        FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(pos == ReadPos);

        while (pos < size)
        {
          FAT_fseek (&stdio_FATFS, &res, &file, pos);
          CHK(res == ior_OK);

          FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
          CHK(res == ior_OK);
          CHK(pos == ReadPos);

          pos += MIN(size - pos, ReadSize);

          if (!ReadSize)
            break;
        }

        FAT_fseek (&stdio_FATFS, &res, &file, 0);
        CHK(res == ior_OK);

        FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(ReadPos == 0);

        FAT_fseek (&stdio_FATFS, &res, &file, size);
        CHK(res == ior_OK);

        FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(ReadPos == size);

        if (CloseIndex)
        {
          FAT_fseek (&stdio_FATFS, &res, &file, size + 1);
          CHK(res == ior_ARGUMENT_OUT_OF_RANGE);

          FAT_ftell (&stdio_FATFS, &res, &file, &ReadPos);
          CHK(res == ior_OK);
          CHK(ReadPos == size);
        }

        FAT_fsize (&stdio_FATFS, &res, &file, &ReadPos);
        CHK(res == ior_OK);
        CHK(size == ReadPos);

        FAT_fclose (&stdio_FATFS, &res, &file);
        CHK(res == ior_OK);

        FAT_unlink (&stdio_FATFS, &res, "file1");
        CHK(res == ior_OK);
      }
    }
  }

  FAT_statvfs (&stdio_FATFS, &res, "\\", &FSStatus2);
  CHK(res == ior_OK);
  CHK(FSStatus2.TotalFreeClusterCount == FSStatus1.TotalFreeClusterCount);

  result = 0;

lend:
  return result;
}