-#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),
.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",
.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
}