149 lines
5.2 KiB
C
149 lines
5.2 KiB
C
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include "unity/unity.h"
|
|
#include "fuse.h"
|
|
#include "fsactions.h"
|
|
#include "fsinterface.h"
|
|
#include "fusestructs.h"
|
|
|
|
FileSystem* fakefs;
|
|
fuseArgStruct dummyFuse;
|
|
int argc = 5;
|
|
char* argv[5];
|
|
|
|
void setUp(void)
|
|
{
|
|
FuseStructInit(&dummyFuse);
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
OpenFS(&dummyFuse, argv[0]);
|
|
fakefs = SetupFS(&dummyFuse);
|
|
}
|
|
|
|
void tearDown(void)
|
|
{
|
|
TearDownFS();
|
|
}
|
|
|
|
void Test_FuseGetArgs_Should_SetDummyArgs(void)
|
|
{
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, dummyFuse.list);
|
|
argv[1] = "-a";
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, dummyFuse.add);
|
|
argv[1] = "-r";
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, dummyFuse.remove);
|
|
argv[1] = "-e";
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, dummyFuse.extract);
|
|
}
|
|
|
|
void Test_FindEmptyBitPosition_Should_ReturnPosition(void)
|
|
{
|
|
TEST_ASSERT_EQUAL(3, FindEmptyBitPosition(7));
|
|
TEST_ASSERT_EQUAL(1, FindEmptyBitPosition(29));
|
|
TEST_ASSERT_EQUAL(5, FindEmptyBitPosition(95));
|
|
TEST_ASSERT_EQUAL(31, FindEmptyBitPosition(2147483647));
|
|
TEST_ASSERT_EQUAL(-1, FindEmptyBitPosition(4294967295));
|
|
}
|
|
|
|
void Test_FileSystem_Should_SuccessfullyOpen(void)
|
|
{
|
|
GetArguments(argc, argv, &dummyFuse);
|
|
OpenFS(&dummyFuse, argv[0]);
|
|
fakefs = SetupFS(&dummyFuse);
|
|
}
|
|
|
|
void Test_FileSystem_Should_AddFirstFile(void)
|
|
{
|
|
RunFuse(fakefs, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
|
|
ino_t inodeLocation = fakefs->inodes[2].blocks[0].inode;
|
|
TEST_ASSERT_NOT_EMPTY(fakefs->dataBlocks[inodeLocation].byte);
|
|
}
|
|
|
|
void Test_FileSystem_Should_AddSecondFile(void)
|
|
{
|
|
RunFuse(fakefs, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test2.txt", fakefs->inodes[2].blocks[1].name, 9);
|
|
ino_t inodeLocation = fakefs->inodes[2].blocks[1].inode;
|
|
TEST_ASSERT_NOT_EMPTY(fakefs->dataBlocks[inodeLocation].byte);
|
|
}
|
|
|
|
void Test_FileSystem_Should_AddThirdFile(void)
|
|
{
|
|
RunFuse(fakefs, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test3.txt", fakefs->inodes[2].blocks[2].name, 9);
|
|
ino_t inodeLocation = fakefs->inodes[2].blocks[2].inode;
|
|
TEST_ASSERT_NOT_EMPTY(fakefs->dataBlocks[inodeLocation].byte);
|
|
}
|
|
|
|
void Test_FileSystem_Should_ListContents(void)
|
|
{
|
|
RunFuse(fakefs, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[0].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", fakefs->inodes[0].blocks[0].name, 4);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[1].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("files", fakefs->inodes[1].blocks[0].name, 5);
|
|
TEST_ASSERT_EQUAL(1, fakefs->inodes[2].isValid);
|
|
TEST_ASSERT_EQUAL_CHAR_ARRAY("test1.txt", fakefs->inodes[2].blocks[0].name, 9);
|
|
TEST_MESSAGE("This only runs the list operation. Check info yourself.");
|
|
}
|
|
void Test_FileSystem_Should_RemoveFile(void)
|
|
{
|
|
RunFuse(fakefs, &dummyFuse);
|
|
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].blocks[0].isValid);
|
|
}
|
|
|
|
void Test_FileSystem_Should_RemoveEmptyDirectories(void)
|
|
{
|
|
TEST_ASSERT_EQUAL(0, fakefs->inodes[2].isValid);
|
|
TEST_ASSERT_EQUAL(0, fakefs->inodes[1].blocks[0].isValid);
|
|
TEST_ASSERT_EQUAL(0, fakefs->inodes[1].isValid);
|
|
TEST_ASSERT_EQUAL(0, fakefs->inodes[0].blocks[0].isValid);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
remove("test/fakefs.test");
|
|
argv[0] = "bin/fuse.out";
|
|
argv[1] = "-l";
|
|
argv[2] = "test/files/test1.txt";
|
|
argv[3] = "-f";
|
|
argv[4] = "test/fakefs.test";
|
|
UNITY_BEGIN();
|
|
RUN_TEST(Test_FuseGetArgs_Should_SetDummyArgs);
|
|
RUN_TEST(Test_FindEmptyBitPosition_Should_ReturnPosition);
|
|
RUN_TEST(Test_FileSystem_Should_SuccessfullyOpen);
|
|
argv[1] = "-a";
|
|
RUN_TEST(Test_FileSystem_Should_AddFirstFile);
|
|
argv[2] = "test/files/test2.txt";
|
|
RUN_TEST(Test_FileSystem_Should_AddSecondFile);
|
|
argv[2] = "test/files/test3.txt";
|
|
RUN_TEST(Test_FileSystem_Should_AddThirdFile);
|
|
argv[1] = "-l";
|
|
RUN_TEST(Test_FileSystem_Should_ListContents);
|
|
argv[1] = "-r";
|
|
argv[2] = "test/files/test2.txt";
|
|
RUN_TEST(Test_FileSystem_Should_RemoveFile);
|
|
RUN_TEST(Test_FileSystem_Should_RemoveEmptyDirectories);
|
|
return UNITY_END();
|
|
}
|