Skip to content

Commit

Permalink
Added yet another three cleanup tests
Browse files Browse the repository at this point in the history
2008-07-06  Armin Burgmeier  <[email protected]>

	* libinfinity/adopted/inf-adopted-algorithm.c
	(inf_adopted_algorithm_can_undo_redo): Changed semantics of this
	function for non-local users so that it returns whether the user in
	question can issue an Undo or Redo command in its own current state
	(as known to the locals site).

	* test/inf-test-text-cleanup.c: Allow can-undo and can-redo
	verifications when the user's vector does not match the current one
	from the algorithm.

	* test/cleanup/cleanup-05.xml:
	* test/cleanup/cleanup-06.xml:
	* test/cleanup/cleanup-07.xml: Yet another three tests.
  • Loading branch information
aburgm committed Jul 6, 2008
1 parent ea3cbfa commit 68c5117
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 77 deletions.
16 changes: 16 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
2008-07-06 Armin Burgmeier <[email protected]>

* libinfinity/adopted/inf-adopted-algorithm.c
(inf_adopted_algorithm_can_undo_redo): Changed semantics of this
function for non-local users so that it returns whether the user in
question can issue an Undo or Redo command in its own current state
(as known to the locals site).

* test/inf-test-text-cleanup.c: Allow can-undo and can-redo
verifications when the user's vector does not match the current one
from the algorithm.

* test/cleanup/cleanup-05.xml:
* test/cleanup/cleanup-06.xml:
* test/cleanup/cleanup-07.xml: Yet another three tests.

2008-07-06 Armin Burgmeier <[email protected]>

* libinfinity/adopted/inf-adopted-algorithm.c
Expand Down
65 changes: 29 additions & 36 deletions libinfinity/adopted/inf-adopted-algorithm.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ inf_adopted_algorithm_least_common_predecessor(InfAdoptedAlgorithm* algorithm,
* compute the Undo operation). */
static gboolean
inf_adopted_algorithm_can_undo_redo(InfAdoptedAlgorithm* algorithm,
InfAdoptedRequestLog* log,
InfAdoptedUser* user,
InfAdoptedRequest* request)
{
InfAdoptedAlgorithmPrivate* priv;
InfAdoptedRequestLog* log;
guint diff;

priv = INF_ADOPTED_ALGORITHM_PRIVATE(algorithm);
Expand All @@ -250,15 +251,13 @@ inf_adopted_algorithm_can_undo_redo(InfAdoptedAlgorithm* algorithm,
{
if(priv->max_total_log_size != G_MAXUINT)
{
log = inf_adopted_user_get_request_log(user);
request = inf_adopted_request_log_original_request(log, request);

/* TODO: Perhaps we should do the vdiff against the user's vector
* instead of priv->current (which is the same for local users) so we
* can check whether the user is allowed to issue in Undo or not. */
diff = inf_adopted_algorithm_state_vector_vdiff(
algorithm,
inf_adopted_request_get_vector(request),
priv->current
inf_adopted_user_get_vector(user)
);

if(diff >= priv->max_total_log_size)
Expand Down Expand Up @@ -368,10 +367,8 @@ inf_adopted_algorithm_cleanup(InfAdoptedAlgorithm* algorithm)
* are additional conditions. However, in the current case, some requests
* are just kept a bit longer than necessary, in favor of simplicity. */

/* TODO: We should create tests with low max-total-log-size and have
* specific tests that verify that the cleanup algorithms work as expected.
* We could then also more easily try out some optimizations as the one
* mentioned above. */
/* TODO: Only take available users into account here, otherwise unavailable
* users prevent cleanup. */
cleanup_data.lcp = inf_adopted_state_vector_copy(priv->current);
for(user = priv->users_begin; user != priv->users_end; ++ user)
{
Expand Down Expand Up @@ -494,13 +491,13 @@ inf_adopted_algorithm_update_undo_redo(InfAdoptedAlgorithm* algorithm)

can_undo = inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
local->user,
inf_adopted_request_log_next_undo(log)
);

can_redo = inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
local->user,
inf_adopted_request_log_next_redo(log)
);

Expand Down Expand Up @@ -601,13 +598,13 @@ inf_adopted_algorithm_add_local_user(InfAdoptedAlgorithm* algorithm,

local->can_undo = inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
user,
inf_adopted_request_log_next_undo(log)
);

local->can_redo = inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
user,
inf_adopted_request_log_next_redo(log)
);

Expand Down Expand Up @@ -2021,7 +2018,11 @@ inf_adopted_algorithm_receive_request(InfAdoptedAlgorithm* algorithm,

inf_adopted_user_set_vector(INF_ADOPTED_USER(user), user_vector);
}


/* TODO: Errorcheck that we can apply the request. That means: If it's a
* DO request, check vector timestamps, if it's an undo or redo request,
* then check can_undo/can_redo. */

if(inf_adopted_state_vector_causally_before(vector, priv->current) == FALSE)
{
priv->queue = g_list_prepend(priv->queue, request);
Expand Down Expand Up @@ -2065,16 +2066,12 @@ inf_adopted_algorithm_receive_request(InfAdoptedAlgorithm* algorithm,
* @algorithm: A #InfAdoptedAlgorithm.
* @user: A local #InfAdoptedUser.
*
* Returns whether @user can issue an undo request in the current state.
*
* Note that if @user is a non-local user, then a Undo request from that user
* may still be valid even though this function returns false if the Undo
* requests was generated in another document state at the remote site. This
* means that this function cannot be used to check whether an Undo request
* received by a non-local user can be applied or not. It only checks whether
* that remote user could do an Undo request if it was in the same state or
* not. This behaviour might change in the future, see also the internal
* function inf_adopted_algorithm_can_undo_redo().
* Returns whether @user can issue an undo request in the current state. Note
* that if @user is non-local, then the result of this function does not
* depend on the current state but on the state that we know @user is
* guaranteed to have reached. This is because @user might still issue an
* Undo request even if the max-total-log-size is already exceeded if @user
* does not know yet that it is exceeded.
*
* Return Value: %TRUE if Undo is possible, %FALSE otherwise.
**/
Expand All @@ -2099,7 +2096,7 @@ inf_adopted_algorithm_can_undo(InfAdoptedAlgorithm* algorithm,

return inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
user,
inf_adopted_request_log_next_undo(log)
);
}
Expand All @@ -2110,16 +2107,12 @@ inf_adopted_algorithm_can_undo(InfAdoptedAlgorithm* algorithm,
* @algorithm: A #InfAdoptedAlgorithm.
* @user: A local #InfAdoptedUser.
*
* Returns whether @user can issue a redo request in the current state.
*
* Note that if @user is a non-local user, then a Redo request from that user
* may still be valid even though this function returns false if the Redo
* requests was generated in another document state at the remote site. This
* means that this function cannot be used to check whether an Redo request
* received by a non-local user can be applied or not. It only checks whether
* that remote user could do an Redo request if it was in the same state or
* not. This behaviour might change in the future, see also the internal
* function inf_adopted_algorithm_can_undo_redo().
* Returns whether @user can issue a redo request in the current state. Note
* that if @user is non-local, then the result of this function does not
* depend on the current state but on the state that we know @user is
* guaranteed to have reached. This is because @user might still issue a
* Redo request even if the max-total-log-size is already exceeded if @user
* does not know yet that it is exceeded.
*
* Return Value: %TRUE if Redo is possible, %FALSE otherwise.
**/
Expand All @@ -2144,7 +2137,7 @@ inf_adopted_algorithm_can_redo(InfAdoptedAlgorithm* algorithm,

return inf_adopted_algorithm_can_undo_redo(
algorithm,
log,
user,
inf_adopted_request_log_next_redo(log)
);
}
Expand Down
33 changes: 33 additions & 0 deletions test/cleanup/cleanup-05.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<infinote-cleanup-test>
<log size="3" />
<user id="1" />
<user id="2" />

<initial-buffer />

<request time="" user="1"><insert pos="0">c</insert></request>

<verify user="1" log-size="1" can-undo="1" can-redo="0" />

<request time="" user="1"><undo /></request>

<verify user="1" log-size="2" can-undo="0" can-redo="1" />

<request time="" user="1"><redo /></request>

<verify user="1" log-size="3" can-undo="0" can-redo="0" />

<request time="" user="1"><insert pos="1">d</insert></request>

<verify user="1" log-size="4" can-undo="1" can-redo="0" />

<request time="1:2" user="2"><no-op /></request>

<verify user="1" log-size="4" can-undo="1" can-redo="0" />

<request time="1:1" user="2"><no-op /></request>

<verify user="1" log-size="1" can-undo="1" can-redo="0" />

</infinote-cleanup-test>
32 changes: 32 additions & 0 deletions test/cleanup/cleanup-06.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<infinote-cleanup-test>
<log size="2" />
<user id="1" />
<user id="2" />

<initial-buffer />

<request time="" user="1"><insert pos="0">c</insert></request>
<request time="" user="2"><insert pos="0">a</insert></request>

<verify user="1" log-size="1" can-undo="1" can-redo="0" />
<verify user="2" log-size="1" can-undo="1" can-redo="0" />

<request time="2:1" user="1"><no-op /></request>

<!-- We need to keep the request from user 1 in the log since user 2 could
still issue a request that depends on it. -->
<verify user="1" log-size="1" can-undo="0" can-redo="0" />

<!-- We also need to keep the request from user 2 in the log since user 2
has not yet processed the request from user 1 (or, we don't know
about it), so user 2 might not yet have exceeded the max-total-log-site
locally and therefore still issue an Undo request. -->
<verify user="2" log-size="1" can-undo="1" can-redo="0" />

<request time="1:1" user="2"><no-op /></request>

<verify user="1" log-size="0" can-undo="0" can-redo="0" />
<verify user="2" log-size="0" can-undo="0" can-redo="0" />

</infinote-cleanup-test>
35 changes: 35 additions & 0 deletions test/cleanup/cleanup-07.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" ?>
<infinote-cleanup-test>
<log size="2" />
<user id="1" />
<user id="2" />
<user id="3" />

<initial-buffer />

<request time="" user="1"><insert pos="0">c</insert></request>
<request time="" user="2"><insert pos="0">a</insert></request>

<verify user="1" log-size="1" can-undo="1" can-redo="0" />
<verify user="2" log-size="1" can-undo="1" can-redo="0" />

<request time="2:1" user="1"><no-op /></request>

<verify user="1" log-size="1" can-undo="0" can-redo="0" />
<verify user="2" log-size="1" can-undo="1" can-redo="0" />

<request time="1:1" user="2"><no-op /></request>

<verify user="1" log-size="1" can-undo="0" can-redo="0" />
<verify user="2" log-size="1" can-undo="0" can-redo="0" />

<request time="" user="1"><insert pos="0">b</insert></request>

<verify user="1" log-size="2" can-undo="1" can-redo="0" />

<request time="1:2;2:1" user="3"><no-op /></request>

<verify user="1" log-size="1" can-undo="1" can-redo="0" />
<verify user="2" log-size="0" can-undo="0" can-redo="0" />

</infinote-cleanup-test>
41 changes: 0 additions & 41 deletions test/inf-test-text-cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ perform_test(guint max_total_log_size,
gint verify_can_undo;
gint verify_can_redo;

InfAdoptedStateVector* user_vector;
InfAdoptedStateVector* cur_vector;

InfAdoptedRequestLog* log;
guint log_size;

Expand Down Expand Up @@ -215,25 +212,6 @@ perform_test(guint max_total_log_size,

if(result)
{
/* TODO: Support this, see InfAdoptedAlgorithm */
user_vector = inf_adopted_user_get_vector(verify_user);
cur_vector = inf_adopted_algorithm_get_current(algorithm);
result =
(inf_adopted_state_vector_compare(user_vector, cur_vector) == 0);

if(result == FALSE)
{
g_set_error(
error,
inf_test_text_cleanup_error_quark(),
INF_TEST_TEXT_CLEANUP_UNSUPPORTED,
"User's state vector does not match local vector, can-undo "
"verification is currently unsupported"
);

goto fail;
}

result = inf_adopted_algorithm_can_undo(algorithm, verify_user);
if(result != verify_can_undo)
{
Expand Down Expand Up @@ -261,25 +239,6 @@ perform_test(guint max_total_log_size,

if(result)
{
/* TODO: Support this, see InfAdoptedAlgorithm */
user_vector = inf_adopted_user_get_vector(verify_user);
cur_vector = inf_adopted_algorithm_get_current(algorithm);
result =
(inf_adopted_state_vector_compare(user_vector, cur_vector) == 0);

if(result == FALSE)
{
g_set_error(
error,
inf_test_text_cleanup_error_quark(),
INF_TEST_TEXT_CLEANUP_UNSUPPORTED,
"User's state vector does not match local vector, can-redo "
"verification is currently unsupported"
);

goto fail;
}

result = inf_adopted_algorithm_can_redo(algorithm, verify_user);
if(result != verify_can_redo)
{
Expand Down

0 comments on commit 68c5117

Please sign in to comment.