ui::testing::TestClipboard¶
Header: winui/testing/TestClipboard.hpp.
Derives from ui::Clipboard.
An in-memory Clipboard for headless tests. It holds one ClipboardContent and never touches the system clipboard.
Behaves like the real backend where a test can observe it: set_text() replaces every part, set_content() with nothing set fails and leaves the old content, every write and clear() advances content_changed(), and available_formats() lists the format names a real copy would put on the system clipboard. history_enabled/roaming_enabled are plain fields a test sets.
Install it with set_clipboard() so ui::clipboard() and every control use it. It uninstalls itself when destroyed, so a test that ends early never leaves a dangling clipboard behind.
Example:
// A test: Ctrl+V pastes from the clipboard.
ui::testing::TestClipboard clipboard;
ui::testing::set_clipboard(&clipboard);
clipboard.set_text("Portland");
REQUIRE(clipboard.contains(ui::StandardDataFormat::Text));
REQUIRE(clipboard.available_formats() == std::vector<std::string>{"CF_UNICODETEXT"});
auto box = std::make_unique<ui::TextBoxControl>();
ui::testing::set_focused(*box, true);
box->handle_key({ui::Key::V, ui::KeyAction::Down, {.ctrl = true}});
REQUIRE(box->text() == "Portland");
int changes = 0;
ui::Subscription watch = clipboard.content_changed().observe([&](const std::uint64_t&) { ++changes; });
clipboard.clear();
REQUIRE(changes == 1);
REQUIRE_FALSE(clipboard.text().has_value());
history_enabled¶
What is_history_enabled() reports; off by default.
roaming_enabled¶
What is_roaming_enabled() reports; off by default.
TestClipboard¶
~TestClipboard¶
Uninstalls it if it is still the installed clipboard.
TestClipboard¶
operator=¶
set_text¶
Replaces the whole content with text, as a real copy does.
text¶
The stored text, or nullopt if none was set.
set_content¶
bool set_content(const ClipboardContent& content, const ClipboardContentOptions& options = {}) override
Stores content and options and raises a change; false (nothing changed) when content has no part set.
bitmap¶
The stored picture, returned as stored (no encode/decode round trip).
storage_items¶
The stored paths, in order.
requested_operation¶
The stored operation, or None when there are no storage items for it to apply to.
contains¶
Whether the stored content has the part format names.
available_formats¶
The system format names for the stored parts: CF_UNICODETEXT for text, PNG and CF_DIBV5 for a bitmap, CF_HDROP and Preferred DropEffect for storage items. The history and cloud opt-out markers follow when the options turned those off.
clear¶
Drops the content and options and raises a change.
is_history_enabled¶
Reports history_enabled.
is_roaming_enabled¶
Reports roaming_enabled.
options¶
The options the last set_content() was given.