Files
hakorune/local_tests/test_p2p_basic.hako

61 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 🧪 P2PBox基本機能テスト
// IntentBoxとP2PBoxの基本的な動作を検証
print("=== P2PBox Basic Test ===")
// 1. IntentBoxの作成
print("\n1. Creating IntentBox...")
local world
world = new IntentBox()
print("✅ IntentBox created: " + world.type())
// 2. P2PBoxードの作成
print("\n2. Creating P2PBox nodes...")
local alice
local bob
local charlie
alice = new P2PBox("alice", world)
bob = new P2PBox("bob", world)
charlie = new P2PBox("charlie", world)
print("✅ Alice created: " + alice.getNodeId())
print("✅ Bob created: " + bob.getNodeId())
print("✅ Charlie created: " + charlie.getNodeId())
// 3. リスナー登録テスト
print("\n3. Testing listener registration...")
bob.on("greeting", "bob_greeting_handler")
charlie.on("greeting", "charlie_greeting_handler")
print("✅ Listeners registered")
// 4. 直接送信テスト
print("\n4. Testing direct send...")
alice.send("greeting", "Hello Bob!", "bob")
alice.send("greeting", "Hello Charlie!", "charlie")
print("✅ Messages sent")
// 5. ブロードキャストテスト
print("\n5. Testing broadcast...")
alice.broadcast("announcement", "Hello everyone!")
print("✅ Broadcast sent")
// 6. リスナー解除テスト
print("\n6. Testing listener removal...")
local result
result = bob.off("greeting")
print("✅ Bob's listener removed: " + result)
// 7. 解除後の送信テスト
print("\n7. Testing send after listener removal...")
alice.send("greeting", "Hello again Bob!", "bob")
print("✅ Message sent (Bob should not receive)")
// 8. 複数リスナーテスト
print("\n8. Testing multiple listeners...")
charlie.on("data", "charlie_data_handler1")
charlie.on("data", "charlie_data_handler2")
alice.send("data", "Test data", "charlie")
print("✅ Multiple listeners tested")
print("\n=== Test Complete ===")