From c1b1ce6951e3c59ae5f77fc8af44bad4bbf56c9b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 12 May 2020 21:43:11 +0200 Subject: [PATCH] Provide unit test for DeepTexts. --- src/db/db/dbHierarchyBuilder.cc | 5 +- src/db/unit_tests/dbDeepTextsTests.cc | 85 ++++++++++++++++++++++++++ src/db/unit_tests/unit_tests.pro | 3 +- testdata/algo/deep_texts_au1.gds | Bin 0 -> 848 bytes testdata/algo/deep_texts_l1.gds | Bin 0 -> 2894 bytes 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 src/db/unit_tests/dbDeepTextsTests.cc create mode 100644 testdata/algo/deep_texts_au1.gds create mode 100644 testdata/algo/deep_texts_l1.gds diff --git a/src/db/db/dbHierarchyBuilder.cc b/src/db/db/dbHierarchyBuilder.cc index 50340a6a1..5ea489b02 100644 --- a/src/db/db/dbHierarchyBuilder.cc +++ b/src/db/db/dbHierarchyBuilder.cc @@ -714,7 +714,10 @@ TextBuildingHierarchyBuilderShapeReceiver::TextBuildingHierarchyBuilderShapeRece void TextBuildingHierarchyBuilderShapeReceiver::push (const db::Shape &shape, const db::ICplxTrans &trans, const db::Box & /*region*/, const db::RecursiveShapeReceiver::box_tree_type * /*complex_region*/, db::Shapes *target) { if (shape.is_text ()) { - target->insert (shape.text ().transformed (trans)); + db::Text t; + shape.text (t); + t.transform (trans); + target->insert (t); } } diff --git a/src/db/unit_tests/dbDeepTextsTests.cc b/src/db/unit_tests/dbDeepTextsTests.cc new file mode 100644 index 000000000..78586ed3e --- /dev/null +++ b/src/db/unit_tests/dbDeepTextsTests.cc @@ -0,0 +1,85 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#include "dbHierarchyBuilder.h" +#include "dbReader.h" +#include "dbTestSupport.h" +#include "dbTexts.h" +#include "dbDeepShapeStore.h" +#include "dbRegion.h" +#include "dbEdges.h" +#include "tlUnitTest.h" +#include "tlStream.h" + +TEST(1_Basics) +{ + db::Layout ly; + { + std::string fn (tl::testsrc ()); + fn += "/testdata/algo/deep_texts_l1.gds"; + tl::InputStream stream (fn); + db::Reader reader (stream); + reader.read (ly); + } + + db::cell_index_type top_cell_index = *ly.begin_top_down (); + db::Cell &top_cell = ly.cell (top_cell_index); + + db::DeepShapeStore dss; + + unsigned int l2 = ly.get_layer (db::LayerProperties (2, 0)); + unsigned int l3 = ly.get_layer (db::LayerProperties (3, 0)); + unsigned int l100 = ly.get_layer (db::LayerProperties (100, 0)); + + db::Texts texts2 (db::RecursiveShapeIterator (ly, top_cell, l2), dss); + db::Texts texts3 (db::RecursiveShapeIterator (ly, top_cell, l3), dss); + db::Texts texts100 (db::RecursiveShapeIterator (ly, top_cell, l100), dss); + + EXPECT_EQ (texts100.empty (), true); + EXPECT_EQ (texts2.empty (), false); + EXPECT_EQ (texts2.bbox ().to_string (), "(-520,0;24040,2800)"); + EXPECT_EQ (texts2.size (), size_t (40)); + EXPECT_EQ (texts2.to_string ().substr (0, 42), "('L2',r0 -520,0);('L2',r0 -520,2800);('L2'"); + + db::Layout target; + unsigned int target_top_cell_index = target.add_cell (ly.cell_name (top_cell_index)); + + db::Region polygons; + texts2.polygons (polygons); + target.insert (target_top_cell_index, target.get_layer (db::LayerProperties (10, 0)), polygons); + + polygons.clear (); + texts3.polygons (polygons); + target.insert (target_top_cell_index, target.get_layer (db::LayerProperties (20, 0)), polygons); + + db::Edges edges; + texts2.edges (edges); + target.insert (target_top_cell_index, target.get_layer (db::LayerProperties (11, 0)), edges); + + // NOTE: insert texts2 as layer 14/0 from a copy - this tests the ability to copy-construct an TC + db::Texts texts2_copy (texts2); + texts2_copy.insert_into_as_polygons (&target, target_top_cell_index, target.get_layer (db::LayerProperties (14, 0)), 1); + + CHECKPOINT(); + db::compare_layouts (_this, target, tl::testsrc () + "/testdata/algo/deep_texts_au1.gds"); +} diff --git a/src/db/unit_tests/unit_tests.pro b/src/db/unit_tests/unit_tests.pro index 20e692741..7962b945a 100644 --- a/src/db/unit_tests/unit_tests.pro +++ b/src/db/unit_tests/unit_tests.pro @@ -74,7 +74,8 @@ SOURCES = \ dbBoxTreeTests.cc \ dbBoxScannerTests.cc \ dbBoxTests.cc \ - dbArrayTests.cc + dbArrayTests.cc \ + dbDeepTextsTests.cc INCLUDEPATH += $$TL_INC $$DB_INC $$GSI_INC DEPENDPATH += $$TL_INC $$DB_INC $$GSI_INC diff --git a/testdata/algo/deep_texts_au1.gds b/testdata/algo/deep_texts_au1.gds new file mode 100644 index 0000000000000000000000000000000000000000..ed1dcab44d6c52186e2a22f74f20f40ec3dc3709 GIT binary patch literal 848 zcmZQzV_;&6V31*CVt>NG%D}@Q%Amrajm&1?U}E#}bYfr-VP>^+>@@d2w)}&o%MSeo zv!g;7WLRhA33BucW?*39U|?Y5Wn$oBVB=$AU|`S@VE+IAe>)I^Ks!)`5lDB! zXs{?$o`FRWp!{ z2R}2A1cnRPHyt1*Pz#ub=wfHU8$KLtY@U8$Mhq-m3=CXCu(09*nf9*$WE#X2?6O=R zu*kAWF*YzT08IdTXaWus(A2=pA>dYETn2gix%&g%1auFF5X9wRo51!U+=?Q{6@cOj u6giOvxaH(N;Fi;Lz%6Ht>T4AHY#-p(=V5?bE~o*wT+9W8954h~SQr2>6r8^R literal 0 HcmV?d00001 diff --git a/testdata/algo/deep_texts_l1.gds b/testdata/algo/deep_texts_l1.gds new file mode 100644 index 0000000000000000000000000000000000000000..fbde83f92de493199bf7c060380afe36937d9df4 GIT binary patch literal 2894 zcma)-K}Zx~6vyAr?tU}7u4ZP2AyHCLU>0eHNTRlti?W8hNiBjNy97ZJ5fwrSmIOha ztb+vE!CMdrdWwkf)G;W+L)Sp)&8m>V^s|7wT2I9FM>ZkioLQHrALes>ycv@>phB{N@05VwnDR}X)l5mj;|^9@c69b z_?odU*5Tt)>{aoV|M|C85&tpHdKJ3+h<#Kjc4i=dpB}M)IO`zmP^+v^?4CZQYZZ6n zt0P=7Yfl{i%hXuUB-{SG&LoN-)=}LGLlvwr`ylVEQ{j%?ec9jdYf@y7T1w^eW9XbT zQMy6;)#?`&_nlnq2HzRyw1~do zLQG<3mnIq>r%1xoR9GEx>TRggIFl$fg>!u=6gx9Qzm8a)x_XJ%x(|e6k9P+2(g(;N z@&2Iq6ca7M_wlz-?94DdPIRBM4zdpMYlUKu)^qof1QUMTiddq5ux#^*lK`nqpg zFBCia$mw~s70>LXr$?@>IKO+Ei7^m!NGNtNM2~ZOgH7i(P0auDL*(O9>}o!sH@*0% z?IWDeil+Smb$o#DF2!D1iPA$e#Cqg@k@X(MPD9c9)RNYx-)g;3?5U+_eNB(nXU=N9 zQ0z55S|6B*G5xmVsfqgFZI{ajyf8B`Hyy9-X<#+0k*h@%h~J>Q%t5@XM|1hhBk;sD zvl{eNbfy@x_`Soz!;OX$S(dqED@vq*R zdmm&vJM*l19+W@ndBFUid9XPMzdqat&_t{f=7CV`s!yN28{aoih$fD+UXyi`%UaJA zdzC(LpEh5>Zw~Q6a|ZYEnMbj!xj=lMp6Gf9>ov_8U(o(KtD~G7aXzMSfQ}XZg^+2UpDLd;eI6& F^bf!QOOF5m literal 0 HcmV?d00001