LUMIERA.clone/tests/lib/time/digxel-configurations-test.cpp
Ichthyostega c85f7e0715 Add more special formatters and Digxel testcases
The Digxel implementation draft can be considered complete now
2011-01-13 03:36:10 +01:00

105 lines
3.3 KiB
C++

/*
DigxelConfigurations(Test) - verify predefined standard Digxel configurations
Copyright (C) Lumiera.org
2011, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/time/display.hpp"
#include "lib/time/digxel.hpp"
#include "lib/error.hpp"
#include "lib/util.hpp"
#include <iostream>
#include <cstdlib>
using lumiera::error::LUMIERA_ERROR_ASSERTION;
using util::isSameObject;
using lib::test::showType;
using std::rand;
using std::cout;
using std::endl;
namespace lib {
namespace time{
namespace test{
/***********************************************************************
* @test verify correctness of the predefined standard Digxels.
* Some widely used standard configurations, including
* - default Digxel for int and double values
* - sexagesimal Digxel
* - hex byte Digxel
* - ...more to come
* @todo cover any newly added Digxel configurations.
*/
class DigxelConfigurations_test : public Test
{
virtual void
run (Arg)
{
verifyConfiguration<Digxel<int> > (123);
verifyConfiguration<Digxel<double> > (123.4567);
verifyConfiguration<SexaDigit > (42);
verifyConfiguration<SexaDigit > (-5);
verifyConfiguration<HexaDigit > (0xc);
verifyConfiguration<HexaDigit > (0x6f);
}
template<class DIX, typename VAL>
void
verifyConfiguration (VAL testval)
{
DIX digxel;
CHECK (0 == digxel);
cout << showType(digxel) << "--empty--"<<digxel;
digxel = testval;
cout << "--(val="<<testval<<")--"<<digxel;
// verify buffer overrun protection
digxel = 123456789.12345;
string formatted;
#if false ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
VERIFY_ERROR (ASSERTION, formatted = digxel.show() ); // should trigger assertion
formatted = digxel.show(); // second time doesn't reformat
CHECK (formatted.length() == digxel.maxlen());
cout << "--(clipped)--"<< digxel;
#endif ///////////////////////////////////////////////////////////////////////////////////////////////TICKET #537 : restore throwing ASSERT
cout <<"|"<< endl;
}
};
/** Register this test class... */
LAUNCHER (DigxelConfigurations_test, "unit common");
}}} // namespace lib::time::test