]>
git.saurik.com Git - android/aapt.git/blob - tests/CrunchCache_test.cpp
2 // Copyright 2011 The Android Open Source Project
4 #include <utils/String8.h>
8 #include "CrunchCache.h"
9 #include "FileFinder.h"
10 #include "MockFileFinder.h"
11 #include "CacheUpdater.h"
12 #include "MockCacheUpdater.h"
14 using namespace android
;
18 void expectEqual(int got
, int expected
, const char* desc
) {
19 cout
<< "Checking " << desc
<< ": ";
20 cout
<< "Got " << got
<< ", expected " << expected
<< "...";
21 cout
<< ( (got
== expected
) ? "PASSED" : "FAILED") << endl
;
22 errno
+= ((got
== expected
) ? 0 : 1);
29 String8
source("res");
32 // Create data for MockFileFinder to feed to the cache
33 KeyedVector
<String8
, time_t> sourceData
;
34 // This shouldn't be updated
35 sourceData
.add(String8("res/drawable/hello.png"),3);
36 // This should be updated
37 sourceData
.add(String8("res/drawable/world.png"),5);
38 // This should cause make directory to be called
39 sourceData
.add(String8("res/drawable-cool/hello.png"),3);
41 KeyedVector
<String8
, time_t> destData
;
42 destData
.add(String8("res2/drawable/hello.png"),3);
43 destData
.add(String8("res2/drawable/world.png"),3);
44 // this should call delete
45 destData
.add(String8("res2/drawable/dead.png"),3);
47 // Package up data and create mock file finder
48 KeyedVector
<String8
, KeyedVector
<String8
,time_t> > data
;
49 data
.add(source
,sourceData
);
50 data
.add(dest
,destData
);
51 FileFinder
* ff
= new MockFileFinder(data
);
52 CrunchCache
cc(source
,dest
,ff
);
54 MockCacheUpdater
* mcu
= new MockCacheUpdater();
55 CacheUpdater
* cu(mcu
);
57 cout
<< "Running Crunch...";
58 int result
= cc
.crunch(cu
);
59 cout
<< ((result
> 0) ? "PASSED" : "FAILED") << endl
;
60 errno
+= ((result
> 0) ? 0 : 1);
62 const int EXPECTED_RESULT
= 2;
63 expectEqual(result
, EXPECTED_RESULT
, "number of files touched");
65 cout
<< "Checking calls to deleteFile and processImage:" << endl
;
66 const int EXPECTED_DELETES
= 1;
67 const int EXPECTED_PROCESSED
= 2;
69 expectEqual(mcu
->deleteCount
, EXPECTED_DELETES
, "deleteFile");
71 expectEqual(mcu
->processCount
, EXPECTED_PROCESSED
, "processImage");
73 const int EXPECTED_OVERWRITES
= 3;
74 result
= cc
.crunch(cu
, true);
75 expectEqual(result
, EXPECTED_OVERWRITES
, "number of files touched with overwrite");
79 cout
<< "ALL TESTS PASSED!" << endl
;
81 cout
<< errno
<< " TESTS FAILED" << endl
;
86 // TESTS BELOW WILL GO AWAY SOON
88 String8
source2("ApiDemos/res");
89 String8
dest2("ApiDemos/res2");
91 FileFinder
* sff
= new SystemFileFinder();
92 CacheUpdater
* scu
= new SystemCacheUpdater();
94 CrunchCache
scc(source2
,dest2
,sff
);