]>
git.saurik.com Git - android/aapt.git/blob - tests/FileFinder_test.cpp
2 // Copyright 2011 The Android Open Source Project
4 #include <utils/Vector.h>
5 #include <utils/KeyedVector.h>
8 #include <utils/String8.h>
11 #include "DirectoryWalker.h"
12 #include "MockDirectoryWalker.h"
13 #include "FileFinder.h"
15 using namespace android
;
26 cout
<< "\n\n STARTING FILE FINDER TESTS" << endl
;
27 String8
path("ApiDemos");
29 // Storage to pass to findFiles()
30 KeyedVector
<String8
,time_t> testStorage
;
32 // Mock Directory Walker initialization. First data, then sdw
33 Vector
< pair
<String8
,time_t> > data
;
34 data
.push( pair
<String8
,time_t>(String8("hello.png"),3) );
35 data
.push( pair
<String8
,time_t>(String8("world.PNG"),3) );
36 data
.push( pair
<String8
,time_t>(String8("foo.pNg"),3) );
37 // Neither of these should be found
38 data
.push( pair
<String8
,time_t>(String8("hello.jpg"),3) );
39 data
.push( pair
<String8
,time_t>(String8(".hidden.png"),3));
41 DirectoryWalker
* sdw
= new StringDirectoryWalker(path
,data
);
43 // Extensions to look for
45 exts
.push(String8(".png"));
49 // Make sure we get a valid mock directory walker
50 // Make sure we finish without errors
51 cout
<< "Checking DirectoryWalker...";
53 cout
<< "PASSED" << endl
;
55 // Make sure we finish without errors
56 cout
<< "Running findFiles()...";
57 bool findStatus
= FileFinder::findFiles(path
,exts
, testStorage
, sdw
);
59 cout
<< "PASSED" << endl
;
61 const size_t SIZE_EXPECTED
= 3;
62 // Check to make sure we have the right number of things in our storage
63 cout
<< "Running size comparison: Size is " << testStorage
.size() << ", ";
64 cout
<< "Expected " << SIZE_EXPECTED
<< "...";
65 if(testStorage
.size() == SIZE_EXPECTED
)
66 cout
<< "PASSED" << endl
;
68 cout
<< "FAILED" << endl
;
72 // Check to make sure that each of our found items has the right extension
73 cout
<< "Checking Returned Extensions...";
76 for (size_t i
= 0; i
< SIZE_EXPECTED
; ++i
) {
77 String8
testExt(testStorage
.keyAt(i
).getPathExtension());
79 if (testExt
!= ".png") {
80 wrongExts
+= testStorage
.keyAt(i
);
86 cout
<< "PASSED" << endl
;
88 cout
<< "FAILED" << endl
;
89 cout
<< "The following extensions didn't check out" << endl
<< wrongExts
;
96 cout
<< "ALL TESTS PASSED" << endl
;
98 cout
<< errno
<< " TESTS FAILED" << endl
;