-
Notifications
You must be signed in to change notification settings - Fork 0
/
aluno.c
134 lines (100 loc) · 2.63 KB
/
aluno.c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "fs.h"
#include "disk.h"
#include "simplegrade.h"
#include <string.h>
void test1(){
DESCRIBE("Modifica o numero de blocos e o tamanho do bloco");
IF("Altero o numero de blocos");
set_block_num(52);
THEN("Valor deve ser modificado com sucesso");
isEqual(get_block_num(),52,1);
IF("Modifica o tamanho dos blocos");
set_block_size(1024);
THEN("tamanho deve ser modificado com sucesso");
isEqual(get_block_size(),1024,1);
char buffer[1024];
memset(buffer,'b',1024); //preenche vetor com b's
IF("Escrevo em 20 blocos");
THEN("Conteudo lido deve corresponde ao conteudo escrito");
fd_write_raw(20,buffer);
fd_read_raw(20,buffer);
int i;
for(i=0;(i < 1024) && (buffer[i] == 'b');++i){
if(buffer[i]!='b'){
break;
}
}
isEqual(i, 1024, 1);
fd_stop();
}
void test2(){
DESCRIBE("Formato o disco e crio um arquivo");
int i_number,fd,i;
char b[4] ={'a','b','c','d'};
set_block_size(100);
IF("Testa a formatação");
THEN("Deve formatar o disco");
isEqual(ffs_format_disk(10,5),1,1);
i_number = ffs_create();
fd = ffs_open(i_number);
IF("Escrevo em 4 blocos do arquivo");
for(i = 0; i < 4; ++i){
ffs_write(fd,b,4);
}
ffs_seek(fd,0,0);
THEN("Deve ler os 4 blocos escritos");
isEqual(ffs_read(fd,b,4),4,1);
ffs_close(fd);
fd_stop();
}
void test3(){
char buf[150];
int i_number,fd[2],i;
DESCRIBE("Teste com dois arquivos");
memset(buf,'c',150); //preenche vetor com b's
set_block_size(150);
ffs_format_disk(50,1);
i_number = ffs_create();
fd[0] = ffs_open(i_number);
IF("Escrevo no primeiro arquivo");
THEN("Deve escrever um bloco");
ffs_write(fd[0],buf,150);
ffs_seek(fd[0],0,0);
ffs_read(fd[0],buf,150);
int flag=0;
for (i = 0; i < 150; ++i){
if(buf[i]=='c')
flag = 1;
else
flag = 0;
}
THEN("Deve ler o mesmo conteudo escrito");
isEqual(flag,1,1);
ffs_close(fd[0]);
ffs_delete(fd[0]);
char buffer[1]={'a'};
fd[1] = ffs_open(i_number);
IF("Escrevo um bloco para o segundo arquivo");
THEN("Deve escrever um bloco");
ffs_write(fd[1],buffer,1);
ffs_seek(fd[1],0,0);
if(buffer[0]=='a'){
isEqual(ffs_read(fd[1],buffer,1),1,1);
}else{
isEqual(ffs_read(fd[1],buffer,1),0,1);
}
ffs_close(fd[1]);
ffs_delete(fd[1]);
fd_stop();
}
int main(){
DESCRIBE("Testes do trabalho 2: Sistema de Arquivos");
test1();
test2();
test3();
GRADEME();
if(grade == maxgrade)
return 0;
else
return grade;
}