diff --git a/src/lay/SaltManagerDialog.ui b/src/lay/SaltManagerDialog.ui new file mode 100644 index 000000000..0a97e8cda --- /dev/null +++ b/src/lay/SaltManagerDialog.ui @@ -0,0 +1,351 @@ + + + SaltManagerDialog + + + + 0 + 0 + 692 + 440 + + + + Manage Packages + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::NoFocus + + + ... + + + + :/import.png:/import.png + + + true + + + + + + + Qt::Horizontal + + + + 50 + 20 + + + + + + + + Qt::NoFocus + + + ... + + + + :/add.png:/add.png + + + true + + + + + + + Qt::NoFocus + + + ... + + + + :/clear.png:/clear.png + + + true + + + + + + + Qt::NoFocus + + + ... + + + + :/new_folder.png:/new_folder.png + + + true + + + + + + + Qt::NoFocus + + + ... + + + + :/rename.png:/rename.png + + + true + + + + + + + + + + + 0 + 0 + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + + 1 + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + <html><body><center>No packages are installed currently.<br><br>You can use:<br> +</center> +<table> + <tr><td width="30"><a href=":import"><img src=":/import.png"></a></td><td>to import a package from an external source</td></tr> + <tr><td><a href=":add"><img src=":/add.png"></a></td><td>to create a new package</td></tr> +</table> +</body></html> + + + Qt::AlignHCenter|Qt::AlignTop + + + true + + + + + + + + + + + + + + + + 1 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 75 + true + + + + Package Details + + + + + + + + + + + + + + + :/new_folder.png:/new_folder.png + + + New Folder + + + + + + :/add.png:/add.png + + + New + + + New Package + + + + + + :/clear.png:/clear.png + + + Delete + + + Delete Package + + + + + + :/rename.png:/rename.png + + + Rename + + + Rename Package + + + + + + :/import.png:/import.png + + + Import + + + Import Package + + + + + treeWidget + toolButton_4 + toolButton_2 + toolButton_3 + toolButton + toolButton_5 + textBrowser + + + + + + diff --git a/src/lay/gsiDeclLayMainWindow.cc b/src/lay/gsiDeclLayMainWindow.cc index a64fad18d..77c8eb45e 100644 --- a/src/lay/gsiDeclLayMainWindow.cc +++ b/src/lay/gsiDeclLayMainWindow.cc @@ -539,6 +539,10 @@ Class decl_MainWindow (QT_EXTERNAL_BASE (QMainWindow) "MainWind "@brief 'cm_technologies' action (bound to a menu)" "\nThis method has been added in version 0.22." ) + + gsi::method ("cm_packages", &lay::MainWindow::cm_packages, + "@brief 'cm_packages' action (bound to a menu)" + "\nThis method has been added in version 0.25." + ) + gsi::method ("cm_open_too", &lay::MainWindow::cm_open_too, "@brief 'cm_open_too' action (bound to a menu)" ) + diff --git a/src/lay/lay.pro b/src/lay/lay.pro index c1451e9b8..7efeae835 100644 --- a/src/lay/lay.pro +++ b/src/lay/lay.pro @@ -45,7 +45,11 @@ HEADERS = \ layTextProgress.h \ layVersion.h \ layCommon.h \ - layConfig.h + layConfig.h \ + laySalt.h \ + laySaltGrain.h \ + laySaltGrains.h \ + laySaltManagerDialog.h FORMS = \ ClipDialog.ui \ @@ -90,7 +94,8 @@ FORMS = \ XORToolDialog.ui \ TechLoadOptionsEditorPage.ui \ TechSaveOptionsEditorPage.ui \ - MainConfigPage7.ui + MainConfigPage7.ui \ + SaltManagerDialog.ui SOURCES = \ gsiDeclLayApplication.cc \ @@ -134,6 +139,10 @@ SOURCES = \ layTechSetupDialog.cc \ layTextProgress.cc \ layVersion.cc \ + laySalt.cc \ + laySaltGrain.cc \ + laySaltGrains.cc \ + laySaltManagerDialog.cc RESOURCES = layBuildInMacros.qrc \ layHelpResources.qrc \ diff --git a/src/lay/layMainWindow.cc b/src/lay/layMainWindow.cc index 809e90fd5..70acd1544 100644 --- a/src/lay/layMainWindow.cc +++ b/src/lay/layMainWindow.cc @@ -87,8 +87,8 @@ #include "layLogViewerDialog.h" #include "layLayerToolbox.h" #include "laySettingsForm.h" -#include "laySettingsForm.h" #include "layTechSetupDialog.h" +#include "laySaltManagerDialog.h" #include "layTipDialog.h" #include "laySelectCellViewForm.h" #include "layLayoutPropertiesForm.h" @@ -950,6 +950,7 @@ MainWindow::init_menu () }; MenuLayoutEntry tools_menu [] = { + MenuLayoutEntry ("packages", tl::to_string (QObject::tr ("Manage Packages")), SLOT (cm_packages ())), MenuLayoutEntry ("technologies", tl::to_string (QObject::tr ("Manage Technologies")), SLOT (cm_technologies ())), MenuLayoutEntry::separator ("verification_group"), MenuLayoutEntry ("drc", tl::to_string (QObject::tr ("DRC")), drc_menu), @@ -4699,6 +4700,13 @@ MainWindow::eventFilter (QObject *obj, QEvent *event) } } +void +MainWindow::cm_packages () +{ + lay::SaltManagerDialog dialog (this); + dialog.exec (); +} + void MainWindow::cm_technologies () { diff --git a/src/lay/layMainWindow.h b/src/lay/layMainWindow.h index 96331cc95..ebcd8d4ba 100644 --- a/src/lay/layMainWindow.h +++ b/src/lay/layMainWindow.h @@ -734,6 +734,7 @@ public slots: void cm_macro_editor (); void cm_new_drc_script (); void cm_edit_drc_scripts (); + void cm_packages (); void cm_technologies (); void cm_open_too (); void cm_open_new_view (); diff --git a/src/lay/laySalt.cc b/src/lay/laySalt.cc new file mode 100644 index 000000000..897fc0457 --- /dev/null +++ b/src/lay/laySalt.cc @@ -0,0 +1,31 @@ + +/* + + 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 "laySalt.h" + +namespace lay +{ + + + + +} diff --git a/src/lay/laySalt.h b/src/lay/laySalt.h new file mode 100644 index 000000000..b4bf3aa2a --- /dev/null +++ b/src/lay/laySalt.h @@ -0,0 +1,34 @@ + +/* + + 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 + +*/ + +#ifndef HDR_laySalt +#define HDR_laySalt + +namespace lay +{ + + + + +} + +#endif diff --git a/src/lay/laySaltGrain.cc b/src/lay/laySaltGrain.cc new file mode 100644 index 000000000..feac7ab16 --- /dev/null +++ b/src/lay/laySaltGrain.cc @@ -0,0 +1,183 @@ + +/* + + 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 "laySaltGrain.h" +#include "tlString.h" +#include "tlXMLParser.h" + +#include +#include + +namespace lay +{ + +static const std::string grain_filename = "grain.xml"; + +SaltGrain::SaltGrain () +{ + // .. nothing yet .. +} + +bool +SaltGrain::operator== (const SaltGrain &other) const +{ + return m_name == other.m_name && + m_version == other.m_version && + m_path == other.m_path && + m_url == other.m_url && + m_title == other.m_title && + m_doc == other.m_doc && + m_dependencies == other.m_dependencies; +} + +void +SaltGrain::set_name (const std::string &n) +{ + m_name = n; +} + +void +SaltGrain::set_version (const std::string &v) +{ + m_version = v; +} + +void +SaltGrain::set_path (const std::string &p) +{ + m_path = p; +} + +void +SaltGrain::set_url (const std::string &u) +{ + m_url = u; +} + +void +SaltGrain::set_title (const std::string &t) +{ + m_title = t; +} + +void +SaltGrain::set_doc (const std::string &t) +{ + m_doc = t; +} + +int +SaltGrain::compare_versions (const std::string &v1, const std::string &v2) +{ + tl::Extractor ex1 (v1.c_str ()); + tl::Extractor ex2 (v2.c_str ()); + + while (true) { + + if (ex1.at_end () && ex2.at_end ()) { + return 0; + } + + int n1 = 0, n2 = 0; + if (! ex1.at_end ()) { + ex1.try_read (n1); + } + if (! ex2.at_end ()) { + ex2.try_read (n2); + } + + if (n1 != n2) { + return n1 < n2 ? -1 : 1; + } + + while (! ex1.at_end ()) { + char c = *ex1; + ++ex1; + if (c == '.') { + break; + } + } + + while (! ex2.at_end ()) { + char c = *ex2; + ++ex2; + if (c == '.') { + break; + } + } + + } +} + +static tl::XMLStruct xml_struct ("salt-grain", + tl::make_member (&SaltGrain::name, &SaltGrain::set_name, "name") + + tl::make_member (&SaltGrain::version, &SaltGrain::set_version, "version") + + tl::make_member (&SaltGrain::title, &SaltGrain::set_title, "title") + + tl::make_member (&SaltGrain::doc, &SaltGrain::set_doc, "doc") + + tl::make_member (&SaltGrain::url, &SaltGrain::set_url, "url") + + tl::make_element (&SaltGrain::begin_dependencies, &SaltGrain::end_dependencies, &SaltGrain::add_dependency, "depends", + tl::make_member (&SaltGrain::Dependency::name, "name") + + tl::make_member (&SaltGrain::Dependency::url, "url") + + tl::make_member (&SaltGrain::Dependency::version, "version") + ) +); + +void +SaltGrain::load (const std::string &p) +{ + tl::XMLFileSource source (p); + xml_struct.parse (source, *this); +} + +void +SaltGrain::save () const +{ + save (tl::to_string (QDir (tl::to_qstring (path ())).filePath (tl::to_qstring (grain_filename)))); +} + +void +SaltGrain::save (const std::string &p) const +{ + tl::OutputStream os (p, tl::OutputStream::OM_Plain); + xml_struct.write (os, *this); +} + +SaltGrain +SaltGrain::from_path (const std::string &path) +{ + QDir dir (tl::to_qstring (path)); + + SaltGrain g; + g.load (tl::to_string (dir.filePath (tl::to_qstring (grain_filename)))); + g.set_path (tl::to_string (dir.absolutePath ())); + return g; +} + +bool +SaltGrain::is_grain (const std::string &path) +{ + QDir dir (tl::to_qstring (path)); + QString gf = dir.filePath (tl::to_qstring (grain_filename)); + return QFileInfo (gf).exists (); +} + +} diff --git a/src/lay/laySaltGrain.h b/src/lay/laySaltGrain.h new file mode 100644 index 000000000..644521750 --- /dev/null +++ b/src/lay/laySaltGrain.h @@ -0,0 +1,264 @@ + +/* + + 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 + +*/ + +#ifndef HDR_laySaltGrain +#define HDR_laySaltGrain + +#include "layCommon.h" +#include "tlObject.h" + +namespace lay +{ + +/** + * @brief This class represents on grain of salt + * "One grain of salt" is one package. + */ +class LAY_PUBLIC SaltGrain + : public tl::Object +{ +public: + /** + * @brief A descriptor for one dependency + * A dependency can be specified either through a name (see name property) + * or a download URL. If download URL are specified, they have precedence + * over names. + * The version is the minimum required version. If empty, any version is + * allowed to resolve this dependency. + */ + struct Dependency + { + std::string name; + std::string url; + std::string version; + + bool operator== (const Dependency &other) const + { + return name == other.name && url == other.url && version == other.version; + } + }; + + /** + * @brief Constructor + */ + SaltGrain (); + + /** + * @brief Equality + */ + bool operator== (const SaltGrain &other) const; + + /** + * @brief Inequality + */ + bool operator!= (const SaltGrain &other) const + { + return !operator== (other); + } + + /** + * @brief Gets the name of the grain + * + * The name is either a plain name (a word) or a path into a collection. + * Name paths are formed using the "/" separator. "mypackage" is a plain name, + * while "mycollection/mypackage" is a package within a collection. Collections + * can be used to group packages. Names are case sensitive in general, but + * names differing only in case should be avoided. + */ + const std::string &name () const + { + return m_name; + } + + /** + * @brief Sets the name of the grain + */ + void set_name (const std::string &p); + + /** + * @brief Gets the title of the grain + * + * The title is a brief description that is shown in the title of the + * package manager. + */ + const std::string &title () const + { + return m_title; + } + + /** + * @brief Sets the title of the grain + */ + void set_title (const std::string &t); + + /** + * @brief Gets the documentation text of the grain + * + * The documentation text is an XML document using + * KLayout's doc format. + */ + const std::string &doc () const + { + return m_doc; + } + + /** + * @brief Sets the documentation text of the grain + */ + void set_doc (const std::string &t); + + /** + * @brief Gets the version of the grain + * + * A version string is of the form "x.y..." where x, y and other version + * components are integer numbers. + */ + const std::string &version () const + { + return m_version; + } + + /** + * @brief Sets the version of the grain + */ + void set_version (const std::string &v); + + /** + * @brief Gets the absolute file path of the installed grain + * This is the file path to the grain folder. + */ + const std::string &path () const + { + return m_path; + } + + /** + * @brief Sets the absolute file path of the installed grain + */ + void set_path (const std::string &p); + + /** + * @brief Gets the download URL + * The download URL is the place from which the grain was installed originally. + */ + const std::string &url () const + { + return m_url; + } + + /** + * @brief Sets the download URL + */ + void set_url (const std::string &u); + + /** + * @brief Gets the dependencies of the grain + * Grains this grain depends on are installed automatically when the grain + * is installed. + */ + const std::vector &dependencies () const + { + return m_dependencies; + } + + /** + * @brief Gets the dependencies of the grain (non-const) + */ + std::vector &dependencies () + { + return m_dependencies; + } + + /** + * @brief Dependency iterator (begin) + */ + std::vector::const_iterator begin_dependencies () const + { + return m_dependencies.begin (); + } + + /** + * @brief Dependency iterator (end) + */ + std::vector::const_iterator end_dependencies () const + { + return m_dependencies.end (); + } + + /** + * @brief Adds a dependency + */ + void add_dependency (const Dependency &dep) + { + m_dependencies.push_back (dep); + } + + /** + * @brief Loads the data from a given file + * This method will *not* set the path. + */ + void load (const std::string &file_path); + + /** + * @brief Saves the data to the path inside the grain folder given by the "path" property + */ + void save () const; + + /** + * @brief Saves the data to the given file + */ + void save (const std::string &file_path) const; + + /** + * @brief Compares two version strings + * Returns -1 if v1 < v2, 0 if v1 == v2 and 1 if v1 > v2. + * Malformed versions are read gracefully. Letters and non-digits are skipped. + * Missing numbers are read as 0. Hence "1.0 == 1" for example. + */ + static int compare_versions (const std::string &v1, const std::string &v2); + + /** + * @brief Detects a grain from the given directory + * This method will return a grain constructed from the given directory. + * The data is read from "path/grain.xml". This method will throw an + * exception if an error occurs during reading. + */ + static SaltGrain from_path (const std::string &path); + + /** + * @brief Returns a value indicating whether the given path represents is a grain + */ + static bool is_grain (const std::string &path); + +private: + std::string m_name; + std::string m_version; + std::string m_path; + std::string m_url; + std::string m_title; + std::string m_doc; + std::vector m_dependencies; +}; + +} + +#endif diff --git a/src/lay/laySaltGrains.cc b/src/lay/laySaltGrains.cc new file mode 100644 index 000000000..8134e3178 --- /dev/null +++ b/src/lay/laySaltGrains.cc @@ -0,0 +1,31 @@ + +/* + + 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 "laySaltGrains.h" + +namespace lay +{ + + + + +} diff --git a/src/lay/laySaltGrains.h b/src/lay/laySaltGrains.h new file mode 100644 index 000000000..74b60b38b --- /dev/null +++ b/src/lay/laySaltGrains.h @@ -0,0 +1,34 @@ + +/* + + 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 + +*/ + +#ifndef HDR_laySaltGrains +#define HDR_laySaltGrains + +namespace lay +{ + + + + +} + +#endif diff --git a/src/lay/laySaltManagerDialog.cc b/src/lay/laySaltManagerDialog.cc new file mode 100644 index 000000000..f63a236cc --- /dev/null +++ b/src/lay/laySaltManagerDialog.cc @@ -0,0 +1,36 @@ + +/* + + 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 "laySaltManagerDialog.h" + +namespace lay +{ + +SaltManagerDialog::SaltManagerDialog (QWidget *parent) + : QDialog (parent) +{ + Ui::SaltManagerDialog::setupUi (this); + + // ... +} + +} diff --git a/src/lay/laySaltManagerDialog.h b/src/lay/laySaltManagerDialog.h new file mode 100644 index 000000000..42e59a993 --- /dev/null +++ b/src/lay/laySaltManagerDialog.h @@ -0,0 +1,49 @@ + +/* + + 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 + +*/ + +#ifndef HDR_laySaltManager +#define HDR_laySaltManager + +#include + +#include "ui_SaltManagerDialog.h" + +namespace lay +{ + +/** + * @brief The dialog for managing the Salt ("Packages") + */ +class SaltManagerDialog + : public QDialog, private Ui::SaltManagerDialog +{ +public: + /** + * @brief Constructor + */ + SaltManagerDialog (QWidget *parent); + +}; + +} + +#endif diff --git a/src/unit_tests/laySaltGrain.cc b/src/unit_tests/laySaltGrain.cc new file mode 100644 index 000000000..516a02698 --- /dev/null +++ b/src/unit_tests/laySaltGrain.cc @@ -0,0 +1,99 @@ + +/* + + 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 "laySaltGrain.h" +#include "utHead.h" + +TEST (1) +{ + lay::SaltGrain g; + + g.set_name ("abc"); + EXPECT_EQ (g.name (), "abc"); + g.set_url ("xyz"); + EXPECT_EQ (g.url (), "xyz"); + g.set_version ("1.0"); + EXPECT_EQ (g.version (), "1.0"); + g.set_path ("a/b"); + EXPECT_EQ (g.path (), "a/b"); + g.set_title ("title"); + EXPECT_EQ (g.title (), "title"); + g.set_doc ("doc"); + EXPECT_EQ (g.doc (), "doc"); + + g.add_dependency (lay::SaltGrain::Dependency ()); + g.dependencies ().back ().name = "depname"; + g.dependencies ().back ().url = "depurl"; + g.dependencies ().back ().version = "0.0"; + EXPECT_EQ (int (g.dependencies ().size ()), 1); + + lay::SaltGrain gg; + EXPECT_EQ (g == gg, false); + EXPECT_EQ (g == g, true); + EXPECT_EQ (g != gg, true); + EXPECT_EQ (g != g, false); + + gg = g; + EXPECT_EQ (g == gg, true); + + gg.set_doc ("blabla"); + EXPECT_EQ (g == gg, false); + + std::string tmp = tmp_file (); + + EXPECT_EQ (g == gg, false); + g.save (tmp); + + EXPECT_EQ (g == gg, false); + + gg = lay::SaltGrain (); + gg.load (tmp); + gg.set_path (g.path ()); // path is not set by load(file) + EXPECT_EQ (int (gg.dependencies ().size ()), 1); + EXPECT_EQ (g == gg, true); +} + +TEST (2) +{ + EXPECT_EQ (lay::SaltGrain::compare_versions ("", ""), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1", "2"), -1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1", ""), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1", "1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("2", "1"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0", "2.0"), -1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0", "1.0"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.1", "1.0"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0.1", "1.0.0"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0.1", "1.0"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0.1", "1"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.0.0", "1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1a", "1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.a.1", "1.0.1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.1a", "1.1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.1a", "1.0"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.1a.1", "1.0"), 1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("1.1a.1", "1.1.1"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("990", "991"), -1); + EXPECT_EQ (lay::SaltGrain::compare_versions ("990", "990"), 0); + EXPECT_EQ (lay::SaltGrain::compare_versions ("991", "990"), 1); +} diff --git a/src/unit_tests/unit_tests.pro b/src/unit_tests/unit_tests.pro index c889a89e2..aba6c9daf 100644 --- a/src/unit_tests/unit_tests.pro +++ b/src/unit_tests/unit_tests.pro @@ -95,7 +95,8 @@ SOURCES = \ tlVariant.cc \ tlXMLParser.cc \ gsiTest.cc \ - tlFileSystemWatcher.cc + tlFileSystemWatcher.cc \ + laySaltGrain.cc # main components: SOURCES += \