CADSTAR Parts: Add QA test for +N0 root with no parts

This commit is contained in:
Roberto Fernandez Bautista 2023-06-26 20:44:17 +02:00
parent dd933b7d0e
commit 09f1df6c94
4 changed files with 4690 additions and 2341 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,52 +2,60 @@
from math import factorial
from itertools import permutations,islice
with open('cadstarDummy.lib', 'w', newline='\r\n') as f:
f.write('# FORMAT 32\n')
for fileindex, filename in enumerate(["dummycadstarlib.lib", "dummycadstarlibwithheader.lib"]):
with open(filename, 'w', newline='\r\n') as f:
f.write('# FORMAT 32\n')
for i in range(100):
f.write('\n')
f.write(f'.PartName{i} ({i*5}) :2 ;Part {i} Description\n')
f.write(f'FOOTPRINT{i} (variant{i*5})\n')
if fileindex > 0:
f.write('+N0 \'root\'\n')
f.write('+N1 N0 ')
for i in range(100):
f.write(f'\'PartName{i}\'&\n')
currentPartData=[]
for i in range(100):
f.write('\n')
f.write(f'.PartName{i} ({i*5}) :2 ;Part {i} Description\n')
f.write(f'FOOTPRINT{i} (variant{i*5})\n')
currentPartData.append(f'*VALUE {i} uH\n')
currentPartData.append(f'*DFN PartName{i}\n')
currentPartData=[]
if i%10 == 1:
currentPartData.append(f'*NGS\n')
currentPartData.append(f'*VALUE {i} uH\n')
currentPartData.append(f'*DFN PartName{i}\n')
if i%5 == 1:
currentPartData.append(f'*NPV\n')
if i%10 == 1:
currentPartData.append(f'*NGS\n')
if i%5 == 1:
currentPartData.append(f'*NPV\n')
currentPartData.append('*STM L\n')
currentPartData.append(f'*MXP {i+10}\n')
currentPartData.append(f'*SPI (PartName{i}) {i}uH\n')
currentPartData.append(f'*PAC (PartName{i}) Acceptance{i}\n')
currentPartData.append(f'*UserFieldpartNo {i*5}\n')
currentPartData.append(f'*"UserFieldpartNoCreated by" Person{i}\n')
currentPartData.append(f'$"SCH val1" (val{i})\n')
currentPartData.append(f'$!SCH val2 (readOnly{i})\n')
currentPartData.append(f'%"PCB val1" (val{i})\n')
currentPartData.append(f'%!PCB val2 (readOnly{i})\n')
currentPartData.append(f'~"Part val1" (val{i})\n')
currentPartData.append(f'~!Part val2 (readOnly{i})\n')
currentPartData.append(f'@SCH and PCB val1 (val{i})\n')
currentPartData.append(f'@!SCH and PCB val2 (readOnly{i})\n')
currentPartData.append('*STM L\n')
currentPartData.append(f'*MXP {i+10}\n')
currentPartData.append(f'*SPI (PartName{i}) {i}uH\n')
currentPartData.append(f'*PAC (PartName{i}) Acceptance{i}\n')
currentPartData.append(f'*UserFieldpartNo {i*5}\n')
currentPartData.append(f'*"UserFieldpartNoCreated by" Person{i}\n')
currentPartData.append(f'$"SCH val1" (val{i})\n')
currentPartData.append(f'$!SCH val2 (readOnly{i})\n')
currentPartData.append(f'%"PCB val1" (val{i})\n')
currentPartData.append(f'%!PCB val2 (readOnly{i})\n')
currentPartData.append(f'~"Part val1" (val{i})\n')
currentPartData.append(f'~!Part val2 (readOnly{i})\n')
currentPartData.append(f'@SCH and PCB val1 (val{i})\n')
currentPartData.append(f'@!SCH and PCB val2 (readOnly{i})\n')
# Change ordering to test parser works
nth=(i*101)%factorial(len(currentPartData)) # make a permutation that exists
permutatedData=next(islice(permutations(currentPartData), nth, None))
# Change ordering to test parser works
nth=(i*101)%factorial(len(currentPartData)) # make a permutation that exists
permutatedData=next(islice(permutations(currentPartData), nth, None))
for data in permutatedData:
f.write(data)
for data in permutatedData:
f.write(data)
# Symbol should always be at the end in fileformat anyway
f.write(f'Symbol{i}\n')
f.write('1.0 2.0\n')
f.write('/GND 3.0\n')
# Symbol should always be at the end in fileformat anyway
f.write(f'Symbol{i}\n')
f.write('1.0 2.0\n')
f.write('/GND 3.0\n')
f.write('\n.END\n')
f.write('\n.END\n')

View File

@ -101,89 +101,96 @@ BOOST_AUTO_TEST_CASE( CheckHeader )
BOOST_AUTO_TEST_CASE( ReadFile )
{
CADSTAR_PARTS_LIB_PARSER p;
// Test a programatically generated files (see writeCadstarFile.py)
std::vector<std::string> testFiles = { "dummycadstarlib.lib", "dummycadstarlibwithheader.lib" };
// Test a programatically generated file (see writeCadstarFile.py)
auto ret = p.ReadFile( getCadstarTestFile( "cadstarDummy.lib" ) );
KI_CHECK_OPT_EQUAL( ret.m_FormatNumber, 32 );
BOOST_CHECK_EQUAL( ret.m_PartEntries.size(), 100 );
int i = 0;
for( CADSTAR_PART_ENTRY& partEntry : ret.m_PartEntries )
for( auto testFile : testFiles )
{
// Part header KI_CHECK_OPT_EQUAL
BOOST_CHECK_EQUAL( partEntry.m_Name, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Number, std::to_string( i * 5 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Version, std::to_string( 2 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Description,
"Part " + std::to_string( i ) + " Description" );
auto ret = p.ReadFile( getCadstarTestFile( testFile ) );
BOOST_CHECK_EQUAL( partEntry.m_Pcb_component, "FOOTPRINT" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Pcb_alternate, "variant" + std::to_string( i * 5 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Value, std::to_string( i ) + " uH" );
BOOST_CHECK_EQUAL( partEntry.m_ComponentStem, "L" );
KI_CHECK_OPT_EQUAL( partEntry.m_MaxPinCount, i + 10 );
BOOST_CHECK_EQUAL( partEntry.m_GateSwappingAllowed, i % 10 != 1 );
BOOST_CHECK_EQUAL( partEntry.m_PinsVisible, i % 5 != 1 );
KI_CHECK_OPT_EQUAL( ret.m_FormatNumber, 32 );
BOOST_CHECK_EQUAL( ret.m_PartEntries.size(), 100 );
KI_CHECK_OPT_EQUAL( partEntry.m_SpicePartName, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_SpiceModel, std::to_string( i ) + "uH" );
int i = 0;
KI_CHECK_OPT_EQUAL( partEntry.m_AcceptancePartName, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_AcceptanceText, "Acceptance" + std::to_string( i ) );
for( CADSTAR_PART_ENTRY& partEntry : ret.m_PartEntries )
{
// Part header KI_CHECK_OPT_EQUAL
BOOST_CHECK_EQUAL( partEntry.m_Name, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Number, std::to_string( i * 5 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Version, std::to_string( 2 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Description,
"Part " + std::to_string( i ) + " Description" );
// User part attributes (* lines)
BOOST_CHECK_EQUAL( partEntry.m_UserAttributes["UserFieldpartNo"],
std::to_string( i * 5 ) );
BOOST_CHECK_EQUAL( partEntry.m_UserAttributes["UserFieldpartNoCreated by"],
"Person" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_Pcb_component, "FOOTPRINT" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Pcb_alternate, "variant" + std::to_string( i * 5 ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Value, std::to_string( i ) + " uH" );
BOOST_CHECK_EQUAL( partEntry.m_ComponentStem, "L" );
KI_CHECK_OPT_EQUAL( partEntry.m_MaxPinCount, i + 10 );
BOOST_CHECK_EQUAL( partEntry.m_GateSwappingAllowed, i % 10 != 1 );
BOOST_CHECK_EQUAL( partEntry.m_PinsVisible, i % 5 != 1 );
// SCH attributes ($ lines)
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val2"].m_Value,
"readOnly" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_SpicePartName, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_SpiceModel, std::to_string( i ) + "uH" );
// PCB attributes (% lines)
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val2"].m_Value,
"readOnly" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_AcceptancePartName, "PartName" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_AcceptanceText, "Acceptance" + std::to_string( i ) );
// Parts attributes (~ lines)
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val2"].m_Value,
"readOnly" + std::to_string( i ) );
// User part attributes (* lines)
BOOST_CHECK_EQUAL( partEntry.m_UserAttributes["UserFieldpartNo"],
std::to_string( i * 5 ) );
BOOST_CHECK_EQUAL( partEntry.m_UserAttributes["UserFieldpartNoCreated by"],
"Person" + std::to_string( i ) );
// PCB and SCH attributes (@ lines)
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val2"].m_Value,
"readOnly" + std::to_string( i ) );
// SCH attributes ($ lines)
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_SchAttributes["SCH val2"].m_Value,
"readOnly" + std::to_string( i ) );
// Check symbol name and pins
BOOST_REQUIRE_EQUAL( partEntry.m_Symbols.size(), 1 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_SymbolName, "Symbol" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Symbols[0].m_SymbolAlternateName,
std::optional<std::string>() );
BOOST_REQUIRE_EQUAL( partEntry.m_Symbols[0].m_Pins.size(), 2 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_Pins[0].m_Identifier, 1 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_Pins[1].m_Identifier, 2 );
// PCB attributes (% lines)
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_PcbAttributes["PCB val2"].m_Value,
"readOnly" + std::to_string( i ) );
// Check hidden pins
BOOST_REQUIRE_EQUAL( partEntry.m_HiddenPins.size(), 1 );
BOOST_CHECK_EQUAL( partEntry.m_HiddenPins.count( "GND" ), 1 );
i++;
// Parts attributes (~ lines)
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val1"].m_ReadOnly, false );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val2"].m_ReadOnly, true );
BOOST_CHECK_EQUAL( partEntry.m_PartAttributes["Part val2"].m_Value,
"readOnly" + std::to_string( i ) );
// PCB and SCH attributes (@ lines)
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val1"].m_ReadOnly,
false );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val1"].m_Value,
"val" + std::to_string( i ) );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val2"].m_ReadOnly,
true );
BOOST_CHECK_EQUAL( partEntry.m_SchAndPcbAttributes["SCH and PCB val2"].m_Value,
"readOnly" + std::to_string( i ) );
// Check symbol name and pins
BOOST_REQUIRE_EQUAL( partEntry.m_Symbols.size(), 1 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_SymbolName,
"Symbol" + std::to_string( i ) );
KI_CHECK_OPT_EQUAL( partEntry.m_Symbols[0].m_SymbolAlternateName,
std::optional<std::string>() );
BOOST_REQUIRE_EQUAL( partEntry.m_Symbols[0].m_Pins.size(), 2 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_Pins[0].m_Identifier, 1 );
BOOST_CHECK_EQUAL( partEntry.m_Symbols[0].m_Pins[1].m_Identifier, 2 );
// Check hidden pins
BOOST_REQUIRE_EQUAL( partEntry.m_HiddenPins.size(), 1 );
BOOST_CHECK_EQUAL( partEntry.m_HiddenPins.count( "GND" ), 1 );
i++;
}
}
}