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