← Back to team overview

kicad-developers team mailing list archive

[PATCH]/Question TITLE_BLOCK tests

 

Hi,

Here's a patch that adds some really basic tests of TITLE_BLOCK
(hopefully leading onto some more interesting changes to do with
avoiding the triple-compilation of the page settings dialog).

However, it did need some finagling to get it working, and I'd like to
ask about why some of it might be.

I can see when it has to specifically compile eda_text.cpp (units,
right?). However, why do I need to compile colours.cpp and
observable.cpp? Why don't they come with the libcommon linkage?

Also it adds a mock KIFACE_I, which seems to be needed to appease
linkage of things that need Kiface().

${INC_AFTER} is used for config.h, is that right?

Cheers,

John
From c6433cddefe70ae0250a3fc84b085e168585c8f0 Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@xxxxxxxxx>
Date: Fri, 5 Oct 2018 17:17:54 +0100
Subject: [PATCH 1/4] QA: Add TITLE_BLOCK tests

Add some unit tests on TITLE_BLOCK

This commit also requires some mocks so the libcommon stuff
can work:

* Needs a Kiface() function to be linkable
* Needs some stuff from common to be build specially
* Needs to define itself as one of the unit-having programs
  to appease the units defines.
---
 qa/common/CMakeLists.txt       | 14 ++++++
 qa/common/common_mocks.cpp     | 29 +++++++++++
 qa/common/test_title_block.cpp | 89 ++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 qa/common/test_title_block.cpp

diff --git a/qa/common/CMakeLists.txt b/qa/common/CMakeLists.txt
index e6c163296..f0b175295 100644
--- a/qa/common/CMakeLists.txt
+++ b/qa/common/CMakeLists.txt
@@ -32,7 +32,15 @@ add_executable( qa_common
     # The main test entry points
     test_module.cpp
 
+    # stuff from common due to...units?
+    ../../common/eda_text.cpp
+
+    # stuff from common which is needed...why?
+    ../../common/colors.cpp
+    ../../common/observable.cpp
+
     test_hotkey_store.cpp
+    test_title_block.cpp
     test_utf8.cpp
 
     geometry/test_fillet.cpp
@@ -43,6 +51,7 @@ include_directories(
     ${CMAKE_SOURCE_DIR}/include
     ${CMAKE_SOURCE_DIR}/polygon
     ${Boost_INCLUDE_DIR}
+    ${INC_AFTER}
 )
 
 target_link_libraries( qa_common
@@ -53,6 +62,11 @@ target_link_libraries( qa_common
     ${wxWidgets_LIBRARIES}
 )
 
+# we need to pretend to be something to appease the units code
+target_compile_definitions( qa_common
+    PRIVATE GERBVIEW
+)
+
 add_test( NAME common
     COMMAND qa_common
 )
\ No newline at end of file
diff --git a/qa/common/common_mocks.cpp b/qa/common/common_mocks.cpp
index 9b54ee6ec..1ac749693 100644
--- a/qa/common/common_mocks.cpp
+++ b/qa/common/common_mocks.cpp
@@ -27,6 +27,7 @@
  */
 
 #include <pgm_base.h>
+#include <kiface_i.h>
 
 
 struct PGM_TEST_FRAME : public PGM_BASE
@@ -39,4 +40,32 @@ PGM_BASE& Pgm()
 {
     static PGM_TEST_FRAME program;
     return program;
+}
+
+static struct IFACE : public KIFACE_I
+{
+    bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
+    {
+        return start_common( aCtlBits );
+    }
+
+    wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
+    {
+        return nullptr;
+    }
+
+    void* IfaceOrAddress( int aDataId ) override
+    {
+        return nullptr;
+    }
+
+    IFACE( const char* aDSOname, KIWAY::FACE_T aType ) :
+        KIFACE_I( aDSOname, aType )
+    {}
+
+} kiface( "common_test", KIWAY::KIWAY_FACE_COUNT );
+
+KIFACE_I& Kiface()
+{
+    return kiface;
 }
\ No newline at end of file
diff --git a/qa/common/test_title_block.cpp b/qa/common/test_title_block.cpp
new file mode 100644
index 000000000..112194524
--- /dev/null
+++ b/qa/common/test_title_block.cpp
@@ -0,0 +1,89 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2018 KiCad Developers, see CHANGELOG.TXT for contributors.
+ *
+ * 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, you may find one here:
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ * or you may search the http://www.gnu.org website for the version 2 license,
+ * or you may write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/test_case_template.hpp>
+
+#include <title_block.h>
+
+
+struct TitleBlockFixture
+{
+    TitleBlockFixture()
+    {
+        m_tb.SetTitle( "title" );
+        m_tb.SetDate( "date" );
+        m_tb.SetCompany( "company" );
+
+        // leave revision blank
+        //m_tb.SetRevision( "revision" );
+
+        // set more than one comment to make sure the indexing of comments works
+        m_tb.SetComment1( "comment1" );
+        m_tb.SetComment2( "comment2" );
+        m_tb.SetComment3( "comment3" );
+        m_tb.SetComment4( "comment4" );
+    }
+
+    TITLE_BLOCK m_tb;
+};
+
+
+/**
+ * Declares a struct as the Boost test fixture.
+ */
+BOOST_FIXTURE_TEST_SUITE( TitleBlock, TitleBlockFixture )
+
+/**
+ * Check basic setting and getting of values
+ */
+BOOST_AUTO_TEST_CASE( SimpleAccess )
+{
+    BOOST_CHECK_EQUAL( "title", m_tb.GetTitle() );
+    BOOST_CHECK_EQUAL( "date", m_tb.GetDate() );
+    BOOST_CHECK_EQUAL( "company", m_tb.GetCompany() );
+
+    // This one is blank
+    BOOST_CHECK_EQUAL( "", m_tb.GetRevision() );
+
+    BOOST_CHECK_EQUAL( "comment1", m_tb.GetComment1() );
+    BOOST_CHECK_EQUAL( "comment2", m_tb.GetComment2() );
+    BOOST_CHECK_EQUAL( "comment3", m_tb.GetComment3() );
+    BOOST_CHECK_EQUAL( "comment4", m_tb.GetComment4() );
+}
+
+/*
+ * Check copy construction
+ */
+BOOST_AUTO_TEST_CASE( Copy )
+{
+    TITLE_BLOCK tb_cpy = m_tb;
+
+    // Check that values came through
+    BOOST_CHECK_EQUAL( "title", tb_cpy.GetTitle() );
+    BOOST_CHECK_EQUAL( "comment1", tb_cpy.GetComment1() );
+    BOOST_CHECK_EQUAL( "comment2", tb_cpy.GetComment2() );
+}
+
+
+BOOST_AUTO_TEST_SUITE_END()
-- 
2.19.0


Follow ups