Add missing files from last commit.

This commit is contained in:
Jeff Young 2020-02-28 22:36:34 +00:00
parent e0bad936bf
commit 149d34fbe1
2 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,81 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "uuid_test_utils.h"
#include <unit_test_utils/unit_test_utils.h>
namespace KI_TEST
{
bool IsUUID( const std::string& aStr )
{
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}" );
std::smatch match;
return std::regex_match( aStr, match, uuid );
}
bool IsUUIDPathWithLevels( const std::string& aStr, unsigned aLevels )
{
// A UUID is formated as 8-4-4-4-12
const unsigned tsLen = 36;
const unsigned levelLen = tsLen + 1; // add the /
if( aStr.size() != aLevels * levelLen + 1 )
{
BOOST_TEST_INFO( "String is the wrong length for " << aLevels << " levels." );
return false;
}
if( aStr[0] != '/' )
{
BOOST_TEST_INFO( "Doesn't start with '/'" );
return false;
}
auto tsBegin = aStr.begin() + 1;
for( unsigned i = 0; i < aLevels; i++ )
{
if( !IsUUID( std::string( tsBegin, tsBegin + tsLen ) ) )
{
BOOST_TEST_INFO( "Not a UUID at level "
<< i << ": " << std::string( tsBegin, tsBegin + tsLen ) );
return false;
}
if( *( tsBegin + tsLen ) != '/' )
{
BOOST_TEST_INFO( "level doesn't end in '/'" );
return false;
}
tsBegin += levelLen;
}
return true;
}
} // namespace KI_TEST

View File

@ -0,0 +1,58 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef QA_UUID_TEST_UTILS__H
#define QA_UUID_TEST_UTILS__H
#include <algorithm>
#include <string>
#include <regex>
/**
* @file
* Test utilities for timestamps
*/
namespace KI_TEST
{
/**
* Check if the string between the iterators looks like a UUID
*/
bool IsUUID( const std::string& aStr );
/**
* Predicate to check a string is a UUID path format
*
* Eg. levels=2: /1d33ca6f-67e8-41ae-a0aa-49d857ab38d5/1d33ca6f-67e8-41ae-a0aa-49d857ab38d5/
*
* @param aStr candidate string
* @param levels expected levels
* @return true if format matches
*/
bool IsUUIDPathWithLevels( const std::string& aStr, unsigned aLevels );
} // namespace KI_TEST
#endif // QA_UUID_TEST_UTILS__H