added some test cases to fsd tests

svn path=/trunk/; revision=2033
This commit is contained in:
Rex Jolliff 2001-07-04 03:07:54 +00:00
parent bd74b6b30a
commit d46de4a28a
4 changed files with 273 additions and 78 deletions

View file

@ -65,8 +65,8 @@ tstdiomisc.exe: tstdiomisc.c
$(CC) tstdiomisc.c -lkernel32 -o tstdiomisc.exe
$(NM) --numeric-sort tstdiomisc.exe > tstdiomisc.sym
testfsd.exe: testfsd.c
$(CC) testfsd.c -lkernel32 -o testfsd.exe
testfsd.exe: testfsd.c testsuite.c
$(CC) testfsd.c testsuite.c -lkernel32 -o testfsd.exe
$(NM) --numeric-sort testfsd.exe > testfsd.sym
include ../../rules.mak

View file

@ -1,4 +1,4 @@
/* $Id: testfsd.c,v 1.3 2001/05/01 19:42:56 narnaoud Exp $
/* $Id: testfsd.c,v 1.4 2001/07/04 03:07:54 rex Exp $
*
* FILE: testFSD.c
* PURPOSE: A test set for the File System Driver
@ -8,19 +8,12 @@
*
*/
#include <errno.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
#define ASSERT(x) doAssertion (x, #x, __FUNCTION__, __LINE__)
struct TestSuite
{
char *name;
void (*testFunc)(void);
};
#define ADD_TEST(x) {#x, x}
#define COUNT_TESTS(x) (sizeof x/sizeof (struct TestSuite))
#include "testsuite.h"
const char *rootDir = "c:\\";
const char *systemRootDir = "c:\\ReactOS";
@ -29,56 +22,8 @@ const char *bogusRootFile = "c:\\bogus";
const char *bogusDirAndFile = "c:\\bogus\\bogus";
const char *bogusSystemRootFile = "c:\\ReactOS\\bogus";
const char *bogusSystemDllFile = "c:\\ReactOS\\System32\\bogus";
int tests, assertions, failures, successes;
void doAssertion (BOOL pTest, PCHAR pTestText, PCHAR pFunction, int pLine);
void testOpenExistant (void);
void testOpenNonExistant (void);
void testCreateExistant (void);
void testCreateNonExistant (void);
void testOverwriteExistant (void);
void testOverwriteNonExistant (void);
void testOpenWithBlankPathElements (void);
struct TestSuite gTests [] =
{
ADD_TEST (testOpenExistant),
ADD_TEST (testOpenNonExistant),
ADD_TEST (testCreateExistant),
ADD_TEST (testCreateNonExistant),
/* ADD_TEST (testOverwriteExistant),*/
/* ADD_TEST (testOverwriteNonExistant),*/
ADD_TEST (testOpenWithBlankPathElements)
};
int main (void)
{
int testIndex;
tests = assertions = failures = successes = 0;
for (testIndex = 0; testIndex < COUNT_TESTS(gTests); testIndex++)
{
gTests [testIndex].testFunc ();
tests++;
}
printf ("\nTotals: tests: %d assertions: %d successes: %d failures: %d\n",
tests,
assertions,
successes,
failures);
if (failures == 0)
{
printf ("\n*** OK ***\n");
}
else
{
printf ("\n*** FAIL ***\n");
}
}
const char *shortFile = "c:\\ReactOS\\boot.bat";
const char *longFile = "c:\\ReactOS\\loadros.com";
void testOpenExistant (void)
{
@ -133,24 +78,18 @@ void testCreateExistant (void)
DWORD status;
HANDLE fileHandle;
printf ("before CreateFile (%s)\n", rootDir);
fileHandle = CreateFile (rootDir, GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
printf ("after CreateFile (%s)\n", rootDir);
ASSERT (fileHandle == INVALID_HANDLE_VALUE);
status = GetLastError ();
ASSERT (status == ERROR_ALREADY_EXISTS);
printf ("before CreateFile (%s)\n", systemRootDir);
fileHandle = CreateFile (systemRootDir, GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
printf ("after CreateFile (%s)\n", rootDir);
ASSERT (fileHandle == INVALID_HANDLE_VALUE);
status = GetLastError ();
ASSERT (status == ERROR_ALREADY_EXISTS);
printf ("before CreateFile (%s)\n", systemDllDir);
fileHandle = CreateFile (systemDllDir, GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
printf ("after CreateFile (%s)\n", rootDir);
ASSERT (fileHandle == INVALID_HANDLE_VALUE);
status = GetLastError ();
ASSERT (status == ERROR_ALREADY_EXISTS);
@ -173,7 +112,6 @@ void testCreateNonExistant (void)
CREATE_NEW, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
CloseHandle (fileHandle);
#if 0
fileHandle = CreateFile (bogusDirAndFile, GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
@ -184,6 +122,55 @@ void testCreateNonExistant (void)
#endif
}
void testDeleteFiles (void)
{
BOOL returnValue;
HANDLE fileHandle;
fileHandle = CreateFile ("bogus", GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
CloseHandle (fileHandle);
returnValue = DeleteFile ("bogus");
ASSERT_MSG (returnValue,
"Delete of bogus failed, error:%d",
GetLastError ());
#if 0
returnValue = DeleteFile (bogusRootFile);
ASSERT_MSG (returnValue,
"Delete of %s failed, error:%d",
bogusRootFile,
GetLastError ());
returnValue = DeleteFile (bogusRootFile);
ASSERT_MSG (!returnValue,
"2nd Delete of %s succeeded but should fail",
bogusRootFile);
returnValue = DeleteFile (bogusSystemRootFile);
ASSERT_MSG (returnValue,
"Delete of %s failed, error:%d",
bogusSystemRootFile,
GetLastError ());
returnValue = DeleteFile (bogusSystemRootFile);
ASSERT_MSG (!returnValue,
"2nd Delete of %s succeeded but should fail",
bogusSystemRootFile);
returnValue = DeleteFile (bogusSystemDllFile);
ASSERT_MSG (returnValue,
"Delete of %s failed, error:%d",
bogusSystemDllFile,
GetLastError ());
returnValue = DeleteFile (bogusSystemDllFile);
ASSERT_MSG (!returnValue,
"2nd Delete of %s succeeded but should fail",
bogusSystemDllFile);
returnValue = DeleteFile (bogusDirAndFile);
ASSERT_MSG (!returnValue,
"Delete of %s succeded but should fail",
bogusDirAndFile);
#endif
}
void testOpenWithBlankPathElements (void)
{
HANDLE fileHandle;
@ -212,18 +199,117 @@ void testOpenWithBlankPathElements (void)
CloseHandle (fileHandle);
}
void doAssertion (BOOL pTest, PCHAR pTestText, PCHAR pFunction, int pLine)
void testReadOnInvalidHandle (void)
{
assertions++;
if (!pTest)
{
printf ("%s(%d): assertion \"%s\" failed", pFunction, pLine, pTestText);
failures++;
BOOL returnValue;
char buffer [256];
DWORD bytesRead;
returnValue = ReadFile (INVALID_HANDLE_VALUE,
buffer,
256,
&bytesRead,
NULL);
ASSERT_MSG (!returnValue,
"Read from invalid handle succeeded but should fail",0);
ASSERT (GetLastError () != ENOFILE);
}
else
void testReadOnZeroLengthFile (void)
{
successes++;
BOOL returnValue;
HANDLE fileHandle;
char buffer [256];
DWORD bytesRead;
fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0,
CREATE_NEW, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
CloseHandle (fileHandle);
fileHandle = CreateFile (bogusRootFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
returnValue = ReadFile (fileHandle, buffer, 256, &bytesRead, NULL);
ASSERT_MSG (!returnValue,
"Read from zero length file succeeded but should fail",0);
ASSERT (GetLastError () != ERROR_HANDLE_EOF);
CloseHandle (fileHandle);
returnValue = DeleteFile (bogusRootFile);
ASSERT_MSG (returnValue,
"Delete of %s failed, error:%d",
bogusRootFile,
GetLastError ());
}
void testReadOnShortFile (void)
{
BOOL returnValue;
HANDLE fileHandle;
char buffer [256];
DWORD bytesRead;
fileHandle = CreateFile (shortFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
returnValue = ReadFile (fileHandle,
buffer,
256,
&bytesRead,
NULL);
ASSERT_MSG (returnValue,
"Read from short length file failed, error:%d",
GetLastError ());
ASSERT (bytesRead > 0 && bytesRead < 256);
CloseHandle (fileHandle);
}
void testReadOnLongFile (void)
{
BOOL returnValue;
HANDLE fileHandle;
char buffer [256];
DWORD bytesRead;
int count;
fileHandle = CreateFile (longFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
ASSERT (fileHandle != INVALID_HANDLE_VALUE);
for (count = 0; count < 20; count++)
{
returnValue = ReadFile (fileHandle,
buffer,
256,
&bytesRead,
NULL);
ASSERT_MSG (returnValue,
"Read from short length file failed, error:%d",
GetLastError ());
ASSERT (bytesRead == 256);
}
CloseHandle (fileHandle);
}
int main (void)
{
TEST_RUNNER testRunner;
TEST_SUITE testsToRun [] =
{
ADD_TEST (testOpenExistant),
ADD_TEST (testOpenNonExistant),
ADD_TEST (testCreateExistant),
ADD_TEST (testCreateNonExistant),
ADD_TEST (testDeleteFiles),
/* ADD_TEST (testOverwriteExistant),*/
/* ADD_TEST (testOverwriteNonExistant),*/
ADD_TEST (testOpenWithBlankPathElements),
ADD_TEST (testReadOnInvalidHandle),
ADD_TEST (testReadOnZeroLengthFile),
ADD_TEST (testReadOnShortFile),
ADD_TEST (testReadOnLongFile),
/* ADD_TEST (test), */
END_TESTS
};
memset (&testRunner, 0, sizeof (TEST_RUNNER));
tsRunTests (&testRunner, testsToRun);
tsReportResults (&testRunner);
}

View file

@ -0,0 +1,65 @@
#include <windows.h>
#include <stdio.h>
#include "testsuite.h"
static PTEST_RUNNER iTestRunner = 0;
void tsRunTests (PTEST_RUNNER pTestRunner, PTEST_SUITE pTests)
{
int testIndex;
iTestRunner = pTestRunner;
for (testIndex = 0; pTests [testIndex].testFunc != 0; testIndex++)
{
pTests [testIndex].testFunc ();
pTestRunner->tests++;
}
}
void tsReportResults (PTEST_RUNNER pTestRunner)
{
printf ("\nTotal of %d tests.\n"
"Assertions: %d\n"
" Assertions which passed: %d\n"
" Assertions which failed: %d\n",
pTestRunner->tests,
pTestRunner->assertions,
pTestRunner->successes,
pTestRunner->failures);
if (pTestRunner->failures == 0)
{
printf ("\n*** OK ***\n");
}
else
{
printf ("\n*** FAIL ***\n");
}
}
void tsDoAssertion (BOOL pTest,
PCHAR pTestText,
PCHAR pFunction,
int pLine,
...)
{
va_list ap;
iTestRunner->assertions++;
if (!pTest)
{
va_start (ap, pLine);
printf ("%s(%d): ", pFunction, pLine);
vprintf (pTestText, ap);
printf ("\n");
va_end(ap);
iTestRunner->failures++;
}
else
{
iTestRunner->successes++;
}
}

View file

@ -0,0 +1,44 @@
#ifndef H_TESTSUITE_H
#define H_TESTSUITE_H
struct TestSuite
{
char *name;
void (*testFunc)(void);
};
typedef struct TestSuite TEST_SUITE, *PTEST_SUITE;
#define ADD_TEST(x) {#x, x}
#define END_TESTS {0, 0}
#define COUNT_TESTS(x) (sizeof x/sizeof (struct TestSuite))
struct TestRunner
{
int tests;
int assertions;
int failures;
int successes;
};
typedef struct TestRunner TEST_RUNNER, *PTEST_RUNNER;
void tsDoAssertion (BOOL pTest,
PCHAR pTestText,
PCHAR pFunction,
int pLine,
...);
#ifdef ASSERT
#undef ASSERT
#endif
#define ASSERT(x) tsDoAssertion (x, "assertion \"" ## #x ## "\" failed", __FUNCTION__, __LINE__)
#define ASSERT_MSG(x,y,a...) tsDoAssertion (x, y, __FUNCTION__, __LINE__,a)
void tsRunTests (PTEST_RUNNER pTestRunner, PTEST_SUITE pTests);
void tsReportResults (PTEST_RUNNER pTestRunner);
#endif