Finished refactoring of unit tests. Now they are modularized.

This commit is contained in:
Matthias Koefferlein
2017-08-27 08:33:02 +02:00
parent 34089ca96b
commit 56ca1899b5
977 changed files with 1323 additions and 1180 deletions
@@ -0,0 +1,417 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "utHead.h"
#include "layAnnotationShapes.h"
#include "dbBox.h"
#include "dbEdge.h"
#include "dbUserObject.h"
#include "dbBoxConvert.h"
template <class Sh>
class shape_as_user_object
: public db::DUserObjectBase
{
public:
shape_as_user_object<Sh> (const Sh &sh)
: m_shape (sh)
{ }
virtual bool equals (const db::DUserObjectBase *d) const
{
return m_shape == (dynamic_cast<const shape_as_user_object<Sh> *> (d))->m_shape;
}
virtual bool less (const db::DUserObjectBase *d) const
{
return m_shape < (dynamic_cast<const shape_as_user_object<Sh> *> (d))->m_shape;
}
virtual unsigned int class_id () const
{
return (unsigned int) (size_t) &tag_func;
}
virtual db::DUserObjectBase *clone () const
{
return new shape_as_user_object<Sh> (m_shape);
}
virtual db::DBox box () const
{
db::box_convert<Sh> bc;
return db::DBox (bc (m_shape));
}
virtual void transform (const db::simple_trans<db::DCoord> &t)
{
m_shape.transform (db::simple_trans<typename Sh::coord_type> (t));
}
virtual void transform (const db::DFTrans &t)
{
m_shape.transform (t);
}
virtual void transform (const db::complex_trans<db::DCoord, db::DCoord> &)
{
tl_assert (false);
}
const Sh &shape () const { return m_shape; }
size_t mem_used () const { return 0; }
size_t mem_reqd () const { return 0; }
private:
Sh m_shape;
static void tag_func () { }
};
template <class Sh>
db::DUserObject us (const Sh &sh)
{
return db::DUserObject (new shape_as_user_object<Sh> (sh));
}
TEST(1)
{
db::Manager m;
lay::AnnotationShapes s (&m);
db::DBox b_empty;
s.update_bbox ();
EXPECT_EQ (s.bbox (), b_empty);
db::DBox b (0, 100, 1000, 1200);
s.insert (us (b));
s.update_bbox ();
EXPECT_EQ (s.bbox (), b);
db::DEdge e (-100, -200, 0, 0);
s.insert (us (e));
s.update_bbox ();
EXPECT_EQ (s.bbox (), db::DBox (-100, -200, 1000, 1200));
lay::AnnotationShapes s2 (s);
s2.update_bbox ();
EXPECT_EQ (s2.bbox (), db::DBox (-100, -200, 1000, 1200));
s2.erase (s2.begin ());
s2.update_bbox ();
EXPECT_EQ (s2.bbox (), db::DBox (-100, -200, 0, 0));
}
std::string shapes_to_string (const lay::AnnotationShapes &shapes)
{
std::string r;
for (lay::AnnotationShapes::iterator shape = shapes.begin (); shape != shapes.end (); ++shape) {
if (dynamic_cast<const shape_as_user_object<db::DPolygon> *> (shape->ptr ())) {
db::DPolygon p (dynamic_cast<const shape_as_user_object<db::DPolygon> *> (shape->ptr ())->shape ());
r += "polygon " + p.to_string ();
} else if (dynamic_cast<const shape_as_user_object<db::DPath> *> (shape->ptr ())) {
db::DPath p (dynamic_cast<const shape_as_user_object<db::DPath> *> (shape->ptr ())->shape ());
r += "path " + p.to_string ();
} else if (dynamic_cast<const shape_as_user_object<db::DText> *> (shape->ptr ())) {
db::DText p (dynamic_cast<const shape_as_user_object<db::DText> *> (shape->ptr ())->shape ());
r += "text " + p.to_string ();
} else if (dynamic_cast<const shape_as_user_object<db::DBox> *> (shape->ptr ())) {
db::DBox p (dynamic_cast<const shape_as_user_object<db::DBox> *> (shape->ptr ())->shape ());
r += "box " + p.to_string ();
} else {
r += "*unknown type*";
}
r += "\n";
}
return r;
}
void read_testdata (lay::AnnotationShapes &shapes, unsigned int what = 0xff)
{
if ((what & 0x1) != 0) {
static db::DPolygon p1 (db::DBox (0, 100, 1000, 2000));
static db::DPolygon p2 (db::DBox (100, 200, 1100, 2100));
static db::DPolygon p3 (db::DBox (150, 150, 1150, 2050));
shapes.insert (us (p1));
shapes.insert (us (p2));
shapes.insert (us (p3));
}
if ((what & 0x4) != 0) {
static db::DPath r1;
static db::DPath r2;
static db::DPath r3;
db::DPoint pts1 [] = { db::DPoint (0, 100), db::DPoint (0, 500), db::DPoint (200, 700) };
db::DPoint pts2 [] = { db::DPoint (0, 1100), db::DPoint (0, 1500), db::DPoint (200, 1300) };
db::DPoint pts3 [] = { db::DPoint (0, 2100), db::DPoint (0, 2500), db::DPoint (-200, 2700) };
r1 = db::DPath (pts1, pts1 + 3, 100);
r2 = db::DPath (pts2, pts2 + 3, 150);
r3 = db::DPath (pts3, pts3 + 3, 200);
shapes.insert (us (r1));
shapes.insert (us (r2));
shapes.insert (us (r3));
}
if ((what & 0x8) != 0) {
static db::DText t1 ("A", db::DTrans (0, db::DVector (10, 35)));
static db::DText t2 ("B", db::DTrans (1, db::DVector (20, 25)));
static db::DText t3 ("C", db::DTrans (6, db::DVector (30, 15)));
shapes.insert (us (t1));
shapes.insert (us (t2));
shapes.insert (us (t3));
}
if ((what & 0x10) != 0) {
static db::DBox b1 (0, 100, 2000, 1000);
static db::DBox b2 (100, 200, 2100, 1100);
static db::DBox b3 (150, 150, 2150, 1050);
shapes.insert (us (b1));
shapes.insert (us (b2));
shapes.insert (us (b3));
}
}
TEST(2)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x1);
lay::AnnotationShapes copy (&m);
EXPECT_EQ (shapes_to_string (shapes),
"polygon (0,100;0,2000;1000,2000;1000,100)\n"
"polygon (100,200;100,2100;1100,2100;1100,200)\n"
"polygon (150,150;150,2050;1150,2050;1150,150)\n"
);
copy.clear ();
for (lay::AnnotationShapes::iterator shape = shapes.begin (); shape != shapes.end (); ++shape) {
copy.insert (*shape);
}
EXPECT_EQ (shapes_to_string (copy),
"polygon (0,100;0,2000;1000,2000;1000,100)\n"
"polygon (100,200;100,2100;1100,2100;1100,200)\n"
"polygon (150,150;150,2050;1150,2050;1150,150)\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes),
"polygon (100,200;100,2100;1100,2100;1100,200)\n"
"polygon (150,150;150,2050;1150,2050;1150,150)\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes),
"polygon (150,150;150,2050;1150,2050;1150,150)\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes), "");
}
TEST(3)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x4);
lay::AnnotationShapes copy (&m);
EXPECT_EQ (shapes_to_string (shapes),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
copy.clear ();
for (lay::AnnotationShapes::iterator shape = shapes.begin (); shape != shapes.end (); ++shape) {
copy.insert (*shape);
}
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes),
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes),
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
shapes.erase (shapes.begin ());
EXPECT_EQ (shapes_to_string (shapes), "");
}
TEST(4)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x4);
lay::AnnotationShapes copy (&m);
EXPECT_EQ (shapes_to_string (shapes),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
copy.clear ();
for (lay::AnnotationShapes::iterator shape = shapes.begin (); shape != shapes.end (); ++shape) {
m.transaction ("x");
copy.insert (*shape);
m.commit ();
}
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string (copy), "");
m.redo ();
m.redo ();
m.redo ();
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
}
TEST(5)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x4);
lay::AnnotationShapes copy (&m);
EXPECT_EQ (shapes_to_string (shapes),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
copy.clear ();
m.transaction ("x");
copy = shapes;
m.commit ();
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
m.undo ();
EXPECT_EQ (shapes_to_string (copy), "");
m.redo ();
EXPECT_EQ (shapes_to_string (copy),
"path (0,100;0,500;200,700) w=100 bx=0 ex=0 r=false\n"
"path (0,1100;0,1500;200,1300) w=150 bx=0 ex=0 r=false\n"
"path (0,2100;0,2500;-200,2700) w=200 bx=0 ex=0 r=false\n"
);
}
TEST(6)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x10);
EXPECT_EQ (shapes_to_string (shapes),
"box (0,100;2000,1000)\n"
"box (100,200;2100,1100)\n"
"box (150,150;2150,1050)\n"
);
shapes.update ();
lay::AnnotationShapes copy (&m);
copy.clear ();
for (lay::AnnotationShapes::touching_iterator shape = shapes.begin_touching (db::DBox (0, 100, 100, 200)); ! shape.at_end (); ++shape) {
copy.insert (*shape);
}
EXPECT_EQ (shapes_to_string (copy),
"box (0,100;2000,1000)\n"
"box (100,200;2100,1100)\n"
);
}
TEST(7)
{
db::Manager m;
lay::AnnotationShapes shapes (&m);
read_testdata (shapes, 0x10);
EXPECT_EQ (shapes_to_string (shapes),
"box (0,100;2000,1000)\n"
"box (100,200;2100,1100)\n"
"box (150,150;2150,1050)\n"
);
lay::AnnotationShapes copy (&m);
shapes.update ();
copy.clear ();
for (lay::AnnotationShapes::overlapping_iterator shape = shapes.begin_overlapping (db::DBox (0, 100, 100, 200)); ! shape.at_end (); ++shape) {
copy.insert (*shape);
}
EXPECT_EQ (shapes_to_string (copy),
"box (0,100;2000,1000)\n"
);
}
+205
View File
@@ -0,0 +1,205 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "layBitmap.h"
#include "utHead.h"
static std::string
to_string (const lay::Bitmap &bm)
{
std::string r;
for (unsigned int j = bm.height (); j > 0; --j) {
std::string s;
for (unsigned int k = 0; k < bm.width (); ++k) {
s += (bm.scanline (j - 1)[k / 32] & (1 << (k % 32))) != 0 ? "#" : "-";
}
r += s;
r += "\n";
}
return r;
}
TEST(1)
{
lay::Bitmap b1 (8, 8, 1.0);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n");
b1.fill (4, 3, 6);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"---###--\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n");
lay::Bitmap b2;
b2 = b1;
EXPECT_EQ (to_string (b1), to_string (b2));
b1 = lay::Bitmap ();
EXPECT_EQ (to_string (b1), "");
b1 = b2;
EXPECT_EQ (to_string (b1), to_string (b2));
}
TEST(2)
{
lay::Bitmap b1 (8, 8, 1.0);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n");
lay::Bitmap b2 (3, 2, 1.0);
b2.fill (0, 0, 3);
b2.fill (1, 1, 3);
EXPECT_EQ (to_string (b2), "-##\n###\n");
b1.merge (&b2, 0, 0);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"-##-----\n"
"###-----\n");
b1.merge (&b2, 1, 1);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--##----\n"
"-###----\n"
"###-----\n");
b1.clear ();
b1.merge (&b2, -1, -1);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"--------\n"
"##------\n");
b1.clear ();
b1.merge (&b2, 6, 2);
EXPECT_EQ (to_string (b1), "--------\n"
"--------\n"
"--------\n"
"--------\n"
"-------#\n"
"------##\n"
"--------\n"
"--------\n");
b1 = lay::Bitmap (40, 8, 1.0);
EXPECT_EQ (to_string (b1), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n");
b2 = lay::Bitmap (40, 8, 1.0);
b2.fill (1, 4, 36);
b2.fill (2, 5, 15);
b2.fill (2, 34, 35);
EXPECT_EQ (to_string (b2), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"-----##########-------------------#-----\n"
"----################################----\n"
"----------------------------------------\n");
b1.merge (&b2, -1, -1);
EXPECT_EQ (to_string (b1), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----##########-------------------#------\n"
"---################################-----\n");
b1.clear ();
b1.merge (&b2, -32, -1);
EXPECT_EQ (to_string (b1), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"--#-------------------------------------\n"
"####------------------------------------\n");
b1.clear ();
b1.merge (&b2, -33, -1);
EXPECT_EQ (to_string (b1), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"-#--------------------------------------\n"
"###-------------------------------------\n");
b1.clear ();
b1.merge (&b2, 1, -1);
EXPECT_EQ (to_string (b1), "----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"----------------------------------------\n"
"------##########-------------------#----\n"
"-----################################---\n");
}
@@ -0,0 +1,943 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "layBitmapsToImage.h"
#include "layBitmap.h"
#include "layDitherPattern.h"
#include "layLineStyles.h"
#include <QImage>
#include <QColor>
#include <QMutex>
#include <utHead.h>
std::string
to_string (const QImage &img, unsigned int mask)
{
std::string s;
for (unsigned int i = 0; i < 32; ++i) {
const unsigned int *data = (const unsigned int *)img.scanLine (i);
for (unsigned int j = 0; j < 32; ++j) {
s += (data[j] & mask) ? "x" : ".";
}
s += "\n";
}
return s;
}
TEST(1)
{
lay::Bitmap b1 (32, 32, 1.0);
lay::Bitmap b2 (32, 32, 1.0);
lay::Bitmap b3 (32, 32, 1.0);
lay::Bitmap b4 (32, 32, 1.0);
lay::Bitmap b5 (32, 32, 1.0);
lay::Bitmap b6 (32, 32, 1.0);
lay::Bitmap b7 (32, 32, 1.0);
lay::Bitmap b8 (32, 32, 1.0);
std::vector<lay::Bitmap *> pbitmaps;
pbitmaps.push_back (&b1);
pbitmaps.push_back (&b2);
pbitmaps.push_back (&b3);
pbitmaps.push_back (&b4);
pbitmaps.push_back (&b5);
pbitmaps.push_back (&b6);
pbitmaps.push_back (&b7);
pbitmaps.push_back (&b8);
b1.scanline (4)[0] |= 0xf0000000;
b2.scanline (4)[0] |= 0x3c000000;
b2.scanline (3)[0] |= 0x000000f0;
b3.scanline (3)[0] |= 0x00000ff0;
b4.scanline (5)[0] |= 0x00000ff0;
b4.scanline (16)[0] |= 0x00400ff0;
b5.scanline (6)[0] |= 0x10000000;
b6.scanline (5)[0] |= 0x10000000;
b6.scanline (6)[0] |= 0x20000000;
b6.scanline (18)[0] |= 0x20400000;
b7.scanline (22)[0] |= 0x00080000;
b8.scanline (23)[0] |= 0x00040000;
std::vector<lay::ViewOp> view_ops;
view_ops.push_back (lay::ViewOp (0x800000, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 1));
view_ops.push_back (lay::ViewOp (0xc00000, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 1));
view_ops.push_back (lay::ViewOp (0xe00000, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 2));
view_ops.push_back (lay::ViewOp (0xf00000, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Cross, 5));
view_ops.push_back (lay::ViewOp (0x008000, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 1));
view_ops.push_back (lay::ViewOp (0x00c000, lay::ViewOp::Or, 0, 0, 0, lay::ViewOp::Cross, 3));
view_ops.push_back (lay::ViewOp (0x000080, lay::ViewOp::Copy, 0, 0, 0, lay::ViewOp::Rect, 1));
view_ops.push_back (lay::ViewOp (0x0000c0, lay::ViewOp::Or, 0, 0, 0, lay::ViewOp::Rect, 3));
QImage img (QSize (32, 32), QImage::Format_RGB32);
img.fill (0);
lay::DitherPattern dp;
lay::LineStyles ls;
QMutex m;
lay::bitmaps_to_image (view_ops, pbitmaps, dp, ls, &img, 32, 32, 0, &m);
EXPECT_EQ (to_string (img, 0x800000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"..xxxxxxxxxxxx......xxxxx.......\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxx....................\n"
"..xxxxxxxxxxxx..................\n"
"....xxxxxxxx..............xxxxxx\n"
"....xxxxxxxxx...................\n"
"....xxxxxxxxx...................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x400000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"..xxxxxxxxxxxx......xxxxx.......\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxx....................\n"
"..xxxxxxxxxxxx..................\n"
"....xxxxxxxx..............xxxx..\n"
"....xxxxxxxxx...................\n"
"....xxxxxxxxx...................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x200000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"..xxxxxxxxxxxx......xxxxx.......\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxx....................\n"
"..xxxxxxxxxxxx..................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxxx...................\n"
"....xxxxxxxxx...................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x100000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"..xxxxxxxxxxxx......xxxxx.......\n"
"....xxxxxxxx..........x.........\n"
"....xxxxxxxx..........x.........\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxx....................\n"
"..xxxxxxxxxxxx..................\n"
"....xxxxxxxx....................\n"
"....xxxxxxxx....................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x080000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x040000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x020000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x010000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x008000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"......................x......x..\n"
".....................xxx....xxx.\n"
"......................x......x..\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
".............................x..\n"
"............................xxx.\n"
"...........................xxx..\n"
"............................x...\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x004000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"......................x......x..\n"
".....................xxx....xxx.\n"
"......................x......x..\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
".............................x..\n"
"............................xxx.\n"
"...........................xxx..\n"
"............................x...\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x002000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x001000),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000800),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000400),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000200),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000100),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000080),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
".................xxx............\n"
".................xxx............\n"
".................xxx............\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000040),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
".................xxx............\n"
".................xxx............\n"
".................xxx............\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000020),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000010),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000008),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000004),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000002),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
EXPECT_EQ (to_string (img, 0x000001),
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
"................................\n"
);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,604 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "layParsedLayerSource.h"
#include "dbLayout.h"
#include "dbCell.h"
#include "utHead.h"
TEST (1)
{
lay::ParsedLayerSource ps1 (1, 2, -1);
EXPECT_EQ (ps1.to_string (), "1/2@*");
lay::ParsedLayerSource ps2 (5, 0, 0);
EXPECT_EQ (ps2.to_string (), "5/0@1");
EXPECT_EQ (ps2.has_name (), false);
lay::ParsedLayerSource ps3 ("aname", 1);
EXPECT_EQ (ps3.to_string (), "aname@2");
EXPECT_EQ (ps3.has_name (), true);
lay::ParsedLayerSource ps4 ("bname", -1);
EXPECT_EQ (ps4.to_string (), "bname@*");
EXPECT_EQ (ps1 < ps2, true);
EXPECT_EQ (ps2 < ps2, false);
EXPECT_EQ (ps2 < ps1, false);
EXPECT_EQ (ps2 < ps3, true);
EXPECT_EQ (ps3 < ps4, false);
EXPECT_EQ (ps4 < ps3, true);
EXPECT_EQ (ps1 == ps2, false);
EXPECT_EQ (ps2 == ps3, false);
EXPECT_EQ (ps3 == ps4, false);
EXPECT_EQ (ps4 == lay::ParsedLayerSource ("x", -1), false);
EXPECT_EQ (ps4 == lay::ParsedLayerSource ("bname", -1), true);
EXPECT_EQ (ps3 == lay::ParsedLayerSource ("aname", 1), true);
EXPECT_EQ (ps2 == lay::ParsedLayerSource (5, 0, 0), true);
EXPECT_EQ (ps4 != lay::ParsedLayerSource ("x", -1), true);
EXPECT_EQ (ps4 != lay::ParsedLayerSource ("bname", -1), false);
EXPECT_EQ (ps1 == lay::ParsedLayerSource (ps1.to_string ()), true);
EXPECT_EQ (ps2 == lay::ParsedLayerSource (ps2.to_string ()), true);
EXPECT_EQ (ps3 == lay::ParsedLayerSource (ps3.to_string ()), true);
EXPECT_EQ (ps4 == lay::ParsedLayerSource (ps4.to_string ()), true);
ps1 = ps2;
lay::ParsedLayerSource psc = ps2;
EXPECT_EQ (ps1 == ps2, true);
EXPECT_EQ (ps2 == psc, true);
EXPECT_EQ (lay::ParsedLayerSource ("4/0@*") == lay::ParsedLayerSource (4, 0, -1), true);
}
TEST (2)
{
lay::ParsedLayerSource ps1 ("@2");
EXPECT_EQ (ps1.to_string (), "*/*@2");
lay::ParsedLayerSource ps2 ("5");
EXPECT_EQ (ps2.to_string (), "5/0@1");
lay::ParsedLayerSource ps3 ("/5");
EXPECT_EQ (ps3.to_string (), "*/5@1");
lay::ParsedLayerSource ps4 ("name@5");
EXPECT_EQ (ps4.to_string (), "name@5");
lay::ParsedLayerSource ps5 ("name");
EXPECT_EQ (ps5.to_string (), "name@1");
lay::ParsedLayerSource ps6 ("%5");
EXPECT_EQ (ps6.to_string (), "%5@1");
lay::ParsedLayerSource ps7 ("1/5%4@7");
EXPECT_EQ (ps7.to_string (), "%4@7");
}
TEST (3)
{
lay::ParsedLayerSource ps1 ("@2");
ps1 += lay::ParsedLayerSource ("1");
EXPECT_EQ (ps1.to_string (), "1/0@2");
lay::ParsedLayerSource ps2 ("@2");
ps2 += lay::ParsedLayerSource ("@3");
EXPECT_EQ (ps2.to_string (), "*/*@2");
lay::ParsedLayerSource ps3 ("1/5@*");
ps3 += lay::ParsedLayerSource ("@3");
EXPECT_EQ (ps3.to_string (), "1/5@3");
lay::ParsedLayerSource ps4 ("namea");
EXPECT_EQ (ps4.has_name (), true);
ps4 += lay::ParsedLayerSource ("nameb");
EXPECT_EQ (ps4.has_name (), true);
EXPECT_EQ (ps4.to_string (), "namea@1");
lay::ParsedLayerSource ps5 ("namea@5");
ps5 += lay::ParsedLayerSource ("1/*");
EXPECT_EQ (ps5.to_string (), "namea 1/*@5");
lay::ParsedLayerSource ps6 ("1/5@4");
EXPECT_EQ (ps6.has_name (), false);
ps6 += lay::ParsedLayerSource ("nameb");
EXPECT_EQ (ps6.has_name (), true);
EXPECT_EQ (ps6.to_string (), "nameb 1/5@4");
lay::ParsedLayerSource ps7 ("*/5");
EXPECT_EQ (ps7.has_name (), false);
ps7 += lay::ParsedLayerSource ("2/7");
EXPECT_EQ (ps7.has_name (), false);
EXPECT_EQ (ps7.to_string (), "2/5@1");
lay::ParsedLayerSource ps8 ("1/*@1");
ps8 += lay::ParsedLayerSource ("*/8@2");
EXPECT_EQ (ps8.to_string (), "1/8@1");
lay::ParsedLayerSource ps9;
EXPECT_EQ (ps9.to_string (), "*/*@*");
EXPECT_EQ (ps9.has_name (), false);
ps9.layer (2);
EXPECT_EQ (ps9.to_string (), "2/*@*");
EXPECT_EQ (ps9.has_name (), false);
ps9.datatype (3);
EXPECT_EQ (ps9.to_string (), "2/3@*");
EXPECT_EQ (ps9.has_name (), false);
ps9.name ("abc");
EXPECT_EQ (ps9.to_string (), "abc 2/3@*");
EXPECT_EQ (ps9.has_name (), true);
ps9.name (std::string ());
EXPECT_EQ (ps9.to_string (), "2/3@*");
EXPECT_EQ (ps9.has_name (), false);
}
TEST (4)
{
lay::ParsedLayerSource ps1 ("@2");
EXPECT_EQ (ps1.to_string (), "*/*@2");
lay::ParsedLayerSource ps2 ("@2 (*0.5 -1.0,17.1 m45)");
EXPECT_EQ (ps2.to_string (), "*/*@2 (m45 *0.5 -1,17.1)");
}
TEST (5)
{
lay::ParsedLayerSource ps0 ("@2");
lay::ParsedLayerSource ps1 ("@2 [ X == #2 ]");
EXPECT_EQ (ps1.to_string (), "*/*@2 ['X'==#2]");
lay::ParsedLayerSource ps2 ("[X==#2||X==Y&&Z!=##4] @2");
EXPECT_EQ (ps2.to_string (), "*/*@2 [('X'==#2||'X'=='Y')&&'Z'!=##4]");
lay::ParsedLayerSource ps2a ("[!(X==#2||X==Y&&Z!=##4)] @2");
EXPECT_EQ (ps2a.to_string (), "*/*@2 [!(('X'==#2||'X'=='Y')&&'Z'!=##4)]");
lay::ParsedLayerSource ps2b ("[(X!=#2&&X!=Y)||Z==##4] @2");
EXPECT_EQ (ps2b.to_string (), "*/*@2 [('X'!=#2&&'X'!='Y')||'Z'==##4]");
lay::ParsedLayerSource ps3 ("[!(X==#2||(X==Y&&Y==X)&&!Z!=##4)] @2");
EXPECT_EQ (ps3.to_string (), "*/*@2 [!(('X'==#2||('X'=='Y'&&'Y'=='X'))&&!('Z'!=##4))]");
lay::ParsedLayerSource ps4 ("@2 [X==#2||X==#3||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4.to_string (), "*/*@2 ['X'==#2||'X'==#3||'X'==#20||'X'==#120||'X'==#210||'X'==#5||'X'==#15||'X'==#11||'X'==#17||'X'==#18]");
EXPECT_EQ (ps4.display_string (0), "@2 ['X'==#2||'X'==#3||'X'==#20||'X'==#120||...]");
lay::ParsedLayerSource ps4a;
ps4a = ps4;
EXPECT_EQ (ps4a.to_string (), ps4.to_string ());
EXPECT_EQ (ps4a == ps4, true);
lay::ParsedLayerSource ps4b (ps4);
EXPECT_EQ (ps4b.to_string (), ps4.to_string ());
lay::ParsedLayerSource ps4c ("@2 [X==#3||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4c == ps4, false);
EXPECT_EQ (ps4c < ps4, true);
EXPECT_EQ (ps4 < ps4c, false);
lay::ParsedLayerSource ps4d ("@2 [X==#2||X==#4||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4d == ps4, false);
EXPECT_EQ (ps4d < ps4, false);
EXPECT_EQ (ps4 < ps4d, true);
lay::ParsedLayerSource ps4e ("@2 [X==##2||X==#3||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4e == ps4, true);
EXPECT_EQ (ps4e < ps4, false);
EXPECT_EQ (ps4 < ps4e, false);
lay::ParsedLayerSource ps4f ("@2 [X==#222||X==#3||X==#4||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4f == ps4, false);
EXPECT_EQ (ps4f < ps4, false);
EXPECT_EQ (ps4 < ps4f, true);
lay::ParsedLayerSource ps4g ("@2 [X!=#2||X==#3||X==#20||X==#120||X==#210||X==#5||X==#15||X==#11||X==#17||X==#18]");
EXPECT_EQ (ps4g == ps4, false);
EXPECT_EQ (ps4g < ps4, false);
EXPECT_EQ (ps4 < ps4g, true);
db::PropertiesRepository::properties_set ps;
db::PropertiesRepository rep;
std::set<db::properties_id_type> ids;
bool inv;
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (2l)));
db::properties_id_type id1 = rep.properties_id (ps);
EXPECT_EQ (ps1.property_selector ().check (rep, id1), true);
EXPECT_EQ (ps0.property_selector ().check (rep, id1), true);
ids.clear ();
inv = ps1.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (1));
EXPECT_EQ (*ids.begin (), id1);
ids.clear ();
inv = ps0.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (0));
ps.clear ();
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (3l)));
db::properties_id_type id2 = rep.properties_id (ps);
EXPECT_EQ (ps1.property_selector ().check (rep, id2), false);
EXPECT_EQ (ps0.property_selector ().check (rep, id2), true);
ids.clear ();
inv = ps1.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (1));
EXPECT_EQ (*ids.begin () == id2, false);
EXPECT_EQ (*ids.begin (), id1);
ids.clear ();
inv = ps0.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (0));
ps.clear ();
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (2l)));
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("Z")), tl::Variant (4.0)));
db::properties_id_type id3 = rep.properties_id (ps);
EXPECT_EQ (ps2.property_selector ().check (rep, id3), false);
EXPECT_EQ (ps0.property_selector ().check (rep, id3), true);
ids.clear ();
inv = ps2.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (1));
EXPECT_EQ (*ids.begin () == id3, false);
EXPECT_EQ (*ids.begin (), id1);
ids.clear ();
inv = ps0.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (0));
ps.clear ();
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (2l)));
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("Z")), tl::Variant (6l)));
db::properties_id_type id4 = rep.properties_id (ps);
EXPECT_EQ (ps2.property_selector ().check (rep, id4), true);
ids.clear ();
inv = ps2.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (2));
EXPECT_EQ (*ids.begin (), id1);
EXPECT_EQ (*(++ids.begin ()), id4);
ps.clear ();
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (2l)));
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("Z")), tl::Variant (5.0)));
db::properties_id_type id5 = rep.properties_id (ps);
EXPECT_EQ (ps2.property_selector ().check (rep, id5), true);
ids.clear ();
inv = ps2.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (3));
EXPECT_EQ (*ids.begin (), id1);
EXPECT_EQ (*(++ids.begin ()), id4);
EXPECT_EQ (*(++(++ids.begin ())), id5);
EXPECT_EQ (ps2a.property_selector ().check (rep, id5), false);
ids.clear ();
inv = ps2a.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (3));
EXPECT_EQ (*ids.begin (), id1);
EXPECT_EQ (*(++ids.begin ()), id4);
EXPECT_EQ (*(++(++ids.begin ())), id5);
EXPECT_EQ (ps2b.property_selector ().check (rep, id5), false);
ids.clear ();
inv = ps2b.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (3));
EXPECT_EQ (*ids.begin (), id1);
EXPECT_EQ (*(++ids.begin ()), id4);
EXPECT_EQ (*(++(++ids.begin ())), id5);
ps.clear ();
db::properties_id_type id6 = rep.properties_id (ps);
EXPECT_EQ (ps2.property_selector ().check (rep, id6), false);
ids.clear ();
inv = ps2.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (3));
EXPECT_EQ (*ids.begin (), id1);
EXPECT_EQ (*(++ids.begin ()), id4);
EXPECT_EQ (*(++(++ids.begin ())), id5);
EXPECT_EQ (ps0.property_selector ().check (rep, id6), true);
ids.clear ();
inv = ps0.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, true);
EXPECT_EQ (ids.size (), size_t (0));
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("Z")), tl::Variant (5l)));
db::properties_id_type id7 = rep.properties_id (ps);
EXPECT_EQ (ps4.property_selector ().check (rep, id7), false);
ids.clear ();
inv = ps4.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (5));
EXPECT_EQ (ids.find (id7) == ids.end (), true);
ps.insert (std::make_pair (rep.prop_name_id (tl::Variant ("X")), tl::Variant (15l)));
db::properties_id_type id8 = rep.properties_id (ps);
EXPECT_EQ (ps4.property_selector ().check (rep, id8), true);
ids.clear ();
inv = ps4.property_selector ().matching (rep, ids);
EXPECT_EQ (inv, false);
EXPECT_EQ (ids.size (), size_t (6));
EXPECT_EQ (ids.find (id8) != ids.end (), true);
}
TEST (6)
{
lay::ParsedLayerSource ps1;
ps1 = lay::ParsedLayerSource ("");
EXPECT_EQ (ps1.to_string (), "*/*@1");
ps1 = lay::ParsedLayerSource ("#1");
EXPECT_EQ (ps1.to_string (), "*/*@1 #0..1");
ps1 = lay::ParsedLayerSource ("#1..4");
EXPECT_EQ (ps1.to_string (), "*/*@1 #1..4");
EXPECT_EQ (ps1 == lay::ParsedLayerSource ("#1..4"), true);
EXPECT_EQ (ps1 != lay::ParsedLayerSource ("#1..4"), false);
EXPECT_EQ (ps1 == lay::ParsedLayerSource ("#1..5"), false);
EXPECT_EQ (ps1 != lay::ParsedLayerSource ("#1..5"), true);
ps1 = lay::ParsedLayerSource ("#1..2");
EXPECT_EQ (ps1.to_string (), "*/*@1 #1..2");
ps1 = lay::ParsedLayerSource (" # .. 2");
EXPECT_EQ (ps1.to_string (), "*/*@1 #..2");
ps1 = lay::ParsedLayerSource (" # 1 .. ");
EXPECT_EQ (ps1.to_string (), "*/*@1 #1..");
ps1 = lay::ParsedLayerSource ();
ps1 += lay::ParsedLayerSource ("#..20");
EXPECT_EQ (ps1.to_string (), "*/*@1 #..20");
ps1 += lay::ParsedLayerSource ("#10..11");
EXPECT_EQ (ps1.to_string (), "*/*@1 #10..20");
ps1 = lay::ParsedLayerSource ();
ps1 += lay::ParsedLayerSource ("#5..");
EXPECT_EQ (ps1.to_string (), "*/*@1 #5..");
ps1 += lay::ParsedLayerSource ("#10..11");
EXPECT_EQ (ps1.to_string (), "*/*@1 #5..11");
ps1 = lay::ParsedLayerSource ("#*");
EXPECT_EQ (ps1.to_string (), "*/*@1 #0..*");
ps1 = lay::ParsedLayerSource ("#..*");
EXPECT_EQ (ps1.to_string (), "*/*@1 #..*");
ps1 = lay::ParsedLayerSource ("#..(*)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #..*");
ps1 = lay::ParsedLayerSource ("#1..*");
EXPECT_EQ (ps1.to_string (), "*/*@1 #1..*");
ps1 = lay::ParsedLayerSource ("#1..(*)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #1..*");
ps1 = lay::ParsedLayerSource ("#(*)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #(0)..*");
ps1 = lay::ParsedLayerSource ("#(-1)..(5)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #(-1)..(5)");
ps1 = lay::ParsedLayerSource ("#(2)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #(0)..(2)");
ps1 = lay::ParsedLayerSource ("#(2)..3");
EXPECT_EQ (ps1.to_string (), "*/*@1 #(2)..3");
ps1 = lay::ParsedLayerSource ("#2..(3)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #2..(3)");
ps1 = lay::ParsedLayerSource ("#>2..(<3)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #>2..(<3)");
ps1 = lay::ParsedLayerSource ("#>2..(<*)");
EXPECT_EQ (ps1.to_string (), "*/*@1 #>2..<*");
}
TEST (7)
{
lay::ParsedLayerSource ps1;
ps1 = lay::ParsedLayerSource ("(*2)");
EXPECT_EQ (ps1.to_string (), "*/*@1 (r0 *2 0,0)");
ps1 = lay::ParsedLayerSource ("(*2) (*1.5)");
EXPECT_EQ (ps1.to_string (), "*/*@1 (r0 *2 0,0) (r0 *1.5 0,0)");
lay::ParsedLayerSource ps2 (ps1);
ps1 += lay::ParsedLayerSource ("(*2)");
EXPECT_EQ (ps1.to_string (), "*/*@1 (r0 *4 0,0) (r0 *3 0,0)");
ps1 = ps2;
ps1 += lay::ParsedLayerSource ("(*2) (*3)");
EXPECT_EQ (ps1.to_string (), "*/*@1 (r0 *4 0,0) (r0 *6 0,0) (r0 *3 0,0) (r0 *4.5 0,0)");
}
TEST (8)
{
lay::ParsedLayerSource ps1;
ps1 = lay::ParsedLayerSource ("(*2) {-* +HALLO}");
EXPECT_EQ (ps1.to_string (), "*/*@1 {-* +HALLO} (r0 *2 0,0)");
ps1 = lay::ParsedLayerSource ("{-HALLO} (*2) (*1.5)");
EXPECT_EQ (ps1.to_string (), "*/*@1 {-HALLO} (r0 *2 0,0) (r0 *1.5 0,0)");
}
TEST (10)
{
lay::CellSelector sel;
tl::Extractor ex;
ex = tl::Extractor ("+HALLO * -H*");
sel.parse (ex);
EXPECT_EQ (sel.to_string (), "+HALLO +* -H*");
ex = tl::Extractor ("+HALLO * -H*}ignored");
sel.parse (ex);
EXPECT_EQ (sel.to_string (), "+HALLO +* -H*");
EXPECT_EQ (ex.test ("}"), true);
ex = tl::Extractor ("+HALLO (* -H*)");
sel.parse (ex);
EXPECT_EQ (sel.to_string (), "+HALLO (+* -H*)");
ex = tl::Extractor ("( +HALLO -H* ) ( *HA 'WITH BLANK' )");
sel.parse (ex);
EXPECT_EQ (sel.to_string (), "(+HALLO -H*) (+*HA +'WITH BLANK')");
std::string c = sel.to_string ();
ex = tl::Extractor (c.c_str ());
sel = lay::CellSelector ();
sel.parse (ex);
EXPECT_EQ (sel.to_string (), "(+HALLO -H*) (+*HA +'WITH BLANK')");
lay::CellSelector sel2;
EXPECT_EQ (sel2.to_string (), "");
EXPECT_EQ (sel2.is_empty (), true);
EXPECT_EQ (sel == sel2, false);
EXPECT_EQ (sel != sel2, true);
EXPECT_EQ (sel < sel2, false);
EXPECT_EQ (sel2 < sel, true);
sel2 = sel;
EXPECT_EQ (sel2.to_string (), "(+HALLO -H*) (+*HA +'WITH BLANK')");
EXPECT_EQ (sel2.is_empty (), false);
EXPECT_EQ (sel == sel2, true);
EXPECT_EQ (sel != sel2, false);
EXPECT_EQ (sel < sel2, false);
EXPECT_EQ (sel2 < sel, false);
lay::CellSelector sel2a (sel2);
EXPECT_EQ (sel2a.to_string (), "(+HALLO -H*) (+*HA +'WITH BLANK')");
}
lay::CellSelector selector_from_string (const char *s)
{
tl::Extractor ex (s);
lay::CellSelector sel;
sel.parse (ex);
return sel;
}
std::string tspath (const db::Layout &l, db::cell_index_type c, lay::PartialTreeSelector &pt)
{
std::string r;
if (pt.is_selected ()) {
r += "+";
} else {
r += "-";
}
r += l.cell_name (c);
bool any = false;
for (db::Cell::child_cell_iterator cc = l.cell (c).begin_child_cells (); ! cc.at_end (); ++cc) {
int cs = pt.is_child_selected (*cc);
if (cs) {
if (! any) {
r += "(";
any = true;
}
pt.descend (*cc);
r += tspath (l, *cc, pt);
pt.ascend ();
}
}
if (any) {
r += ")";
}
return r;
}
TEST (11)
{
db::Layout layout;
db::Cell &c1 = layout.cell (layout.add_cell ("C1"));
db::Cell &c2 = layout.cell (layout.add_cell ("C2"));
db::Cell &c3 = layout.cell (layout.add_cell ("C3"));
db::Cell &c4 = layout.cell (layout.add_cell ("C4"));
db::Cell &c5 = layout.cell (layout.add_cell ("C5"));
db::Cell &cc1 = layout.cell (layout.add_cell ("CC1"));
db::Cell &cc2 = layout.cell (layout.add_cell ("CC2"));
db::Cell &cc3 = layout.cell (layout.add_cell ("CC3"));
db::Cell &cc4 = layout.cell (layout.add_cell ("CC4"));
c1.insert (db::CellInstArray (c2.cell_index (), db::Trans ()));
c2.insert (db::CellInstArray (c3.cell_index (), db::Trans ()));
c2.insert (db::CellInstArray (c4.cell_index (), db::Trans ()));
c2.insert (db::CellInstArray (cc2.cell_index (), db::Trans ()));
c4.insert (db::CellInstArray (cc4.cell_index (), db::Trans ()));
c3.insert (db::CellInstArray (cc3.cell_index (), db::Trans ()));
c3.insert (db::CellInstArray (c5.cell_index (), db::Trans ()));
c1.insert (db::CellInstArray (cc1.cell_index (), db::Trans ()));
lay::PartialTreeSelector pt (selector_from_string("").create_tree_selector (layout, c1.cell_index ()));
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+C2(+C3(+C5+CC3)+C4(+CC4)+CC2)+CC1)");
pt = selector_from_string("+C1").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+C2(+C3(+C5+CC3)+C4(+CC4)+CC2)+CC1)");
pt = selector_from_string("-C1").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "-C1");
pt = selector_from_string("-C2").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+CC1)");
pt = selector_from_string("+C1 -C2").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+CC1)");
pt = selector_from_string("+C1 ( -C* +CC* )").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+CC1)");
pt = selector_from_string("-C2 +C3").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(-C2(+C3(+C5+CC3)-C4(-CC4)-CC2)+CC1)");
pt = selector_from_string("-C2 +CC*").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(-C2(-C3(-C5+CC3)-C4(+CC4)+CC2)+CC1)");
pt = selector_from_string("+CC*").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "-C1(-C2(-C3(-C5+CC3)-C4(+CC4)+CC2)+CC1)");
pt = selector_from_string("-* +CC*").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "-C1(-C2(-C3(-C5+CC3)-C4(+CC4)+CC2)+CC1)");
pt = selector_from_string("-* ( -* +CC* )").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "-C1(+CC1)");
pt = selector_from_string("-C3 +CC*").create_tree_selector (layout, c1.cell_index ());
EXPECT_EQ (tspath (layout, c1.cell_index (), pt), "+C1(+C2(-C3(-C5+CC3)+C4(+CC4)+CC2)+CC1)");
}
+276
View File
@@ -0,0 +1,276 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "layRenderer.h"
#include "layBitmapRenderer.h"
#include "layBitmap.h"
#include "utHead.h"
static std::string
to_string (const lay::Bitmap &bm)
{
std::string r;
for (unsigned int j = bm.height (); j > 0; --j) {
std::string s;
for (unsigned int k = 0; k < bm.width (); ++k) {
const char *t = (bm.scanline (j - 1)[k / 32] & (1 << (k % 32))) != 0 ? "#" : "-";
s += t;
}
r += s;
r += "\n";
}
return r;
}
static std::string
to_string (const lay::Bitmap &bm, const lay::Bitmap &bf)
{
std::string r;
for (unsigned int j = bm.height (); j > 0; --j) {
std::string s;
for (unsigned int k = 0; k < bm.width (); ++k) {
const char *t = (bm.scanline (j - 1)[k / 32] & (1 << (k % 32))) != 0 ? "#" : "-";
if ((bf.scanline (j - 1)[k / 32] & (1 << (k % 32))) != 0) {
t = "*";
}
s += t;
}
r += s;
r += "\n";
}
return r;
}
TEST(1)
{
lay::Bitmap b1 (16, 16, 1.0);
lay::BitmapRenderer r (16, 16, 1.0);
r.insert (db::DEdge (3.4, 2.1, 12.7, -2.1));
r.insert (db::DEdge (12.7, -2.1, 3.4, 2.1));
r.insert (db::DEdge (3.4, 2.1, 12.7, 2.1));
r.insert (db::DEdge (12.7, 2.1, 3.4, 2.1));
r.insert (db::DEdge (3.4, 2.1, -12.7, 2.1));
r.insert (db::DEdge (-12.7, 2.1, 3.4, 2.1));
r.insert (db::DEdge (3.4, 2.1, 12.7, 12.1));
r.insert (db::DEdge (12.7, 12.1, 3.4, 2.1));
r.render_vertices (b1, 0);
EXPECT_EQ (to_string (b1), "----------------\n"
"----------------\n"
"----------------\n"
"-------------#--\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"---#---------#--\n"
"----------------\n"
"----------------\n");
}
TEST(2)
{
lay::Bitmap b1 (16, 16, 1.0);
lay::BitmapRenderer r(16, 16, 1.0);
r.clear ();
r.insert (db::DEdge (3.4, 2.1, 12.7, 12.1));
r.insert (db::DEdge (3.4, 0.1, 100.0, 22.5));
r.insert (db::DEdge (3.4, 5.1, 12.7, 5.1));
r.insert (db::DEdge (-3.4, 5.1, 25.7, 30.0));
r.render_contour (b1);
EXPECT_EQ (to_string (b1), "--------#-------\n"
"-------#--------\n"
"------#---------\n"
"-----#-------#--\n"
"---##-------#---\n"
"--#--------#----\n"
"-#--------#-----\n"
"#--------#------\n"
"--------#-------\n"
"-------#--------\n"
"---###########--\n"
"-----#----------\n"
"----#---------##\n"
"---#------####--\n"
"------####------\n"
"---###----------\n");
r.clear ();
r.insert (db::DEdge (12.7, 2.1, 3.4, 12.1));
r.insert (db::DEdge (100.0, 0.1, 3.4, 14.5));
r.insert (db::DEdge (12.7, 5.1, 3.4, 5.1));
r.insert (db::DEdge (15.3, -5.1, -5.1, 5.0));
b1 = lay::Bitmap (16, 16, 1.0);
r.render_contour (b1);
EXPECT_EQ (to_string (b1), "---#------------\n"
"----#######-----\n"
"-----------#####\n"
"---#------------\n"
"----#-----------\n"
"-----#----------\n"
"------#---------\n"
"-------#--------\n"
"--------#-------\n"
"---------#------\n"
"---###########--\n"
"-----------#----\n"
"------------#---\n"
"##-----------#--\n"
"--##------------\n"
"----###---------\n");
}
TEST(3)
{
lay::Bitmap b1 (16, 16, 1.0);
lay::Bitmap b2 (16, 16, 1.0);
lay::BitmapRenderer r(16, 16, 1.0);
r.insert (db::DEdge (3.4, 2.1, 12.7, 14.5));
r.insert (db::DEdge (12.7, 14.5, 10.7, 0.6));
r.insert (db::DEdge (10.7, 0.6, 3.4, 2.1));
r.render_fill (b1);
r.render_contour (b2);
EXPECT_EQ (to_string (b1, b2), "-------------*--\n"
"------------*---\n"
"-----------**---\n"
"-----------**---\n"
"----------*#*---\n"
"---------*##*---\n"
"--------*##*----\n"
"--------*##*----\n"
"-------*###*----\n"
"------*####*----\n"
"-----*#####*----\n"
"-----*#####*----\n"
"----*######*----\n"
"---****####*----\n"
"-------*****----\n"
"----------------\n");
r.clear ();
r.insert (db::DEdge (3.1, 9.0, 12.7, 14.5));
r.insert (db::DEdge (12.7, 14.5, 10.7, 0.6));
r.insert (db::DEdge (10.7, 0.6, 3.1, 9.0));
b1 = lay::Bitmap (16, 16, 1.0);
b2 = lay::Bitmap (16, 16, 1.0);
r.render_fill (b1);
r.render_contour (b2);
EXPECT_EQ (to_string (b1, b2), "-------------*--\n"
"-----------**---\n"
"----------*#*---\n"
"--------**##*---\n"
"------**####*---\n"
"----**######*---\n"
"---*#######*----\n"
"----*######*----\n"
"-----*#####*----\n"
"------*####*----\n"
"-------*###*----\n"
"--------*##*----\n"
"---------*#*----\n"
"---------*#*----\n"
"----------**----\n"
"----------------\n");
r.clear ();
r.insert (db::DEdge (3.0, 9.0, 3.0, 14.0));
r.insert (db::DEdge (3.0, 14.0, 12.0, 14.0));
r.insert (db::DEdge (12.0, 14.0, 12.0, 9.0));
r.insert (db::DEdge (12.0, 9.0, 3.0, 9.0));
b1 = lay::Bitmap (16, 16, 1.0);
b2 = lay::Bitmap (16, 16, 1.0);
r.render_fill (b1);
// r.render_contour (b2);
EXPECT_EQ (to_string (b1, b2), "----------------\n"
"---##########---\n"
"---##########---\n"
"---##########---\n"
"---##########---\n"
"---##########---\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n"
"----------------\n");
r.clear ();
r.insert (db::DEdge (0.2, 9.6, 2.2, 3.8));
r.insert (db::DEdge (2.2, 3.8, 10.7, 6.6));
r.insert (db::DEdge (10.7, 6.6, 7.0, 11.4));
r.insert (db::DEdge (7.0, 11.4, 14.2, 12.5));
r.insert (db::DEdge (14.2, 12.5, 12.3, 4.9));
r.insert (db::DEdge (12.3, 4.9, 5.9, 11.1));
r.insert (db::DEdge (5.9, 11.1, 8.8, 6.0));
r.insert (db::DEdge (8.8, 6.0, 4.2, 2.9));
r.insert (db::DEdge (4.2, 2.9, 12.2, 0.4));
r.insert (db::DEdge (12.2, 0.4, 0.2, 9.6));
b1 = lay::Bitmap (16, 16, 1.0);
b2 = lay::Bitmap (16, 16, 1.0);
r.render_fill (b1);
r.render_contour (b2);
EXPECT_EQ (to_string (b1, b2), "----------------\n"
"----------------\n"
"--------------*-\n"
"--------*******-\n"
"------**#####*--\n"
"*------**####*--\n"
"-*-----***###*--\n"
"-**-----***##*--\n"
"-*#**---*#***---\n"
"--*##*--*****---\n"
"--*##****---*---\n"
"--***-***-------\n"
"----**###*------\n"
"------***#*-----\n"
"---------***----\n"
"------------*---\n");
}
+146
View File
@@ -0,0 +1,146 @@
/*
KLayout Layout Viewer
Copyright (C) 2006-2017 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 "laySnap.h"
#include "layLayoutView.h"
#include "utHead.h"
TEST(1)
{
db::Manager mgr;
lay::LayoutView view (&mgr, is_editable (), 0);
int cv1 = view.create_layout ("", true, false);
db::Layout &ly1 = view.cellview (cv1)->layout ();
db::Cell &top = ly1.cell (ly1.add_cell ("TOP"));
unsigned int l1 = ly1.insert_layer (db::LayerProperties (1, 0));
view.select_cell (0, top.cell_index ());
lay::LayerPropertiesNode lp;
lp.set_source ("1/0@1");
view.insert_layer (view.begin_layers (), lp);
db::Polygon poly;
db::Point pts[] = {
db::Point (0, 0),
db::Point (1000, 0),
db::Point (0, 1000)
};
poly.assign_hull (pts, pts + sizeof (pts) / sizeof (pts[0]));
top.shapes (l1).insert (poly);
view.set_max_hier_levels (1);
std::pair<bool, db::DPoint> res;
// not hit
res = lay::obj_snap (&view, db::DPoint (1.505, 1.505), db::DVector (), 0.1);
EXPECT_EQ (res.first, false);
EXPECT_EQ (res.second.to_string (), "1.505,1.505");
res = lay::obj_snap (&view, db::DPoint (0.505, 0.505), db::DVector (), 0.1);
EXPECT_EQ (res.first, true);
EXPECT_EQ (res.second.to_string (), "0.5,0.5");
res = lay::obj_snap (&view, db::DPoint (0.485, 0.505), db::DVector (0.01, 0.01), 0.1);
EXPECT_EQ (res.first, true);
EXPECT_EQ (res.second.to_string (), "0.49,0.51");
res = lay::obj_snap (&view, db::DPoint (0.205, 0.215), db::DVector (0.01, 0.025), 0.1);
EXPECT_EQ (res.first, false);
EXPECT_EQ (res.second.to_string (), "0.21,0.225");
res = lay::obj_snap (&view, db::DPoint (0.505, 1.005), db::DVector (), 0.1);
EXPECT_EQ (res.first, false);
EXPECT_EQ (res.second.to_string (), "0.505,1.005");
res = lay::obj_snap (&view, db::DPoint (0.005, 1.005), db::DVector (), 0.1);
EXPECT_EQ (res.first, true);
EXPECT_EQ (res.second.to_string (), "0,1");
res = lay::obj_snap (&view, db::DPoint (1.000, 0.505), db::DPoint (0.505, 0.500), db::DVector (), lay::AC_Horizontal, 0.1);
EXPECT_EQ (res.first, true);
EXPECT_EQ (res.second.to_string (), "0.495,0.505");
// projected snapping
res = lay::obj_snap (&view, db::DPoint (1.000, 0.505), db::DPoint (0.005, 1.005), db::DVector (), lay::AC_Horizontal, 0.1);
EXPECT_EQ (res.first, true);
EXPECT_EQ (res.second.to_string (), "0,0.505");
std::pair<bool, db::DEdge> res2;
res2 = lay::obj_snap2 (&view, db::DPoint (1.5, 1.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, false);
EXPECT_EQ (res2.second.to_string (), "(0,0;0,0)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0.3525,0.6475;0,0.295)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (), lay::AC_Horizontal, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0,0.5;0.5,0.5)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (0.03, 0.03), lay::AC_Horizontal, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0,0.51;0.49,0.51)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (), lay::AC_Vertical, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0.205,0.795;0.205,0)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (), lay::AC_Diagonal, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0.3525,0.6475;0,0.295)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.505), db::DVector (), lay::AC_Ortho, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0,0.505;0.495,0.505)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.5), db::DVector (), lay::AC_Any, 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0.3525,0.6475;0,0.295)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.205, 0.495), db::DVector (0.01, 0.01), 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0.355,0.645;0,0.29)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.5, 0.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, false);
EXPECT_EQ (res2.second.to_string (), "(0,0;0,0)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.005, 0.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, true);
EXPECT_EQ (res2.second.to_string (), "(0,0.5;0.5,0.5)");
res2 = lay::obj_snap2 (&view, db::DPoint (0.0, 0.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, false);
EXPECT_EQ (res2.second.to_string (), "(0,0;0,0)");
res2 = lay::obj_snap2 (&view, db::DPoint (-0.2, 0.5), db::DVector (), 0.005, 1.0);
EXPECT_EQ (res2.first, false);
EXPECT_EQ (res2.second.to_string (), "(0,0;0,0)");
}
// .. TODO: implement ..
+22
View File
@@ -0,0 +1,22 @@
DESTDIR_UT = $$OUT_PWD/../..
DESTDIR = $$OUT_PWD/..
TARGET = laybasic_tests
include($$PWD/../../lib_ut.pri)
SOURCES = \
layAnnotationShapes.cc \
layBitmap.cc \
layBitmapsToImage.cc \
layLayerProperties.cc \
layParsedLayerSource.cc \
layRenderer.cc \
laySnap.cc \
INCLUDEPATH += $$TL_INC $$LAYBASIC_INC $$DB_INC $$GSI_INC $$UT_INC
DEPENDPATH += $$TL_INC $$LAYBASIC_INC $$DB_INC $$GSI_INC $$UT_INC
LIBS += -L$$DESTDIR_UT -lklayout_laybasic -lklayout_db -lklayout_tl -lklayout_gsi -lklayout_ut