TuttleOFX  1
TuttleOFX/libraries/tuttle/tests/ofx/properties/main.cpp
Go to the documentation of this file.
00001 #define BOOST_TEST_MODULE properties_tests
00002 #include <tuttle/test/unit_test.hpp>
00003 
00004 #include <tuttle/common/utils/global.hpp>
00005 #include <tuttle/host/Core.hpp>
00006 
00007 #include <iostream>
00008 
00009 using namespace boost::unit_test;
00010 
00011 BOOST_AUTO_TEST_SUITE( properties_tests_suite01 )
00012 
00013 BOOST_AUTO_TEST_CASE( properties_get_and_set )
00014 {
00015         using namespace std;
00016         using namespace tuttle::host;
00017 
00018 #define testString_1_ro "testString_1_ro"
00019 #define testString_2_rw "testString_2_rw"
00020 #define testPointer_1_rw "testPointer_1_rw"
00021 #define testDouble_2_ro "testDouble_2_ro"
00022 #define testDouble_1_rw "testDouble_1_rw"
00023 #define testInt_1_rw "testInt_1_rw"
00024 #define testInt_2_rw "testInt_2_rw"
00025 #define testInt_4_ro "testInt_4_ro"
00026 
00027         static const ofx::property::OfxhPropSpec testStuff[] = {
00028                 /* name                                 type                   dim.   r/o    default value */
00029                 { testString_1_ro, ofx::property::ePropTypeString, 1, true, "default_value" },
00030                 { testString_2_rw, ofx::property::ePropTypeString, 2, false, "default_value" },
00031                 { testPointer_1_rw, ofx::property::ePropTypePointer, 1, false, NULL },
00032                 { testDouble_2_ro, ofx::property::ePropTypeDouble, 2, true, "0" },
00033                 { testDouble_1_rw, ofx::property::ePropTypeDouble, 1, false, "0" },
00034                 { testInt_1_rw, ofx::property::ePropTypeInt, 1, false, "0" },
00035                 { testInt_2_rw, ofx::property::ePropTypeInt, 2, false, "8" },
00036                 { testInt_4_ro, ofx::property::ePropTypeInt, 4, true, "0" },
00037                 { 0 }
00038         };
00039 
00040         // init values
00041         ofx::property::OfxhSet testSet( testStuff );
00042         testSet.setStringProperty( testString_1_ro, "testcontext" );
00043         testSet.setIntProperty( testInt_1_rw, true );
00044         int tab4Int[4] = { 11, 22, 33, 44 };
00045         testSet.setIntProperty( testInt_4_ro, tab4Int[0], 0 );
00046         testSet.setIntProperty( testInt_4_ro, tab4Int[1], 1 );
00047         testSet.setIntProperty( testInt_4_ro, tab4Int[2], 2 );
00048         testSet.setIntProperty( testInt_4_ro, tab4Int[3], 3 );
00049         double tab2Double[2] = { 11, 22 };
00050         testSet.setDoublePropertyN( testDouble_2_ro, tab2Double, 2 );
00051 
00052         // tests
00053         BOOST_CHECK_EQUAL( testSet.getStringProperty( testString_1_ro ), "testcontext" );
00054         BOOST_CHECK_EQUAL( testSet.getStringProperty( testString_2_rw, 0 ), "default_value" );
00055         BOOST_CHECK_EQUAL( testSet.getStringProperty( testString_2_rw, 1 ), "default_value" );
00056 
00057         BOOST_CHECK_EQUAL( testSet.getIntProperty( testInt_1_rw ), true );
00058         BOOST_CHECK_EQUAL( testSet.getIntProperty( testInt_2_rw, 0 ), 8 );
00059         BOOST_CHECK_EQUAL( testSet.getIntProperty( testInt_2_rw, 1 ), 8 );
00060 
00061         for( unsigned int i = 0; i < 4; ++i )
00062                 BOOST_CHECK_EQUAL( testSet.getIntProperty( testInt_4_ro, i ), tab4Int[i] );
00063 
00064         int tabGet4Int[4] = { 0, 0, 0, 0 };
00065         testSet.getIntPropertyN( testInt_4_ro, tabGet4Int, 4 );
00066         for( unsigned int i = 0; i < 4; ++i )
00067                 BOOST_CHECK_EQUAL( tabGet4Int[i], tab4Int[i] );
00068 
00069         for( unsigned int i = 0; i < 2; ++i )
00070                 BOOST_CHECK_EQUAL( testSet.getDoubleProperty( testDouble_2_ro, i ), tab2Double[i] );
00071 
00072         BOOST_CHECK_THROW( testSet.getStringProperty( "unexisting_properties" ), ofx::OfxhException );
00073         BOOST_CHECK_THROW( testSet.getIntProperty( testString_2_rw ), std::bad_cast );
00074 
00075         // Assignment and comparison tests
00076         ofx::property::OfxhSet testBSet( testSet );
00077         BOOST_CHECK( testBSet == testSet );
00078 
00079         testBSet.setIntProperty( testInt_4_ro, tab4Int[0] + 1, 0 );
00080         BOOST_CHECK( testBSet != testSet );
00081 
00082         testBSet.setIntProperty( testInt_4_ro, tab4Int[0], 0 );
00083         BOOST_CHECK( testBSet == testSet );
00084 
00085         ofx::property::OfxhSet testCSet;
00086         testCSet = testBSet;
00087         BOOST_CHECK( testCSet == testBSet );
00088 
00089         testCSet.setIntProperty( testInt_4_ro, tab4Int[0] + 11, 0 );
00090         BOOST_CHECK( testCSet != testBSet );
00091         testBSet.setIntProperty( testInt_4_ro, tab4Int[0] + 11, 0 );
00092         BOOST_CHECK( testCSet == testBSet );
00093 
00094         //      bool sequential = descriptor.getProperties().getIntProperty( kOfxImageEffectInstancePropSequentialRender ) != 0;
00095 }
00096 
00097 BOOST_AUTO_TEST_SUITE_END()
00098