Пример #1
0
        //============================================================
        // Test Suite: improperSetTest()
        //============================================================
        //
        //  Test to see if setting improper values induces the
        //  correct exception handling.
        //============================================================
        int improperSetTest( void )
        {
            CommonTime Test;
            Test.set (700000, 0, 0.);

            TestUtil testFramework( "CommonTime", "set", __FILE__, __LINE__ );

            // Break the input in various ways and make sure the proper exception is called

            //----------------------------------------
            // Does CommonTime.set() work with negative days?
            //----------------------------------------
            try
            {
                Test.set(-1,0,0.);
                testFramework.assert( false, "[testing] CommonTime.set() with negative day, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            // QUESTION: Why test for gpstk::InvalidRequest exception instead of gpstk::Exception?
            // ANSWER: gpstk::InvalidRequest is a child of gpstk::Exception, and depending on CommonTime.cpp
            // we might sometimes need to be more specific than catching gpstk::Exception
            //     catch( gpstk::InvalidParameter e)
            // For now, I'm replacing gpstk::InvalidParameter with gpstk::Exception to be consistent throughout this test application
            catch( gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.set() with negative day should throw a gpstk::Exception", __LINE__ );
            }
            catch(...)
            {
                testFramework.assert( false, "[testing] CommonTime.set() with negative day, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does CommonTime.set() work with too many days?
            //----------------------------------------
            try
            {
                Test.set(3442449,0,0.);
                testFramework.assert( false, "[testing] CommonTime.set() with too many days, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.set() with too many days should throw a gpstk::Exception", __LINE__  );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.set() with too many days, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does CommonTime.set() work with negative seconds?
            //----------------------------------------
            try
            {
                Test.set(700000,-1,0.);
                testFramework.assert( false, "[testing] CommonTime.set() with negative seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.set() with negative seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "Fail", __LINE__ );
            }

            //----------------------------------------
            // Does a set method work with too many seconds?
            //----------------------------------------
            try
            {
                Test.set(700000,24*60*60+1,0.);
                testFramework.assert( false, "[testing] CommonTime.set() with too many seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.set() with too many seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.set() with too many seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does a set method work with negative fractional seconds?
            //----------------------------------------
            try
            {
                Test.set(700000,0,-1.);
                testFramework.assert( false, "[testing] CommonTime.set() with negative fractional seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.set() with negative fractional seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.set() with negative fractional seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does a set method work with too many fractional seconds?
            //----------------------------------------
            try
            {
                Test.set(700000,0,2.);
                testFramework.assert( false, "[testing] CommonTime.set() with too many fractional seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch( gpstk::Exception e )
            {
                testFramework.assert( true, "[expected] CommonTime.set() with too many fractional seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch(...)
            {
                testFramework.assert( false, "[testing] CommonTime.set() with too many fractional seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does CommonTime.setInterval() work with negative days?
            //----------------------------------------
            try
            {
                Test.setInternal(-1,0,0.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative days, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch( gpstk::Exception e )
            {
                testFramework.assert( true, "[expected] CommonTime.set() with negative days should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative days, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does CommonTime.setInterval() work with too many days?
            //----------------------------------------
            try
            {
                Test.setInternal(3442449,0,0.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with too many days, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.setInterval() with too many days should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.setInterval() with too many days, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does CommonTime.setInterval() work with negative seconds?
            //----------------------------------------
            try
            {
                Test.setInternal(700000,-1,0.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.setInterval() with negative seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does a set method work with too many seconds?
            //----------------------------------------
            try
            {
                Test.setInternal(700000,24*60*60+1,0.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with too many seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.setInterval() with too many seconds should throw a gpstk::Exception", __LINE__ );
            }
            // catch(...)
            // {
            //     testFramework.assert( false, "[testing] CommonTime.setInterval() with too many seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            // }

            //----------------------------------------
            // Does a set method work with negative fractional seconds?
            //----------------------------------------
            try
            {
                Test.setInternal(700000,1001,-1.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative fractional seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.setInterval() with negative fractional seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch (...)
            {
                testFramework.assert( false, "[testing] CommonTime.setInterval() with negative fractional seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // Does a set method work with too many fractional seconds?
            //----------------------------------------
            try
            {
                Test.setInternal(700000,1001,1001.);
                testFramework.assert( false, "[testing] CommonTime.setInterval() with too many fractional seconds, [expected] exception gpstk::Exception, [actual] threw no exception", __LINE__ );
            }
            catch(gpstk::Exception e)
            {
                testFramework.assert( true, "[expected] CommonTime.setInterval() with too many fractional seconds should throw a gpstk::Exception", __LINE__ );
            }
            catch(...)
            {
                testFramework.assert( false, "[testing] CommonTime.setInterval() with too many fractional seconds, [expected] exception gpstk::Exception, [actual] threw wrong exception", __LINE__ );
            }

            //----------------------------------------
            // The End!
            //----------------------------------------
            return testFramework.countFails();
        }