Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TestPolyFile

 

TestPolyFile is a tool to test the PolyFile class.

 

 

 

 

 

Downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolTestPolyFile/ToolTestPolyFileConsole.pro

 

include(../../ConsoleApplication.pri)

include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)

#Specific, console
include(../../Classes/CppContainer/CppContainer.pri)
include(../../Classes/CppPolyFile/CppPolyFile.pri)

include(ToolTestPolyFileConsole.pri)

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolTestPolyFile/ToolTestPolyFileDesktop.pro

 

include(../../DesktopApplication.pri)

include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

#Specific for this application
include(../../Classes/CppContainer/CppContainer.pri)
include(../../Classes/CppPolyFile/CppPolyFile.pri)
include(../../Tools/ToolTestPolyFile/ToolTestPolyFileDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

./ToolTestPolyFile/ToolTestPolyFileConsole.pri

 

INCLUDEPATH += \
    ../../Tools/ToolTestPolyFile

SOURCES += \
    ../../Tools/ToolTestPolyFile/testpolyfilemenudialog.cpp

HEADERS += \
    ../../Tools/ToolTestPolyFile/testpolyfilemenudialog.h

OTHER_FILES += \
    ../../Tools/ToolTestPolyFile/Licence.txt

RESOURCES += \
    ../../Tools/ToolTestPolyFile/ToolTestPolyFile.qrc

 

 

 

 

 

./ToolTestPolyFile/ToolTestPolyFileDesktop.pri

 

include(../../Tools/ToolTestPolyFile/ToolTestPolyFileConsole.pri)

FORMS += \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemenudialog.ui \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemaindialog.ui

SOURCES += \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemenudialog.cpp \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemaindialog.cpp

HEADERS += \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemenudialog.h \
    ../../Tools/ToolTestPolyFile/qttestpolyfilemaindialog.h

 

 

 

 

 

./ToolTestPolyFile/ToolTestPolyFileWebsite.pri

 

include(../../Tools/ToolTestPolyFile/ToolTestPolyFileConsole.pri)
SOURCES +=
HEADERS +=

 

 

 

 

 

./ToolTestPolyFile/main.cpp

 

#include "testpolyfilemenudialog.h"

int main(int argc, char* argv[])
{
  const std::vector<std::string> args { ribi::MenuDialog::ConvertArguments(argc,argv) };
  return ribi::TestPolyFileMenuDialog().Execute(args);
}

 

 

 

 

 

./ToolTestPolyFile/qtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2012-2013 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <QApplication>
#include "qttestpolyfilemenudialog.h"
#include "trace.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  START_TRACE();
  ribi::QtTestPolyFileMenuDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./ToolTestPolyFile/qttestpolyfilemaindialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#ifndef QTTESTPOLYFILEMAINDIALOG_H
#define QTTESTPOLYFILEMAINDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qthideandshowdialog.h"
#pragma GCC diagnostic pop

namespace Ui {
  class QtTestPolyFileMainDialog;
}

namespace ribi {

class QtTestPolyFileMainDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtTestPolyFileMainDialog(QWidget *parent = 0);
  QtTestPolyFileMainDialog(const QtTestPolyFileMainDialog&) = delete;
  QtTestPolyFileMainDialog& operator=(const QtTestPolyFileMainDialog&) = delete;
  ~QtTestPolyFileMainDialog() noexcept;

private slots:
  void on_edit_textChanged(const QString &arg1);

private:
  Ui::QtTestPolyFileMainDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

};

} //~namespace ribi

#endif // QTTESTPOLYFILEMAINDIALOG_H

 

 

 

 

 

./ToolTestPolyFile/qttestpolyfilemaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qttestpolyfilemaindialog.h"

#include <fstream>
#include <sstream>

#include <QFileDialog>

#include "fileio.h"
#include "polyfile.h"
#include "testpolyfilemenudialog.h"
#include "testtimer.h"
#include "trace.h"
#include "ui_qttestpolyfilemaindialog.h"
#pragma GCC diagnostic pop

ribi::QtTestPolyFileMainDialog::QtTestPolyFileMainDialog(QWidget *parent) :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtTestPolyFileMainDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  ui->edit->setText("Classes/CppPolyFile/polyfile1.poly");
}

ribi::QtTestPolyFileMainDialog::~QtTestPolyFileMainDialog() noexcept
{
  delete ui;
}

void ribi::QtTestPolyFileMainDialog::on_edit_textChanged(const QString &arg1)
{
  ui->text_result->clear();

  const std::string filename = "../../" + arg1.toStdString();
  if (!fileio::FileIo().IsRegularFile(filename))
  {
    const std::string text = "File '" + filename + "' does not exist.";
    ui->text_result->setPlainText(text.c_str());
    return;
  }


  std::stringstream s;
  try
  {
    PolyFile p(filename);
    s << p;
  }
  catch (std::exception& e)
  {
    s << "Error: " << e.what();
  }
  ui->text_result->setPlainText(s.str().c_str());

}

#ifndef NDEBUG
void ribi::QtTestPolyFileMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

 

 

 

 

 

./ToolTestPolyFile/qttestpolyfilemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#ifndef QTTESTPOLYFILEMENUDIALOG_H
#define QTTESTPOLYFILEMENUDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qthideandshowdialog.h"
#pragma GCC diagnostic pop

namespace Ui {
  class QtTestPolyFileMenuDialog;
}

namespace ribi {

class QtTestPolyFileMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtTestPolyFileMenuDialog(QWidget *parent = 0);
  QtTestPolyFileMenuDialog(const QtTestPolyFileMenuDialog&) = delete;
  QtTestPolyFileMenuDialog& operator=(const QtTestPolyFileMenuDialog&) = delete;
  ~QtTestPolyFileMenuDialog() noexcept;

private slots:
  void on_button_start_clicked();
  void on_button_about_clicked();
  void on_button_quit_clicked();

private:
  Ui::QtTestPolyFileMenuDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // QTTESTPOLYFILEMENUDIALOG_H

 

 

 

 

 

./ToolTestPolyFile/qttestpolyfilemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "qttestpolyfilemenudialog.h"

#include "qtaboutdialog.h"
#include "qttestpolyfilemaindialog.h"
#include "testpolyfilemenudialog.h"
#include "testtimer.h"
#include "trace.h"
#include "ui_qttestpolyfilemenudialog.h"
#pragma GCC diagnostic pop

ribi::QtTestPolyFileMenuDialog::QtTestPolyFileMenuDialog(QWidget *parent) :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtTestPolyFileMenuDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);
}

ribi::QtTestPolyFileMenuDialog::~QtTestPolyFileMenuDialog() noexcept
{
  delete ui;
}

void ribi::QtTestPolyFileMenuDialog::on_button_start_clicked()
{
  QtTestPolyFileMainDialog d;
  this->ShowChild(&d);
}

void ribi::QtTestPolyFileMenuDialog::on_button_about_clicked()
{
  this->hide();
  About a = TestPolyFileMenuDialog().GetAbout();
  //a.AddLibrary("QtRichelBilderbeekGalleryDialog version: " + QtRichelBilderbeekGalleryDialog::GetVersion());
  //a.AddLibrary("QtRichelBilderbeekResources version: " + RichelBilderbeek::QtResources::GetVersion());
  QtAboutDialog d(a);
  this->ShowChild(&d);
}

void ribi::QtTestPolyFileMenuDialog::on_button_quit_clicked()
{
  close();
}

#ifndef NDEBUG
void ribi::QtTestPolyFileMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

 

 

 

 

 

./ToolTestPolyFile/testpolyfilemenudialog.h

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#ifndef TESTPOLYFILEMENUDIALOG_H
#define TESTPOLYFILEMENUDIALOG_H

#include "menudialog.h"

namespace ribi {

struct TestPolyFileMenuDialog final : public MenuDialog
{
  TestPolyFileMenuDialog();
  About GetAbout() const noexcept override;
  Help GetHelp() const noexcept override;
  boost::shared_ptr<const Program> GetProgram() const noexcept override;
  std::string GetVersion() const noexcept override;
  std::vector<std::string> GetVersionHistory() const noexcept override;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept override;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // TESTPOLYFILEMENUDIALOG_H

 

 

 

 

 

./ToolTestPolyFile/testpolyfilemenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestPolyFile, tool to test the PolyFile class
Copyright (C) 2014-2015 Richel Bilderbeek

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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestPolyFile.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include "testpolyfilemenudialog.h"

#include <cassert>
#include <iostream>

#include <QFile>

#include "container.h"
#include "fileio.h"
#include "polyfile.h"
#include "richelbilderbeekprogram.h"
#include "trace.h"
#include "testtimer.h"
#pragma GCC diagnostic pop

ribi::TestPolyFileMenuDialog::TestPolyFileMenuDialog()
{
  #ifndef NDEBUG
  Test();
  #endif
}

int ribi::TestPolyFileMenuDialog::ExecuteSpecific(const std::vector<std::string>& args) noexcept
{
  const int argc = static_cast<int>(args.size());

  bool silent{false};
  if (std::count(args.begin(),args.end(),"-s") || std::count(args.begin(),args.end(),"--silent"))
  {
    silent = true;
  }

  std::stringstream s;
  if (argc >= 3 && (args[1] == "-f" || args[1] == "--filename"))
  {
    const std::string filename = args[2];
    if (filename.empty())
    {
      s << "Please specify a filename.\n";
    }
    else if (filename.size() < 5)
    {
      s << "Please specify a full poly (.poly) filename.\n";
    }
    else if (filename.substr(filename.size() - 5,5) != ".poly")
    {
      s << "Please specify a filename ending on .poly.\n";
    }
    else if (!fileio::FileIo().IsRegularFile(filename))
    {
      s << "Please specify a poly (.poly) filename that exists.\n";
    }
    else
    {
      PolyFile p(filename);
      s << p << '\n';
      if (!silent) { std::cout << s.str(); }
      return 0;
    }
    if (!silent) { std::cout << s.str(); }
    return 1;
  }
  if (!silent) { std::cout << GetHelp() << '\n'; }
  return 1;
}

ribi::About ribi::TestPolyFileMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "TestPolyFile",
    "tool to test the PolyFile class",
    "the 2nd of June 2014",
    "2014-2015",
    "http://www.richelbilderbeek.nl/ToolTestPolyFile.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("Container version: " + Container().GetVersion());
  a.AddLibrary("ribi::fileio::FileIo version: " + fileio::FileIo().GetVersion());
  a.AddLibrary("PolyFile version: " + PolyFile::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());

  return a;
}

ribi::Help ribi::TestPolyFileMenuDialog::GetHelp() const noexcept
{
  return Help(
    GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {
      Help::Option('f',"filename","filename of the poly (.poly) file"),
      Help::Option('s',"silent","produce no output")
    },
    {
      GetAbout().GetFileTitle() + " -f somefile.poly",
      GetAbout().GetFileTitle() + " --filename somefile.poly"
    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::TestPolyFileMenuDialog::GetProgram() const noexcept
{
  const boost::shared_ptr<const Program> p {
    new ProgramTestPolyFile
  };
  assert(p);
  return p;
}

std::string ribi::TestPolyFileMenuDialog::GetVersion() const noexcept
{
  return "1.1";
}

std::vector<std::string> ribi::TestPolyFileMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2014-06-02: version 1.0: initial version"
    "2014-08-08: version 1.1: added silent flag to console version"
  };
}

#ifndef NDEBUG
void ribi::TestPolyFileMenuDialog::Test() noexcept
{
  //Test exactly once
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  {
    Container();
    fileio::FileIo();
    PolyFile( {}, {} );
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  //Load a .poly file
  {
    const std::string filename = fileio::FileIo().GetTempFileName(".poly");
    {
      const std::string qtfilename = ":/polyfile/polyfile1.poly";
      QFile qfile(qtfilename.c_str());
      assert(qfile.size() > 0);
      qfile.copy(filename.c_str());
    }
    assert(fileio::FileIo().IsRegularFile(filename));
    TestPolyFileMenuDialog d;
    d.ExecuteSpecific(
      {
        "TestPolyFile", "-f", filename, "--silent"
      }
    );
    fileio::FileIo().DeleteFile(filename);
  }
}
#endif

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml