Split switchuser API test into chunks 82/325482/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 10 Jun 2025 18:27:53 +0000 (20:27 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 10 Jun 2025 19:41:09 +0000 (21:41 +0200)
Helps timeouts and is generally a good idea.

Also fixes the "callback always fails because there
is no callback at all" nonsense.

Change-Id: I2a35398673dc35d713007fb8580107b9c63e9c93
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
tests/api_tests/test_api_switchuser.cpp
tests/api_tests/test_hlp.hpp

index 4cd42f5329bbdcf9d58f634f6d111432952130fc..5c9879a5eb3d118ba4cbb3eaf7bf61f451796da5 100644 (file)
@@ -1,16 +1,15 @@
-#include<iostream>
+#include <chrono>
+#include <thread>
+#include <iostream>
 #include <gtest/gtest.h>
 #include <gio/gio.h>
 #include <pthread.h>
 #include "sessiond.h"
 #include "test_hlp.hpp"
 
-// Test
-
-const int action_items = 31;
-
-TEST(subsession_switch_user_test, APISwitchUserTest) {
+TEST(subsession_switch_user_test, SwitchInitialSelf) {
 
+       const int action_items = 4;
        using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
 
        ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
@@ -21,171 +20,257 @@ TEST(subsession_switch_user_test, APISwitchUserTest) {
                                                        .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
+               }
+       };
+
+       loop_run_for_test(callback_pending<ud_t, api_call_res_t>, &ud_data, ud_data.loop);
+       summarize<action_items>(ud_data.results);
+}
+
 
+TEST(subsession_switch_user_test, SwitchRegRegSelf) {
+
+       const int action_items = 12;
+       using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
+
+       ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
+               .results = std::array<api_call_res_t, action_items>  {
 
+                       // Create 2 regulars
                        api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if add [ " + std::string(TestUserStr::user_1) + " ] is successful (regular-dir backend)",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if add " + std::string(TestUserStr::user_1) + " ] callback is successful", },
-
                        api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if add [  " + std::string(TestUserStr::user_2) + " ] is successful (regular-dir backend)",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if add  [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestUserStr::user_3)),
+                       // Switch to 1
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_3) + " ] is successful (regular-dir backend)",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if add [ " + std::string(TestUserStr::user_3) + " ] callback is successful", },
-
-                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_4, 15*1024)),
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_4) + " ] is successful (fixed-size backend, 15 MB)",
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if add [ " + std::string(TestUserStr::user_4) + " ] callback is successful", },
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_1) + " ]  is done", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_5, 30*1024)),
+                       // Regular -> different regular
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_5) + " ] is successful (fixed-size backend, 30 MB)",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if add [ " + std::string(TestUserStr::user_5) + " ] callback is successful", },
-
-                       // Default -> regular dir
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_3)),
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_3) + " ] is successful",
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_3) + " ] callback is successful", },
-
-                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_3)),
-                                                       .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_3) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
-                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_3) + " ]  is done", },
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
-                       // Regular dir -> regular dir
+                       // Regular -> self
                        api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
-
                        api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
-                       // Regular dir -> fixed size
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_4)),
+                       // Regular -> initial
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_4) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_4) + " ] callback is successful", },
-
-                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_4)),
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_4) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
-                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_4) + " ]  is done", },
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
 
-                       // Fixed size -> fixed size
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_5)),
+                       // Cleanup
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_5) + " ] is successful",
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_5) + " ] callback is successful", },
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] callback is successful", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_5)),
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_5) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
-                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_5) + " ]  is done", },
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] callback is successful", },
+               }
+       };
+
+       loop_run_for_test(callback_pending<ud_t, api_call_res_t>, &ud_data, ud_data.loop);
+       summarize<action_items>(ud_data.results);
+       std::this_thread::sleep_for(std::chrono::seconds(30)); // let the daemon process the Remove calls
+}
+
 
-                       // Fixed size -> self
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_5)),
+TEST(subsession_switch_user_test, SwitchFixedFixedSelf) {
+
+       const int action_items = 12;
+       using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
+
+       ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
+               .results = std::array<api_call_res_t, action_items>  {
+
+                       // Create 2 fixed-size
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_1, 10240)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_1) + " ] is successful (fixed-size backend)",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if add " + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_2, 10240)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_5) + " ] is successful",
+                                                       .desc = "Check if add [  " + std::string(TestUserStr::user_2) + " ] is successful (fixed-size backend)",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_5) + " ] callback is successful", },
+                                                       .cb_desc = "Check if add  [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
 
-                       // Fixed size -> regular dir
+                       // Switch to 1
                        api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
-
                        api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if current  [ " + std::string(TestUserStr::user_1) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_1) + " ]  is done", },
 
-                       // Regular dir -> self
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
+                       // Fixed -> different fixed of same size
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
+                       // Fixed -> self
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
-                       // Regular dir -> default
+                       // Fixed -> initial
                        api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to" + std::string(TestUserStr::user_0) + " ] callback is successful", },
-
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
                        api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
 
-                       // Default -> default
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
+                       // Cleanup
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] callback is successful", },
+
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to" + std::string(TestUserStr::user_0) + " ] callback is successful", },
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] callback is successful", },
+               }
+       };
 
-                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
+       loop_run_for_test(callback_pending<ud_t, api_call_res_t>, &ud_data, ud_data.loop);
+       summarize<action_items>(ud_data.results);
+       std::this_thread::sleep_for(std::chrono::seconds(30)); // let the daemon process the Remove calls
+}
+
+
+TEST(subsession_switch_user_test, SwitchFixedDifferentSizedFixed) {
+
+       const int action_items = 9;
+       using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
+
+       ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
+               .results = std::array<api_call_res_t, action_items>  {
+
+                       // Create 2 fixed-size, differently sized
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_1, 10240)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
-                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
+                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_1) + " ] is successful (fixed-size backend, 10 MB)",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if add " + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_2, 15360)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if add [  " + std::string(TestUserStr::user_2) + " ] is successful (fixed-size backend, 15 MB)",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if add  [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
 
-                       // Default -> fixed-size
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_5)),
+                       // Switch to 1
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_5) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to" + std::string(TestUserStr::user_5) + " ] callback is successful", },
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_1)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_1) + " ]  is done", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_5)),
+                       // Fixed -> differently-sized fixed
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_5) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to" + std::string(TestUserStr::user_5) + " ] callback is successful", },
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
-                       // Fixed-size -> default
+                       // Reset and cleanup
                        api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if switch to" + std::string(TestUserStr::user_0) + " ] callback is successful", },
-
-                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_0)),
-                                                       .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_0) + " ] is successful",
-                                                       .cb_expected = SUBSESSION_ERROR_INVALID_PARAMETER,
-                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_0) + " ]  is done", },
-
-                       // Cleanup
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
                        api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
                                                        .desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] is successful",
@@ -197,27 +282,92 @@ TEST(subsession_switch_user_test, APISwitchUserTest) {
                                                        .desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
                                                        .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] callback is successful", },
+               }
+       };
+
+       loop_run_for_test(callback_pending<ud_t, api_call_res_t>, &ud_data, ud_data.loop);
+       summarize<action_items>(ud_data.results);
+       std::this_thread::sleep_for(std::chrono::seconds(30)); // let the daemon process the Remove calls
+}
 
-                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_3)),
+
+
+TEST(subsession_switch_user_test, SwitchDifferentBackend) {
+
+       const int action_items = 11;
+       using ud_t = ud_data_t<std::array<api_call_res_t, action_items>>;
+
+       ud_t ud_data = { .loop = g_main_loop_new(NULL, FALSE),
+               .results = std::array<api_call_res_t, action_items>  {
+
+                       // Create both types of backend
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_l<subsession_5001>( TestUserStr::user_1)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if add [ " + std::string(TestUserStr::user_1) + " ] is successful (regular backend)",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if add " + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_add_user_fixed_size_l<subsession_5001>( TestUserStr::user_2, 10240)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if add [  " + std::string(TestUserStr::user_2) + " ] is successful (fixed-size backend)",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if add  [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+
+                       // Switch to 1
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_1)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_1) + " ]  is done", },
+
+                       // Regular -> fixed
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_2)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_3) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_2) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_3) + " ] callback is successful", },
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_2) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_2) + " ]  is done", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_4)),
+                       // Fixed -> regular
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_4) + " ] is successful",
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_1) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_get_current_user_l<subsession_5001>( TestUserStr::user_1)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if current  [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_4) + " ] callback is successful", },
+                                                       .cb_desc = "Check if getting current user [" + std::string(TestUserStr::user_1) + " ]  is done", },
 
-                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_5)),
+                       // Reset to initial & cleanup
+                       api_call_res_t{ .call_result = std::move(subsession_switch_user_l<subsession_5001>( TestUserStr::user_0)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if switch to [ " + std::string(TestUserStr::user_0) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if switch to [" + std::string(TestUserStr::user_0) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_1)),
                                                        .expected = SUBSESSION_ERROR_NONE,
-                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_5) + " ] is successful",
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] is successful",
                                                        .cb_expected = SUBSESSION_ERROR_NONE,
-                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_5) + " ] callback is successful", },
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_1) + " ] callback is successful", },
+                       api_call_res_t{ .call_result = std::move(subsession_remove_user_l<subsession_5001>(TestUserStr::user_2)),
+                                                       .expected = SUBSESSION_ERROR_NONE,
+                                                       .desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] is successful",
+                                                       .cb_expected = SUBSESSION_ERROR_NONE,
+                                                       .cb_desc = "Check if remove [ " + std::string(TestUserStr::user_2) + " ] callback is successful", },
                }
        };
 
        loop_run_for_test(callback_pending<ud_t, api_call_res_t>, &ud_data, ud_data.loop);
        summarize<action_items>(ud_data.results);
+       std::this_thread::sleep_for(std::chrono::seconds(30)); // let the daemon process the Remove calls
 }
index 9c0ac667dd7229200a2bcb4c5dd0674bcf1a632e..0f1f170193defcef05896bc687f93d76caa7fca8 100644 (file)
@@ -460,6 +460,7 @@ auto subsession_get_current_user_l = [](char * user_id){
        if(func_res == SUBSESSION_ERROR_NONE && compare == 0) {
                res = SUBSESSION_ERROR_NONE;
        }
+       p->first.callback_result = SUBSESSION_ERROR_NONE; // always synced, there is no callback
        g_atomic_int_inc(&p->first.callback_reference);
        p->second = res;
        return p;