-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabelTests.cpp
144 lines (121 loc) · 3.33 KB
/
LabelTests.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
#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>
#pragma managed
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace SPASMTestsVS2008
{
[TestClass]
public ref class LabelTests
{
private:
TestContext^ testContextInstance;
public:
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
{
Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
{
return testContextInstance;
}
System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
{
testContextInstance = value;
}
};
[TestInitialize]
void Init()
{
output_contents = (unsigned char *) malloc(output_buf_size);
init_storage();
curr_input_file = strdup("..\\..\\..\\..\\..\\Tests\\SPASMTests\\Tests.asm");
output_filename = "output.bin";
mode = MODE_NORMAL;
int nResult = run_assembly();
Assert::AreEqual((int) EXIT_NORMAL, nResult, "Could not open test file");
}
[TestCleanup]
void Cleanup()
{
free_storage();
free(output_contents);
}
[TestMethod]
void LocalLabel1()
{
char buffer[256] = "LocalLabel1()";
error_occurred = false;
run_first_pass(buffer);
Assert::IsFalse(error_occurred);
bool success;
int result;
success = parse_num("-_", &result);
Assert::IsTrue(success, "Failed to parse the local label");
Assert::AreEqual(3, result);
};
[TestMethod]
void LocalLabel2()
{
bool success;
int result;
pass_one = false;
success = parse_num("_", &result);
Assert::IsFalse(success, "Did not fail when it should have");
Assert::AreEqual((DWORD) SPASM_ERR_LOCAL_LABEL_FORWARD_REF, GetLastSPASMError());
};
[TestMethod]
void LocalLabel3()
{
char buffer[256] = "LocalLabel3()";
error_occurred = false;
run_first_pass(buffer);
Assert::IsFalse(error_occurred);
bool success;
int result;
success = parse_num("-_+--_", &result);
Assert::IsTrue(success, "Failed to parse the local label");
Assert::AreEqual(8, result);
};
[TestMethod]
void LocalLabel4()
{
out_ptr = output_contents;
char buffer[256] = "LocalLabel4()";
error_occurred = false;
run_first_pass(buffer);
Assert::IsFalse(error_occurred);
run_second_pass();
Assert::AreEqual((unsigned char) 7, output_contents[2]);
};
[TestMethod]
void Error104_org()
{
out_ptr = output_contents;
char buffer[256] = ".org ";
error_occurred = false;
run_first_pass(buffer);
Assert::AreEqual((DWORD) SPASM_ERR_VALUE_EXPECTED, GetLastSPASMError());
};
[TestMethod]
void Error107_org()
{
out_ptr = output_contents;
char buffer[256] = ".org -1";
error_occurred = false;
run_first_pass(buffer);
Assert::AreEqual((DWORD) SPASM_ERR_INVALID_ADDRESS, GetLastSPASMError());
};
};
}