Remove time64_to_string and string_to_time64 and their tests.

Each was used exactly once and simply wrapped a function call.
Also replace static function time_parse_failure that just returned a
constant with the constant.
This commit is contained in:
John Ralls 2018-08-03 13:52:47 -07:00
parent 62b17ca5db
commit b32a8a9390
7 changed files with 8 additions and 106 deletions

View File

@ -131,18 +131,12 @@ commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c)
return ret;
}
char*
time64_to_string (time64 time)
{
return gnc_print_time64 (time, TIMESPEC_TIME_FORMAT " %q");
}
xmlNodePtr
time64_to_dom_tree (const char* tag, const time64 time)
{
xmlNodePtr ret;
g_return_val_if_fail (time != INT64_MAX, NULL);
auto date_str = time64_to_string (time);
auto date_str = gnc_print_time64 (time, "%Y-%m-%d %H:%M:%S %q");
if (!date_str)
return NULL;
ret = xmlNewNode (NULL, BAD_CAST tag);

View File

@ -41,7 +41,6 @@ xmlNodePtr boolean_to_dom_tree (const char* tag, gboolean val);
xmlNodePtr guid_to_dom_tree (const char* tag, const GncGUID* gid);
xmlNodePtr commodity_ref_to_dom_tree (const char* tag, const gnc_commodity* c);
xmlNodePtr time64_to_dom_tree (const char* tag, time64);
gchar* time64_to_string (time64);
xmlNodePtr gdate_to_dom_tree (const char* tag, const GDate* spec);
xmlNodePtr gnc_numeric_to_dom_tree (const char* tag, const gnc_numeric* num);
xmlNodePtr qof_instance_slots_to_dom_tree (const char* tag,

View File

@ -524,12 +524,6 @@ dom_tree_to_gnc_numeric (xmlNodePtr node)
return ret;
}
static time64
time_parse_failure ()
{
return INT64_MAX;
}
time64
dom_tree_to_time64 (xmlNodePtr node)
@ -562,21 +556,17 @@ dom_tree_to_time64 (xmlNodePtr node)
{
if (seen_s)
{
return time_parse_failure ();
return INT64_MAX;
}
else
{
gchar* content = dom_tree_to_text (n);
if (!content)
{
return time_parse_failure ();
return INT64_MAX;
}
if (!string_to_time64 (content, &ret))
{
g_free (content);
return time_parse_failure ();
}
ret = gnc_iso8601_to_time64_gmt (content);
g_free (content);
seen_s = TRUE;
}

View File

@ -362,13 +362,6 @@ simple_chars_only_parser_new (sixtp_end_handler end_handler)
all goes well, returns the time64 as the result.
*/
gboolean
string_to_time64 (const gchar* str, time64* time)
{
*time = gnc_iso8601_to_time64_gmt (str);
return (TRUE);
}
/* Top level timespec node:
input: user end handler *
@ -436,17 +429,17 @@ generic_timespec_secs_end_handler (gpointer data_for_children,
{
gchar* txt = NULL;
Time64ParseInfo* info = (Time64ParseInfo*) parent_data;
gboolean ok;
g_return_val_if_fail (parent_data, FALSE);
txt = concatenate_child_result_chars (data_from_children);
g_return_val_if_fail (txt, FALSE);
ok = string_to_time64 (txt, & info->time);
info->time = gnc_iso8601_to_time64_gmt (txt);
g_free (txt);
g_return_val_if_fail (ok, FALSE);
// gnc_iso8601_to_time64_gmt returns INT64_MAX on failure.
g_return_val_if_fail (info->time < INT64_MAX, FALSE);
info->s_block_count++;
return (TRUE);

View File

@ -35,10 +35,6 @@ typedef struct
guint s_block_count;
} Time64ParseInfo;
#define TIMESPEC_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define TIMESPEC_PARSE_TIME_FORMAT "%Y-%m-%d %H:%M:%S"
#define TIMESPEC_SEC_FORMAT_MAX 256
gboolean isspace_str (const gchar* str, int nomorethan);
gboolean allow_and_ignore_only_whitespace (GSList* sibling_data,
@ -84,8 +80,6 @@ gboolean generic_return_chars_end_handler (gpointer data_for_children,
sixtp* simple_chars_only_parser_new (sixtp_end_handler end_handler);
gboolean string_to_time64 (const gchar* str, time64* ts);
gboolean generic_timespec_start_handler (GSList* sibling_data,
gpointer parent_data,
gpointer global_data,

View File

@ -57,7 +57,7 @@ set(test_backend_xml_module_SOURCES
)
set_local_dist(test_backend_xml_DIST_local CMakeLists.txt grab-types.pl
README test-date-converting.cpp test-dom-converters1.cpp
README test-dom-converters1.cpp
test-dom-parser1.cpp test-file-stuff.cpp test-file-stuff.h test-kvp-frames.cpp
test-load-backend.cpp test-load-example-account.cpp test-load-xml2.cpp
test-save-in-lang.cpp test-string-converters.cpp test-xml2-is-file.cpp
@ -65,7 +65,6 @@ set_local_dist(test_backend_xml_DIST_local CMakeLists.txt grab-types.pl
test-xml-pricedb.cpp test-xml-transaction.cpp)
set(test_backend_xml_DIST ${test_backend_xml_DIST_local} ${test_backend_xml_test_files_DIST} PARENT_SCOPE)
add_xml_test(test-date-converting "${test_backend_xml_base_SOURCES};test-date-converting.cpp")
add_xml_test(test-dom-converters1 "${test_backend_xml_base_SOURCES};test-dom-converters1.cpp")
add_xml_test(test-kvp-frames "${test_backend_xml_base_SOURCES};test-kvp-frames.cpp")
add_xml_test(test-load-backend test-load-backend.cpp)

View File

@ -1,67 +0,0 @@
/********************************************************************\
* 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, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
extern "C"
{
#include <config.h>
#include "test-engine-stuff.h"
#include <stdlib.h>
}
#include "test-file-stuff.h"
#include "sixtp-utils.h"
#include "sixtp-dom-generators.h"
#include "test-stuff.h"
#define GNC_V2_STRING "gnc-v2"
const gchar* gnc_v2_xml_version_string = GNC_V2_STRING;
int
main (int argc, char** argv)
{
int i;
for (i = 0; i < 20; i++)
{
time64 spec2;
auto spec1 = get_random_time ();
auto sec_str = time64_to_string (spec1);
if (!string_to_time64 (sec_str, &spec2))
{
failure_args ("string_to_timespec_secs", __FILE__, __LINE__,
"string is %s", sec_str);
}
else if (spec1 != spec2)
{
failure_args ("timespec_secs", __FILE__, __LINE__,
"not equal ints are %" G_GINT64_FORMAT
" and %" G_GINT64_FORMAT "\n",
spec1, spec2);
}
else
{
success ("timespec");
}
g_free (sec_str);
}
print_test_results ();
exit (get_rv ());
}