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 <Application.h>
10 #include <CalendarView.h>
11 #include <Window.h>
12
13 #include <cppunit/TestCaller.h>
14 #include <cppunit/TestSuite.h>
15
16
17 using namespace BPrivate;
18
19
CalendarViewTest()20 CalendarViewTest::CalendarViewTest()
21 {
22 }
23
24
~CalendarViewTest()25 CalendarViewTest::~CalendarViewTest()
26 {
27 }
28
29
30 void
TestSetters()31 CalendarViewTest::TestSetters()
32 {
33 // TODO: CalendarView probably uses some other library, test that instead
34 BApplication app(
35 "application/x-vnd.CalendarViewTest_TestSetters.test");
36 BWindow window(BRect(50,50,550,550),
37 "CalendarViewTest_TestSetters", B_TITLED_WINDOW,
38 B_QUIT_ON_WINDOW_CLOSE, 0);
39 BCalendarView *view = new BCalendarView("test");
40 window.AddChild(view);
41
42 NextSubTest();
43 view->SetDate(2004, 2, 29);
44 CPPUNIT_ASSERT_EQUAL(2004, view->Year());
45 CPPUNIT_ASSERT_EQUAL(2, view->Month());
46 CPPUNIT_ASSERT_EQUAL(29, view->Day());
47
48 NextSubTest();
49 // Moving from leap year to leap year on 29 feb. must not change day
50 view->SetYear(2008);
51 CPPUNIT_ASSERT_EQUAL(2008, view->Year());
52 CPPUNIT_ASSERT_EQUAL(2, view->Month());
53 CPPUNIT_ASSERT_EQUAL(29, view->Day());
54
55 NextSubTest();
56 // Moving from leap year to non-leap year on 29 feb. must go back to 28
57 view->SetYear(2014);
58 CPPUNIT_ASSERT_EQUAL(2014, view->Year());
59 CPPUNIT_ASSERT_EQUAL(2, view->Month());
60 CPPUNIT_ASSERT_EQUAL(28, view->Day());
61
62 NextSubTest();
63 view->SetDate(2014, 8, 31);
64 CPPUNIT_ASSERT_EQUAL(2014, view->Year());
65 CPPUNIT_ASSERT_EQUAL(8, view->Month());
66 CPPUNIT_ASSERT_EQUAL(31, view->Day());
67
68 NextSubTest();
69 // Moving to month with less days should adjust day
70 view->SetMonth(2);
71 CPPUNIT_ASSERT_EQUAL(2014, view->Year());
72 CPPUNIT_ASSERT_EQUAL(2, view->Month());
73 CPPUNIT_ASSERT_EQUAL(28, view->Day());
74 }
75
76
77 /*static*/ void
AddTests(BTestSuite & parent)78 CalendarViewTest::AddTests(BTestSuite& parent)
79 {
80 CppUnit::TestSuite& suite = *new CppUnit::TestSuite("CalendarViewTest");
81
82 suite.addTest(new CppUnit::TestCaller<CalendarViewTest>(
83 "CalendarViewTest::TestSetters", &CalendarViewTest::TestSetters));
84
85 parent.addTest("CalendarViewTest", &suite);
86 }
87