5
dim proj_path,ext,pos,proj_dir,MyCppFile,MyCppName,MyHFile,MyHName,ClassName,HText,CPPText
6
proj_path = ActiveProject.fullname
10
ext = Mid(proj_path, pos, 1)
13
proj_dir = left(proj_path, pos+1)
14
ClassName=InputBox("Enter the class name:", "Class Name")
15
if ActiveProject.Type <> "Build" then
16
MsgBox "This project is not valid. Ending macro."
19
if (len(ClassName) <= 0) then
20
MsgBox "Invalid class name. Ending macro."
25
MyCppName=proj_dir+ClassName+".cpp"
26
MyHName=proj_dir+ClassName+".h"
27
ActiveProject.AddFile MyCppName
28
ActiveProject.AddFile MyHName
30
ActiveDocument.Selection.StartOfDocument
32
HText= "#ifndef "+ClassName+"DEF"+VbCrLf& _
33
"#define "+ClassName+"DEF"+VbCrLf& _
35
"#include <cppunit\testcase.h>"+VbCrLf& _
36
"#include <cppunit\extensions\HelperMacros.h>"+VbCrLf& _
37
"class "+ClassName+":public CppUnit::TestCase"+VbCrLf& _
39
" CPPUNIT_TEST_SUITE( "+ClassName+" );"+VbCrLf& _
40
" CPPUNIT_TEST_SUITE_END();"+VbCrLf& _
42
" "+ClassName+"();"+VbCrLf& _
43
" virtual ~"+ClassName+"();"+VbCrLf& _
46
ActiveDocument.Selection = HText
47
ActiveDocument.Save MyHName
48
' WriteFile MyHName,HText
50
ActiveDocument.Selection.StartOfDocument
51
CPPText = "#include "+chr(34)+"stdafx.h"+chr(34)+VbCrLf& _
52
"#include "+chr(34)+ClassName+".h"+chr(34)+VbCrLf& _
55
"CPPUNIT_TEST_SUITE_REGISTRATION( "+ClassName+ " );"+VbCrLf& _
58
ClassName+"::"+ClassName+"()"+VbCrLf& _
63
ClassName+"::~"+ClassName+"()"+VbCrLf& _
66
' WriteFile MyCppName,CPPText
67
ActiveDocument.Selection = CPPText
68
ActiveDocument.Save MyCppName
74
'DESCRIPTION: Opens the .cpp or .h file for the current document.
75
'Toggles between the .cpp & .h file
76
ext = ActiveDocument.FullName
78
msgbox ("Error, not a .cpp or .h file")
83
If Right(DocName,4) = ".CPP" Then
84
fn = left(DocName, Len(DocName)-3) & "h"
85
ElseIf Right(DocName,2) = ".H" Then
86
fn = Left(DocName, Len(DocName)-1) & "cpp"
88
msgbox ("Error, not a .cpp or a .h file")
97
strHpt = ActiveDocument.FullName
98
if right(strHpt,3) = "CPP" Or right (strHpt,3) = "cpp" Then
99
ActiveDocument.Selection.SelectLine
100
strText = ActiveDocument.Selection.Text
101
if (Instr(strText, "::" ) = 0) Then
102
MsgBox("Line not valid !!")
108
pos = Instr(strText, "::")
109
strName = Right(strText, (Len(strText) - (pos+1)))
110
pos = Instr(strName,"(")
111
strName = Left(strName,pos-1)
112
strClass = Left(strText,pos - 1)
113
while (instr(strClass, " ") > 0)
114
pos = instr(strClass, " ")
115
strTyp = strTyp & Left(strClass, pos)
116
strClass = Right(strClass, Len(strClass) - (pos) )
120
ActiveDocument.Selection.SelectAll
121
strHead = ActiveDocument.Selection.Text
123
if (instr(strHead,strClass) = 0) Then
124
MsgBox(" Can't find class " & strClass & " !!")
128
ActiveDocument.Selection.EndOfDocument
129
lineBottom = ActiveDocument.Selection.CurrentLine
131
ActiveDocument.Selection.StartOfDocument
132
ActiveDocument.Selection.StartOfLine
133
ActiveDocument.Selection.SelectLine
134
strLine = ActiveDocument.Selection.Text
135
while (instr(strLine, strName) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom)
136
ActiveDocument.Selection.StartOfLine
137
ActiveDocument.Selection.LineDown dsMove
138
ActiveDocument.Selection.SelectLine
139
strLine = ActiveDocument.Selection.Text
141
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then
142
if( instr(strLine, "CPPUNIT_TEST" ) <> 0 )Then
148
ActiveDocument.Selection.StartOfDocument
149
ActiveDocument.Selection.StartOfLine
150
ActiveDocument.Selection.SelectLine
151
strLine = ActiveDocument.Selection.Text
152
while (instr(strLine, " CPPUNIT_TEST_SUITE_END();" ) = 0 And ActiveDocument.Selection.CurrentLine <> lineBottom)
153
ActiveDocument.Selection.StartOfLine
154
ActiveDocument.Selection.LineDown dsMove
155
ActiveDocument.Selection.SelectLine
156
strLine = ActiveDocument.Selection.Text
158
if (ActiveDocument.Selection.CurrentLine < lineBottom) Then
159
ActiveDocument.Selection.EndOfLine
160
ActiveDocument.Selection.LineUp
161
ActiveDocument.Selection.EndOfLine
162
ActiveDocument.Selection.NewLine
163
ActiveDocument.Selection = "CPPUNIT_TEST( "&strName&" );"
165
MsgBox("CPPUNIT_TEST_SUITE_END not found")
b'\\ No newline at end of file'