Loading [MathJax]/extensions/TeX/AMSsymbols.js
Radium Engine  1.5.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
portfactory.cpp
1#include "Dataflow/Core/Sources/SingleDataSourceNode.hpp"
2#include <Dataflow/RaDataflow.hpp>
3#include <catch2/catch_test_macros.hpp>
4
5#include <Dataflow/Core/PortFactory.hpp>
6#include <string>
7using namespace Ra::Dataflow::Core;
8using namespace Ra::Core;
9TEST_CASE( "Dataflow/Core/PortFactory", "[unittests][Dataflow][PortFactory]" ) {
10
12 REQUIRE( PortFactory::getInstance() != nullptr );
13 auto factory = PortFactory::getInstance();
14
15 SECTION( "After init default port types are available" ) {
16 REQUIRE( factory->output_setter( std::type_index( typeid( Scalar ) ) ) );
17 REQUIRE( factory->output_setter( std::type_index( typeid( int ) ) ) );
18 REQUIRE( factory->output_setter( std::type_index( typeid( unsigned int ) ) ) );
19 REQUIRE( factory->output_setter( std::type_index( typeid( Utils::Color ) ) ) );
20 REQUIRE( factory->output_setter( std::type_index( typeid( Vector2 ) ) ) );
21 REQUIRE( factory->output_setter( std::type_index( typeid( Vector3 ) ) ) );
22 REQUIRE( factory->output_setter( std::type_index( typeid( Vector4 ) ) ) );
23 REQUIRE( factory->input_getter( std::type_index( typeid( Scalar ) ) ) );
24 REQUIRE( factory->input_getter( std::type_index( typeid( int ) ) ) );
25 REQUIRE( factory->input_getter( std::type_index( typeid( unsigned int ) ) ) );
26 REQUIRE( factory->input_getter( std::type_index( typeid( Utils::Color ) ) ) );
27 REQUIRE( factory->input_getter( std::type_index( typeid( Vector2 ) ) ) );
28 REQUIRE( factory->input_getter( std::type_index( typeid( Vector3 ) ) ) );
29 REQUIRE( factory->input_getter( std::type_index( typeid( Vector4 ) ) ) );
30 }
31
32 SECTION( "Other types aren't available" ) {
33 REQUIRE_THROWS( factory->output_setter( std::type_index( typeid( std::string ) ) ) );
34 REQUIRE_THROWS( factory->output_setter( std::type_index( typeid( std::vector<int> ) ) ) );
35 REQUIRE_THROWS( factory->input_getter( std::type_index( typeid( std::string ) ) ) );
36 REQUIRE_THROWS( factory->input_getter( std::type_index( typeid( std::vector<int> ) ) ) );
37 }
38
39 auto node = Sources::SingleDataSourceNode<int>( "node" );
40
41 SECTION( "Can add port with default types" ) {
42 REQUIRE( factory->make_input_port( &node, "port", typeid( Scalar ) ) );
43 REQUIRE( factory->make_output_port( &node, "port", typeid( Scalar ) ) );
44 }
45 SECTION( "Can't add port with other types" ) {
46 REQUIRE( !factory->make_input_port( &node, "port0", typeid( std::string ) ) );
47 REQUIRE( !factory->make_output_port( &node, "port0", typeid( std::string ) ) );
48 REQUIRE( !factory->make_output_port( &node, "port1", typeid( std::vector<int> ) ) );
49 REQUIRE( !factory->make_input_port( &node, "port1", typeid( std::vector<int> ) ) );
50 }
51 SECTION( "Add new port type and can add port with other types" ) {
52 add_port_type<std::string>();
53 add_port_type<std::vector<int>>();
54 REQUIRE( factory->make_input_port( &node, "port0", typeid( std::string ) ) );
55 REQUIRE( factory->make_output_port( &node, "port0", typeid( std::string ) ) );
56 REQUIRE( factory->make_output_port( &node, "port1", typeid( std::vector<int> ) ) );
57 REQUIRE( factory->make_input_port( &node, "port1", typeid( std::vector<int> ) ) );
58 }
59}
Base class for nodes that will give access to some input data to the graph. This class can be used to...
This namespace contains everything "low level", related to data, datastuctures, and computation.
Definition Cage.cpp:5
auto factory(const NodeFactorySet::key_type &name) -> NodeFactorySet::mapped_type
Gets the given factory from the manager.