-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreprocessorTests.cpp
158 lines (127 loc) · 2.89 KB
/
PreprocessorTests.cpp
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
#pragma unmanaged
#pragma comment(lib, "spasm.lib")
#include "..\SPASM\pass_one.h"
#include "..\SPASM\pass_two.h"
#include "..\SPASM\parser.h"
#include "..\SPASM\spasm.h"
#include "..\SPASM\errors.h"
#include "..\SPASM\storage.h"
#include <stdio.h>
#include <direct.h>
//#include <string>
#pragma managed
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
using namespace std;
namespace SPASMTestsVS2008
{
[TestClass]
public ref class PreprocessorTests
{
public:
[TestInitialize]
void Init()
{
ClearSPASMErrorSessions();
OutputDebugString(TEXT("Start\n"));
output_contents = (unsigned char *) malloc(output_buf_size);
init_storage();
curr_input_file = _strdup("..\\..\\..\\..\\..\\Tests\\SPASMTests\\PreprocessorTests.z80");
output_filename = "output.bin";
mode = MODE_LIST;
char buffer[256];
_getcwd(buffer, sizeof(buffer));
int nResult = run_assembly();
Assert::AreEqual((int) EXIT_NORMAL, nResult, "Could not assemble test file");
ClearSPASMErrorSessions();
mode = 0;
}
[TestCleanup]
void Cleanup()
{
OutputDebugString(TEXT("End\n"));
free_storage();
free(output_contents);
}
void RunTest(const char *function_name)
{
char szFunctionName[256];
strcpy_s(szFunctionName, strrchr(function_name, ':') + 1);
char buffer[256];
sprintf_s(buffer, " %s()", szFunctionName);
TCHAR szFileName[256];
sprintf_s(szFileName, "%s.txt", szFunctionName);
add_define (strdup ("OUTPUT_FILE"), NULL)->contents = strdup (szFileName);
ClearSPASMErrorSessions();
int session = StartSPASMErrorSession();
run_first_pass(buffer);
EndSPASMErrorSession(session);
String ^sfunction = gcnew String(szFileName);
System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(sfunction);
System::String ^str = sr->ReadLine();
Assert::AreEqual(gcnew String("PASS"), str);
}
[TestMethod]
void Ifdef()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Ifndef()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Else()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Else2()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Else3()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void If()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Elif()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Elif2()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void LessThan()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void LessThanEqualTo()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void DoubleEquals()
{
RunTest(__FUNCTION__);
}
[TestMethod]
void Equals()
{
RunTest(__FUNCTION__);
}
};
}