file: Update tests to check for empty filepaths

And make sure files follow the design by return false when opening an
invalid file.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-08-14 21:39:49 -04:00 committed by Anna Schumaker
parent 8ef1e2f8e6
commit 412964bcf4
4 changed files with 9 additions and 1 deletions

View File

@ -132,6 +132,9 @@ bool File :: open(OpenMode m)
if (m == NOT_OPEN) {
dprint("ERROR: NOT_OPEN is not a legal OpenMode (%s)\n", filepath.c_str());
return false;
} else if (hint == FILE_TYPE_INVALID) {
dprint("ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened\n");
return false;
} else if (m == OPEN_READ)
return open_read();
else /* m == OPEN_WRITE */

View File

@ -10,6 +10,7 @@ int main(int argc, char **argv)
{
int a, b, c, d, e;
File file("test.io", FILE_TYPE_DATA);
File inval("", FILE_TYPE_DATA);
rm_test_data();
@ -47,5 +48,8 @@ int main(int argc, char **argv)
if (!file.close())
return 1;
if (inval.open(OPEN_READ) == true)
return 1;
return 0;
}

View File

@ -5,3 +5,4 @@ File version is: 0
Hello, World!
This is a multi-line file =)
a: 1, b: 2, c: 3, d: 4, e: 5
ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened

View File

@ -18,5 +18,5 @@ Test 4c: Passed
Test 5: Passed
ERROR: File does not exist (INVALID)
ERROR: A file with hint = FILE_TYPE_INVALID cannot be opened
Test 6: Passed