use std::path::{Path, PathBuf};
use openusd::usd::{SchemaRegistryBuilder, Stage};
use openusd_build::Views;
use crate::here::CrateSchema;
mod common;
#[allow(
dead_code,
reason = "the file carries every item of its library; this test reaches the reflected schema"
)]
mod elsewhere {
include!("reflect/elsewhere.rs");
}
#[allow(
dead_code,
reason = "the file carries every item of its library; this test reaches the reflecting classes"
)]
mod here {
include!("reflect/here.rs");
}
fn fixture() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reflect")
}
fn expected(name: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/reflect").join(name)
}
#[test]
fn compiled_reflection() {
let builder = openusd_build::configure()
.search_path(fixture())
.extern_library("testElsewhere", "crate::elsewhere");
let elsewhere = builder
.build_library(fixture().join("base.usda"), Views::Generate)
.expect("the reflected library builds");
let here = builder
.build_library(fixture().join("schema.usda"), Views::Generate)
.expect("the reflecting library builds");
common::matches(&expected("elsewhere.rs"), &elsewhere.rust);
common::matches(&expected("here.rs"), &here.rust);
let registry = SchemaRegistryBuilder::empty()
.register(elsewhere::SCHEMAS)
.register(here::SCHEMAS)
.build()
.expect("the two families compose");
let stage = Stage::builder()
.schema_registry(registry)
.in_memory("reflect.usda")
.expect("a stage");
let crate_ = here::Crate::define(&stage, "/Crate").expect("defines a crate");
crate_
.create_weight_attr()
.expect("authors the reflected attribute")
.set(2.5)
.expect("sets it");
assert_eq!(crate_.weight_attr().get::<f64>().expect("reads"), Some(2.5));
crate_.create_owner_rel().expect("authors the reflected relationship");
let thing: elsewhere::ThingAPI = crate_.thing_api();
assert_eq!(thing.path(), crate_.path());
assert_eq!(thing.weight_attr().get::<f64>().expect("reads"), Some(2.5));
let badge = here::BadgeAPI::apply(&crate_).expect("applies the badge");
let through_badge: elsewhere::ThingAPI = badge.thing_api();
assert_eq!(through_badge.path(), crate_.path());
assert_eq!(badge.weight_attr().get::<f64>().expect("reads"), Some(2.5));
}