Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8952,6 +8952,7 @@ dependencies = [
"egui",
"egui_kittest",
"egui_tiles",
"ndarray",
"parking_lot",
"re_protos",
"re_redap_client",
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions tests/rust/re_integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ re_viewport_blueprint.workspace = true
egui_kittest.workspace = true
egui_tiles.workspace = true
egui.workspace = true
ndarray.workspace = true
parking_lot.workspace = true
tempfile.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
Expand Down
17 changes: 17 additions & 0 deletions tests/rust/re_integration_test/src/kittest_harness_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub trait HarnessExt<'h> {
fn drag_at(&mut self, pos: egui::Pos2);
fn hover_at(&mut self, pos: egui::Pos2);
fn drop_at(&mut self, pos: egui::Pos2);
fn right_click_at(&mut self, pos: egui::Pos2);

// Changes the value of a dropdown menu.
fn change_dropdown_value(&mut self, dropdown_label: &str, value: &str);
Expand Down Expand Up @@ -328,6 +329,22 @@ impl<'h> HarnessExt<'h> for egui_kittest::Harness<'h, re_viewer::App> {
self.run_ok();
}

fn right_click_at(&mut self, pos: egui::Pos2) {
self.event(egui::Event::PointerButton {
pos,
button: PointerButton::Secondary,
pressed: true,
modifiers: Modifiers::NONE,
});
self.event(egui::Event::PointerButton {
pos,
button: PointerButton::Secondary,
pressed: false,
modifiers: Modifiers::NONE,
});
self.run();
}

fn debug_viewer_state(&mut self) {
println!(
"Active recording: {:#?}",
Expand Down
246 changes: 246 additions & 0 deletions tests/rust/re_integration_test/tests/origin_heuristics_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
use egui_kittest::kittest::Queryable as _;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a module-level comment explaining roughly what this test is all about

use re_integration_test::HarnessExt as _;
use re_sdk::TimePoint;
use re_sdk::log::RowId;
use re_viewer::external::re_viewer_context::ViewClass as _;
use re_viewer::external::{re_types, re_view_spatial};
use re_viewer::viewer_test_utils::{self, HarnessOptions};
use re_viewport_blueprint::ViewBlueprint;

fn make_test_image() -> re_types::archetypes::Image {
let image = ndarray::Array3::from_shape_fn((256, 256, 3), |(y, x, c)| match c {
0 => x as u8,
1 => y as u8,
2 => 128,
_ => unreachable!(),
});
Comment on lines +10 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image


re_types::archetypes::Image::from_color_model_and_tensor(
re_types::datatypes::ColorModel::RGB,
image,
)
.expect("Failed to create image")
}

fn make_test_harness<'a>() -> egui_kittest::Harness<'a, re_viewer::App> {
let mut harness = viewer_test_utils::viewer_harness(&HarnessOptions::default());
harness.init_recording();
harness.set_selection_panel_opened(true);

// Log some data
harness.log_entity("/", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_types::archetypes::Boxes3D::from_centers_and_half_sizes(
[(0.0, 0.0, 0.0)],
[(0.3, 0.3, 0.3)],
)
.with_colors([0xFF9001FF]),
)
});

harness.log_entity("/world", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_types::archetypes::ViewCoordinates::RIGHT_HAND_Y_DOWN(),
)
});

harness.log_entity("/world/camera", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_types::archetypes::Transform3D::from_rotation(
re_types::components::RotationAxisAngle::new(
[-1.0, 0.9, 0.0],
std::f32::consts::PI / 2.0,
),
),
)
});

harness.log_entity("/world/camera/image", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_types::archetypes::Pinhole::from_focal_length_and_resolution(
[128.0, 128.0],
[256.0, 256.0],
)
.with_principal_point([128.0, 128.0])
.with_image_plane_distance(0.2),
)
});

harness.log_entity("/world/camera/image", |builder| {
builder.with_archetype(RowId::new(), TimePoint::default(), &make_test_image())
});

harness.log_entity("/world/camera/image/keypoint", |builder| {
builder.with_archetype(
RowId::new(),
TimePoint::default(),
&re_types::archetypes::Points2D::new([(10.0, 10.0), (128.0, -0.0), (50.0, -50.0)])
.with_radii([-10.0, -10.0, -10.0])
.with_colors([0xFF9001FF, 0x9001FFFF, 0x90FF01FF]),
)
});

// Set up a multi-view blueprint
harness.clear_current_blueprint();

let mut view3d =
ViewBlueprint::new_with_root_wildcard(re_view_spatial::SpatialView3D::identifier());
view3d.display_name = Some("3D view".into());

harness.setup_viewport_blueprint(move |_viewer_context, blueprint| {
blueprint.add_view_at_root(view3d);
});

harness
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_keypoint_3d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.right_click_at(harness.get_by_label("keypoint").rect().left_center());
harness.hover_label_contains("Add to new view");
harness.click_label("3D");
harness.snapshot_app("origin_keypoint_3d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_keypoint_2d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.right_click_at(harness.get_by_label("keypoint").rect().left_center());
harness.hover_label_contains("Add to new view");
harness.click_label("2D");
harness.remove_cursor();
harness.snapshot_app("origin_keypoint_2d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_image_3d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

// Close the selection panel before clicking on the image entity
// because rendering its download button requires the UI to be on
// the main thread. We are in a tokio test and it will crash.
harness.set_selection_panel_opened(false);
Comment on lines +139 to +142
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this about? Is this related to MainThreadToken? Do we really need to be on main thread to render the button? I would assume we would only need it to process the save-action (i.e. handle clicking it)!

What happens if you remove this line? Does something crash?


harness.blueprint_tree().right_click_label("image");
harness.hover_label_contains("Add to new view");
harness.click_label("3D");
harness.set_selection_panel_opened(true);
harness.snapshot_app("origin_image_3d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_image_2d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

// Close the selection panel before clicking on the image entity
// because rendering its download button requires the UI to be on
// the main thread. We are in a tokio test and it will crash.
harness.set_selection_panel_opened(false);

harness.blueprint_tree().right_click_label("image");
harness.hover_label_contains("Add to new view");
harness.click_label("2D");
harness.set_selection_panel_opened(true);
harness.snapshot_app("origin_image_2d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_camera_3d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("camera");
harness.hover_label_contains("Add to new view");
harness.click_label("3D");
harness.snapshot_app("origin_camera_3d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_camera_2d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("camera");
harness.hover_label_contains("Add to new view");
harness.click_label("2D");
harness.snapshot_app("origin_camera_2d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_world_3d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("world");
harness.hover_label_contains("Add to new view");
harness.click_label("3D");
harness.snapshot_app("origin_world_3d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_world_2d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("world");
harness.hover_label_contains("Add to new view");
harness.click_label("2D");
harness.snapshot_app("origin_world_2d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_root_3d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("/ (root)");
harness.hover_label_contains("Add to new view");
harness.click_label("3D");
harness.snapshot_app("origin_root_3d");
}

#[tokio::test(flavor = "multi_thread")]
pub async fn test_origin_root_2d() {
let mut harness = make_test_harness();

harness.blueprint_tree().right_click_label("3D view");
harness.click_label("Expand all");

harness.blueprint_tree().right_click_label("/ (root)");
harness.hover_label_contains("Add to new view");
harness.click_label("2D");
harness.snapshot_app("origin_root_2d");
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading