15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
32 CPPUNIT_TEST_SUITE_END();
47 handler.onGetClearingDecisionMapByPfile =
48 [](
int ,
int ) -> std::map<int, int>
50 return {{101, 20}, {50, 10}};
55 CPPUNIT_ASSERT_EQUAL(2u,
static_cast<unsigned>(result.size()));
56 CPPUNIT_ASSERT(result.find(101) != result.end());
57 CPPUNIT_ASSERT_EQUAL(20, result.at(101));
58 CPPUNIT_ASSERT(result.find(50) != result.end());
59 CPPUNIT_ASSERT_EQUAL(10, result.at(50));
73 CPPUNIT_ASSERT(result.empty());
87 handler.onGetUploadTreePksForPfiles =
89 const std::vector<int>& )
90 -> std::map<
int, std::vector<int>>
92 return {{101, {1001, 1002}}, {50, {1200}}};
95 std::vector<int> pfiles = {101, 50};
98 CPPUNIT_ASSERT_EQUAL(2u,
static_cast<unsigned>(result.size()));
100 CPPUNIT_ASSERT(result.find(101) != result.end());
101 CPPUNIT_ASSERT_EQUAL(2,
static_cast<int>(result.at(101).size()));
102 CPPUNIT_ASSERT_EQUAL(1001, result.at(101)[0]);
103 CPPUNIT_ASSERT_EQUAL(1002, result.at(101)[1]);
105 CPPUNIT_ASSERT(result.find(50) != result.end());
106 CPPUNIT_ASSERT_EQUAL(1,
static_cast<int>(result.at(50).size()));
107 CPPUNIT_ASSERT_EQUAL(1200, result.at(50)[0]);
121 CPPUNIT_ASSERT(result.empty());
134 handler.onGetReusedUploads =
135 [](
int ,
int ) -> std::vector<ReuseTriple>
137 return {{10, 1, REUSE_MAIN}, {20, 2, REUSE_ENHANCED | REUSE_COPYRIGHT}};
142 CPPUNIT_ASSERT_EQUAL(2u,
static_cast<unsigned>(result.size()));
143 CPPUNIT_ASSERT_EQUAL(10, result[0].reusedUploadId);
144 CPPUNIT_ASSERT_EQUAL(REUSE_MAIN, result[0].reuseMode);
145 CPPUNIT_ASSERT_EQUAL(20, result[1].reusedUploadId);
146 CPPUNIT_ASSERT_EQUAL(REUSE_ENHANCED | REUSE_COPYRIGHT,
147 result[1].reuseMode);
161 handler.onGetParentItemBounds =
164 out = {500,
"uploadtree", 7, 1, 42};
172 CPPUNIT_ASSERT_EQUAL(500, bounds.uploadtree_pk);
173 CPPUNIT_ASSERT_EQUAL(std::string(
"uploadtree"), bounds.uploadTreeTableName);
174 CPPUNIT_ASSERT_EQUAL(7, bounds.upload_fk);
175 CPPUNIT_ASSERT_EQUAL(1, bounds.lft);
176 CPPUNIT_ASSERT_EQUAL(42, bounds.rgt);
Mock ReuserDatabaseHandler for unit tests.
Test double for ReuserDatabaseHandler.
bool getParentItemBounds(int uploadId, ItemTreeBounds &out) override
Fetch the parent item bounds for a given upload.
std::map< int, std::vector< int > > getUploadTreePksForPfiles(int uploadId, const std::vector< int > &pfileIds) override
For a set of pfile ids, return a map pfile_fk to [uploadtree_pk].
std::vector< ReuseTriple > getReusedUploads(int uploadId, int groupId) override
Return the list of uploads that should be reused for uploadId.
std::map< int, int > getClearingDecisionMapByPfile(int uploadId, int groupId) override
Build a pfile_fk to clearing_decision_pk map for uploadId.
void testGetClearingDecisionMapReturnsFirstDecisionPerPfile()
getClearingDecisionMapByPfile returns one entry per distinct pfile_fk.
void testGetClearingDecisionMapEmptyOnNoData()
getClearingDecisionMapByPfile returns an empty map when no callback is set.
void testGetParentItemBoundsPopulatesStruct()
getParentItemBounds populates all ItemTreeBounds fields on success.
void testGetReusedUploadsReturnedInOrder()
getReusedUploads preserves the order and content of ReuseTriple entries.
void testGetUploadTreePksEmptyOnEmptyInput()
getUploadTreePksForPfiles returns an empty map for an empty pfile list.
void testGetUploadTreePksGroupedByPfile()
getUploadTreePksForPfiles groups uploadtree_pk values by pfile_fk.
Bounds of an item within an uploadtree table.