KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_block_additional.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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
25
26#include "allegro_block_tests.h"
27
28#include <hash.h>
29
30
43
44
45using namespace ALLEGRO;
46using namespace KI_TEST;
47
48
53{
54 std::string m_BoardName;
56
57 bool operator==( const BLOCK_TEST_KEY& other ) const
58 {
59 return m_BoardName == other.m_BoardName &&
61 }
62};
63
64
65namespace std
66{
67template <>
68struct hash<BLOCK_TEST_KEY>
69{
70 size_t operator()( const BLOCK_TEST_KEY& key ) const
71 {
72 return hash_val( key.m_BoardName, key.m_BlockOffset );
73 }
74};
75} // namespace std
76
77
78using BLOCK_TEST_FUNC = std::function<void( const BLOCK_BASE& )>;
79using DB_OBJ_TEST_FUNC = std::function<void( const DB_OBJ& )>;
80
81
82static void TestOlympus0x20( const BLOCK_BASE& aBlock )
83{
84 BOOST_REQUIRE( aBlock.GetBlockType() == 0x20 );
85
86 const auto& blk = static_cast<const BLOCK<BLK_0x20_UNKNOWN>&>( aBlock ).GetData();
87 BOOST_TEST( blk.m_R == 0x0507 );
88 BOOST_TEST( blk.m_Key == 0x812AB498 );
89 BOOST_TEST( blk.m_Next == 0x824DF8F0 );
90}
91
92
101// clang-format off
102static const std::unordered_map<BLOCK_TEST_KEY, BLOCK_TEST_FUNC> additionalBlockTests{
103 { { "Olympus_15061-1b_v165", 0x0131553c }, TestOlympus0x20 },
104};
105
106
107static const std::unordered_map<BLOCK_TEST_KEY, DB_OBJ_TEST_FUNC> additionalDbObjTests{
108 { { "Olympus_15061-1b_v165", 0x0131553c }, []( const DB_OBJ& obj )
109 {
110 BOOST_REQUIRE( obj.GetType() == DB_OBJ::TYPE::x20 );
111
112 const auto& blk = static_cast<const UNKNOWN_0x20&>( obj );
113 BOOST_TEST( blk.m_Next.m_TargetKey == 0x824DF8F0 );
114 }
115 },
116};
117
118// clang-format on
119
120
121void KI_TEST::RunAdditionalBlockTest( const std::string& aBoardName, size_t aBlockOffset, const BLOCK_BASE& block )
122{
123 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
124
125 auto it = additionalBlockTests.find( key );
126 if( it != additionalBlockTests.end() )
127 {
128 const auto& testFunc = it->second;
129 BOOST_REQUIRE( testFunc );
130
131 testFunc( block );
132 }
133 else
134 {
135 BOOST_TEST_MESSAGE( "No additional test defined for this block" );
136 }
137}
138
139
140void KI_TEST::RunAdditionalObjectTest( const std::string& aBoardName, size_t aBlockOffset, const DB_OBJ& obj )
141{
142 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
143
144 auto it = additionalDbObjTests.find( key );
145 if( it != additionalDbObjTests.end() )
146 {
147 const auto& testFunc = it->second;
148 BOOST_REQUIRE( testFunc );
149
150 testFunc( obj );
151 }
152 else
153 {
154 BOOST_TEST_MESSAGE( "No additional test defined for this DB_OBJ" );
155 }
156}
The base class for all blocks in the main body of an Allegro file.
uint8_t GetBlockType() const
static constexpr std::size_t hash_val(const Types &... args)
Definition hash.h:51
void RunAdditionalObjectTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::DB_OBJ &aDbObj)
Look up and run any additional ad-hoc tests for a DB_OBJ (parsed and converted block)
void RunAdditionalBlockTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::BLOCK_BASE &aBlock)
Look up and run any additional ad-hoc tests for a block.
STL namespace.
A DB_OBJ represents one object in an Allegro database.
Definition allegro_db.h:162
Unique key for identifying a block test, used for looking up additional validation functions.
bool operator==(const BLOCK_TEST_KEY &other) const
size_t operator()(const BLOCK_TEST_KEY &key) const
static const std::unordered_map< BLOCK_TEST_KEY, DB_OBJ_TEST_FUNC > additionalDbObjTests
static void TestOlympus0x20(const BLOCK_BASE &aBlock)
std::function< void(const DB_OBJ &)> DB_OBJ_TEST_FUNC
std::function< void(const BLOCK_BASE &)> BLOCK_TEST_FUNC
static const std::unordered_map< BLOCK_TEST_KEY, BLOCK_TEST_FUNC > additionalBlockTests
The registry of additional block tests, keyed by board name and block offset.
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")