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
9df8b692aSKacper Kasper#include <Application.h>
10afd5ec11SAdrien Destugues#include <CalendarView.h>
11df8b692aSKacper Kasper#include <Window.h>
12afd5ec11SAdrien Destugues
13afd5ec11SAdrien Destugues#include <cppunit/TestCaller.h>
14afd5ec11SAdrien Destugues#include <cppunit/TestSuite.h>
15afd5ec11SAdrien Destugues
16afd5ec11SAdrien Destugues
17afd5ec11SAdrien Destuguesusing namespace BPrivate;
18afd5ec11SAdrien Destugues
19afd5ec11SAdrien Destugues
20afd5ec11SAdrien DestuguesCalendarViewTest::CalendarViewTest()
21afd5ec11SAdrien Destugues{
22afd5ec11SAdrien Destugues}
23afd5ec11SAdrien Destugues
24afd5ec11SAdrien Destugues
25afd5ec11SAdrien DestuguesCalendarViewTest::~CalendarViewTest()
26afd5ec11SAdrien Destugues{
27afd5ec11SAdrien Destugues}
28afd5ec11SAdrien Destugues
29afd5ec11SAdrien Destugues
30afd5ec11SAdrien Destuguesvoid
31afd5ec11SAdrien DestuguesCalendarViewTest::TestSetters()
32afd5ec11SAdrien Destugues{
33df8b692aSKacper Kasper	// TODO: CalendarView probably uses some other library, test that instead
34df8b692aSKacper Kasper	BApplication app(
35df8b692aSKacper Kasper		"application/x-vnd.CalendarViewTest_TestSetters.test");
36df8b692aSKacper Kasper	BWindow window(BRect(50,50,550,550),
37df8b692aSKacper Kasper		"CalendarViewTest_TestSetters", B_TITLED_WINDOW,
38df8b692aSKacper Kasper		B_QUIT_ON_WINDOW_CLOSE, 0);
39df8b692aSKacper Kasper	BCalendarView *view = new BCalendarView("test");
40df8b692aSKacper Kasper	window.AddChild(view);
41afd5ec11SAdrien Destugues
42afd5ec11SAdrien Destugues	NextSubTest();
43df8b692aSKacper Kasper	view->SetDate(2004, 2, 29);
44df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2004, view->Year());
45df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2, view->Month());
46df8b692aSKacper 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
50df8b692aSKacper Kasper	view->SetYear(2008);
51df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2008, view->Year());
52df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2, view->Month());
53df8b692aSKacper 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
57df8b692aSKacper Kasper	view->SetYear(2014);
58df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2014, view->Year());
59df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2, view->Month());
60df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(28, view->Day());
61afd5ec11SAdrien Destugues
62afd5ec11SAdrien Destugues	NextSubTest();
63df8b692aSKacper Kasper	view->SetDate(2014, 8, 31);
64df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2014, view->Year());
65df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(8, view->Month());
66df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(31, view->Day());
67afd5ec11SAdrien Destugues
68afd5ec11SAdrien Destugues	NextSubTest();
69afd5ec11SAdrien Destugues	// Moving to month with less days should adjust day
70df8b692aSKacper Kasper	view->SetMonth(2);
71df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2014, view->Year());
72df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(2, view->Month());
73df8b692aSKacper Kasper	CPPUNIT_ASSERT_EQUAL(28, view->Day());
74afd5ec11SAdrien Destugues}
75afd5ec11SAdrien Destugues
76afd5ec11SAdrien Destugues
77afd5ec11SAdrien Destugues/*static*/ void
78afd5ec11SAdrien DestuguesCalendarViewTest::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