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 auto reusedUploads =
db.getReusedUploads(uploadId, groupId);
32 for (
const auto& triple : reusedUploads)
35 if (!
db.getParentItemBounds(triple.reusedUploadId, bounds))
38 if (triple.reuseMode & REUSE_ENHANCED)
40 if (!
db.processEnhancedUploadReuse(uploadId, triple.reusedUploadId,
41 groupId, triple.reusedGroupId, userId))
46 if (!
db.processUploadReuse(uploadId, triple.reusedUploadId,
47 groupId, triple.reusedGroupId, userId))
51 if (triple.reuseMode & REUSE_MAIN)
52 db.reuseMainLicense(uploadId, groupId, triple.reusedUploadId,
53 triple.reusedGroupId);
55 if (triple.reuseMode & REUSE_CONF)
56 db.reuseConfSettings(uploadId, triple.reusedUploadId);
58 if (triple.reuseMode & REUSE_COPYRIGHT)
59 db.reuseCopyrights(uploadId, triple.reusedUploadId, userId);
73 CPPUNIT_TEST_SUITE_END();
86 bool standardCalled =
false;
87 bool enhancedCalled =
false;
89 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
90 {
return {{10, 1, 0 }}; };
92 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
93 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
95 handler.onProcessUploadReuse =
96 [&](int, int, int, int, int) ->
bool
97 { standardCalled =
true;
return true; };
99 handler.onProcessEnhancedUploadReuse =
100 [&](int, int, int, int, int) ->
bool
101 { enhancedCalled =
true;
return true; };
106 CPPUNIT_ASSERT(standardCalled);
107 CPPUNIT_ASSERT(!enhancedCalled);
120 bool standardCalled =
false;
121 bool enhancedCalled =
false;
123 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
124 {
return {{10, 1, REUSE_ENHANCED}}; };
126 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
127 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
129 handler.onProcessUploadReuse =
130 [&](int, int, int, int, int) ->
bool
131 { standardCalled =
true;
return true; };
133 handler.onProcessEnhancedUploadReuse =
134 [&](int, int, int, int, int) ->
bool
135 { enhancedCalled =
true;
return true; };
140 CPPUNIT_ASSERT(!standardCalled);
141 CPPUNIT_ASSERT(enhancedCalled);
155 bool mainCalled =
false;
156 bool confCalled =
false;
157 bool copyrightCalled =
false;
159 int allFlags = REUSE_ENHANCED | REUSE_MAIN | REUSE_CONF | REUSE_COPYRIGHT;
160 handler.onGetReusedUploads = [allFlags](int, int) -> std::vector<ReuseTriple>
161 {
return {{10, 1, allFlags}}; };
163 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
164 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
166 handler.onReuseMainLicense =
167 [&](int, int, int, int) ->
bool
168 { mainCalled =
true;
return true; };
170 handler.onReuseConfSettings =
171 [&](int, int) ->
bool
172 { confCalled =
true;
return true; };
174 handler.onReuseCopyrights =
175 [&](int, int, int) ->
bool
176 { copyrightCalled =
true;
return true; };
181 CPPUNIT_ASSERT(mainCalled);
182 CPPUNIT_ASSERT(confCalled);
183 CPPUNIT_ASSERT(copyrightCalled);
211 int processCalledCount = 0;
213 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
214 {
return {{10, 1, 0}, {20, 1, 0}}; };
218 handler.onGetParentItemBounds =
221 if (uploadId == 10)
return false;
222 out = {1,
"uploadtree", uploadId, 1, 10};
226 handler.onProcessUploadReuse =
227 [&](int, int, int, int, int) ->
bool
228 { ++processCalledCount;
return true; };
233 CPPUNIT_ASSERT_EQUAL(1, processCalledCount);
246 handler.onGetReusedUploads = [](int, int) -> std::vector<ReuseTriple>
247 {
return {{10, 1, 0}}; };
249 handler.onGetParentItemBounds = [](int,
ItemTreeBounds& out) ->
bool
250 { out = {1,
"uploadtree_a", 10, 1, 100};
return true; };
252 handler.onProcessUploadReuse =
253 [](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.