KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_teardrop_uuid.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
30
32
33#include <kiid.h>
34
35
36BOOST_AUTO_TEST_SUITE( TeardropUUID )
37
38
39BOOST_AUTO_TEST_CASE( CombineTrackAndPadUuids )
40{
41 // Simulate the teardrop UUID generation: combine track and pad UUIDs
42 KIID trackUuid;
43 KIID padUuid;
44
45 KIID teardropUuid = KIID::Combine( trackUuid, padUuid );
46
47 // The combined UUID should be different from both inputs
48 BOOST_CHECK( teardropUuid != trackUuid );
49 BOOST_CHECK( teardropUuid != padUuid );
50
51 // The same inputs should always produce the same output
52 KIID teardropUuid2 = KIID::Combine( trackUuid, padUuid );
53 BOOST_CHECK_EQUAL( teardropUuid.AsString(), teardropUuid2.AsString() );
54}
55
56
57BOOST_AUTO_TEST_CASE( MaskUuidIsIncrementedFromTeardropUuid )
58{
59 // Teardrop masks use the combined UUID, then increment to differentiate
60 KIID trackUuid;
61 KIID padUuid;
62
63 KIID teardropUuid = KIID::Combine( trackUuid, padUuid );
64
65 KIID maskUuid = KIID::Combine( trackUuid, padUuid );
66 maskUuid.Increment();
67
68 // The mask UUID should be different from the teardrop UUID
69 BOOST_CHECK( maskUuid != teardropUuid );
70
71 // Both should be deterministic
72 KIID teardropUuid2 = KIID::Combine( trackUuid, padUuid );
73 KIID maskUuid2 = KIID::Combine( trackUuid, padUuid );
74 maskUuid2.Increment();
75
76 BOOST_CHECK_EQUAL( teardropUuid.AsString(), teardropUuid2.AsString() );
77 BOOST_CHECK_EQUAL( maskUuid.AsString(), maskUuid2.AsString() );
78}
79
80
81BOOST_AUTO_TEST_CASE( DifferentTracksProduceDifferentTeardropUuids )
82{
83 // Two tracks connecting to the same pad should produce different teardrop UUIDs
84 KIID track1Uuid;
85 KIID track2Uuid;
86 KIID padUuid;
87
88 KIID teardrop1Uuid = KIID::Combine( track1Uuid, padUuid );
89 KIID teardrop2Uuid = KIID::Combine( track2Uuid, padUuid );
90
91 // Different tracks should produce different teardrops
92 BOOST_CHECK( teardrop1Uuid != teardrop2Uuid );
93
94 // Each should still be deterministic
95 KIID teardrop1Uuid2 = KIID::Combine( track1Uuid, padUuid );
96 KIID teardrop2Uuid2 = KIID::Combine( track2Uuid, padUuid );
97
98 BOOST_CHECK_EQUAL( teardrop1Uuid.AsString(), teardrop1Uuid2.AsString() );
99 BOOST_CHECK_EQUAL( teardrop2Uuid.AsString(), teardrop2Uuid2.AsString() );
100}
101
102
103BOOST_AUTO_TEST_CASE( StableAcrossRegenerations )
104{
105 // Simulates regenerating teardrops: same track+pad should always give same UUID
106 KIID trackUuid( "12345678-1234-1234-1234-123456789012" );
107 KIID padUuid( "abcdef01-abcd-abcd-abcd-abcdef012345" );
108
109 // First generation
110 KIID teardropUuid1 = KIID::Combine( trackUuid, padUuid );
111
112 // Simulate regeneration by computing again
113 KIID teardropUuid2 = KIID::Combine( trackUuid, padUuid );
114
115 // Should be identical
116 BOOST_CHECK_EQUAL( teardropUuid1.AsString(), teardropUuid2.AsString() );
117}
118
119
Definition kiid.h:49
wxString AsString() const
Definition kiid.cpp:247
static KIID Combine(const KIID &aFirst, const KIID &aSecond)
Creates a deterministic KIID from two input KIIDs by XORing their underlying UUIDs.
Definition kiid.cpp:289
void Increment()
Generates a deterministic replacement for a given ID.
Definition kiid.cpp:274
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CombineTrackAndPadUuids)
BOOST_CHECK_EQUAL(result, "25.4")