Timespec removal, engine odds-and-ends.

This commit is contained in:
John Ralls
2018-08-03 12:51:11 -07:00
parent 358cd979d9
commit 62b17ca5db
9 changed files with 32 additions and 89 deletions

View File

@@ -211,7 +211,6 @@ SplitList * qof_query_run_subquery (QofQuery *q, const QofQuery *q);
%ignore GNC_ERROR_REMAINDER;
%include <gnc-numeric.h>
Timespec timespecCanonicalDayTime(Timespec t);
time64 time64CanonicalDayTime(time64 t);
%include <gnc-budget.h>

View File

@@ -51,7 +51,7 @@ void qof_instance_set_slots (QofInstance *, KvpFrame *);
* used for comparing version in local memory to that in remote
* server.
*/
void qof_instance_set_last_update (QofInstance *inst, Timespec ts);
void qof_instance_set_last_update (QofInstance *inst, time64 time);
/** Set the dirty flag of just the instance. Don't modify the
* collection flag at all. */

View File

@@ -86,7 +86,7 @@ typedef struct QofInstancePrivate
* SQL backend, this field is reserved for SQL use, to compare
* the version in local memory to the remote, server version.
*/
Timespec last_update;
time64 last_update;
/* Keep track of nesting level of begin/end edit calls */
int editlevel;
@@ -264,8 +264,7 @@ qof_instance_init (QofInstance *inst)
priv = GET_PRIVATE(inst);
priv->book = NULL;
inst->kvp_data = new KvpFrame;
priv->last_update.tv_sec = 0;
priv->last_update.tv_nsec = -1;
priv->last_update = 0;
priv->editlevel = 0;
priv->do_free = FALSE;
priv->dirty = FALSE;
@@ -415,7 +414,7 @@ qof_instance_set_property (GObject *object,
GParamSpec *pspec)
{
QofInstance *inst;
Timespec *ts;
Time64 t;
g_return_if_fail(QOF_IS_INSTANCE(object));
@@ -435,8 +434,8 @@ qof_instance_set_property (GObject *object,
static_cast<QofBook*>(g_value_get_object(value)));
break;
case PROP_LAST_UPDATE:
ts = static_cast<Timespec*>(g_value_get_pointer(value));
qof_instance_set_last_update(inst, *ts);
t = *(static_cast<Time64*>(g_value_get_pointer(value)));
qof_instance_set_last_update(inst, t.t);
break;
case PROP_DESTROYING:
qof_instance_set_destroying(inst, g_value_get_boolean(value));
@@ -598,10 +597,10 @@ qof_instance_set_slots (QofInstance *inst, KvpFrame *frm)
}
void
qof_instance_set_last_update (QofInstance *inst, Timespec ts)
qof_instance_set_last_update (QofInstance *inst, time64 t)
{
if (!inst) return;
GET_PRIVATE(inst)->last_update = ts;
GET_PRIVATE(inst)->last_update = t;
}
gint
@@ -640,11 +639,8 @@ qof_instance_version_cmp (const QofInstance *left, const QofInstance *right)
lpriv = GET_PRIVATE(left);
rpriv = GET_PRIVATE(right);
if (lpriv->last_update.tv_sec < rpriv->last_update.tv_sec) return -1;
if (lpriv->last_update.tv_sec > rpriv->last_update.tv_sec) return +1;
if (lpriv->last_update.tv_nsec < rpriv->last_update.tv_nsec) return -1;
if (lpriv->last_update.tv_nsec > rpriv->last_update.tv_nsec) return +1;
return 0;
return lpriv->last_update < rpriv->last_update ? -1 :
lpriv->last_update > rpriv->last_update ? 1 : 0;
}
gboolean

View File

@@ -1827,9 +1827,12 @@ qof_query_printValueForParam (QofQueryPredData *pd, GString * gs)
if (!g_strcmp0 (pd->type_name, QOF_TYPE_DATE))
{
query_date_t pdata = (query_date_t) pd;
char datebuff[MAX_DATE_LENGTH + 1];
memset (datebuff, 0, sizeof(datebuff));
qof_print_date_buff (datebuff, sizeof(datebuff), pdata->date);
g_string_append_printf (gs, " Match type %s",
qof_query_printDateMatch (pdata->options));
g_string_append_printf (gs, " query_date: %s", gnc_print_date ({pdata->date, 0}));
g_string_append_printf (gs, " query_date: %s", datebuff);
return;
}
if (!g_strcmp0 (pd->type_name, QOF_TYPE_CHAR))

View File

@@ -450,7 +450,7 @@ date_to_string (gpointer object, QofParam *getter)
time64 tt = ((query_date_getter)getter->param_getfcn)(object, getter);
if (tt != INT64_MAX)
return g_strdup (gnc_print_date ({tt, 0}));
return qof_print_date (tt);
return NULL;
}

View File

@@ -157,20 +157,6 @@ kvp_type_excluded (KvpValue::Type kvp_type)
static gboolean zero_nsec = FALSE;
void
random_timespec_zero_nsec (gboolean zero_nsec_in)
{
zero_nsec = zero_nsec_in;
}
static gboolean usec_resolution = FALSE;
void
random_timespec_usec_resolution (gboolean usec_resolution_in)
{
usec_resolution = usec_resolution_in;
}
/* ========================================================== */
static inline gboolean
@@ -236,20 +222,6 @@ get_random_time (void)
return ret;
}
Timespec*
get_random_timespec(void)
{
Timespec *ret;
ret = g_new0(Timespec, 1);
while (ret->tv_sec <= 0)
ret->tv_sec = rand();
ret->tv_nsec = 0;
return ret;
}
GncGUID*
get_random_guid(void)
{

View File

@@ -45,10 +45,8 @@ typedef struct KvpValueImpl KvpValue;
typedef struct KvpFrameImpl KvpFrame;
#define __KVP_FRAME
#endif
Timespec* get_random_timespec(void);
time64 get_random_time(void);
void random_timespec_zero_nsec (gboolean zero_nsec);
void random_timespec_usec_resolution (gboolean usec_resolution);
KvpValue* get_random_kvp_value(int type);

View File

@@ -391,7 +391,7 @@ run_test (void)
ts.tv_nsec = 0;
check_time (ts, do_print);
ts = *get_random_timespec ();
ts.tv_sec = get_random_time ();
for (i = 0; i < 10000; i++)
{
@@ -402,7 +402,7 @@ run_test (void)
for (i = 0; i < 5000; i++)
{
ts = *get_random_timespec ();
ts.tv_sec = get_random_time ();
if (!check_time (ts, FALSE))
return;

View File

@@ -194,7 +194,7 @@ test_instance_new_destroy( void )
QofInstance *inst;
QofInstanceClass *klass;
/* test var */
Timespec *timespec_priv;
Time64 *time_priv;
const char *msg1 = "qof_instance_get_collection: assertion 'QOF_IS_INSTANCE(ptr)' failed";
const char *msg2 = "qof_instance_get_editlevel: assertion 'QOF_IS_INSTANCE(ptr)' failed";
const char *msg3 = "qof_instance_get_destroying: assertion 'QOF_IS_INSTANCE(ptr)' failed";
@@ -217,9 +217,8 @@ test_instance_new_destroy( void )
g_assert( !qof_instance_get_collection( inst ) );
g_assert( qof_instance_get_book( inst ) == NULL );
g_assert( inst->kvp_data );
g_object_get( inst, "last-update", &timespec_priv, NULL);
g_assert_cmpint( timespec_priv->tv_sec, == , 0 );
g_assert_cmpint( timespec_priv->tv_nsec, == , -1 );
g_object_get( inst, "last-update", &time_priv, NULL);
g_assert_cmpint( time_priv->t, == , 0 );
g_assert_cmpint( qof_instance_get_editlevel( inst ), == , 0 );
g_assert( !qof_instance_get_destroying( inst ) );
g_assert( !qof_instance_get_dirty_flag( inst ) );
@@ -311,7 +310,7 @@ test_instance_version_cmp( void )
{
QofInstance *left, *right;
int result;
Timespec timespec_left, timespec_right;
time64 time_left = 0, time_right = 1;
/* set up*/
left = static_cast<QofInstance*>(g_object_new( QOF_TYPE_INSTANCE, NULL ));
@@ -330,48 +329,24 @@ test_instance_version_cmp( void )
g_assert_cmpint( result, == , 1 );
g_test_message( "Test left tv_sec lesser than right" );
timespec_left.tv_sec = 0;
timespec_right.tv_sec = 1;
qof_instance_set_last_update( left, timespec_left );
qof_instance_set_last_update( right, timespec_right );
qof_instance_set_last_update( left, time_left );
qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , -1 );
g_test_message( "Test right tv_sec lesser than left" );
timespec_left.tv_sec = 1;
timespec_right.tv_sec = 0;
qof_instance_set_last_update( left, timespec_left );
qof_instance_set_last_update( right, timespec_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , 1 );
g_test_message( "Test left tv_nsec lesser than right" );
timespec_left.tv_sec = 1;
timespec_left.tv_nsec = 0;
timespec_right.tv_sec = 1;
timespec_right.tv_nsec = 1;
qof_instance_set_last_update( left, timespec_left );
qof_instance_set_last_update( right, timespec_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , -1 );
g_test_message( "Test right tv_sec lesser than left" );
timespec_left.tv_sec = 1;
timespec_left.tv_nsec = 1;
timespec_right.tv_sec = 1;
timespec_right.tv_nsec = 0;
qof_instance_set_last_update( left, timespec_left );
qof_instance_set_last_update( right, timespec_right );
time_left = 1;
time_right = 0;
qof_instance_set_last_update( left, time_left );
qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , 1 );
g_test_message( "Test both equal" );
timespec_left.tv_sec = 1;
timespec_left.tv_nsec = 1;
timespec_right.tv_sec = 1;
timespec_right.tv_nsec = 1;
qof_instance_set_last_update( left, timespec_left );
qof_instance_set_last_update( right, timespec_right );
time_left = 1;
time_right = 1;
qof_instance_set_last_update( left, time_left );
qof_instance_set_last_update( right, time_right );
result = qof_instance_version_cmp( left, right );
g_assert_cmpint( result, == , 0 );