Files
MetaCrate/tests/compat/tests/avatar_manager_shims.rs
Chili Palmer 21f85a1b58
Some checks failed
Native code generation / deterministic (push) Successful in 18m19s
Imaging and meshing gate / native (push) Failing after 4m28s
Native Rust workspace compile / compile (push) Failing after 12m58s
Implement remaining TestClient service commands (#94)
2026-08-11 13:10:27 +00:00

132 lines
4.1 KiB
Rust

use libremetaverse::animesh::AnimeshManager;
use libremetaverse::appearance::CurrentOutfitFolder;
use libremetaverse::{
AgentManager, Animations, AppearanceManagerWearableData, AssetDownload, AssetManager,
AssetUpload, ChatEventArgs, ChatType, InventoryException, InventoryItem, InventoryManager,
TeleportEventArgs,
};
use libremetaverse_types::compat::{CancellationToken, EventHandler, Subscription};
use libremetaverse_types::{AssetType, AttachmentPoint, UUID};
fn member_id<T>(result: Result<T, libremetaverse::Error>) -> &'static str {
result
.err()
.expect("failure-only shim unexpectedly returned a value")
.csharp_member()
.expect("failure-only shim error")
}
fn compile_bot_and_animation_calls(
agent: &AgentManager,
chat_type: ChatType,
animation: UUID,
chat_handler: EventHandler<ChatEventArgs>,
) {
let _: Subscription = agent.subscribe_chat_from_simulator(chat_handler);
let _ = agent.chat(String::new(), 0, chat_type, Some(true));
let _ = agent.animation_start(animation, true);
}
async fn compile_outfit_call(
outfit: &CurrentOutfitFolder,
item: InventoryItem,
point: AttachmentPoint,
token: CancellationToken,
) {
let _ = outfit.attach(item, point, true, Some(token)).await;
}
async fn compile_inventory_call(
inventory: &InventoryManager,
item_id: UUID,
owner_id: UUID,
token: CancellationToken,
) {
let _ = inventory
.request_fetch_inventory_with_uuid_uuid_cancellation_token_6647b02a(
item_id,
owner_id,
Some(token),
)
.await;
}
async fn compile_asset_download_call(
assets: &AssetManager,
asset_id: UUID,
asset_type: AssetType,
token: CancellationToken,
) {
let _ = assets
.request_asset_with_uuid_asset_type_boolean_cancellation_token(
asset_id,
asset_type,
true,
Some(token),
)
.await;
}
async fn compile_teleport_call(
agent: &AgentManager,
landmark: UUID,
token: CancellationToken,
handler: EventHandler<TeleportEventArgs>,
) {
let _: Subscription = agent.subscribe_teleport_progress(handler);
let _ = agent
.teleport_with_uuid_cancellation_token(landmark, Some(token))
.await;
}
fn compile_animesh_call(animesh: &AnimeshManager, object_id: UUID) {
let _ = animesh.get_player(object_id);
let _ = animesh.update(1.0 / 60.0);
}
#[test]
fn avatar_facing_flows_have_typed_callable_signatures() {
let _ = compile_bot_and_animation_calls;
let _ = compile_outfit_call;
let _ = compile_inventory_call;
let _ = compile_asset_download_call;
let _ = compile_teleport_call;
let _ = compile_animesh_call;
}
#[test]
fn avatar_facing_constructors_preserve_native_defaults_and_catalog_errors() {
let download = AssetDownload::new().expect("AssetDownload constructor");
assert_eq!(download.asset_id, UUID::zero());
assert_eq!(download.next_packet, 0);
assert!(download.out_of_order_packets.read().unwrap().is_empty());
let upload = AssetUpload::new().expect("AssetUpload constructor");
assert_eq!(upload.asset_id, UUID::zero());
assert_eq!(upload.packet_num, 0);
assert_eq!(upload.xfer_id, 0);
let wearable = AppearanceManagerWearableData::new().expect("WearableData constructor");
assert_eq!(wearable.asset_id, UUID::zero());
assert_eq!(wearable.item_id, UUID::zero());
assert!(wearable.asset.is_none());
assert_eq!(
member_id(InventoryException::new_with_constructor()),
"M:LibreMetaverse.InventoryException.#ctor"
);
}
#[test]
fn built_in_animation_dictionary_matches_the_pinned_source_catalog() {
let catalog = Animations::to_dictionary().expect("animation dictionary").0;
assert_eq!(catalog.len(), 135);
assert_eq!(
catalog.get(&Animations::dance1()).map(String::as_str),
Some("DANCE1")
);
let yoga = UUID::new_with_string("42ecd00b-9947-a97c-400a-bbc9174c7aeb".into())
.expect("YOGA_FLOAT UUID");
assert_eq!(catalog.get(&yoga).map(String::as_str), Some("YOGA_FLOAT"));
}