@@ -10,22 +10,37 @@ import (
10
10
"testing"
11
11
)
12
12
13
- func TestOpenRootFile (t * testing.T ) {
13
+ func TestRead (t * testing.T ) {
14
14
fs , _ := initTestFAT ()
15
- var fp File
16
- fr := fs .f_open (& fp , "rootfile\x00 " , faRead )
17
- if fr != frOK {
18
- t .Fatal (fr .Error ())
15
+ var rootFile File
16
+ fr := fs .f_open (& rootFile , "rootfile" , faRead )
17
+ mustBeOK (t , fr )
18
+
19
+ buf := make ([]byte , 512 )
20
+ n , fr := rootFile .f_read (buf )
21
+ mustBeOK (t , fr )
22
+
23
+ got := string (buf [:n ])
24
+ if got != rootFileContents {
25
+ t .Errorf ("mismatched rootfile contents:\n %q\n %q\n " , got , rootFileContents )
26
+ }
27
+
28
+ var dirfile File
29
+ fr = fs .f_open (& dirfile , "rootdir/dirfile" , faRead )
30
+ mustBeOK (t , fr )
31
+ n , fr = dirfile .f_read (buf )
32
+ mustBeOK (t , fr )
33
+ got = string (buf [:n ])
34
+ if got != dirFileContents {
35
+ t .Errorf ("mismatched dirfile contents:\n %q\n %q\n " , got , dirFileContents )
19
36
}
20
37
}
21
38
22
39
func TestFileInfo (t * testing.T ) {
23
40
fs , _ := initTestFAT ()
24
41
var dir dir
25
- fr := fs .f_opendir (& dir , "rootdir\x00 " )
26
- if fr != frOK {
27
- t .Fatal (fr .Error ())
28
- }
42
+ fr := fs .f_opendir (& dir , "rootdir" )
43
+ mustBeOK (t , fr )
29
44
var finfo fileinfo
30
45
fr = dir .f_readdir (& finfo )
31
46
if fr != frOK {
@@ -43,7 +58,7 @@ func TestFileInfo(t *testing.T) {
43
58
44
59
func ExampleRead () {
45
60
const (
46
- filename = "test.txt\x00 "
61
+ filename = "test.txt"
47
62
data = "abc123"
48
63
)
49
64
var fs FS
@@ -120,6 +135,12 @@ func DefaultFATByteBlocks(numBlocks int) *BytesBlocks {
120
135
buf : buf ,
121
136
}
122
137
}
138
+ func mustBeOK (t * testing.T , fr fileResult ) {
139
+ t .Helper ()
140
+ if fr != frOK {
141
+ t .Fatal (fr .Error ())
142
+ }
143
+ }
123
144
124
145
type BytesBlocks struct {
125
146
blk blkIdxer
@@ -312,3 +333,6 @@ var fatInit = map[int64][512]byte{
312
333
0x35 , 0x20 , 0x6c , 0x69 , 0x6e , 0x65 , 0x73 , 0x2e , 0x0a , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // |5 lines.........|
313
334
},
314
335
}
336
+
337
+ const rootFileContents = "this is\n the root file\n "
338
+ const dirFileContents = "this is not\n not the root\n not the root file\n nope. \n This file has 5 lines.\n "
0 commit comments