132 lines
3.9 KiB
C++
132 lines
3.9 KiB
C++
#include "platform_api/platform_services.h"
|
|
#include "test_harness.h"
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
|
|
namespace {
|
|
|
|
class FakePlatformServices final : public pp::platform::PlatformServices {
|
|
public:
|
|
explicit FakePlatformServices(std::string clipboard_value)
|
|
: clipboard_value_(std::move(clipboard_value))
|
|
{
|
|
}
|
|
|
|
[[nodiscard]] std::string clipboard_text() override
|
|
{
|
|
++clipboard_reads;
|
|
return clipboard_value_;
|
|
}
|
|
|
|
[[nodiscard]] bool set_clipboard_text(std::string_view text) override
|
|
{
|
|
++clipboard_writes;
|
|
clipboard_value_.assign(text);
|
|
return true;
|
|
}
|
|
|
|
void set_cursor_visible(bool visible) override
|
|
{
|
|
++cursor_updates;
|
|
cursor_visible = visible;
|
|
}
|
|
|
|
void set_virtual_keyboard_visible(bool visible) override
|
|
{
|
|
++keyboard_updates;
|
|
keyboard_visible = visible;
|
|
}
|
|
|
|
void display_file(std::string_view path) override
|
|
{
|
|
++display_file_requests;
|
|
displayed_path.assign(path);
|
|
}
|
|
|
|
void share_file(std::string_view path) override
|
|
{
|
|
++share_file_requests;
|
|
shared_path.assign(path);
|
|
}
|
|
|
|
int clipboard_reads = 0;
|
|
int clipboard_writes = 0;
|
|
int cursor_updates = 0;
|
|
int keyboard_updates = 0;
|
|
int display_file_requests = 0;
|
|
int share_file_requests = 0;
|
|
bool cursor_visible = false;
|
|
bool keyboard_visible = false;
|
|
std::string displayed_path;
|
|
std::string shared_path;
|
|
|
|
private:
|
|
std::string clipboard_value_;
|
|
};
|
|
|
|
void platform_services_dispatch_clipboard_reads_and_writes(pp::tests::Harness& harness)
|
|
{
|
|
FakePlatformServices fake("#112233");
|
|
pp::platform::PlatformServices& services = fake;
|
|
|
|
PP_EXPECT(harness, services.clipboard_text() == "#112233");
|
|
PP_EXPECT(harness, services.set_clipboard_text("#ff00aa"));
|
|
PP_EXPECT(harness, services.clipboard_text() == "#ff00aa");
|
|
PP_EXPECT(harness, fake.clipboard_reads == 2);
|
|
PP_EXPECT(harness, fake.clipboard_writes == 1);
|
|
}
|
|
|
|
void platform_services_preserve_empty_clipboard_writes(pp::tests::Harness& harness)
|
|
{
|
|
FakePlatformServices fake("initial");
|
|
pp::platform::PlatformServices& services = fake;
|
|
|
|
PP_EXPECT(harness, services.set_clipboard_text(""));
|
|
PP_EXPECT(harness, services.clipboard_text().empty());
|
|
PP_EXPECT(harness, fake.clipboard_writes == 1);
|
|
}
|
|
|
|
void platform_services_dispatch_visibility_updates(pp::tests::Harness& harness)
|
|
{
|
|
FakePlatformServices fake("unused");
|
|
pp::platform::PlatformServices& services = fake;
|
|
|
|
services.set_cursor_visible(true);
|
|
services.set_virtual_keyboard_visible(true);
|
|
services.set_cursor_visible(false);
|
|
services.set_virtual_keyboard_visible(false);
|
|
|
|
PP_EXPECT(harness, fake.cursor_updates == 2);
|
|
PP_EXPECT(harness, fake.keyboard_updates == 2);
|
|
PP_EXPECT(harness, !fake.cursor_visible);
|
|
PP_EXPECT(harness, !fake.keyboard_visible);
|
|
}
|
|
|
|
void platform_services_dispatch_file_actions(pp::tests::Harness& harness)
|
|
{
|
|
FakePlatformServices fake("unused");
|
|
pp::platform::PlatformServices& services = fake;
|
|
|
|
services.display_file("D:/Paint/export.png");
|
|
services.share_file("D:/Paint/demo.ppi");
|
|
|
|
PP_EXPECT(harness, fake.display_file_requests == 1);
|
|
PP_EXPECT(harness, fake.share_file_requests == 1);
|
|
PP_EXPECT(harness, fake.displayed_path == "D:/Paint/export.png");
|
|
PP_EXPECT(harness, fake.shared_path == "D:/Paint/demo.ppi");
|
|
}
|
|
|
|
}
|
|
|
|
int main()
|
|
{
|
|
pp::tests::Harness harness;
|
|
harness.run("platform services dispatch clipboard reads and writes", platform_services_dispatch_clipboard_reads_and_writes);
|
|
harness.run("platform services preserve empty clipboard writes", platform_services_preserve_empty_clipboard_writes);
|
|
harness.run("platform services dispatch visibility updates", platform_services_dispatch_visibility_updates);
|
|
harness.run("platform services dispatch file actions", platform_services_dispatch_file_actions);
|
|
return harness.finish();
|
|
}
|