X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=test%2Ftime%2Fmain.cpp;h=8ad07fc411e99e1db6704950a905cb2faaf0bc26;hb=63c74af5519ae3db82627b9cd3b36bb2cfa3bd72;hp=b7b0b189e839a08cfb07a74e3c5fb647af02c2f1;hpb=a539fef8b5a3b87ab7306138eba0ebc0db764e29;p=anna.git diff --git a/test/time/main.cpp b/test/time/main.cpp index b7b0b18..8ad07fc 100644 --- a/test/time/main.cpp +++ b/test/time/main.cpp @@ -1,87 +1,68 @@ -// ANNA - Anna is Not 'N' Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// https://bitbucket.org/testillano/anna -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // -#define BOOST_TEST_MODULE ANNA_TIME_TEST - -#include - -//#include #include - #include #include +#include + using namespace std; using namespace anna; -// see http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools.html -// http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/testing-tools/reference.html -BOOST_AUTO_TEST_CASE(date) { - const char * tzarg = NULL; +TEST(date, Conversions) +{ anna::time::functions::initialize(); anna::time::Date current, current2; - current.setCurrent(); + current.setNow(); unsigned int ntptime = current.getNtpTimestamp(); time_t unixtime = current.getUnixTimestamp(); current2.storeNtp(ntptime); std::string ntpStr = current2.asString(); current2.storeUnix(unixtime); std::string unixStr = current2.asString(); - BOOST_REQUIRE_EQUAL(ntpStr, unixStr); + EXPECT_EQ(ntpStr, unixStr); + anna::time::Date myBirth("CET"); // 19 December 1974, 10:00 (GMT+1 = UTC + 1 = CET) - //anna::time::Date myBirth; // if Context TZ = shell TZ = "CET" myBirth.store("19741219101500"); // yyyymmddHHmmss anna::time::Date same_moment_canary_island("GMT"); same_moment_canary_island.store(myBirth.getUnixTimestamp()); - myBirth.setTzContext("GMT"); - BOOST_REQUIRE_EQUAL(same_moment_canary_island.yyyymmddHHmmss(), myBirth.yyyymmddHHmmss()); + myBirth.setTz("GMT"); + EXPECT_EQ(same_moment_canary_island.yyyymmddHHmmss(), myBirth.yyyymmddHHmmss()); + anna::time::Date birthday("EET"); birthday.store(same_moment_canary_island.getTm(), "GMT"); // TZ origin = "GMT" - //BOOST_REQUIRE_EQUAL(birthday, myBirth); - BOOST_REQUIRE_EQUAL(birthday.getUnixTimestamp(), myBirth.getUnixTimestamp()); - myBirth.setTzContext(anna::time::functions::getLocalTz().getValue().c_str()); - birthday.setTzContext(anna::time::functions::getLocalTz().getValue().c_str()); // Go from "EET" to "CET" - // TODO: review the following test case: - //BOOST_REQUIRE_EQUAL(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss()); + EXPECT_EQ(birthday.getUnixTimestamp(), myBirth.getUnixTimestamp()); + + myBirth.setTz(); + birthday.setTz(); + EXPECT_EQ(myBirth.asString(), birthday.asString()); + EXPECT_EQ(myBirth.yyyymmddHHmmss(), birthday.yyyymmddHHmmss()); + + myBirth.setTz("GMT"); + EXPECT_EQ(myBirth.yyyymmddHHmmss(), "19741219091500"); + // Adding 18 years to 'myBirth': + same_moment_canary_island.setTz("CET"); + anna::time::Date eighteen("CET"); struct tm Tm = myBirth.getTm(); Tm.tm_year += 18; - anna::time::Date eighteen("CET"); - eighteen.store(Tm); - BOOST_REQUIRE(eighteen >= same_moment_canary_island); + eighteen.store(Tm, "GMT"); + EXPECT_TRUE(eighteen >= same_moment_canary_island); + EXPECT_EQ(eighteen.yyyymmddHHmmss(), "19921219101500"); +} + + + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); }