14 #include <cppunit/TestFixture.h>
15 #include <cppunit/extensions/HelperMacros.h>
18 #include "ReuserState.hpp"
19 #include "ReuserTypes.hpp"
29 int groupId,
int userId)
31 if (!
db.processBulkReuser(uploadId, groupId, userId))
36 auto reusedUploads =
db.getReusedUploads(uploadId, groupId);
37 for (
const auto& triple : reusedUploads)
40 if (!
db.getParentItemBounds(triple.reusedUploadId, bounds))
43 if (triple.reuseMode & REUSE_ENHANCED)
45 if (!
db.processEnhancedUploadReuse(uploadId, triple.reusedUploadId,
46 groupId, triple.reusedGroupId, userId))
51 if (!
db.processUploadReuse(uploadId, triple.reusedUploadId,
52 groupId, triple.reusedGroupId, userId))
56 if (triple.reuseMode & REUSE_MAIN)
57 db.reuseMainLicense(uploadId, groupId, triple.reusedUploadId,
58 triple.reusedGroupId);
60 if (triple.reuseMode & REUSE_CONF)
61 db.reuseConfSettings(uploadId, triple.reusedUploadId);
63 if (triple.reuseMode & REUSE_COPYRIGHT)
64 db.reuseCopyrights(uploadId, triple.reusedUploadId, userId);
78 CPPUNIT_TEST_SUITE_END();
91 bool standardCalled =
false;
92 bool enhancedCalled =
false;
94 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
95 {
return {{10, 1, 0 }}; };
97 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
98 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
100 handler.onProcessUploadReuse =
101 [&](int, int, int, int, int) ->
bool
102 { standardCalled =
true;
return true; };
104 handler.onProcessEnhancedUploadReuse =
105 [&](int, int, int, int, int) ->
bool
106 { enhancedCalled =
true;
return true; };
111 CPPUNIT_ASSERT(standardCalled);
112 CPPUNIT_ASSERT(!enhancedCalled);
125 bool standardCalled =
false;
126 bool enhancedCalled =
false;
128 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
129 {
return {{10, 1, REUSE_ENHANCED}}; };
131 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
132 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
134 handler.onProcessUploadReuse =
135 [&](int, int, int, int, int) ->
bool
136 { standardCalled =
true;
return true; };
138 handler.onProcessEnhancedUploadReuse =
139 [&](int, int, int, int, int) ->
bool
140 { enhancedCalled =
true;
return true; };
145 CPPUNIT_ASSERT(!standardCalled);
146 CPPUNIT_ASSERT(enhancedCalled);
160 bool mainCalled =
false;
161 bool confCalled =
false;
162 bool copyrightCalled =
false;
164 int allFlags = REUSE_ENHANCED | REUSE_MAIN | REUSE_CONF | REUSE_COPYRIGHT;
165 handler.onGetReusedUploads = [allFlags](int, int) -> std::vector<ReuseTriple>
166 {
return {{10, 1, allFlags}}; };
168 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
169 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
171 handler.onReuseMainLicense =
172 [&](int, int, int, int) ->
bool
173 { mainCalled =
true;
return true; };
175 handler.onReuseConfSettings =
176 [&](int, int) ->
bool
177 { confCalled =
true;
return true; };
179 handler.onReuseCopyrights =
180 [&](int, int, int) ->
bool
181 { copyrightCalled =
true;
return true; };
186 CPPUNIT_ASSERT(mainCalled);
187 CPPUNIT_ASSERT(confCalled);
188 CPPUNIT_ASSERT(copyrightCalled);
216 int processCalledCount = 0;
218 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
219 {
return {{10, 1, 0}, {20, 1, 0}}; };
223 handler.onGetParentItemBounds =
226 if (uploadId == 10)
return false;
227 out = {1,
"uploadtree", uploadId, 1, 10};
231 handler.onProcessUploadReuse =
232 [&](int, int, int, int, int) ->
bool
233 { ++processCalledCount;
return true; };
238 CPPUNIT_ASSERT_EQUAL(1, processCalledCount);
251 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
252 {
return {{10, 1, 0}}; };
254 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
255 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
257 handler.onProcessUploadReuse =
258 [](int, int, int, int, int) ->
bool
Mock ReuserDatabaseHandler for unit tests.
Test double for ReuserDatabaseHandler.
Database handler for the reuser agent.
void testProcessUploadReuseFailurePropagates()
A false return from processUploadReuse propagates to the caller.
void testStandardReuseDispatch()
reuseMode == 0 routes to processUploadReuse (standard path).
void testMissingParentBoundsSkipsUpload()
A reuse link whose parent bounds cannot be determined is skipped.
void testEnhancedReuseDispatch()
REUSE_ENHANCED bit routes to processEnhancedUploadReuse.
void testAllFlagsDispatch()
All optional flag bits together cause all optional methods to be called.
void testNoReusedUploadsSucceeds()
An empty reuse list results in immediate success without any processing.
Bounds of an item within an uploadtree table.
static bool runProcessUpload(ReuserDatabaseHandler &db, int uploadId, int groupId, int userId)
Minimal replica of processUploadId for unit-testing.