KiCad PCB EDA Suite
Loading...
Searching...
No Matches
uuid_test_utils.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, see <https://www.gnu.org/licenses/>.
18 */
19
22
23namespace KI_TEST
24{
25
26bool IsUUID( const std::string& aStr )
27{
28 std::regex uuid( "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" );
29 std::smatch match;
30
31 return std::regex_match( aStr, match, uuid );
32}
33
34
35bool IsUUIDPathWithLevels( const std::string& aStr, unsigned aLevels )
36{
37 // A UUID is formatted as 8-4-4-4-12
38 const unsigned tsLen = 36;
39 const unsigned levelLen = tsLen + 1; // add the /
40
41 if( aStr.size() != aLevels * levelLen + 1 )
42 {
43 BOOST_TEST_INFO( "String is the wrong length for " << aLevels << " levels." );
44 return false;
45 }
46
47 if( aStr[0] != '/' )
48 {
49 BOOST_TEST_INFO( "Doesn't start with '/'" );
50 return false;
51 }
52
53 auto tsBegin = aStr.begin() + 1;
54
55 for( unsigned i = 0; i < aLevels; i++ )
56 {
57 if( !IsUUID( std::string( tsBegin, tsBegin + tsLen ) ) )
58 {
59 BOOST_TEST_INFO( "Not a UUID at level "
60 << i << ": " << std::string( tsBegin, tsBegin + tsLen ) );
61 return false;
62 }
63
64 if( *( tsBegin + tsLen ) != '/' )
65 {
66 BOOST_TEST_INFO( "level doesn't end in '/'" );
67 return false;
68 }
69
70 tsBegin += levelLen;
71 }
72
73 return true;
74}
75
76} // namespace KI_TEST
bool IsUUIDPathWithLevels(const std::string &aStr, unsigned aLevels)
Predicate to check a string is a UUID path format.
bool IsUUID(const std::string &aStr)
Check if the string between the iterators looks like a UUID.
BOOST_TEST_INFO("Two-port Series .op current = "<< iDevice)
Test utilities for timestamps.