tools: added support for reoriented screens in bwatch
[barry/progweb.git] / test / date.cc
blobca77f90000d4344702f5b9a9f4123ac9b40fe562
1 ///
2 /// \file date.cc
3 /// Tests for the Date class
4 ///
6 /*
7 Copyright (C) 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/record.h>
23 #include "libtest.h"
24 #include <iostream>
25 #include <sstream>
26 #include <iomanip>
27 #include <string.h>
28 using namespace std;
29 using namespace Barry;
31 bool TestDate()
33 struct tm t;
34 memset(&t, 0, sizeof(t));
35 t.tm_year = 111;
36 t.tm_mon = 1;
37 t.tm_mday = 28;
39 Date d(&t);
40 TEST( d.ToYYYYMMDD() == "20110228", "ToYYYYMMDD() failed");
41 TEST( d.ToBBString() == "28/02/2011", "ToBBString() failed");
43 ostringstream oss;
44 oss << hex << d;
45 TEST( oss.str() == "2011/02/28", "Stream output failed: " << oss.str());
47 Date d2;
48 d2.FromTm(&t);
49 TEST( d2.ToYYYYMMDD() == "20110228", "FromTm() failed");
51 struct tm myt;
52 d.ToTm(&myt);
53 d2.FromTm(&myt);
54 TEST( d2.ToYYYYMMDD() == "20110228", "ToTm() failed");
56 d2.FromBBString(d.ToBBString());
57 TEST( d2.ToYYYYMMDD() == "20110228", "FromBBString() failed");
59 d2.FromYYYYMMDD(d.ToYYYYMMDD());
60 TEST( d2.ToYYYYMMDD() == "20110228", "FromYYYMMDD() failed");
62 return true;
65 NewTest testdate("Date class", &TestDate);