g_mutex_unlock(&mutex);
}
-int switch_user_test(int user_id)
+bool switch_user_test(int user_id)
{
volatile test_user_data test_switch_ud;
test_switch_ud.callback_result = CALLBACK_DATA_MAGIC;
{
g_mutex_unlock(&mutex);
printf("Error subsession_switch_user res is%d\n", switch_user_res);
- return -1;
+ return false;
}
/* The wait has to be in a loop because of
int new_user;
int r = subsession_get_current_user(SESSION_UID, &new_user);
if (r != SUBSESSION_ERROR_NONE)
- return -1;
- return new_user;
+ return false;
+ return new_user == user_id;
+}
+
+bool switch_to_each_user_to_generate_events()
+{
+ for (int i = firstUser; i <= lastUser; ++i) {
+ if (!switch_user_test(i)) {
+ printf("Failed to switch user\n");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool check_callbacks_called(int expected)
+{
+ int cc = g_atomic_int_get(&callbackCount);
+ if (cc != expected) {
+ printf("Failed to call the appropriate number of callbacks (%d expected, got %d)\n", expected, cc);
+ return false;
+ }
+
+ green_print("done");
+ return true;
}
void wait_for_all_pending_callbacks(GMainLoop *loop, GThread *loop_thread)
return EXIT_FAILURE;
}
- for (int i = firstUser; i < registered_users + firstUser; ++i)
- {
- int res = switch_user_test(i);
- if (res != i)
- {
- printf("Switch user error\n");
- return EXIT_FAILURE;
- }
- }
-
- green_print("done");
-
- printf("Register event callback test... ");
- int cc = g_atomic_int_get(&callbackCount);
- if (cc == registered_users)
- green_print("ok");
- else
- {
- printf("Failed to call all callbacks (%d expected, got %d)\n", registered_users, cc);
+ if (!switch_to_each_user_to_generate_events()
+ || !check_callbacks_called(registered_users))
return EXIT_FAILURE;
- }
+
///===================================///
printf("Subsession unregister event callback test...");
return EXIT_FAILURE;
}
- for (int i = firstUser; i < registered_users + firstUser; ++i)
- {
- int res = switch_user_test(i);
- if (res != i)
- {
- printf("Switch user error\n");
- return EXIT_FAILURE;
- }
-
- }
-
- cc = g_atomic_int_get(&callbackCount);
- if (cc == 0)
- green_print("done");
- else
- {
- printf("Failed to unregister all callbacks (%d went through)\n", cc);
+ if (!switch_to_each_user_to_generate_events()
+ || !check_callbacks_called(0))
return EXIT_FAILURE;
- }
///======================================///
printf("Removing users...");
- int end_res = switch_user_test(0);
- if (end_res != 0)
- {
+ if (!switch_user_test(0)) {
printf("Error setting user to 0\n");
return EXIT_FAILURE;
}