xref: /haiku/src/tests/kits/shared/CalendarViewTest.cpp (revision 9642f7705b27e5c270c15fa526d14e1848c2c27d)
1 /*
2  * Copyright 2014, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "CalendarViewTest.h"
8 
9 #include <CalendarView.h>
10 
11 #include <cppunit/TestCaller.h>
12 #include <cppunit/TestSuite.h>
13 
14 
15 using namespace BPrivate;
16 
17 
18 CalendarViewTest::CalendarViewTest()
19 {
20 }
21 
22 
23 CalendarViewTest::~CalendarViewTest()
24 {
25 }
26 
27 
28 void
29 CalendarViewTest::TestSetters()
30 {
31 	BCalendarView view("test");
32 
33 	NextSubTest();
34 	view.SetDate(2004, 2, 29);
35 	CPPUNIT_ASSERT_EQUAL(2004, view.Year());
36 	CPPUNIT_ASSERT_EQUAL(2, view.Month());
37 	CPPUNIT_ASSERT_EQUAL(29, view.Day());
38 
39 	NextSubTest();
40 	// Moving from leap year to leap year on 29 feb. must not change day
41 	view.SetYear(2008);
42 	CPPUNIT_ASSERT_EQUAL(2008, view.Year());
43 	CPPUNIT_ASSERT_EQUAL(2, view.Month());
44 	CPPUNIT_ASSERT_EQUAL(29, view.Day());
45 
46 	NextSubTest();
47 	// Moving from leap year to non-leap year on 29 feb. must go back to 28
48 	view.SetYear(2014);
49 	CPPUNIT_ASSERT_EQUAL(2014, view.Year());
50 	CPPUNIT_ASSERT_EQUAL(2, view.Month());
51 	CPPUNIT_ASSERT_EQUAL(28, view.Day());
52 
53 	NextSubTest();
54 	view.SetDate(2014, 8, 31);
55 	CPPUNIT_ASSERT_EQUAL(2014, view.Year());
56 	CPPUNIT_ASSERT_EQUAL(8, view.Month());
57 	CPPUNIT_ASSERT_EQUAL(31, view.Day());
58 
59 	NextSubTest();
60 	// Moving to month with less days should adjust day
61 	view.SetMonth(2);
62 	CPPUNIT_ASSERT_EQUAL(2014, view.Year());
63 	CPPUNIT_ASSERT_EQUAL(2, view.Month());
64 	CPPUNIT_ASSERT_EQUAL(28, view.Day());
65 }
66 
67 
68 /*static*/ void
69 CalendarViewTest::AddTests(BTestSuite& parent)
70 {
71 	CppUnit::TestSuite& suite = *new CppUnit::TestSuite("CalendarViewTest");
72 
73 	suite.addTest(new CppUnit::TestCaller<CalendarViewTest>(
74 		"CalendarViewTest::TestSetters", &CalendarViewTest::TestSetters));
75 
76 	parent.addTest("CalendarViewTest", &suite);
77 }
78