KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_kiid.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 (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21#include <kiid.h>
22#include <wx/string.h>
23#include <set>
24
26
27
29{
31
32 KIID a0;
33 KIID b0;
34 KIID c0;
35 KIID d0;
36
37 // Make sure the hashes are unique
38 std::set<size_t> hashes;
39 hashes.insert( a0.Hash() );
40 hashes.insert( b0.Hash() );
41 hashes.insert( c0.Hash() );
42 hashes.insert( d0.Hash() );
43 BOOST_CHECK_EQUAL( hashes.size(), 4 );
44
46
47 KIID a;
48 BOOST_CHECK_EQUAL( a.Hash(), a0.Hash() );
49
50 KIID b;
51 BOOST_CHECK_EQUAL( b.Hash(), b0.Hash() );
52
53 KIID c;
54 BOOST_CHECK_EQUAL( c.Hash(), c0.Hash() );
55
56 KIID d;
57 BOOST_CHECK_EQUAL( d.Hash(), d0.Hash() );
58}
59
60
61BOOST_AUTO_TEST_CASE( KiidPathTest )
62{
63 KIID a, b, c, d;
64
65 KIID_PATH path1;
66 KIID_PATH path2;
67
68 path1.push_back( a );
69 path1.push_back( b );
70 path1.push_back( c );
71 path1.push_back( d );
72
73 path2.push_back( b );
74 path2.push_back( c );
75 path2.push_back( d );
76
77 BOOST_CHECK( path1.EndsWith( path2 ) == true );
78 BOOST_CHECK( path2.EndsWith( path1 ) == false );
79}
80
81
82BOOST_AUTO_TEST_CASE( LegacyTimestamp )
83{
84 timestamp_t ts_a = 0xAABBCCDD;
85 timestamp_t ts_b = 0x00000012;
86
87 wxString str_a( wxS( "AABBCCDD" ) );
88 wxString str_b( wxS( "00000012" ) );
89
90 KIID a( ts_a );
91 KIID b( ts_b );
92
93 BOOST_CHECK( a.AsLegacyTimestamp() == ts_a );
94 BOOST_CHECK( a.AsLegacyTimestampString() == str_a );
95
96 BOOST_CHECK( b.AsLegacyTimestamp() == ts_b );
97 BOOST_CHECK( b.AsLegacyTimestampString() == str_b );
98
99 BOOST_CHECK( KIID( str_a ).AsLegacyTimestamp() == ts_a );
100 BOOST_CHECK( KIID( str_b ).AsLegacyTimestamp() == ts_b );
101
102 BOOST_CHECK( KIID( str_a ).AsLegacyTimestampString() == str_a );
103 BOOST_CHECK( KIID( str_b ).AsLegacyTimestampString() == str_b );
104}
105
106
bool EndsWith(const KIID_PATH &aPath) const
Test if aPath from the last path towards the first path.
Definition: kiid.cpp:327
Definition: kiid.h:49
static void SeedGenerator(unsigned int aSeed)
Re-initialize the UUID generator with a given seed (for testing or QA purposes)
Definition: kiid.cpp:286
size_t Hash() const
Definition: kiid.cpp:226
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:250
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:213
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: kiid.h:46
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Seeding)
Definition: test_kiid.cpp:28