5 #include <cppunit/TestCaller.h>
6 #include <cppunit/TestSuite.h>
13 #include "StatableTest.h"
24 StatableTest::tearDown()
26 BasicTest::tearDown();
31 StatableTest::GetStatTest()
33 TestStatables testEntries
;
38 CreateROStatables(testEntries
);
39 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
41 CPPUNIT_ASSERT( statable
->GetStat(&st1
) == B_OK
);
42 CPPUNIT_ASSERT( lstat(entryName
.c_str(), &st2
) == 0 );
43 CPPUNIT_ASSERT( st1
== st2
);
45 testEntries
.delete_all();
46 // uninitialized objects
48 CreateUninitializedStatables(testEntries
);
49 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
51 CPPUNIT_ASSERT( statable
->GetStat(&st1
) == B_NO_INIT
);
53 testEntries
.delete_all();
56 CreateROStatables(testEntries
);
57 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); )
58 CPPUNIT_ASSERT( statable
->GetStat(NULL
) != B_OK
);
59 testEntries
.delete_all();
64 StatableTest::IsXYZTest()
66 TestStatables testEntries
;
71 CreateROStatables(testEntries
);
72 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
74 CPPUNIT_ASSERT( lstat(entryName
.c_str(), &st
) == 0 );
75 CPPUNIT_ASSERT( statable
->IsDirectory() == S_ISDIR(st
.st_mode
) );
76 CPPUNIT_ASSERT( statable
->IsFile() == S_ISREG(st
.st_mode
) );
77 CPPUNIT_ASSERT( statable
->IsSymLink() == S_ISLNK(st
.st_mode
) );
79 testEntries
.delete_all();
80 // uninitialized objects
82 CreateUninitializedStatables(testEntries
);
83 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
84 CPPUNIT_ASSERT( statable
->IsDirectory() == false );
85 CPPUNIT_ASSERT( statable
->IsFile() == false );
86 CPPUNIT_ASSERT( statable
->IsSymLink() == false );
88 testEntries
.delete_all();
93 StatableTest::GetXYZTest()
95 TestStatables testEntries
;
98 // test with existing entries
100 CreateROStatables(testEntries
);
101 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
110 // R5: access time unused
111 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
115 CPPUNIT_ASSERT( lstat(entryName
.c_str(), &st
) == 0 );
116 CPPUNIT_ASSERT( statable
->GetNodeRef(&ref
) == B_OK
);
117 CPPUNIT_ASSERT( statable
->GetOwner(&owner
) == B_OK
);
118 CPPUNIT_ASSERT( statable
->GetGroup(&group
) == B_OK
);
119 CPPUNIT_ASSERT( statable
->GetPermissions(&perms
) == B_OK
);
120 CPPUNIT_ASSERT( statable
->GetSize(&size
) == B_OK
);
121 CPPUNIT_ASSERT( statable
->GetModificationTime(&mtime
) == B_OK
);
122 CPPUNIT_ASSERT( statable
->GetCreationTime(&ctime
) == B_OK
);
123 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
124 CPPUNIT_ASSERT( statable
->GetAccessTime(&atime
) == B_OK
);
126 CPPUNIT_ASSERT( statable
->GetVolume(&volume
) == B_OK
);
127 CPPUNIT_ASSERT( ref
.device
== st
.st_dev
&& ref
.node
== st
.st_ino
);
128 CPPUNIT_ASSERT( owner
== st
.st_uid
);
129 CPPUNIT_ASSERT( group
== st
.st_gid
);
130 // R5: returns not only the permission bits, so we need to filter for the test
131 // CPPUNIT_ASSERT( perms == (st.st_mode & S_IUMSK) );
132 CPPUNIT_ASSERT( (perms
& S_IUMSK
) == (st
.st_mode
& S_IUMSK
) );
133 CPPUNIT_ASSERT( size
== st
.st_size
);
134 CPPUNIT_ASSERT( mtime
== st
.st_mtime
);
135 CPPUNIT_ASSERT( ctime
== st
.st_crtime
);
136 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
137 CPPUNIT_ASSERT( atime
== st
.st_atime
);
139 CPPUNIT_ASSERT( volume
== BVolume(st
.st_dev
) );
141 testEntries
.delete_all();
142 // test with uninitialized objects
144 CreateUninitializedStatables(testEntries
);
145 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
155 CPPUNIT_ASSERT( statable
->GetNodeRef(&ref
) == B_NO_INIT
);
156 CPPUNIT_ASSERT( statable
->GetOwner(&owner
) == B_NO_INIT
);
157 CPPUNIT_ASSERT( statable
->GetGroup(&group
) == B_NO_INIT
);
158 CPPUNIT_ASSERT( statable
->GetPermissions(&perms
) == B_NO_INIT
);
159 CPPUNIT_ASSERT( statable
->GetSize(&size
) == B_NO_INIT
);
160 CPPUNIT_ASSERT( statable
->GetModificationTime(&mtime
) == B_NO_INIT
);
161 CPPUNIT_ASSERT( statable
->GetCreationTime(&ctime
) == B_NO_INIT
);
162 CPPUNIT_ASSERT( statable
->GetAccessTime(&atime
) == B_NO_INIT
);
163 CPPUNIT_ASSERT( statable
->GetVolume(&volume
) == B_NO_INIT
);
165 testEntries
.delete_all();
168 CreateROStatables(testEntries
);
169 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
170 // R5: crashs, if passing NULL to any of these methods
172 CPPUNIT_ASSERT( statable
->GetNodeRef(NULL
) == B_BAD_VALUE
);
173 CPPUNIT_ASSERT( statable
->GetOwner(NULL
) == B_BAD_VALUE
);
174 CPPUNIT_ASSERT( statable
->GetGroup(NULL
) == B_BAD_VALUE
);
175 CPPUNIT_ASSERT( statable
->GetPermissions(NULL
) == B_BAD_VALUE
);
176 CPPUNIT_ASSERT( statable
->GetSize(NULL
) == B_BAD_VALUE
);
177 CPPUNIT_ASSERT( statable
->GetModificationTime(NULL
) == B_BAD_VALUE
);
178 CPPUNIT_ASSERT( statable
->GetCreationTime(NULL
) == B_BAD_VALUE
);
179 CPPUNIT_ASSERT( statable
->GetAccessTime(NULL
) == B_BAD_VALUE
);
180 CPPUNIT_ASSERT( statable
->GetVolume(NULL
) == B_BAD_VALUE
);
183 testEntries
.delete_all();
188 StatableTest::SetXYZTest()
190 TestStatables testEntries
;
193 // test with existing entries
195 CreateRWStatables(testEntries
);
196 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
200 mode_t perms
= 0x0ab; // -w- r-x -wx -- unusual enough? ;-)
201 time_t mtime
= 1234567;
202 time_t ctime
= 654321;
203 // R5: access time unused
204 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
205 time_t atime
= 2345678;
207 CPPUNIT_ASSERT( statable
->SetOwner(owner
) == B_OK
);
208 CPPUNIT_ASSERT( statable
->SetGroup(group
) == B_OK
);
209 CPPUNIT_ASSERT( statable
->SetPermissions(perms
) == B_OK
);
210 CPPUNIT_ASSERT( statable
->SetModificationTime(mtime
) == B_OK
);
211 CPPUNIT_ASSERT( statable
->SetCreationTime(ctime
) == B_OK
);
212 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
213 CPPUNIT_ASSERT( statable
->SetAccessTime(atime
) == B_OK
);
215 CPPUNIT_ASSERT( lstat(entryName
.c_str(), &st
) == 0 );
216 CPPUNIT_ASSERT( owner
== st
.st_uid
);
217 CPPUNIT_ASSERT( group
== st
.st_gid
);
218 CPPUNIT_ASSERT( perms
== (st
.st_mode
& S_IUMSK
) );
219 CPPUNIT_ASSERT( mtime
== st
.st_mtime
);
220 CPPUNIT_ASSERT( ctime
== st
.st_crtime
);
221 #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
222 CPPUNIT_ASSERT( atime
== st
.st_atime
);
225 testEntries
.delete_all();
226 // test with uninitialized objects
228 CreateUninitializedStatables(testEntries
);
229 for (testEntries
.rewind(); testEntries
.getNext(statable
, entryName
); ) {
232 mode_t perms
= 0x0ab; // -w- r-x -wx -- unusual enough? ;-)
233 time_t mtime
= 1234567;
234 time_t ctime
= 654321;
235 time_t atime
= 2345678;
236 CPPUNIT_ASSERT( statable
->SetOwner(owner
) != B_OK
);
237 CPPUNIT_ASSERT( statable
->SetGroup(group
) != B_OK
);
238 CPPUNIT_ASSERT( statable
->SetPermissions(perms
) != B_OK
);
239 CPPUNIT_ASSERT( statable
->SetModificationTime(mtime
) != B_OK
);
240 CPPUNIT_ASSERT( statable
->SetCreationTime(ctime
) != B_OK
);
241 CPPUNIT_ASSERT( statable
->SetAccessTime(atime
) != B_OK
);
243 testEntries
.delete_all();