Skip to content

Commit a4f7a8a

Browse files
committed
fix emscripten build.
1 parent af54de3 commit a4f7a8a

File tree

4 files changed

+58
-44
lines changed

4 files changed

+58
-44
lines changed

test/unit/chart/events.cpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using test::assert;
99
using test::check;
1010
using test::skip;
1111
using test::operator""_is_true;
12+
using test::operator""_is_false;
1213

1314
Geom::Size Gfx::ICanvas::textBoundary(const Font &font,
1415
const std::string &text)
@@ -17,7 +18,7 @@ Geom::Size Gfx::ICanvas::textBoundary(const Font &font,
1718
font.size};
1819
}
1920

20-
struct MyCanvas : Gfx::ICanvas, Vizzu::Draw::Painter
21+
struct MyCanvas final : Gfx::ICanvas, Vizzu::Draw::Painter
2122
{
2223
MyCanvas() noexcept = default;
2324
~MyCanvas() final = default;
@@ -61,6 +62,17 @@ struct chart_setup
6162
{
6263
std::vector<std::pair<Vizzu::Gen::ChannelId, const char *>>
6364
series;
65+
bool is_emscripten{[]
66+
{
67+
bool is_emscripten{
68+
#ifdef __EMSCRIPTEN__
69+
true
70+
#endif
71+
};
72+
73+
skip->*is_emscripten == "Emscripten build"_is_false;
74+
return is_emscripten;
75+
}()};
6476
Vizzu::Chart chart{};
6577

6678
explicit(false) operator Vizzu::Chart &()
@@ -92,17 +104,14 @@ struct event_as
92104
{
93105
std::string json;
94106
const Util::EventTarget *target;
95-
std::variant<std::monostate,
96-
Vizzu::Draw::Rect,
97-
Vizzu::Draw::Line,
98-
Vizzu::Events::OnTextDrawDetail>
107+
std::variant<std::monostate, Vizzu::Draw::Rect, Vizzu::Draw::Line>
99108
drawn;
100109
};
101110

102-
std::multimap<std::string, event_as, std::less<>>
103-
get_events(Vizzu::Chart &chart, const double &position = 1.0)
111+
std::multimap<std::string, event_as, std::less<>> get_events(
112+
Vizzu::Chart &chart)
104113
{
105-
chart.getAnimOptions().control.position = position;
114+
chart.getAnimOptions().control.position = 1.0;
106115

107116
bool ends{};
108117
chart.setKeyframe();
@@ -113,43 +122,36 @@ get_events(Vizzu::Chart &chart, const double &position = 1.0)
113122
});
114123

115124
std::multimap<std::string, event_as, std::less<>> events;
125+
126+
auto line =
127+
chart.getOptions().geometry == Vizzu::Gen::ShapeType::line;
116128
chart.getEventDispatcher().registerOnEachEvent(0,
117-
[&events](Util::EventDispatcher::Params &params)
129+
[&events, &line](Util::EventDispatcher::Params &params)
118130
{
119-
if (typeid(params)
120-
== typeid(Util::EventDispatcher::Params)
121-
|| dynamic_cast<Vizzu::Events::OnUpdateDetail *>(
122-
&params)) {
123-
events.emplace(std::piecewise_construct,
124-
std::tuple{params.eventName},
125-
std::tuple{params.toJSON(), params.target});
126-
}
127-
else if (auto *p = dynamic_cast<
128-
Vizzu::Events::OnTextDrawDetail *>(
129-
&params)) {
130-
events.emplace(std::piecewise_construct,
131-
std::tuple{params.eventName},
132-
std::tuple{params.toJSON(), params.target, *p});
133-
}
134-
else if (auto *p = dynamic_cast<
135-
Vizzu::Events::OnRectDrawEvent *>(&params)) {
131+
auto marker = params.eventName == "plot-marker-draw";
132+
if ((marker && line)
133+
|| params.eventName == "plot-axis-draw") {
136134
events.emplace(std::piecewise_construct,
137135
std::tuple{params.eventName},
138136
std::tuple{params.toJSON(),
139137
params.target,
140-
p->rect});
138+
static_cast<Vizzu::Events::OnLineDrawEvent &>(
139+
params)
140+
.line});
141141
}
142-
else if (auto *p = dynamic_cast<
143-
Vizzu::Events::OnLineDrawEvent *>(&params)) {
142+
else if (marker) {
144143
events.emplace(std::piecewise_construct,
145144
std::tuple{params.eventName},
146145
std::tuple{params.toJSON(),
147146
params.target,
148-
p->line});
147+
static_cast<Vizzu::Events::OnRectDrawEvent &>(
148+
params)
149+
.rect});
149150
}
150151
else
151-
skip->*false
152-
== "Not all draw events type handled"_is_true;
152+
events.emplace(std::piecewise_construct,
153+
std::tuple{params.eventName},
154+
std::tuple{params.toJSON(), params.target});
153155
});
154156

155157
using clock_t = std::chrono::steady_clock;
@@ -204,7 +206,7 @@ const static auto tests =
204206
using Axis = Vizzu::Events::Targets::Axis;
205207
for (auto &&[beg, end] = events.equal_range("plot-axis-draw");
206208
const auto &[j, t, l] : values(subrange(beg, end)))
207-
if (!dynamic_cast<Axis const &>(*t).horizontal)
209+
if (!static_cast<Axis const &>(*t).horizontal)
208210
xCenter = std::get<Vizzu::Draw::Line>(l).line.begin.x;
209211

210212
std::set<double> zero_count{};

test/unit/util/case.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct skip_error : std::runtime_error
4040
class case_type
4141
{
4242
public:
43+
enum class result_t { OK, SKIP, FAIL };
44+
4345
case_type(std::string_view suite_name,
4446
std::string_view case_name,
4547
runnable runner,
@@ -50,7 +52,7 @@ class case_type
5052
location(location)
5153
{}
5254

53-
void operator()()
55+
result_t operator()()
5456
{
5557
using std::chrono::steady_clock;
5658

@@ -61,6 +63,8 @@ class case_type
6163

6264
auto duration = steady_clock::now() - start;
6365
print_summary(duration);
66+
67+
return static_cast<result_t>(*this);
6468
}
6569

6670
void fail(const src_location &location,
@@ -82,9 +86,10 @@ class case_type
8286
return location.get_file_name();
8387
}
8488

85-
explicit operator bool() const
89+
explicit operator result_t() const
8690
{
87-
return skip || error_messages.empty();
91+
using enum result_t;
92+
return skip ? SKIP : error_messages.empty() ? OK : FAIL;
8893
}
8994

9095
void set_latest_location(const src_location &loc)

test/unit/util/collection.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class collection : public case_registry
7676
{
7777
std::size_t run{};
7878
std::size_t failed{};
79+
std::size_t skipped{};
7980
statistics() = default;
8081
};
8182

@@ -88,10 +89,13 @@ class collection : public case_registry
8889

8990
for (auto &act_case : cases) {
9091
if (condition(act_case)) {
91-
stats.run++;
9292
running_case = &act_case;
93-
act_case();
94-
if (!act_case) stats.failed++;
93+
switch (act_case()) {
94+
using enum case_type::result_t;
95+
case FAIL: ++stats.failed; [[fallthrough]];
96+
case OK: ++stats.run; break;
97+
case SKIP: ++stats.skipped; break;
98+
}
9599
}
96100
}
97101
return stats;
@@ -103,10 +107,13 @@ class collection : public case_registry
103107
<< "all tests: " << cases.size() << "\n"
104108
<< "tests run: " << stats.run << "\n"
105109
<< "tests failed: " << stats.failed << "\n";
110+
if (stats.skipped > 0)
111+
std::cout << "test skipped: " << stats.skipped << "\n";
106112

107113
if (stats.failed > 0)
108114
for (auto &act_case : cases)
109-
if (!act_case)
115+
if (static_cast<case_type::result_t>(act_case)
116+
== case_type::result_t::FAIL)
110117
std::cout << "\t" << act_case.full_name() << "\n";
111118

112119
std::cout << "\n";

test/unit/util/condition.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ struct bool_check_t : check_t
214214
if (throw_error) {
215215
throw_error(std::string("expectation failed\n")
216216
+ "\t\"" + std::string{exp.msg}
217-
+ "\" is not "
218-
+ (exp.value ? "true" : "false"),
217+
+ "\" is "
218+
+ (exp.value ? "false" : "true"),
219219
location);
220220
}
221221

222222
collection::instance().running_test()->fail(location,
223223
std::string("Check expectation failed\n") + "\t\""
224-
+ std::string{exp.msg} + "\" is not "
225-
+ (exp.value ? "true" : "false"));
224+
+ std::string{exp.msg} + "\" is "
225+
+ (exp.value ? "false" : "true"));
226226
}
227227
}
228228
};

0 commit comments

Comments
 (0)