File indexing completed on 2025-01-26 04:05:04

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 Alvin Wong <alvin@alvinhc.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #include <simpletest.h>
0008 #include <testflake.h>
0009 
0010 #include "MockShapes.h"
0011 
0012 #include <SvgSavingContext.h>
0013 
0014 #include <QBuffer>
0015 
0016 class TestSvgSavingContext : public QObject
0017 {
0018     Q_OBJECT
0019 private Q_SLOTS:
0020     void testCreateUID1();
0021     void testCreateUID2();
0022     void testDuplicatedId1();
0023 };
0024 
0025 void TestSvgSavingContext::testCreateUID1()
0026 {
0027     QBuffer buffer;
0028     buffer.open(QIODevice::Append);
0029     SvgSavingContext context(buffer);
0030 
0031     MockShape shape1;
0032     shape1.setName("shape0");
0033 
0034     MockShape shape2;
0035     shape2.setName("shape2");
0036 
0037     QCOMPARE(context.getID(&shape1), "shape0");
0038     QCOMPARE(context.createUID("shape"), "shape1");
0039     QCOMPARE(context.getID(&shape2), "shape2");
0040     QCOMPARE(context.createUID("shape"), "shape3");
0041 }
0042 
0043 void TestSvgSavingContext::testCreateUID2()
0044 {
0045     QBuffer buffer;
0046     buffer.open(QIODevice::Append);
0047     SvgSavingContext context(buffer);
0048 
0049     MockShape shape1;
0050     shape1.setName("shape0");
0051 
0052     MockShape shape2;
0053     shape2.setName("shape01");
0054 
0055     QCOMPARE(context.getID(&shape1), "shape0");
0056     QCOMPARE(context.getID(&shape2), "shape01");
0057     QCOMPARE(context.createUID("shape"), "shape1");
0058     QCOMPARE(context.createUID("shape0"), "shape02");
0059     QCOMPARE(context.createUID("shape0"), "shape03");
0060 }
0061 
0062 void TestSvgSavingContext::testDuplicatedId1()
0063 {
0064     QBuffer buffer;
0065     buffer.open(QIODevice::Append);
0066     SvgSavingContext context(buffer);
0067 
0068     MockShape shape1;
0069     shape1.setName("shape0");
0070 
0071     MockShape shape2;
0072     shape2.setName("shape0");
0073 
0074     MockShape shape3;
0075     shape3.setName("shape0");
0076 
0077     MockShape shape4;
0078     shape4.setName("shape01");
0079 
0080     QCOMPARE(context.getID(&shape1), "shape0");
0081     QCOMPARE(context.getID(&shape2), "shape01");
0082     QCOMPARE(context.getID(&shape3), "shape02");
0083     QCOMPARE(context.getID(&shape4), "shape011");
0084 }
0085 
0086 KISTEST_MAIN(TestSvgSavingContext)
0087 
0088 #include "TestSvgSavingContext.moc"