Skip to content

Commit

Permalink
Merge pull request #39 from macmillanpublishers/wdv-392-versioncheck
Browse files Browse the repository at this point in the history
fix and test for wdv-392 versioncheck
  • Loading branch information
mattretzer authored Jun 17, 2021
2 parents 1b9cfe7 + cb1ea38 commit e3f4b7a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 8 deletions.
Binary file modified RSuite_Word-template.dotm
Binary file not shown.
Binary file modified StyleTemplate_auto-generate/RSuite.dotx
Binary file not shown.
Binary file modified StyleTemplate_auto-generate/RSuite_NoColor.dotx
Binary file not shown.
90 changes: 90 additions & 0 deletions src/RSuite_Word-template/TestModule7_misc_functions.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Attribute VB_Name = "TestModule7_misc_functions"
Option Explicit
Option Private Module

'@TestModule
'@Folder("Tests")

Private Assert As Object
Private Fakes As Object

'@ModuleInitialize
Private Sub ModuleInitialize()
'this method runs once per module.
Set Assert = CreateObject("Rubberduck.AssertClass")
Set Fakes = CreateObject("Rubberduck.FakesProvider")
' Load public vars:
Application.ScreenUpdating = False
End Sub

'@ModuleCleanup
Private Sub ModuleCleanup()
'this method runs once per module.
Set Assert = Nothing
Set Fakes = Nothing
'reset loaded public vars
Application.ScreenUpdating = True
End Sub

'@TestInitialize
Private Sub TestInitialize()
'This method runs before every test in the module..

End Sub

'@TestCleanup
Private Sub TestCleanup()
'this method runs after every test in the module.

End Sub

'@TestMethod("MiscFunctions")
Private Sub Test_versionCompare() 'TODO Rename test
Dim results_gt As String, results_gt_version As String, results_same As String, _
results_same_version As String, results_lt As String, results_lt_version As String, _
results_emptyA As String, results_emptyB As String, results_empty As String, _
results_zeroA As String, results_zeroB As String, results_zero As String, _
results_nondoubleA As String, results_nondoubleB As String, results_nondouble As String
On Error GoTo TestFail
'Arrange:
'Act:
results_gt = VersionCheck.versionCompare("6", "5.0")
results_gt_version = VersionCheck.versionCompare("6.1.1", "6.0.1")
results_same = VersionCheck.versionCompare("6.1", "6.1")
results_same_version = VersionCheck.versionCompare("5.0.3", "5.0.2")
results_lt = VersionCheck.versionCompare("3", "4.0")
results_lt_version = VersionCheck.versionCompare("2.0.3", "5.0.2")
results_emptyA = VersionCheck.versionCompare("", "5.0.2")
results_emptyB = VersionCheck.versionCompare("2.0.3", "")
results_empty = VersionCheck.versionCompare("", "")
results_zeroA = VersionCheck.versionCompare("0", "42.5")
results_zeroB = VersionCheck.versionCompare("3", "0.0")
results_zero = VersionCheck.versionCompare("0", "0")
results_nondoubleA = VersionCheck.versionCompare("vab6", "0")
results_nondoubleB = VersionCheck.versionCompare("0", "v6.1.3")
results_nondouble = VersionCheck.versionCompare("v6", "v7")


'Assert:
Assert.Succeed
Assert.areequal ">", results_gt
Assert.areequal ">", results_gt_version
Assert.areequal "same", results_same
Assert.areequal "same", results_same_version
Assert.areequal "<", results_lt
Assert.areequal "<", results_lt_version
Assert.areequal "unable to compare", results_emptyA
Assert.areequal "unable to compare", results_emptyB
Assert.areequal "unable to compare", results_empty
Assert.areequal "<", results_zeroA
Assert.areequal ">", results_zeroB
Assert.areequal "same", results_zero
Assert.areequal "unable to compare", results_nondoubleA
Assert.areequal "unable to compare", results_nondoubleB
Assert.areequal "unable to compare", results_nondouble

TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
End Sub
18 changes: 11 additions & 7 deletions src/RSuite_Word-template/VersionCheck.bas
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sub AttachedVersion()
Dim templateNameStr As String
Dim strTemplatePath As String
Dim installVersion As String, cdpVersion As String, attachVersion As String
Dim msgstr As String
Dim msgstr As String, err_msgstr As String

templateFile = "RSuite.dotx" 'the template file you are checking
templateFileNoColor = "RSuite_NoColor.dotx"
Expand All @@ -26,23 +26,26 @@ Sub AttachedVersion()

' if valid template files not attached, check version from DocProps
If attachVersion = "" Then
err_msgstr = "Unable to determine this document's RSuite-styles version:" + vbCr + vbCr + _
"Please click 'Activate Template' in the RSuite Tools toolbar and check again."
cdpVersion = customDocPropValue("Version")
templateNameStr = customDocPropValue("TemplateName")
' nothing currently attached, nothing ever attached:
If cdpVersion = "" Then
msgstr = "Unable to determine this document's RSuite-styles version:" + vbCr + vbCr + _
"Please click 'Activate Template' in the RSuite Tools toolbar and check again."
msgstr = err_msgstr
GoTo ShowMsgbox
' let's see if installed version matches
Else
If templateNameStr = "" Then templateNameStr = templateFile
installVersion = GetVersion(strTemplatePath, templateNameStr)
' if no installversion, versions match, or comparison fails, use cdpversion:
If installVersion = "none" Or _
versionCompare(cdpVersion, installVersion) = "same" Or _
versionCompare(cdpVersion, installVersion) = "unable to compare" Then
versionCompare(cdpVersion, installVersion) = "same" Then
attachVersion = cdpVersion
GoTo ShowMsgbox
ElseIf versionCompare(cdpVersion, installVersion) = "unable to compare" Then
msgstr = err_msgstr
GoTo ShowMsgbox
' warn if local style-template is older
ElseIf versionCompare(cdpVersion, installVersion) = ">" Then
msgstr = "The version of RSuite styles in this document (v" & cdpVersion & _
Expand All @@ -51,14 +54,15 @@ Sub AttachedVersion()
"Please contact [email protected] for assistance in getting your installed template updated!"
GoTo ShowMsgbox
' warn if docstyles are older
ElseIf versionCompare(cdpVersion, installVersion) = "<" And cdpVersion >= 6 Then
ElseIf versionCompare(cdpVersion, installVersion) = "<" And (versionCompare(cdpVersion, "6") = ">" Or _
versionCompare(cdpVersion, "6") = "same") Then
msgstr = "The version of RSuite styles in this document (v" & cdpVersion & _
") is older than the version of RSuite styles in your installed RSuite style-template (v" & installVersion & _
")" & vbCr & vbCr & _
"Please click 'Activate Template' in the RSuite Tools toolbar to update this document to the latest RSuite styles!"
GoTo ShowMsgbox
' warn if pre-rsuite styles as per older version cdp declaration
ElseIf cdpVersion < 6 Then
ElseIf versionCompare(cdpVersion, "6") = "<" Then
msgstr = "This document may be styled with Macmillan's legacy, pre-RSuite style-set." & vbCr & vbCr & _
"You may want to update/edit styles using the old Macmillan template, or you can click 'Activate Template'" & _
" in the RSuite Tools toolbar to add RSuite styles." & vbCr & vbCr & _
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.1
6.4.2

0 comments on commit e3f4b7a

Please sign in to comment.