• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "experimental/skrive/include/SkRive.h"
9 #include "tests/Test.h"
10 
11 template <typename T, typename U>
check_type(skiatest::Reporter * reporter,const sk_sp<U> & node,bool expected)12 void check_type(skiatest::Reporter* reporter, const sk_sp<U>& node, bool expected) {
13     REPORTER_ASSERT(reporter, node->template is<T>() == expected);
14     REPORTER_ASSERT(reporter, !!static_cast<const T*>(*node.get()) == expected);
15 }
16 
DEF_TEST(SkRive_DomTypes,reporter)17 DEF_TEST(SkRive_DomTypes, reporter) {
18     {
19         auto node = sk_make_sp<skrive::Node>();
20 
21         check_type<skrive::Component             >(reporter, node, true);
22         check_type<skrive::TransformableComponent>(reporter, node, true);
23         check_type<skrive::Node                  >(reporter, node, true);
24         check_type<skrive::Drawable              >(reporter, node, false);
25         check_type<skrive::Shape                 >(reporter, node, false);
26     }
27 
28     {
29         auto node = sk_make_sp<skrive::Shape>();
30 
31         check_type<skrive::Component             >(reporter, node, true);
32         check_type<skrive::TransformableComponent>(reporter, node, true);
33         check_type<skrive::Node                  >(reporter, node, true);
34         check_type<skrive::Drawable              >(reporter, node, true);
35         check_type<skrive::Shape                 >(reporter, node, true);
36     }
37 
38     {
39         auto node = sk_make_sp<skrive::ColorPaint>(SkPaint::Style::kFill_Style);
40 
41         check_type<skrive::Component             >(reporter, node, true);
42         check_type<skrive::TransformableComponent>(reporter, node, false);
43         check_type<skrive::Node                  >(reporter, node, false);
44         check_type<skrive::Drawable              >(reporter, node, false);
45         check_type<skrive::Shape                 >(reporter, node, false);
46         check_type<skrive::Paint                 >(reporter, node, true );
47         check_type<skrive::ColorPaint            >(reporter, node, true );
48     }
49 
50     {
51         auto node = sk_make_sp<skrive::Ellipse>();
52 
53         check_type<skrive::Component             >(reporter, node, true);
54         check_type<skrive::TransformableComponent>(reporter, node, true);
55         check_type<skrive::Node                  >(reporter, node, true);
56         check_type<skrive::Drawable              >(reporter, node, false);
57         check_type<skrive::Shape                 >(reporter, node, false);
58         check_type<skrive::Paint                 >(reporter, node, false );
59         check_type<skrive::ColorPaint            >(reporter, node, false );
60         check_type<skrive::Geometry              >(reporter, node, true);
61         check_type<skrive::Ellipse               >(reporter, node, true);
62     }
63 }
64