summaryrefslogtreecommitdiff
path: root/contrib/msvc/AddingUnitTestMethod.dsm
blob: c95ba5acc2d7b07cf615b51dd0ef6d74ca6f1194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'Made by bloodchen 
'bloodchen@hotmail.com 
Sub NewTestClass 
On Error Resume Next 
dim proj_path,ext,pos,proj_dir,MyCppFile,MyCppName,MyHFile,MyHName,ClassName,HText,CPPText 
proj_path = ActiveProject.fullname 
ext = "" 
pos = len (proj_path) 
Do While ext <> "\" 
ext = Mid(proj_path, pos, 1) 
pos = pos -1 
Loop 
proj_dir = left(proj_path, pos+1) 
ClassName=InputBox("Enter the class name:", "Class Name") 
if ActiveProject.Type <> "Build" then 
MsgBox "This project is not valid. Ending macro." 
Exit Sub 
end if 
if (len(ClassName) <= 0) then 
MsgBox "Invalid class name. Ending macro." 
Exit Sub 
end if 

' ClassName="CTest" 
MyCppName=proj_dir+ClassName+".cpp" 
MyHName=proj_dir+ClassName+".h" 
ActiveProject.AddFile MyCppName 
ActiveProject.AddFile MyHName 
Documents.Add "Text" 
ActiveDocument.Selection.StartOfDocument 

HText= "#ifndef "+ClassName+"DEF"+VbCrLf& _ 
"#define "+ClassName+"DEF"+VbCrLf& _ 
""+VbCrLf& _ 
"#include <cppunit\testcase.h>"+VbCrLf& _ 
"#include <cppunit\extensions\HelperMacros.h>"+VbCrLf& _ 
"class "+ClassName+":public CppUnit::TestCase"+VbCrLf& _ 
"{"+VbCrLf& _ 
" CPPUNIT_TEST_SUITE( "+ClassName+" );"+VbCrLf& _ 
" CPPUNIT_TEST_SUITE_END();"+VbCrLf& _ 
"public:"+VbCrLf& _ 
" "+ClassName+"();"+VbCrLf& _ 
" virtual ~"+ClassName+"();"+VbCrLf& _ 
"};"+VbCrLf& _ 
"#endif"+VbCrLf 
ActiveDocument.Selection = HText 
ActiveDocument.Save MyHName 
' WriteFile MyHName,HText 
Documents.Add "Text" 
ActiveDocument.Selection.StartOfDocument 
CPPText = "#include "+chr(34)+"stdafx.h"+chr(34)+VbCrLf& _ 
"#include "+chr(34)+ClassName+".h"+chr(34)+VbCrLf& _ 
""+VbCrLf& _ 
""+VbCrLf& _ 
"CPPUNIT_TEST_SUITE_REGISTRATION( "+ClassName+ " );"+VbCrLf& _ 
""+VbCrLf& _ 
""+VbCrLf& _ 
ClassName+"::"+ClassName+"()"+VbCrLf& _ 
"{"+VbCrLf& _ 
"}"+VbCrLf& _ 
""+VbCrLf& _ 
""+VbCrLf& _ 
ClassName+"::~"+ClassName+"()"+VbCrLf& _ 
"{"+VbCrLf& _ 
"}" 
' WriteFile MyCppName,CPPText 
ActiveDocument.Selection = CPPText 
ActiveDocument.Save MyCppName 

End Sub 


Sub ToggleHandCPP() 
'DESCRIPTION: Opens the .cpp or .h file for the current document. 
'Toggles between the .cpp & .h file 
ext = ActiveDocument.FullName 
If ext = "" Then 
msgbox ("Error, not a .cpp or .h file") 
exit sub 
End If 
DocName = UCase(ext) 

If Right(DocName,4) = ".CPP" Then 
fn = left(DocName, Len(DocName)-3) & "h" 
ElseIf Right(DocName,2) = ".H" Then 
fn = Left(DocName, Len(DocName)-1) & "cpp" 
Else 
msgbox ("Error, not a .cpp or a .h file") 
exit sub 
End If 
'msgbox (fn) 
on error resume next 
Documents.Open (fn) 
End Sub 

Sub ADDTestMethod() 
strHpt = ActiveDocument.FullName 
if right(strHpt,3) = "CPP" Or right (strHpt,3) = "cpp" Then 
ActiveDocument.Selection.SelectLine 
strText = ActiveDocument.Selection.Text 
if (Instr(strText, "::" ) = 0) Then 
MsgBox("Line not valid !!") 
Exit Sub 
End If 
else exit sub 
end if 

pos = Instr(strText, "::") 
strName = Right(strText, (Len(strText) - (pos+1))) 
pos = Instr(strName,"(") 
strName = Left(strName,pos-1) 
strClass = Left(strText,pos - 1) 
while (instr(strClass, " ") > 0) 
pos = instr(strClass, " ") 
strTyp = strTyp & Left(strClass, pos) 
strClass = Right(strClass, Len(strClass) - (pos) ) 
wend 
ToggleHandCPP 

ActiveDocument.Selection.SelectAll 
strHead = ActiveDocument.Selection.Text 

if (instr(strHead,strClass) = 0) Then 
MsgBox(" Can't find class " & strClass & " !!") 
ToggleHandCPP 
Exit Sub 
End If 
ActiveDocument.Selection.EndOfDocument 
lineBottom = ActiveDocument.Selection.CurrentLine 

ActiveDocument.Selection.StartOfDocument 
ActiveDocument.Selection.StartOfLine 
ActiveDocument.Selection.SelectLine 
strLine = ActiveDocument.Selection.Text 
while (instr(strLine, strName) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom) 
ActiveDocument.Selection.StartOfLine 
ActiveDocument.Selection.LineDown dsMove 
ActiveDocument.Selection.SelectLine 
strLine = ActiveDocument.Selection.Text 
Wend 
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then 
if( instr(strLine, "CPPUNIT_TEST" ) <> 0 )Then 
ToggleHandCPP 
Exit Sub 
end if 
End If 

ActiveDocument.Selection.StartOfDocument 
ActiveDocument.Selection.StartOfLine 
ActiveDocument.Selection.SelectLine 
strLine = ActiveDocument.Selection.Text 
while (instr(strLine, " CPPUNIT_TEST_SUITE_END();" ) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom) 
ActiveDocument.Selection.StartOfLine 
ActiveDocument.Selection.LineDown dsMove 
ActiveDocument.Selection.SelectLine 
strLine = ActiveDocument.Selection.Text 
Wend 
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then 
ActiveDocument.Selection.EndOfLine 
ActiveDocument.Selection.LineUp 
ActiveDocument.Selection.EndOfLine 
ActiveDocument.Selection.NewLine 
ActiveDocument.Selection = "CPPUNIT_TEST( "&strName&" );" 
else 
MsgBox("CPPUNIT_TEST_SUITE_END not found") 
end if 
ToggleHandCPP 

End Sub