[california/wip/728838-transitions: 2/3] Add Calendar.MonthSpan tests
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/728838-transitions: 2/3] Add Calendar.MonthSpan tests
- Date: Sat, 26 Apr 2014 01:34:49 +0000 (UTC)
commit 4183df67a1afb4116c36a56e9228ea21de9fd598
Author: Jim Nelson <jim yorba org>
Date: Fri Apr 25 16:07:39 2014 -0700
Add Calendar.MonthSpan tests
src/Makefile.am | 1 +
src/tests/tests-calendar-month-span.vala | 81 ++++++++++++++++++++++++++++++
src/tests/tests.vala | 1 +
src/unit-test/unit-test-harness.vala | 2 +
4 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c41eeeb..549805d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -101,6 +101,7 @@ california_VALASOURCES = \
\
tests/tests.vala \
tests/tests-calendar-date.vala \
+ tests/tests-calendar-month-span.vala \
tests/tests-quick-add.vala \
\
toolkit/toolkit.vala \
diff --git a/src/tests/tests-calendar-month-span.vala b/src/tests/tests-calendar-month-span.vala
new file mode 100644
index 0000000..5f200d3
--- /dev/null
+++ b/src/tests/tests-calendar-month-span.vala
@@ -0,0 +1,81 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+namespace California.Tests {
+
+private class CalendarMonthSpan : UnitTest.Harness {
+ public CalendarMonthSpan() {
+ add_case("todays-month", todays_month);
+ add_case("contains-date", contains_date);
+ add_case("has-month", has_month);
+ add_case("iterator", iterator);
+ }
+
+ protected override void setup() throws Error {
+ Calendar.init();
+ }
+
+ protected override void teardown() {
+ Calendar.terminate();
+ }
+
+ private Calendar.Date from_today(int days) {
+ return Calendar.System.today.adjust(days, Calendar.DateUnit.DAY);
+ }
+
+ private bool todays_month() throws Error {
+ Calendar.MonthSpan span = new Calendar.MonthSpan(new Calendar.DateSpan(
+ from_today(0), from_today(0)));
+
+ return span.start().equal_to(Calendar.System.today.month_of_year())
+ && span.end().equal_to(Calendar.System.today.month_of_year());
+ }
+
+ private bool contains_date() throws Error {
+ Calendar.Date first = new Calendar.Date(Calendar.DayOfMonth.for_checked(1), Calendar.Month.JAN, new
Calendar.Year(2014));
+ Calendar.Date last = new Calendar.Date(Calendar.DayOfMonth.for_checked(30), Calendar.Month.JAN, new
Calendar.Year(2014));
+ Calendar.MonthSpan span = new Calendar.MonthSpan(new Calendar.DateSpan(first, last));
+
+ return span.contains(first.adjust(15, Calendar.DateUnit.DAY));
+ }
+
+ private bool has_month() throws Error {
+ Calendar.Date first = new Calendar.Date(Calendar.DayOfMonth.for_checked(1), Calendar.Month.JAN, new
Calendar.Year(2014));
+ Calendar.Date last = new Calendar.Date(Calendar.DayOfMonth.for_checked(30), Calendar.Month.MAR, new
Calendar.Year(2014));
+ Calendar.MonthSpan span = new Calendar.MonthSpan(new Calendar.DateSpan(first, last));
+
+ return span.has(new Calendar.MonthOfYear(Calendar.Month.FEB, new Calendar.Year(2014)));
+ }
+
+ private bool iterator() throws Error {
+ Calendar.Date first = new Calendar.Date(Calendar.DayOfMonth.for_checked(1), Calendar.Month.JAN, new
Calendar.Year(2014));
+ Calendar.Date last = new Calendar.Date(Calendar.DayOfMonth.for_checked(30), Calendar.Month.JUN, new
Calendar.Year(2014));
+ Calendar.MonthSpan span = new Calendar.MonthSpan(new Calendar.DateSpan(first, last));
+
+ Calendar.Month[] months = {
+ Calendar.Month.JAN,
+ Calendar.Month.FEB,
+ Calendar.Month.MAR,
+ Calendar.Month.APR,
+ Calendar.Month.MAY,
+ Calendar.Month.JUN,
+ };
+
+ int ctr = 0;
+ foreach (Calendar.MonthOfYear moy in span) {
+ if (moy.month != months[ctr++])
+ return false;
+
+ if (moy.year.value != 2014)
+ return false;
+ }
+
+ return ctr == 6;
+ }
+}
+
+}
+
diff --git a/src/tests/tests.vala b/src/tests/tests.vala
index 0684618..c242023 100644
--- a/src/tests/tests.vala
+++ b/src/tests/tests.vala
@@ -9,6 +9,7 @@ namespace California.Tests {
public int run(string[] args) {
UnitTest.Harness.register(new QuickAdd());
UnitTest.Harness.register(new CalendarDate());
+ UnitTest.Harness.register(new CalendarMonthSpan());
return UnitTest.Harness.exec_all();
}
diff --git a/src/unit-test/unit-test-harness.vala b/src/unit-test/unit-test-harness.vala
index 249aae9..d221621 100644
--- a/src/unit-test/unit-test-harness.vala
+++ b/src/unit-test/unit-test-harness.vala
@@ -38,6 +38,8 @@ public abstract class Harness : BaseObject {
protected Harness(string? name = null) {
this.name = name ?? get_class().get_type().name();
+
+ register(this);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]