Bump version to 6.4.7.2.M8
[LibreOffice.git] / basic / qa / vba_tests / datediff.vb
blob1b5e7ebf449d6e06bf442950f8dc118940d6a624
1 Option VBASupport 1
2 Option Explicit
3 Dim passCount As Integer
4 Dim failCount As Integer
5 Dim result As String
7 Function doUnitTest() As String
8 result = verify_testDateDiff()
9 If failCount <> 0 Or passCount = 0 Then
10 doUnitTest = result
11 Else
12 doUnitTest = "OK"
13 End If
14 End Function
18 Function verify_testDateDiff() As String
20 passCount = 0
21 failCount = 0
23 result = "Test Results" & Chr$(10) & "============" & Chr$(10)
25 Dim testName As String
26 Dim date1
27 Dim date2
28 testName = "Test DateDiff function"
29 On Error GoTo errorHandler
31 date2 = 10
32 date1 = DateDiff("yyyy", "22/11/2003", "22/11/2013")
33 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
35 date2 = 40
36 date1 = DateDiff("q", "22/11/2003", "22/11/2013")
37 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
39 date2 = 120
40 date1 = DateDiff("m", "22/11/2003", "22/11/2013")
41 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
43 date2 = 3653
44 date1 = DateDiff("y", "22/11/2003", "22/11/2013")
45 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
47 date2 = 3653
48 date1 = DateDiff("d", "22/11/2003", "22/11/2013")
49 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
51 date2 = 521
52 date1 = DateDiff("w", "22/11/2003", "22/11/2013")
53 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
55 date2 = 522
56 date1 = DateDiff("ww", "22/11/2003", "22/11/2013")
57 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
59 date2 = 87672
60 date1 = DateDiff("h", "22/11/2003", "22/11/2013")
61 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
63 date2 = 525600
64 date1 = DateDiff("n", "22/11/2012", "22/11/2013")
65 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
67 date2 = 2678400
68 date1 = DateDiff("s", "22/10/2013", "22/11/2013")
69 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
71 date2 = 3653
72 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbFriday)
73 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
75 date2 = 3653
76 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbMonday)
77 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
79 date2 = 3623
80 date1 = DateDiff("d", "22/12/2003", "22/11/2013", vbSaturday)
81 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
83 date2 = 3684
84 date1 = DateDiff("d", "22/10/2003", "22/11/2013", vbSunday)
85 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
87 date2 = 3653
88 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbThursday)
89 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
91 date2 = 3653
92 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbTuesday)
93 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
95 date2 = 3653
96 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbFriday, vbFirstJan1)
97 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
99 date2 = 3653
100 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbThursday, vbFirstFourDays)
101 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
103 date2 = 3653
104 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbSunday, vbFirstFullWeek)
105 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
107 date2 = 3653
108 date1 = DateDiff("d", "22/11/2003", "22/11/2013", vbSaturday, vbFirstFullWeek)
109 TestLog_ASSERT date1 = date2, "the return DateDiff is: " & date1
111 result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10)
112 verify_testDateDiff = result
114 Exit Function
115 errorHandler:
116 TestLog_ASSERT (False), testName & ": hit error handler"
117 End Function
119 Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String)
121 If assertion = True Then
122 passCount = passCount + 1
123 Else
124 Dim testMsg As String
125 If Not IsMissing(testId) Then
126 testMsg = testMsg + " : " + testId
127 End If
128 If Not IsMissing(testComment) And Not (testComment = "") Then
129 testMsg = testMsg + " (" + testComment + ")"
130 End If
132 result = result & Chr$(10) & " Failed: " & testMsg
133 failCount = failCount + 1
134 End If
136 End Sub