FOSSology  4.7.1
Open Source License Compliance by Open Source Software
test_types.cc
Go to the documentation of this file.
1 /*
2  SPDX-License-Identifier: GPL-2.0-only
3  Author: Dietmar Helmut Leher <helmut.leher.ext@vaillant-group.com>
4  SPDX-FileCopyrightText: © 2026 Vaillant GmbH
5 */
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 
17 #include "ReuserState.hpp"
18 #include "ReuserTypes.hpp"
19 
20 class ReuserTypesTest : public CPPUNIT_NS::TestFixture
21 {
22  CPPUNIT_TEST_SUITE(ReuserTypesTest);
23  CPPUNIT_TEST(testReuserStateMutation);
24  CPPUNIT_TEST(testReuseModeFlags);
25  CPPUNIT_TEST(testItemTreeBoundsDefaults);
26  CPPUNIT_TEST_SUITE_END();
27 
28 protected:
36  {
37  ReuserState state(42);
38  CPPUNIT_ASSERT_EQUAL(42, state.getAgentId());
39  state.setAgentId(99);
40  CPPUNIT_ASSERT_EQUAL(99, state.getAgentId());
41  }
42 
51  {
52  // Flags must be distinct powers-of-two (no overlap).
53  CPPUNIT_ASSERT((REUSE_ENHANCED & REUSE_MAIN) == 0);
54  CPPUNIT_ASSERT((REUSE_ENHANCED & REUSE_CONF) == 0);
55  CPPUNIT_ASSERT((REUSE_ENHANCED & REUSE_COPYRIGHT) == 0);
56  CPPUNIT_ASSERT((REUSE_MAIN & REUSE_CONF) == 0);
57  CPPUNIT_ASSERT((REUSE_MAIN & REUSE_COPYRIGHT) == 0);
58  CPPUNIT_ASSERT((REUSE_CONF & REUSE_COPYRIGHT) == 0);
59 
60  // Combined mode works as expected.
61  int combined = REUSE_ENHANCED | REUSE_MAIN | REUSE_CONF | REUSE_COPYRIGHT;
62  CPPUNIT_ASSERT((combined & REUSE_ENHANCED) != 0);
63  CPPUNIT_ASSERT((combined & REUSE_MAIN) != 0);
64  CPPUNIT_ASSERT((combined & REUSE_CONF) != 0);
65  CPPUNIT_ASSERT((combined & REUSE_COPYRIGHT) != 0);
66  }
67 
76  {
77  ItemTreeBounds b{};
78  CPPUNIT_ASSERT_EQUAL(0, b.uploadtree_pk);
79  CPPUNIT_ASSERT_EQUAL(0, b.lft);
80  CPPUNIT_ASSERT_EQUAL(0, b.rgt);
81  CPPUNIT_ASSERT_EQUAL(0, b.upload_fk);
82  }
83 };
84 
85 CPPUNIT_TEST_SUITE_REGISTRATION(ReuserTypesTest);
Holds the runtime state of the reuser agent (agent id).
Definition: ReuserState.hpp:15
void testReuseModeFlags()
Reuse mode flag constants are distinct and combine correctly.
Definition: test_types.cc:50
void testReuserStateMutation()
ReuserState stores and mutates the agent id correctly.
Definition: test_types.cc:35
void testItemTreeBoundsDefaults()
ItemTreeBounds is zero-initialised when value-initialised.
Definition: test_types.cc:75
Bounds of an item within an uploadtree table.
Definition: ReuserTypes.hpp:14