mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00

There is already a constructor that takes a char*, so there should be an assignment operator as well
82 lines
2 KiB
C++
82 lines
2 KiB
C++
/* LICENSE BEGIN
|
|
This file is part of the SixtyFPS Project -- https://sixtyfps.io
|
|
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
|
|
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
|
|
|
|
SPDX-License-Identifier: GPL-3.0-only
|
|
This file is also available under commercial licensing terms.
|
|
Please contact info@sixtyfps.io for more information.
|
|
LICENSE END */
|
|
|
|
#include <chrono>
|
|
#define CATCH_CONFIG_MAIN
|
|
#include "catch2/catch.hpp"
|
|
|
|
#include <sixtyfps.h>
|
|
|
|
SCENARIO("SharedString API")
|
|
{
|
|
sixtyfps::SharedString str;
|
|
|
|
REQUIRE(str.empty());
|
|
|
|
SECTION("Construct from string_view")
|
|
{
|
|
std::string foo("Foo");
|
|
std::string_view foo_view(foo);
|
|
str = foo_view;
|
|
REQUIRE(str == "Foo");
|
|
}
|
|
|
|
SECTION("Construct from char*")
|
|
{
|
|
str = "Bar";
|
|
REQUIRE(str == "Bar");
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Basic SharedVector API", "[vector]")
|
|
{
|
|
sixtyfps::SharedVector<int> vec;
|
|
REQUIRE(vec.empty());
|
|
|
|
SECTION("Initializer list")
|
|
{
|
|
sixtyfps::SharedVector<int> vec({ 1, 4, 10 });
|
|
REQUIRE(vec.size() == 3);
|
|
REQUIRE(vec[0] == 1);
|
|
REQUIRE(vec[1] == 4);
|
|
REQUIRE(vec[2] == 10);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Property Tracker")
|
|
{
|
|
using namespace sixtyfps;
|
|
PropertyTracker tracker1;
|
|
PropertyTracker tracker2;
|
|
Property<int> prop(42);
|
|
|
|
auto r = tracker1.evaluate([&]() { return tracker2.evaluate([&]() { return prop.get(); }); });
|
|
REQUIRE(r == 42);
|
|
|
|
prop.set(1);
|
|
REQUIRE(tracker2.is_dirty());
|
|
REQUIRE(tracker1.is_dirty());
|
|
|
|
r = tracker1.evaluate(
|
|
[&]() { return tracker2.evaluate_as_dependency_root([&]() { return prop.get(); }); });
|
|
REQUIRE(r == 1);
|
|
prop.set(100);
|
|
REQUIRE(tracker2.is_dirty());
|
|
REQUIRE(!tracker1.is_dirty());
|
|
}
|
|
|
|
TEST_CASE("C++ Timers")
|
|
{
|
|
using namespace sixtyfps;
|
|
|
|
Timer testTimer(std::chrono::milliseconds(16), []() { sixtyfps::quit_event_loop(); });
|
|
|
|
sixtyfps::run_event_loop();
|
|
}
|