This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-myfs.cpp
99 lines (66 loc) · 2.07 KB
/
test-myfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// tests-myfs.cpp
// testing
//
// Created by Oliver Waldhorst on 15.12.17.
// Copyright © 2017 Oliver Waldhorst. All rights reserved.
//
#include "catch.hpp"
#include <iostream>
#include "helper.hpp"
#include "myfs.h"
#include <stdio.h>
#include <string.h>
using namespace std;
// TODO: Implement your helper functions here!
TEST_CASE( "intToChar / charToInt" ) {
MyFS myfs;
char test[3] = "a";
REQUIRE(myfs.charToInt(test, 1) == 97);
strcpy(test, "b");
REQUIRE(myfs.charToInt(test, 1) == 98);
strcpy(test, "K");
REQUIRE(myfs.charToInt(test, 1) == 75);
strcpy(test, "aa");
REQUIRE(myfs.charToInt(test, 2) == 24929);
strcpy(test, "\0");
REQUIRE(myfs.charToInt(test, 1) == 0);
strcpy(test, "ba");
REQUIRE(myfs.charToInt(test, 2) == 24930);
char buffer[5];
buffer[2] = '\0';
myfs.intToChar(24929, buffer, 2);
REQUIRE(strcmp(buffer, "aa") == 0);
buffer[1] = '\0';
myfs.intToChar(97, buffer, 1);
REQUIRE(strcmp(buffer, "a") == 0);
buffer[1] = '\0';
myfs.intToChar(0, buffer, 1);
REQUIRE(strcmp(buffer, "\0") == 0);
buffer[2] = '\0';
myfs.intToChar(24930, buffer, 2);
REQUIRE(strcmp(buffer, "ba") == 0);
char testBuffer[4];
int testnumber = 1981;
myfs.intToChar(testnumber, testBuffer, 4);
REQUIRE(testnumber == myfs.charToInt(testBuffer, 4));
testnumber = 61601;
myfs.intToChar(testnumber, testBuffer, 4);
REQUIRE(testnumber == myfs.charToInt(testBuffer, 4));
testnumber = (int) time(NULL);
myfs.intToChar(testnumber, testBuffer, 4);
REQUIRE(testnumber == myfs.charToInt(testBuffer, 4));
testnumber = (int) S_IFREG | 0644;
myfs.intToChar(testnumber, testBuffer, 4);
REQUIRE(testnumber == myfs.charToInt(testBuffer, 4));
}
TEST_CASE("remDirPath"){
MyFS myfs;
char* testDirectoryPath = "./test/lukas/newfile";
REQUIRE(strcmp(myfs.remDirPath(testDirectoryPath), "newfile") == 0);
}
TEST_CASE("sizeToBlocks"){
MyFS myfs;
REQUIRE(myfs.sizeToBlocks(1000) == 2);
REQUIRE(myfs.sizeToBlocks(2000) == 4);
}