@@ -25,58 +25,77 @@ TEST_F(DAPSessionManagerTest, GetInstanceReturnsSameSingleton) {
2525 EXPECT_EQ (&instance1, &instance2);
2626}
2727
28- TEST_F (DAPSessionManagerTest, SharedDebuggerSetAndGet ) {
28+ TEST_F (DAPSessionManagerTest, StoreAndTakeTarget ) {
2929 DAPSessionManager &manager = DAPSessionManager::GetInstance ();
3030
3131 SBDebugger debugger = SBDebugger::Create ();
3232 ASSERT_TRUE (debugger.IsValid ());
33+ // Create an empty target (no executable) since we're only testing session
34+ // management functionality, not actual debugging operations.
35+ SBTarget target = debugger.CreateTarget (" " );
36+ ASSERT_TRUE (target.IsValid ());
3337
34- uint32_t target_id = 12345 ;
35- manager.SetSharedDebugger (target_id, debugger );
38+ uint32_t target_id = target. GetGloballyUniqueID () ;
39+ manager.StoreTargetById (target_id, target );
3640
37- // Retrieval consumes the debugger (removes from map).
38- std::optional<SBDebugger > retrieved = manager.GetSharedDebugger (target_id);
41+ // Retrieval consumes the target (removes from map).
42+ std::optional<SBTarget > retrieved = manager.TakeTargetById (target_id);
3943 ASSERT_TRUE (retrieved.has_value ());
4044 EXPECT_TRUE (retrieved->IsValid ());
41- EXPECT_EQ (retrieved->GetID (), debugger.GetID ());
45+ // Verify we got the correct target back.
46+ EXPECT_EQ (retrieved->GetDebugger ().GetID (), debugger.GetID ());
47+ EXPECT_EQ (*retrieved, target);
4248
43- // Second retrieval should fail.
44- std::optional<SBDebugger> second_retrieval =
45- manager.GetSharedDebugger (target_id);
49+ // Second retrieval should fail (one-time retrieval semantics).
50+ std::optional<SBTarget> second_retrieval = manager.TakeTargetById (target_id);
4651 EXPECT_FALSE (second_retrieval.has_value ());
4752
4853 SBDebugger::Destroy (debugger);
4954}
5055
51- TEST_F (DAPSessionManagerTest, GetSharedDebuggerWithInvalidId ) {
56+ TEST_F (DAPSessionManagerTest, GetTargetWithInvalidId ) {
5257 DAPSessionManager &manager = DAPSessionManager::GetInstance ();
5358
54- std::optional<SBDebugger > result = manager.GetSharedDebugger (99999 );
59+ std::optional<SBTarget > result = manager.TakeTargetById (99999 );
5560
5661 EXPECT_FALSE (result.has_value ());
5762}
5863
59- TEST_F (DAPSessionManagerTest, MultipleSharedDebuggersWithDifferentIds ) {
64+ TEST_F (DAPSessionManagerTest, MultipleTargetsWithDifferentIds ) {
6065 DAPSessionManager &manager = DAPSessionManager::GetInstance ();
6166
6267 SBDebugger debugger1 = SBDebugger::Create ();
6368 SBDebugger debugger2 = SBDebugger::Create ();
6469 ASSERT_TRUE (debugger1.IsValid ());
6570 ASSERT_TRUE (debugger2.IsValid ());
71+ // Create empty targets (no executable) since we're only testing session
72+ // management functionality, not actual debugging operations.
73+ SBTarget target1 = debugger1.CreateTarget (" " );
74+ SBTarget target2 = debugger2.CreateTarget (" " );
75+ ASSERT_TRUE (target1.IsValid ());
76+ ASSERT_TRUE (target2.IsValid ());
6677
67- uint32_t target_id_1 = 1001 ;
68- uint32_t target_id_2 = 1002 ;
78+ uint32_t target_id_1 = target1. GetGloballyUniqueID () ;
79+ uint32_t target_id_2 = target2. GetGloballyUniqueID () ;
6980
70- manager. SetSharedDebugger (target_id_1, debugger1);
71- manager. SetSharedDebugger (target_id_2, debugger2 );
81+ // Sanity check the targets have distinct IDs.
82+ EXPECT_NE (target_id_1, target_id_2 );
7283
73- std::optional<SBDebugger> retrieved1 = manager.GetSharedDebugger (target_id_1);
84+ manager.StoreTargetById (target_id_1, target1);
85+ manager.StoreTargetById (target_id_2, target2);
86+
87+ std::optional<SBTarget> retrieved1 = manager.TakeTargetById (target_id_1);
7488 ASSERT_TRUE (retrieved1.has_value ());
75- EXPECT_EQ (retrieved1->GetID (), debugger1.GetID ());
89+ EXPECT_TRUE (retrieved1->IsValid ());
90+ // Verify we got the correct target by comparing debugger and target IDs.
91+ EXPECT_EQ (retrieved1->GetDebugger ().GetID (), debugger1.GetID ());
92+ EXPECT_EQ (*retrieved1, target1);
7693
77- std::optional<SBDebugger > retrieved2 = manager.GetSharedDebugger (target_id_2);
94+ std::optional<SBTarget > retrieved2 = manager.TakeTargetById (target_id_2);
7895 ASSERT_TRUE (retrieved2.has_value ());
79- EXPECT_EQ (retrieved2->GetID (), debugger2.GetID ());
96+ EXPECT_TRUE (retrieved2->IsValid ());
97+ EXPECT_EQ (retrieved2->GetDebugger ().GetID (), debugger2.GetID ());
98+ EXPECT_EQ (*retrieved2, target2);
8099
81100 SBDebugger::Destroy (debugger1);
82101 SBDebugger::Destroy (debugger2);
@@ -87,14 +106,32 @@ TEST_F(DAPSessionManagerTest, CleanupSharedResources) {
87106
88107 SBDebugger debugger = SBDebugger::Create ();
89108 ASSERT_TRUE (debugger.IsValid ());
90- manager.SetSharedDebugger (5555 , debugger);
91- std::optional<SBDebugger> initial_result = manager.GetSharedDebugger (5555 );
92- ASSERT_TRUE (initial_result.has_value ());
109+ // Create empty targets (no executable) since we're only testing session
110+ // management functionality, not actual debugging operations.
111+ SBTarget target1 = debugger.CreateTarget (" " );
112+ SBTarget target2 = debugger.CreateTarget (" " );
113+ ASSERT_TRUE (target1.IsValid ());
114+ ASSERT_TRUE (target2.IsValid ());
115+
116+ uint32_t target_id_1 = target1.GetGloballyUniqueID ();
117+ uint32_t target_id_2 = target2.GetGloballyUniqueID ();
118+
119+ // Sanity check the targets have distinct IDs.
120+ EXPECT_NE (target_id_1, target_id_2);
93121
122+ // Store multiple targets to verify cleanup removes them all.
123+ manager.StoreTargetById (target_id_1, target1);
124+ manager.StoreTargetById (target_id_2, target2);
125+
126+ // Cleanup should remove all stored targets.
94127 manager.CleanupSharedResources ();
95128
96- std::optional<SBDebugger> result = manager.GetSharedDebugger (5555 );
97- EXPECT_FALSE (result.has_value ());
129+ // Verify both targets are gone after cleanup.
130+ std::optional<SBTarget> result1 = manager.TakeTargetById (target_id_1);
131+ EXPECT_FALSE (result1.has_value ());
132+
133+ std::optional<SBTarget> result2 = manager.TakeTargetById (target_id_2);
134+ EXPECT_FALSE (result2.has_value ());
98135
99136 SBDebugger::Destroy (debugger);
100137}
0 commit comments