~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/micro_timestamp_test.cc

  • Committer: Lee Bieber
  • Date: 2010-11-07 19:34:48 UTC
  • mfrom: (1910.1.2 build)
  • Revision ID: kalebral@gmail.com-20101107193448-64kdu912qej354sh
Merge Stewart - including adapting and expanding the "differences from mysql" page from the wiki.
Merge Stewart - fix bug 668143: drizzleslap with --commit runs second iteration data load in a transaction

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2010 Pawel Blokus
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#include "config.h"
22
 
 
23
 
#define BOOST_TEST_DYN_LINK
24
 
#include <boost/test/unit_test.hpp>
25
 
 
26
 
#include <drizzled/temporal.h>
27
 
 
28
 
#include "temporal_generator.h"
29
 
 
30
 
using namespace drizzled;
31
 
 
32
 
class MicroTimestampTest
33
 
{
34
 
  protected:
35
 
    MicroTimestamp micro_timestamp;
36
 
    bool result;
37
 
};
38
 
 
39
 
BOOST_FIXTURE_TEST_SUITE(MicroTimestampTestSuite, MicroTimestampTest)
40
 
BOOST_AUTO_TEST_CASE(is_valid_minOfMicroTimestampRange_shouldReturn_True)
41
 
{
42
 
  uint32_t year= 1970, month= 1, day= 1, hour= 0, minute= 0, second= 0, microsecond= 0;
43
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
44
 
 
45
 
  result= micro_timestamp.is_valid();
46
 
 
47
 
  BOOST_REQUIRE(result);
48
 
}
49
 
 
50
 
BOOST_AUTO_TEST_CASE(is_valid_maxOfMicroTimestampRange_shouldReturn_True)
51
 
{
52
 
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 7, microsecond= 0;
53
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
54
 
 
55
 
  result= micro_timestamp.is_valid();
56
 
 
57
 
  BOOST_REQUIRE(result);
58
 
}
59
 
 
60
 
BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondBeforeMicroTimestampMinOfRange_shouldReturn_False)
61
 
{
62
 
  uint32_t year= 1969, month= 12, day= 31, hour= 23, minute= 59, second= 59, microsecond= 999999;
63
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
64
 
 
65
 
  result= micro_timestamp.is_valid();
66
 
 
67
 
  BOOST_REQUIRE(not result);
68
 
}
69
 
 
70
 
BOOST_AUTO_TEST_CASE(is_valid_oneMicroSecondAfterMicroTimestampMaxOfRange_shouldReturn_False)
71
 
{
72
 
  uint32_t year= 2038, month= 1, day= 19, hour= 3, minute= 14, second= 8, microsecond= 1;
73
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
74
 
 
75
 
  result= micro_timestamp.is_valid();
76
 
 
77
 
  BOOST_REQUIRE(not result);
78
 
}
79
 
 
80
 
BOOST_AUTO_TEST_CASE(is_valid_InsideOfMicroTimestampRange_shouldReturn_True)
81
 
{
82
 
  uint32_t year= 1980, month= 11, day= 1, hour= 5, minute= 8, second= 5, microsecond= 18263;
83
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
84
 
 
85
 
  result= micro_timestamp.is_valid();
86
 
 
87
 
  BOOST_REQUIRE(result);
88
 
}
89
 
 
90
 
BOOST_AUTO_TEST_CASE(to_string_shouldProduce_hyphenSeperatedDateElements_and_colonSeperatedTimeElements)
91
 
{
92
 
  char expected[MicroTimestamp::MAX_STRING_LENGTH]= "2010-05-01 08:07:06.007654";
93
 
  char returned[MicroTimestamp::MAX_STRING_LENGTH];
94
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, 2010, 5, 1, 8, 7, 6, 7654);
95
 
  
96
 
  micro_timestamp.to_string(returned, MicroTimestamp::MAX_STRING_LENGTH);
97
 
  
98
 
  BOOST_REQUIRE_EQUAL(expected, returned);
99
 
}
100
 
 
101
 
BOOST_AUTO_TEST_CASE(to_timeval)
102
 
{
103
 
  struct timeval filled;
104
 
  uint32_t year= 2009, month= 6, day= 3, hour= 4, minute= 59, second= 1, microsecond= 675;
105
 
  TemporalGenerator::TimestampGen::make_micro_timestamp(&micro_timestamp, year, month, day, hour, minute, second, microsecond);
106
 
 
107
 
  micro_timestamp.to_timeval(filled);
108
 
 
109
 
  BOOST_REQUIRE_EQUAL(1244005141, filled.tv_sec);
110
 
  BOOST_REQUIRE_EQUAL(675, filled.tv_usec);
111
 
}
112
 
BOOST_AUTO_TEST_SUITE_END()