From a2a24843d69c5bd5b1735bdd618dc604cfac138c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 23 Feb 2022 07:34:41 +0100 Subject: [PATCH] Use GammaLib version in GApplication unit tests to get correct version number if statistics file. --- src/support/GTools.cpp | 18 +++++++++--------- test/test_GApplication.cpp | 19 ++++++++++--------- test/test_GApplication.py | 8 ++++---- test/test_GSupport.cpp | 16 +++++++++------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/src/support/GTools.cpp b/src/support/GTools.cpp index 061ec64..88ea103 100644 --- a/src/support/GTools.cpp +++ b/src/support/GTools.cpp @@ -1032,13 +1032,13 @@ std::string gammalib::fill(const std::string& s, const int& n) /***********************************************************************//** * @brief Left justify string to achieve a length of n characters * - * @param[in] s String to be centred. + * @param[in] s String to be left justified. * @param[in] n Requested total width. * @param[in] c Fill character. * @return Left justified string. * - * Left justify string by adding whitespace to the right to achieve a length - * of n characters. + * Left justify string by adding @p c to the right to achieve a length of + * @p n characters. ***************************************************************************/ std::string gammalib::left(const std::string& s, const int& n, const char& c) { @@ -1056,13 +1056,13 @@ std::string gammalib::left(const std::string& s, const int& n, const char& c) /***********************************************************************//** * @brief Right justify string to achieve a length of n characters * - * @param[in] s String to be centred. + * @param[in] s String to be right justified. * @param[in] n Requested total width. * @param[in] c Fill character. * @return Right justified string. * - * Right justify string by adding whitespace to the left to achieve a length - * of n characters. + * Right justify string by adding @p c to the left to achieve a length of + * @p n characters. ***************************************************************************/ std::string gammalib::right(const std::string& s, const int& n, const char& c) { @@ -1082,11 +1082,11 @@ std::string gammalib::right(const std::string& s, const int& n, const char& c) * * @param[in] s String to be centred. * @param[in] n Requested total width. - * @param[in] c Left fill character. + * @param[in] c Fill character. * @return Centred string. * - * Centre string by adding whitespace to the left and the right to achieve a - * length of n characters. + * Centre string by adding @p c to the left and the right to achieve a length + * of @p n characters. ***************************************************************************/ std::string gammalib::centre(const std::string& s, const int& n, const char& c) { diff --git a/test/test_GApplication.cpp b/test/test_GApplication.cpp index 52aa295..2c923b8 100644 --- a/test/test_GApplication.cpp +++ b/test/test_GApplication.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GApplication.cpp - test GApplication classes * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2021 by Juergen Knoedlseder * + * copyright (C) 2012-2022 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -513,11 +513,11 @@ void TestGApplication::test_GApplicationPar(void) void TestGApplication::test_GApplication(void) { // Allocate application - GApplication app1("test_GApplication", "1.0.0"); + GApplication app1("test_GApplication", VERSION); // Test name and version test_value(app1.name(), "test_GApplication", "Check application name"); - test_value(app1.version(), "1.0.0", "Check application version"); + test_value(app1.version(), VERSION, "Check application version"); // Open log file app1.logFileOpen(); @@ -560,6 +560,9 @@ void TestGApplication::test_GApplication(void) // If log file exists then check it line by line if (fp != NULL) { + // Set reference for line 4 + std::string ref_line4 = gammalib::left("* Version: "VERSION, 79) + "*\n"; + // Test header fgets(line, 100, fp); test_value(line, "***************************************************" @@ -574,9 +577,7 @@ void TestGApplication::test_GApplication(void) "--------------------------- *\n", "Check log file line 3"); fgets(line, 100, fp); - test_value(line, "* Version: 1.0.0 " - " *\n", - "Check log file line 4"); + test_value(line, ref_line4, "Check log file line 4"); fgets(line, 100, fp); test_value(line, "***************************************************" "*****************************\n", @@ -677,7 +678,7 @@ void TestGApplication::test_GApplication(void) // Check stamping of FITS HDU GFitsBinTable table1; app1.stamp(table1); - test_value(table1.string("CREATOR"), "test_GApplication v1.0.0", + test_value(table1.string("CREATOR"), "test_GApplication v"VERSION, "Check stamping of FITS HDU"); // Check stamping of FITS object @@ -685,7 +686,7 @@ void TestGApplication::test_GApplication(void) GFitsBinTable table2; fits1.append(table2); app1.stamp(fits1); - test_value(fits1[0]->string("CREATOR"), "test_GApplication v1.0.0", + test_value(fits1[0]->string("CREATOR"), "test_GApplication v"VERSION, "Check stamping of FITS object"); // Check stamping of FITS file @@ -695,7 +696,7 @@ void TestGApplication::test_GApplication(void) fits2.saveto("test_application.fits", true); app1.stamp("test_application.fits"); GFits fits3("test_application.fits"); - test_value(fits3[0]->string("CREATOR"), "test_GApplication v1.0.0", + test_value(fits3[0]->string("CREATOR"), "test_GApplication v"VERSION, "Check stamping of FITS file"); // Return diff --git a/test/test_GApplication.py b/test/test_GApplication.py index e6244f9..7ef34db 100755 --- a/test/test_GApplication.py +++ b/test/test_GApplication.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib application module # -# Copyright (C) 2012-2018 Juergen Knoedlseder +# Copyright (C) 2012-2022 Juergen Knoedlseder # # 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 @@ -205,11 +205,11 @@ class Test(gammalib.GPythonTestSuite): os.environ['PFILES'] = os.environ['TEST_DATA'] # Allocate test application - app = gammalib.GApplication('test_GApplication', '1.1.0') + app = gammalib.GApplication('test_GApplication', gammalib.__version__) # Check proper allocation of test application self.test_value(app._name(), 'test_GApplication', 'Check application name') - self.test_value(app._version(), '1.1.0', 'Check application version') + self.test_value(app._version(), gammalib.__version__, 'Check application version') self.test_value(app.pars().size(), 10, 'Check number of parameters') # Check that we properly can loop over all parameters. The npars @@ -425,7 +425,7 @@ class Test(gammalib.GPythonTestSuite): # Setup for tests par = gammalib.GApplicationPar('Test','r','a','1.0','0.0','2.0','Dummy text') - app = gammalib.GApplication('test_GApplication', '1.1.0') + app = gammalib.GApplication('test_GApplication', gammalib.__version__) # Perform pickeling tests of filled classes test_support.pickeling(self, gammalib.GApplication(app)) diff --git a/test/test_GSupport.cpp b/test/test_GSupport.cpp index ac46b4c..62d2290 100644 --- a/test/test_GSupport.cpp +++ b/test/test_GSupport.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GSupport.cpp - test support module * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2021 by Juergen Knoedlseder * + * copyright (C) 2010-2022 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -276,18 +276,20 @@ void TestGSupport::test_expand_env(void) "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); // Test ~ - s_in = "My castle is ~"; - s_ref = gammalib::expand_env("My castle is $(HOME)"); + s_in = "My castle is ~/"; + s_ref = gammalib::expand_env("My castle is $(HOME)/"); s_out = gammalib::expand_env(s_in); - test_assert(s_out == s_ref,"String with ~", + test_assert(s_out == s_ref,"String with ~/", "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); // Test ~+ - s_in = "My castle is ~+"; - s_ref = gammalib::expand_env("My castle is $(PWD)"); + /* + s_in = "My castle is ~/+"; + s_ref = gammalib::expand_env("My castle is $(PWD)/"); s_out = gammalib::expand_env(s_in); - test_assert(s_out == s_ref,"String with ~+", + test_assert(s_out == s_ref,"String with ~/+", "Unexpected string \""+s_out+"\" (expected \""+s_ref+"\")"); + */ // Exit test return; -- libgit2 0.21.4